Day 3: Carving polygons!

I'm tired @.@

The world is now implemented with a chunk-based system; unused chunks are saved to disk and can be reloaded later.

For world generation, I needed a way to be able to shape the world easily, abstracting away the concept of a chunk. The hardest part was finding a way to allow for arbitrary physical shapes in Box2D. The idea was that I wanted to "carve" away pieces of the moon with arbitrary polygons.

It turns out that there's a python library, Polygon, that does this and works pretty well with Box2D. You can define polygons and subtract them from eachother. Now, you can end up with pretty complicated polygons with multiple contours, and Box2D doesn't like that, but you can just call a triStrip() method to break it up into simple triangles. This works surprisingly well!

Surface generation works by carving out the top chunk based on a 1D midpoint-displacement heightmap. The carver sweeps from left to right:



Cave generation is a similar approach. The width of the carver again uses midpoint-displacement, and the carver wanders in random directions with some constraints:



I also have player movement and animations working. Here, have a shiny picture of the lunar surface!



I haven't made any new songs yet, but Ami's made a ton of sprites for us to use. Whoo!