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:

No comments:

Post a Comment