Saturday, August 31, 2013

Game:Caves And Whatnot

Hello there, audience.After some hard work and continuous testing and experimenting (and a lot of googling)
I have pretty much finished the cave generation system. As an added bonus, I also found a way to place different materials, like rock and gold with the same algorithm. You can see the end result below:
That little white rectangle is the player. The caves look pretty good in my opinion. What do you think?


Can you figure out how it's done? I used a nifty thing called cellular automaton. Whoa, what the heck is a cellar automan? Well a CA is a simple simulation based on cells(hence, cellular). It takes a grid of cells which can be either alive or dead and applies some rules to them in every simulation step. For example, take the following rules:
  • Any live cell with fewer than two live neighbours dies, as if caused by under-population.
  • Any live cell with two or three live neighbours lives on to the next generation.
  • Any live cell with more than three live neighbours dies, as if by overcrowding.
  • Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
These rules would be applied to each cell in a grid as time passes.These rules in particular are the rules applied in Conway's Game of Life which, is one of the simplest CAs. Even if it has these seemingly simple rules it produces very complex and interesting patterns. However, there exist even more complex CAs with very complex rules, which simulate anything from the flow of electricity to ant behaviour.

The "player", about to get filthy rich...
So CAs can get quite complex, but I didn't think you'd be able to generate caves using them, until I found this article. I started from that algorithm, but I quickly found out, that for the large space that I was using, the caves didn't look as good, especially when zoomed out. So I had to muck around and keep testing different starting grids and different rules until I got it right. This was actually the hardest part, but I'm quite content with what I have now. I'm going to keep these magic numbers I came up with, a seeeeeecret. After all, I think I spent a whole week just testing variants out. Do you know what that kind of repetitive work can do to a man?! I was starting see stuff and draw numbers on the walls.

Anyway, with cave generation the "world mesh" has become a lot more complex, and the whole thing runs at about 10 FPS right now. But I still have a lot of optimisation to do. Some temporary thing i did, was to make it so you can't see past the surface, there would be a black "shadow" underneath it. I will work more on this once I learn how to use shaders and when gameplay comes into discussion. For now, there is a tiny rectangle that represents, what the player size would be in relation with the world. I think its a pretty good ratio, small enough so that performance won't be an issue because you will spend most of the time zoomed in. I can't help but think how the game will turn out once actual gameplay will be added.

Well, I guess this is another blog post written and another feature added. The next thing on the list is green lush fresh vegetation. I've already started working on a prototype. Until then you can check out the facebook page for more screenshots or give this game of life demo a shot. Also, please leave a comment and tell me if these caves look natural to you. I can't tell because I've been looking at them all month now! 

Have a nice weekend fellas and fellettes!

No comments:

Post a Comment