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!


Ingen kommentarer:

Send en kommentar