fredag den 8. februar 2013

Bees, Rain and more.

So video 10 has been out a little while, so I wanted to write a little about it, before it gets too old. But before I delve into video 10, I want to tell a bit about my newest video. The video is focused more on the work I do, instead of just showing the results and commenting on them. I will still continue the Phantobra - The Game series, but I figured I'd throw in a "Behind the scenes" video now and then, when I feel I have something to show. With that out of the way - Lets take a look at the 10th video.

This video includes the new Beehive mob, scrolling backgrounds, throwable snowballs, rain, wooden bowls, and a few more things, that the observant viewer might see :-)
Also, thanks to Dennis Panduro Hess for making an original music track for the game.
Check out his music at www.soundcloud.com/Panduro

What's New

- New Beehive and Bee mob
- Scrolling backgrounds (Work in progress)
- Throwable weapons - Snowball
- Rain
- Wooden bowls
- The first music track for the game!

Beehives and bees

When I sat down to design my next mob I wanted to use some new mechanics. This ended up with me taking a trip down memory lane, back to when I was like 8-10 years old, maybe a bit younger. Back then I was fascinated with bees, partly because I played this game where you helped a train full of cereal through some levels, where you controlled a bee that was responsible for adding honey and such to the cereal, but also because I loved honey back then. (Today I'm not so fond of it though :P )
So I decided that my next mob should be bees. Early in the design process I realized that having bees appear randomly didn't work for me. I then thought of having bee swarms appear as one mob, but that didn't agree with me as well. So I started thinking out of the box, and got the idea that, maybe the mob shouldn't be a bee, but a beehive, that shoots bees. Initially that was the way I decided to go, but I quickly realized that beehives would then turn out to be nothing but a cannon sitting in a tree shooting at you. The next logical step was then to make both beehives and bees as mobs. This way of thinking made things interesting. So I ended up with making the Beehive mob send out bees, whenever a player gets too close. The bees then follow the player until one of three things has happened:
1. The bees hit/sting the player
2. The be is killed.
3. The player hides under water.
If either 1 or 3 happens, the bees will return home to their hive. I decided on this behavior since bees usually only stings once (and usually dies from tearing off their stinger as far as I know), and they can't follow you under water.
The bees themselves do not drop any loot. To get anything you need to destroy the hive. The hive then drops  some honey, and occasionally some honeycomb. Honey can be consumed, which reduces hunger slightly. I am considering making it possible to bottle the honey for increased hunger satisfaction. If you gather enough honey comb, the plan is that you can create your own beehive, that produces honey over time. You might have to feed the bees something else, like sugar water or something.

Scrolling Backgrounds

Any platformer with respect for itself will have a background, and in most cases scrolling backgrounds. As with most things in this project, scrolling backgrounds is something I've never done before. I read up on it on the web, and it is, for the most part rather simple. The further away the background layer is, the slower it moves. Currently I only have two layers (not counting the sky), but I think I will be adding a third, possibly a fourth. The real challenge for me here was drawing the background. I am somewhat satisfied with the mountains I've made, but sometime in the future I might remake them. The hills in the foreground are undoubtedly going to be replaced, partly because they really aren't that great, and partly because I would like to have the hills separated into two layers. I will also change the backgrounds so that the react to vertical movement, at least to some degree. This way I could have a layer that might only be visible from a certain height. Small things like this adds to the depth and dynamic of the world.

Throwable Weapon - Snowballs

The first throwing weapon has been implemented. This, of course, also means that the throwing mechanism has been added. Snowballs are collected by harvesting snow with a shovel. One tile gives one snowball. This means that snowballs are easily replaced during winter. Snowballs deal very little damage, and are currently ineffective against everything, but bees. A bee that gets hit by a snowball, dies immediately. Snowballs are used off the quickbar, like every other item, and are thrown in the direction of the mouse cursor. I really like how they turned out, both visually but also on a physics level. There's no reason to try and explain how they behave, since the video does a good job of showing it.
Now that the throwing mechanism has been created, it's only a question of me designing new throwable weapons, like grenades, dynamites, darts, etc. I might have to add a weight value to the throwing weapons, which will allow me to limit the range of very heavy, or very light weapons.

Rain

Last time it was snow, now it's rain! Codewise rain is using most of the same code that snow uses, which made it extremely easy to implement. The sound for the rain, is just a placeholder, but it just felt too tame without any sound at all. As shown in the video, rain will increase the volume of water in existing water tiles, but won't create new ones. There's really not much to say about it. I am considering adding more weather effects like thunder, and maybe hail. I also need to create a "grey sky" for when it rains. It looks rather weird that it's sunny when it pours down (At least when no rainbow is present).

Wooden Bowls

The first "bucket" item has been implemented. The bowls, are able to pick up water, so that you can either drink it, or pour it somewhere else. I am still working out how much water, compared to a full tile, a bowl can hold, but this will be an easier task when I decided to add buckets and bottles.
Bowls stack in stacks up to 255, when they are empty. A filled bowl is not stackable. The reason for this, is to make better water containers worth more. Let me try to explain this further:
Lets assume that a bowl and a bottle can hold the same amount of water- Why would you spend your hard to come by glass on making bottles, when you can simply use wood to make a bowl? The reason is that bottles stack, bowls don't. If you decide to go on a large trek, you need to stock up on water. Let's say you decide that you need to bring 3 supplies of water. The bowls would take up 3 inventory slots, where the bottles might only take up one. This way I get to increase the quality of certain water containers over others, even though they can carry the same amount. Maybe crystal bottles can be stacked in stacks of 10, which makes them better for long treks. The same may be true for certain kinds of food. They might be equally satisfying, but the "better" food would stack in larger amounts.

Music!

The game has gotten its first exclusive music piece. This was made by Dennis Panduro Hess - Check out his music at www.soundcloud.com/Panduro
You will be able to hear the track in the video.

I think that was most of it covered for the 10th video. Thank you for reading. I know I've been behind with the blog for a while, but I am catching up. The next post will be a supplement to the new Phantobra Behind The Scenes series. The first video is already up, where I show off my level editor, and explain why I even have a level editor, for a supposedly randomly generated game. But enough from me, enjoy the 10th video, and again, thank you for reading!
Please do share this with friends, and the same goes for the video, if you know someone who might be interested in reading/watching any of this :-)
Enjoy!

Phantobra - The Game - Part 10: Bee Careful, It Might Rain





tirsdag den 15. januar 2013

Natural Look and Particles!

It's been a while since my last post here, but a lot has happened.
This post will cover the changes shown in video 8 and 9. Video 10 will be covered soon.

All of the natural tiles have been given a more natural look- This includes: Dirt, grass, sand, stone, and all the ores(3 Types of ore have also been added). World items has been introduced, like Workbench, furnace and anvils. Even chests have been implemented.  On top of that I finally got around to making particle effects.. and I think some of the results are pretty nifty. Effects include particles from mined tiles, plant particles when plants are destroyed, blood splatter and snow.

What's New?

- Natural tiles have received a more natural look.
- Three new ore types have been added - Copper, Iron, Gold.
- World items have been added - Including the furnace, which is used to smelt the ore into ingots.
- More craftable items have been added to make use of the newly added materials.
- Chests have been added- It is now possible to store items and saving loading of items works too.
- Equipable Items & equipment slots
- Particle system has been implemented. Various new particles have been created.
- Weather has been implemented. Currently only snow is available.
- Some extra christmas related stuff (See video 9)

Natural Look

All natural tiles, including background tiles have received a more natural look. This complicates the way backgrounds work though. When building a wall (background tiles) the edges only cover about half the outer tile. Part of the reason for this is to make doors more realistic looking, so that when you place a door, there will be wall on one side, but not on the outside. This works very well for the "artificial" tiles, but for natural tiles this was quite a challenge, one that I still haven't decided if I have "owned". I didn't show any of this off in the video, since I'm still not sure I will keep the result. I might make a little video about it in the future to better explain the issues.

Copper, Iron, Gold

With the first three ore types added to the game, a new level of depth has been added to the game.  Part of the goal in the game is to gather resources, and use them to craft various objects. There will be a difference in the rarity of the ores. Gold will be much more rare than both copper and iron, but copper will be more common than iron. A lot games handle resources in tiers. So that copper in this case would be Tier 1, iron Tier 2 and Gold Tier 3, increasing in effectivity. What I wish to do is to follow this direction some of the way, but I would like to keep every material you find usable, no matter how advanced you are. Thus recipes for items created with gold will still require some components based in copper and iron. This way copper or iron won't have to be "yet another ore deposit" you come across when you explore, but instead provoke a small feeling of success.

World Items

"World Items" have been added to the game. Currently this include a Workbench, furnace, and the anvil. These three items are all involved in crafting. You need the furnace to melt your ore into ingots, and the anvil to craft them into weapons. The workbench are used to create various items, including the furnace. In the future world items will also include things like chairs, tables, beds, candles, and other furniture. Currently a word item occupies four tiles, 2X2. The orientation of a world item tile is fixed, su 2X2 tiles will include "UpperLeft, UpperRight, LowerRight and LowerLeft. When I draw the tiles I simply only draw it if it has the UpperLeft orientation. That way I stay true to the tile grid, while at the same time avoid drawing the same thing four times.

Chests

The chests works mostly like the World items, the only difference is that a chest has an inventory. A chest (or a containerTile) also occupies 2X2 tiles, and are drawn in the same way as the world items. Each containerTile can potentially hold one baseItem array (The inventory), but only ContainerTiles with the UpperLeft orientation will actually have one. This means if you right click the chest to access its inventory, the tile you actually click, will point towards the UpperLeft tile and then access the inventory there.
GUI elements has been added for the chests as well, so they are fully implemented in the game.

Equipable items

I've finally gotten around to making the equipment slots, and thus added a few equipable items. Currently there's the Copper armor (Looks more like a leather armor, so that might change), and a few other things you can see in video 9. Currently there's only armor, but it is represented visually on your character.
Things like jewelry and trinkets, will not have a visual effect on the player, except in some rare cases. Currently the armors does give some protection, but I won't go into detail with the mathematics behind that, since currently they are more or less untested, and rather simple.

Particles

Particles.... Finally. Something as small, and fairly simple as particles can really add some feel to the game, and I think my first attempts are pretty decent. Currently there's blood when hitting mobs with weapons, plant particles, when you destroy plants, mining particles, movement dust and snow particles. Overall I am very happy with the results, and I am surprised of how simple they actually were to make. - At a later time I might tell a bit about how I am making and handling particles.

Weather

Snow! What better type of weather to start out with in the holly days. Having the particle system in place it was a small matter to create snow, but after that I felt something was missing. I wanted the snow to have an effect on the world, thus I create the snow tile. Everytime a snowflake collides with a tile, there's a 1/100 chance that it will place a snow tile on top of that tile. There was one issue with this though- Since I've just made all tiles look more natural, there would, in some cases, be small pockets of air under the snow, due to the fact that the tile under the snowtile wasn't filling out the entire square. I fixed this by drawing the snow tile, a few pixels lower than its actual position- So basically The snow is pushed a few pixels down, to give the illusion that the snow has filled the small gabs in the tile below. Snow can then be harvested with a shovel, which gives you one snowball pr snow tile. As of video 9, snowballs aren't yet usable (They are in video 10, but I'll get to that in the next post).

I've also added a few extra christmas goodies, as you will see in the video. All of the christmas stuff (including snow) was something my daughter inspired me to do, since she asked me to make something related to christmas. So everything christmas related had to be approved by her, before I added it to the game.

Again I apologize for the long delay, and I will be posting my next two blog entries within the week. The first one, related to my 10th video, which is already out. The other post will be more about how I do things. The intention with this blod initially was to show the process, and I think I haven't quite lived up to that.

Anyways - Below are the videos - Please enjoy them and share them if you like:
Phantobra - The Game - Part 8: More Tiles, Less Tiley

Phantobra - The Game - Part 9: Here's The Season To Be Jolly

Thanks for reading / watching - See you soon!

mandag den 29. oktober 2012

Water!

So I finally came around to doing water... This was quite the battle, but I consider the results a success. I still haven't decided if the results will be the final version that will be kept in the game, but for now I will keep it there.

What's New?

Here's the list of changes since last time:
- Water has been added.
- Hunger and thirst has been added (Currently only affects the indicators on the GUI)
- Save/load algorithm updated to support water.
- Stone and stone wall has been added (Though the stone wall graphics are temporary)

Water

So the biggest thing added this time is water. Adding water was a long battle, but the end results are satisfying.
My first attempt, which was decent for a first attempt, worked out okay, but the water just wouldn't even out proberly. Even after several minutes of waiting the water would most of the time be leaning in one direction.
At other times the water would just flow uncontrolled into the air.
I actualyl created a small video showing the issues I had, take a look if you want:


The method I used at first was very simple, I checked all the water tiles from the bottom and moved upwards, for every water tile I checked if there was room to dump water below, and if so, dump all the water possible. If there were still water remaining in the tile it would then dump 1/4 of the remaining value to the left tile and 1/4 to the right tile. This process was repeated for every water tile.
I did actually create a whole new tile for handling water, but this ended up giving me some gamebreaking problems. See when the water flooded the ground and hit any passable tiles, it would merely overwrite them. Since water was a tile, in order to spread I had to overwrite the old tile with the new water tile. Figuring this wouldn't work I decided to add a variable to the base tile class, where the water value was kept, thus removing the need of a water tile, and making it possible for every tile in the game to contain water. Although this fixed my problems with the tiles, and saved me a few checks in the algorithm it still didn't bring me closer to a solution.
Then one night just before I was heading to bed I found this article. The article describes how to make water using Cellular Automata. I gave it a quick read, and found it interesting, although I was too tired to grasp it all.
So the next day I looked it up and decided to give it a go. About an hour and a half later, plus twenty minutes of tweaking I ended up with the system I have now. How it looks you can see in the video at the end of this post.

Hunger and Thirst

Eventually I want the game to be more than just killing and mining to get better gear. I also want the player to have to deal with simple things like hunger and thirst. While this is not very complicated to add, it does add a lot of changes to the general gameplay. The player now has to keep in mind that he needs food and water to stay alive. Currently only the graphical implementation is done, but the rest isn't that hard to code, balancing it might be quite harder though. I want hunger and thirst to be an extra challenge for the player, but I don't want it to make exploration and leaving the comforts of your own base too difficult. On the other hand I don't want it to be an insignificant element of the game. I look forward to balancing this in the future.

Stone and Stone Wall

Stone has finally been added to the game. It is minable, and stone wall can be crafted. The graphics for the stonewall is temporary though, since I want the stone wall you build from raw stone to have a more raw and natural look. You will then be able to craft the stone into chiseled stone, or something similar. Building walls from those stones might get the current graphics that stone walls currently have.. I haven't decided yet.

That's it for this time. I didn't want to go into the save/load algorithm, I think I mentioned it earlier, and the changes are minor anyways.

As usual, I have made a video containing all the updates, albeit few this time. So enjoy the video:

Phantobra - The Game - Part 7: Now with water... and stuff!



fredag den 19. oktober 2012

The world (of Phantobra) is no longer safe!

It finally happened. I added the very first hostile mob to the game. It may be insanely stupid, and has next to no pathfinding skills, but it's a start! The first hostile mob - The Grey Wolf. Grey wolves are now roaming around in the game, killing any rabbits they come across, with the main focus of chasing and killing the player- And yes, it is now possible to die in the game (Sort of- more on that below).

What's New?

Without further delay, here's the list:
- Wolves have been added - The very first hostile mob.
- Player health has been added, death now lurks around every corner... if there's a wolf around.
- A health bar (row of hearts) has been added to the upper right of the GUI.
- Plants have been added. Ten different with four stages each!
- The shovel has been fully implemented (may need a bit of tweaking though).
- Inventory has been slightly updated.
- It is now possible to save and load the world.
- More bugfixes.

Wolves

So I finally came around to adding a hostile mob to the game. This might not be one of the biggest accomplishments but it has a huge impact on the game. Although there might be several minutes between each wolf encounter, the feeling of being one hundred percent safe is no longer there, this also adds a feeling of life to the game, albeit not much yet.
For the wolves to be challenging I need to improve further upon them. I have been studying and playing around with A* pathfinding, and I have no trouble grasping the main concept of it, and I would have no problem writing an algorithm for a top down, gravity free world, but I still struggle with finding a solution, and maybe also understanding how to apply it to a platformer game, where jumping and falling needs to be taken into account.
Currently the wolf is fairly simple in design. It choses a target on spawn, which is the nearest of rabbit or player. Every two seconds it checks if there are a better (closer) target, and if so, chooses that. It then just moves in the targets direction, by checking if the targets X-position is higher or lower than its own. There's some basic coding for jumping obstacles and small holes in the ground.
This means that if you are underground and the wolf is above you it will simply follow your x-position until there's a direct passage down towards you, it will not try to find any path at all.
So in short, my wolves are very basic at the moment, and they really need to be improved upon. Once I have my pathfinding code in place it will be easier to add more mobs.. at least mobs with similar movement.

Health and Healthbar

After adding the wolves it felt kinda weird that the wolves would chase you, but they wouldn't do anything. So I quickly went into Paint.net, made a heart shape, and colored it light grey. This one heart now makes up my 10 heart healthbar. What I do is I paint the 10 hearts, and tint them red, when the indicate health, or tint them dark grey if there's no health in it... This requires further explanation I think.
The player has hitpoints just as any other creature has. The healthbar is supposed to give an estimate of how much health the player has left, thus I have a property I can call that calculates the current health in percent.
So I have a for loop, where my variable "i" starts at ten and move down towards one. Ten being the rightmost heart and one the leftmost. When I draw the heart it is either drawn as a red heart or a grey one. The way I determine that is by checking if  CurrentHealthPercentage + (i * 10) < 100, and if this is true I color the heart grey, otherwise it will be colored red. This gives a slightly "positive" healthbar, since the first heart won't turn grey until you've lost 10% of your health. I am still considering to change this, since it shouldn't be that hard. But I've played around with the thought that some item abilities will only work when all hearts are full.. And having 10% health as a buffer for that might make those requirements more fair.. or maybe too fair.. I will give it some thought.
The reason I said you could die "sort of" in my intro, is because although you die (dissapears with no animation) you can still use the mouse and do all the actions you would do with the mouse, thus you can build stuff near where you died. This is of course just a funny easily fixable bug, but for now it amuses me :-)

Plants

Ten new plants have been added, each with four different stages. Currently all the plants are just randomly placed on top of grass tiles, but at a later time some of the plants will only be able to grow in certain places and at certain times. It took me quite some time to get my first plant finished, but once I got the hang of it, it took me maybe around 30-45 minutes for each plant. I have no idea if that is fast or slow, but I'll rather spend two hours (as I did on the first plant) to get a result I am happy with, than rushing through it. Plants are harvestable with a shovel. If you swing any other tool at a plant it will be destroyed, with no chance of any loot. Currently only one plant has any loot associated with it. When the plant is in stage 3 there's 75% chance you get a couple of plant seeds, on stage four the chance is 100%. You will get the plant on stage 3 and 4 no matter what. Currently you won't get anything from the earlier stages, but I have considered adding lower percentages for that. The seeds can then be used to plant a new plant, while the flower is meant for crafting, though a use for it is not in the game yet. Currently plants are planned to be decorational, for crafting and alchemy (not yet implemented) and some cases for food.

The Shovel

When I started creating the game, the shovel was used to remove background tiles, this was changed at a later time though, since I felt it was just plain wrong to remove a wooden background wall with a shovel. This also means that currently there are no means to remove background tiles in the world, although all the code to do so is in place. The shovel will instead be used to harvest plants. The reason I decided to do it like this is that I wanted the player to be able to simply destroy plants by swinging a sword (or any other non shovel tool) at the plants, if they were in the way, instead of forcing players to harvest plants and give them potentially unwanted loot (Since some plants will be there in abundance.) So now you just chose to either destroy the plants, or harvest them. Also where all tools swing downwards, the shovel swings upwards, which makes much more sense for a shovel.
For reasons I don't fully understand yet, the shovel is a bit off in the swing animation compared to the players arm. This is not happening when I swing downwards, so this will need a bit of tweaking.

Inventory Changes

The changes to the inventory aren't very big, and they're not included in the video below. I actually did the inventory changes just before I started to write todays blog. What I changed was the way the inventory is searched everytime you add something to it. As you can see in my previous video where I show off crafting, when I craft some torches initially the stack up nicely in the same slot. But when I use the last of the animal fat, a quickbar slot is freed, and since that slot is checked for free room sooner than the slot with the torches it simply drops them in that spot. This was slightly anoying, so now what happens is that first it will search the quickbar, and then the inventory for any matching items. It will then attempt to stack it if possible. If there are room for some of the items, but not all it will add what little there's room for and continue to search for another possible place to stack it. If every inventory slot has been searched and there are still some items left that needs a spot, it will be placed in the first avaible empty quickbar or inventory slot. I am quite happy with how it turned out, and the inventory feels much more solid now, and the code even got a bit cleaner, although it took a few more lines.

Bugfixes

So I've had a few nasty bugs over the past few weeks, and today I sat down and crushed them.
I won't go into too much detail, but I felt like listing them.
- Doors that could break and become unremoveable, are now again both usable and removable.
- When building a solid tile on top of a grass tile it would cause the grass tile to dissapear, until it was involved in another update cycle. This has now been fixed by correctly updating the tile after changing its orientation rather than before.
- Sometimes plants was able to enter a state higher than four, causing the plants to be invisible, but still be in the way for construction. They're no longer hidden, and has been told to behave in the future.

I think I managed to cover everything this time (Probably not though). You can see the new video below.

Enjoy!

Phantobra - The Game - Part 6: I'll see your rabbit and raise you a wolf!


tirsdag den 25. september 2012

Crafting and Combat

I remember less than two months ago, I posted a video of me building a house in Phantobra - The Game. This was done by spawning the materials and then build the house. I was proud to have come so far. Now... I've met the next milestone- Building a house without any kind of cheats or commands.
For a long time I've postponed the making of a crafting system, so I ended up making one of those bets with a friend, where you give each other a task, and failing means you have to give the other part something. So my task was to implement crafting in the game, which I did.

What's new?

Both combat and crafting has been implemented in the game. The complete list of updates since last post:
- Added Crafting to the game. Currently there is 10 craftable items.
- Added new items to the game. Currently there is 18 items in the game.
- Combat has been implemented. You can now kill (and loot) rabbits.
- Two loot items has been added to the rabbit. Animal fat and Rabbit Hide.
- Sand tiles and the sand item has been added to the game.
- New background(s) for both day and night time.
- Tiles now crack when mined to visually show where you are currently mining.
- Terrain has been updated- This is still at an experimental stage, as you can easily see in the video.
- Random caves and holes has been added in the terrain. This is also very experimental.
- Optimized on RAM usage. Reduced the memory required for each tile by approximately 20%.

Crafting

Ever since I got mining implemented into the game I've wanted to add a crafting system. I thought it would be a lot of boring coding, so I kept doing other more exciting stuff. Now where the basics are complete I can see I was a bit wrong. The thing that took the most time was figuring out how my crafting system should work. On top of that I had to make it so that it was easy to understand, which I think I did accomplish. At the moment, you can craft any craftable item, as long as you have the required material. Since crafting is a major part of this type of game, I will expand on the crafting system later. Further restrictions, such as work benches, forges, etc. will be requirements for some items later. I've also though about adding recipes for some of the more unique and rare items in the game, where you need to find the recipe before you can craft the item.
Currently all recipes are hardcoded into the game. Actually what I do is keep all the recipes in one Method, within a switch case. I throw in the ItemID of the desired item, and it returns a list of Vector2 containing the ID and the amount of each required item in the recipe. Currently the code to retrieve the recipes are running every loop as long as the inventory is open. This is not optimal, but I needed to be sure that if I remove an item while the inventory is open that It wouldn't allow me to craft items that I didn't have the ingredients for. This is not that hard to fix. All I need to do is run the CraftingUpdate everytime I open my inventory, or change something in it while it is open.
I really should do that soon...
The UI for crafting is simple and straight forward, at least in my opinion. I haven't decided on the colors yet, but for now I'll stick to what I've got. I am planning on making the colorscheme for the UI customisable anyways.

Items and Loot

As a consequence of both combat and crafting I've added a few more items to the game. This includes "Wooden Sticks, Animal Fat, Rabbit hide and sand. Except for sand, all of these were added because of either combat or crafting. I did put a lot of thought into what items I wanted to add to the game, especially the items needed to create torches. In this style of game torches are a very important aspect of the game, and their availability greatly impacts the game. Personally I believe that torches should be relatively easy to come by, but still require a bit of effort on the players part.
Since I don't want my game to be an exact copy of Terraria, I don't want to do the "get gel from slimes" thing. So I've decided to have more than one source of "fuel" for the torches. The first one being animal fat. Using one unit of animal fat, and one stick currently yields two torches. Animal fat currently only drops from rabbits, which is a harmless mob. My plan is to have a low to medium drop chance (somewhere between 5-20%) for every mob you kill that can be considered an animal. This will (hopefully) give a steady flow of "fuel" for your torches. I also want the player to be able to mine for his fuel, rather than kill animals. So being able to find coal while digging around was an obvious choice. Coal is not yet implemented in the game, but it will be added at a later time.
The rabbit hide has currently no use in the game. My first idea with it was to use it to craft animal fat by removing it from the raw newly skinned hide, but I decided against that. Instead I decided that a rabbit could drop both things. Currently there is a 25% drop chance on rabbit hide, and 20% on animal fat.
I also added the sand item and sand tile. There really isn't much to say about it. It was like a natural thing to add it sooner or later. It reacts to gravity, and falls down if something beneath it is removed. The physics for the sand is very basic. If a column of sand drops it drops just as a I shaped tetris block would do in a game of tetris (except for the grid based movement thing). Currently I am happy with the simplicity of it, so I might keep it that way... I haven't decided yet.

Combat

So eventually combat had to be implemented, and now was the time. I don't think I mentioned it in my earlier posts, but I've actually done some of the code for combat a while back now. I got stuck though, since the rotation of the weapon has some heavy mathematics around it. My math skills aren't sufficient for a lot of the more advanced stuff, so I do a lot of reading, and get help and find examples online, and basically I get something together by doing a mix of that.
So currently Swords, Axes and pickaxes are usable as weapons in the game. Already back before I even did anything related to graphics in this game, I fleshed out the tool/weapon classes very well, so after finishing the combat system it was all a matter of combining it with the calculated stats of the weapons and tools. Damage and mining efficiency are calculated from item type, material and other effects you can add to items. Speed is based on material and weapon/tool type. All three of these weapons are all swinging weapons, which means the swing in an arch from top to bottom in front of you. These are all working and are implemented.
How this works is, I rotate the weapon, and the origin of the weapon (Origin = hilt position). I tweaked the numbers so the sword arched nicely in front of the player. After that I added the swing animations to the sprite and polished the numbers a bit, and voila, Emma can now swing her sword. After I did that the next problem came up- I needed to have some decent collision detection so that I could kill some rabbits. Now when XNA rotates the sword visually, you don't have any boundingbox out of the box, that you can do collision detection on. So after reading up on the subject I found another solution. On your weapon you add a few points, in my case 3 points, and check if they intersect with the rabbit, and if so, you deal damage. Basically what I do is add 3 points, in line with the start position of the tool, and rotate it around the same origin (sword hilt). This way the points follow the sword and you have a decent collision detection for your combat.
I still need to implement stabbing weapons, and a digging weapon. The digging weapon (shovel) will rotate just like the swords and axes, but going from down to up instead.
I belive the stabbing collision will be simple enough, as there is no rotation involved there. I belive using a single point for collision detection would be viable here.

Terrain and Mining crack

I have been playing around with the terrain quite a bit. There are underground caves, and randomized terrain. Everything is highly experimental at this stage, and although I've spend a lot of time playing around with it, and reading up on it, I don't have much to share about it currently. I use a variation of the Perlin Noise algorithm, which I haven't written by myself, but pieced together online. As you will see in the video, the results are promising, but definately needs improvement.
I've also added a small feature- The mining crack. When mining a tile a crack will now appear, indicating your progress. The further along you are, the more the tile will crack. If I remember correctly the crack is a 5 frame animation, and was implented very easily. Basically I just compare the tiles current hp to it's max hp, and based off on the percentage I draw the crack. So every 20% increases the size of the crack.

Backgrounds

So I've added some simple backgrounds, the most noticable is probably the night sky. It's very simple, but it does add a lot of mood to the scene. I do have a lot of plans with the backgrounds. I think I mentioned last time that the moon can be used to symbolize events, like a red moon in terraria causes zombies to invade. Their idea is very good, but sadly they don't utilize the potential of this idea very well, at least in my opinion. I can think of quite a few more events you can related to the moon. Even without the moon there is a lot of things you can do with the background. Imagine that sometimes a rare constellation will be visible on the night sky. This could be a subtle hint to the player that something is going on. Maybe a rare flower, needed for alchemy only spawns whenever there's a certain constellation on the night sky, or a certain kind of mob or animal only shows up during a specifik constellation. Adding lots of small events, gives the player options that can benefit them, but it will not be game breaking if you are unable to react to them.
Now I do know that adding tons of events like this can quickly become a lot of work, so my longterm goal is to see if I can find a fast, and yet solid way of handling these events. Something like everytime I want to add an event, it's all a matter of adding a few lines of code and store it in some event collection. As long as there are some solid, yet flexible, rules for these events, this should be possible.

I think that covered most of it. I didn't get around the RAM optimization at all, but really there's not much to it. I realized some time ago that my tiles had a lot of information in them, that I could possibly store elsewhere. Information like whether or not a certain tile type reacts to gravity. Instead of storing that information in the tile, I would just go look it up somewhere. I was hesitant to do that since then I'd have to jump through ifs or switch cases, for every single tile on the screen. So I went online and got some very nice advice. I create a list of tiles with static information (Not a static class). One for each TileType. Then all I need in the tile to access all the static information is the index number for the list. An example would be: Dirt is placed in the 2nd. spot in the list, thus it would be on location 1 in the zero based index. I than keep a short with the value one on the dirt tile, and use that as an argument everytime I want to retrieve information from the list. This way I save a lot of information from being stored in the memory, and I avoid having to juggle with switch cases hundres of times each cycle.

Phew.. This turned out to be quite a wall of text this time. It's getting late and there is school tomorrow, so I'll wrap it up.
Enjoy the video, and don't hesitate to comment, rate or subscribe, if you feel like it.
 
Phantobra - The Game - Part 5: Crafting, Killing, Construction and ...




mandag den 3. september 2012

Sprites and Animations

I've finally taken the first step towards my programmer education. My current education is an IT Technician (IT Supporter) - But there's not much programming in that one. So I decided to study computer science. So over the next two years I'm reading up on some classes, to reach the requirements to get in.
What this means is, that there will effectively be less time to work on this game, but as it turns out, the need to plan my time better seems to give more productivity, so this might not be all bad for this game.
 
What's new?
I finally managed to put some life into this game. This update includes:
- The player rectangle has been retired, and replaced by a new player sprite.
- Rabbits have been added to the game.
- A full cycle moon has been added to the game (Before it was just a big yellow square).
- Clouds have been added to the game.
- Some minor bug fixes.
 
The player sprite
I finally got around to making a (almost) fully animated sprite of the player. Since this first version looks more like a female than a male, my daughter decided to name the sprite "Emma"- So until further notice, this will be the name of the player sprite.
I think I've mentioned before that all the graphics in the game are made solely by me- And it's no secret that I am not very good at drawing at all. I am... satisfied for now, with my current sprite.
After I finished making the basic frame in Paint.Net I found an awesome beta version of a program called Spriter (Made by BrashMonkey) that required me to chop up my sprite into smaller pieces. This left me with separate pictures of the hair, head, torso, legs, hands and feet. This allowed me to animate my character in a very simple way, by moving these images/parts around as desired.
This gave me the idea to create separate animations for each part, and then draw them on top of each other in the game. This allows me to change the animation, or appearance of each body part individually. So in the near future I will be adding various clothing and hairstyles, which can then easily be changes while playing. I think this is the first step towards changing equipment visually.
I still need to add the Stab and swing animation to the character.
 
Rabbits
So after some moderate success with the player sprite I decided to add rabbits to the world.
Before I started to draw them I went online and looked at various pictures of rabbits, and after that I decided to give it a go. What was really difficult was to keep the rabbit in each frame, about the same size as the rest, while at the same time showing the rabbit stretching (which it does when it jumps).
I consider the rabbits my biggest success this update. I made the entire animation strip, without testing, I then went on to program the rabbits basic AI, compiled and tested it. And voila - Hole in one. It just worked. I stared at those small bunnies jumping around my screen for like 5 minutes, and I was speechless. For me- This was the experience of the month, no doubt about it.
I did end up having to add a bit extra code to the rabbits physics method to keep them falling through the ground occasionally.
 
The Moon
For quite a while, my moon has just been a big yellow square. So last night I had some spare time on my hands, so I decided to make a moon. This time I decided to do this without any help. An hour later or so I had a full moon cycle strip, just ready to be implemented. I colored the moon light grey, which gives the opportunity to tint it with any color I want in game. This allows me to create various moon related events like "Blue moon", "Blood moon", "Hunters Moon", etc.
The moon will have an impact on what happens during the night, based on the current state of the moon, and based on the rare events where the moon will be colored.
 
Clouds
Finally I managed to create some clouds to implement. Currently all clouds moves east (right). I do have a wind variable to play around with, but weather and such will not be implemented for some time.
 
So with all that out of the way, here's the video for this update. It's short, since all the new things does not take that long to show- Enjoy :) 
Phantobra - The Game - Part 4: Rabbits, Clouds and a Moon
 

fredag den 10. august 2012

Building my first house.

I've finally come far enough with my game to be able to build a basic house.
Not much has changed since last video, in terms of new features. I've added a few more materials and added trees and doors to the game. Also I'm still struggling with my lighting system. In the video below you will notice a bug after the house has been build and I place the first torch. This bug is now fixed. I am still not happy with the lighting system, but at least I'm getting closer to a solution- But for now I've benched the lighting issues so I can continue to add new features.

Trees
So the trees was a bit tricky to import to my game. Since everything is tile based I try to create everything as tiles. For the trees I "broke" that rule. The trunk of the tree is tiles, as it should be. But the tree top is a different story. Since the treetops aren't really supposed to influence the game in any way, I decided to draw the treetops as a full picture, and place it at the top trunk tile. So basically the treetops are just an image placed strategically to make the trees look whole.
Currently trees will be drawn in front of any background tiles, but behind any "solid" tiles.
A side effect of "forcing" the treetops onto the topmost trunk tile is if you don't chop down the entire tree (i.e. you chop at the middle trunk tile) the treetop will simply be drawn on the new topmost trunk tile- thus making it look like the tree is shrinking. For now I will keep it this way, since I kinda like it.
When I generate a tree, the 3 bottom tree tiles are always the same. Then for each trunk tile upwards, I randomize what to draw by changing the tiles Orientation enumerator accordingly. This gives a slightly varried look for all the tree trunks.

Doors
As I mentioned above, I try to handle everything as a tile, which I did with the doors. I ended up using a quite messed up way of doing it, and I will surely rewrite it in the future. For now I'm pushing ahead to get more stuff into the game, and then take a week now and then where I will clean up code here and there.
So the reason it got messy is, that a closed door takes up 3 tiles, and an open door takes up 6 tiles. (2X3). A door can open both left and right, meaning it can touch a total of 9 tiles. This also means that since everything is drawn as a tile I will need to have an image to represent each tile, in each door state. Meaning 3 tiles for the closed door, and 6 for each of the open ones, so a total of 15 different tiles. Each tile in the world, has an enumerator which holds the type of the tile, like Grass, dirt, stone, tree, etc. Every tile also has an enumerator holding the orientation of the tile (Top, bottom, centered, free (not surrounded), etc.
I decided to use a combination of the type and the orientation to keep track of what to draw. So basically a closed door would consist of 3 tiles of TileType.ClosedDoor. Each tile would then have their own Orientation like Orientation.Top, Orientation.Middle and Orientation.Bottom. Since it would not make sense to use any other orientation, I decided to create 4 additional TileTypes to handle the door. OpenDoorLeft01 and OpenDoorLeft02 for a door opening to the left, and then do the same for the right direction. By using the orientation each door type would then hold the top, middle and bottom part of a door, but since the open doors consist of 6 tiles, OpenDoorLeft01 is one half of the door, and OpenDoorLeft02 is the other half.

A solution could be to simply break/bend the rules of keeping it all as tiles. It would be no problem to add the door as one entity (as long as I maintain the correct size) and simply draw the door as open or closed, based on either a bool or maybe an enumerator (DoorState.OpenLeft, DoorState.OpenRight, DoorState.Closed) and reserve the tiles in the world accordingly.
This would also save me a lot of (imo rubbish) code.

But enough from me for now. Here's the newest video I've made where I chop a few trees, and build a small house. - Note that the there is still no crafting system, so the materials was spawned prior to recording the video.