Wednesday, March 30, 2011

Some progress

About time I got around to another post.

There's been quite a lot of changes since my last post. I now have a working pathfinding system and several working buildings.


I've left out the menu system as it hasn't changed.

My units are currently called dwarves because that was more fun than humans when I started but I'm sure I'll get around to refactoring that sometime. Currently a building can claim a dwarf from a pool of unemployed dwarves and once that dwarf reaches the building he will be employed. The only jobs at the moment I have are Farmer and Porter though.

Originally I made the farmers sit at their farms and plant crops, harvest etc. Then the porter would slowly make his rounds of all the buildings near the storehouse, collecting as many resources as the farms had. If it was taking too long to get to everyone, another porter would be employed by that storehouse.
This worked well but it was very boring and static, as the farmers would just sit in their farm and only one or two dwarves for every 20 or so would actually move.

So I've changed it to be more in the style of Settlers where workers are responsible for taking their produce to the storehouse and collecting what they need from there. Porters will just move stuff between storehouses.

Also paths from buildings to storehouses are now stored so there's very little expensive pathfinding going on. Dwarves use a different pathfinding method depending whether they are on paths or offroad.

I've implemented regions into my map data so getting building and pathing info is relatively quick no matter how much you add. That was done in the Hexitridecimal? method, similar to Minecraft.
However my various attempts at making the map generation more speedy haven't done very well. Currently whenever the screen shifts it calculates a whole new bitmap data for the entire screen in order to display the correct tiles. Hopefully I'll find a better method than this soon.
My current thoughts are to do some more research into generating consistent Perlin data in smaller amounts. Also thinking of storing several screen worth of data, as the user is likely to stay in one place only shifting slightly every now and then.

I've also started the port over to XNA/C# which isn't proving very difficult. Eventually I know I'll need the greater power of C# but for now I'm quite happy prototyping in flash. Hopefully no matter how complicated the game gets I'll atleast be able to have some version working online in flash.

I'm also using my own tileset now for buildings etc. My girlfriend has also started creating tiles to help. Current issues in that area are doing tile transitions to hide the square corners and having consistent, efficient rotations so that the hills look better. For that to work I need to get the same "random" rotation everytime I load that tile, which is either proving costly or difficult.
As for the artwork itself, I've started posting on Pixelation for advice, hopefully they have some great advice/examples for me to learn off.

The farms just look like normal buildings in this version as I'm in the process of adding fields.

As always, post if you read or want some specific information about anything. Or if you have advice/thoughts!

Thursday, March 17, 2011

Wasn't in the plan I had

Well, things reallllly didn't go to plan. The day after my last post we had a 6.3 quake down here in Christchurch. Luckily myself and all those I know got out OK. Others weren't so lucky.

All my notes are still in our work building, which has been red stickered so we can't access, but my PC fell over next to me when I was cowering under the desk, so I unplugged my harddrive and shoved it in my pocket, so I still have all my personal projects. At the time I would rather have grabbed my cellphone, as contacting anyone afterwords was very difficult, but as we may never get access to our building I'm glad I have my harddrive.

Then I was umemployed until the government brought out a support package, now I'm back at work again, although working from home.

Because of all this I haven't really been in the mood to code until recently, so not much to report in that area. I did some work on a flash tile-based system similar to most roguelikes, finishing up the underlying layout. So now comes the fun part where I actually get to add interesting things like working buildings and people that make decisions rather than randomly pathing around.

I learnt a lot about how to do this from code posted by Nolithius relating to his world generation for Dance of Death. Very impressive what he's done using flash.

Linky to his site: http://www.nolithius.com/

The main feature I wanted working was infinite terrain generation in all directions, seeded so you always get the same terrain. This means I only have to save the changes I make. It also has background and foreground layers for tiles versus sprites. With a very basic menu system.


Terrain generation is done using Perlin Noise, with offsets passed in based on where in the map you want to look. This was actually quite simple. Just have to remember that you need to use offsets for each octave you're using. What I need to implement next is a region/chunk system like Minecraft. At the moment all modified tiles are stored in an array which is iterated through when checking what the tile is in an area. This is horrible and sounds even worse now I write it. That was I can also update based upon how far away a region is.

The hardest part about the whole system was getting transparency to work. My sprite tiles were overwriting my background tiles. In the end I used BitmapData.getVector to pull that data from the sprite sheet then, based upon the parameters handed in, could look for all pixels of a certain colour and replace them with  transparent pixels using the aRGB format.

If anyone is interested in a more detailed explanation I'm more than happy to post regarding specific
things. 

Here's a screeny using some Minecraft textures because I haven't finished replacing them with my own: