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!