Oct 312011
 

If you’ve been following my recent posts, you know that I’m working on a procedural level generator for the Neil Rajah levels. For now it’s just a ground generator. I’m using Artemis, which is an entity-component system. The code for creating the ground in Artemis started out pretty simple – for each tile, I create a new entity which has components for the physics and spatial / renderable information. My first performance fix was to ensure that the Sprite objects don’t get invalidated on each frame, which forced them to recalculate their vertices. This fixed an issue which caused the game to run at 15fps on my phone. My next optimization was physics related – instead of one box2d object per tile, I’m using one object (basically a large rectangle) per ground section. Both of these helped with running the game, but I still had a problem each time I started a level – the level creation took a long time, so the game stalled for a while before you could play it. I’ve spent some time looking into this, and trying to figure out what I can do to fix it.

Continue reading »

Oct 292011
 

Another update on my procedural level generation experiments.

I’ve modified the physics object generation logic to create one big rectangle for each flat section of the ground platform. I’m sure it could be optimized further, since box2d allows polygons with 8 vertices. But this is pretty close to ideal, and getting to the next level will be quite a bit more complex. The code to do this was pretty easy:

    • Remember the bottom left corner when I’m starting a new section
    • When I get to a height change, create a polygon that covers the previous region
    • Reset the bottom left corner to this column, start a new region

I also played with the level generator constraints and the game speed. I think I like where it’s at now. The character runs faster, so I had to increase the minimum platform size right before a gap, to ensure that the player has a fair chance at making the jump. Since you can’t control the run, and you could be falling down from a higher platform, sometimes it became very difficult to jump in time to clear the platform.

Here’s a video showing the current state of the game:

What do you think? I’m pretty happy with it. Now it’s time to decide how to move on. I’ll probably spend some time trying to generate other game world elements programmatically as well, but if that doesn’t work out, then I’ll need to come up with some kind of level editor to let me place those elements by hand.

 

Oct 282011
 

That’s a bit of an obvious subject line, but it was driven home to me today. I decided that before I get too much further with this experiment, I should make sure that my procedurally generated world is playable on my phone. Well, guess what – the code I posted yesterday ran at 15-30fps on my phone (Samsung Galaxy S). All my other games run at 56fps, which seems to be the maximum my phone can do. I believe it’s fill-rate limited. Anyway, 15fps on a Galaxy S meant that it would be unplayable on a large number of phones, so I had to figure out what was causing this.

Continue reading »

Oct 282011
 

As promised in the previous post, here are some code snippets showing how this works. As I mentioned, it’s not very different from the level generator in the original Mario level generator. I’m working in box2d coordinates where 0,0 is the bottom left corner, while the original was with 0,0 in the top left corner, so I’ve had to invert some comparisons on the y axis, but that’s about all I’ve changed.

Continue reading »

Oct 262011
 

I’ve been trying to sketch out some levels for Neil Rajah, so I have something to play through as I add enemies, test run speeds and jump heights, and so on. I’ve discovered that playing through the same level over and over again gets boring really quickly. And after that, it becomes kinda hard to tell if the level would be interesting to a new player or not, because I hate it. I’ve toyed with the idea of writing some code that could automatically generate levels, but I never considered it seriously. Mostly because I think writing code to generate an interesting level would be quite a bit harder than creating an interesting level by hand. I have a very simple procedural platform generator in Bus Jumper, which works for that game, but it wouldn’t work for a full platformer.

Continue reading »