Tilemap Game Engine Development – Agon Light C Programming

In this video, I’ll show you how I built a tilemap system from scratch in C for the Agon Light, and integrated it into my existing game engine. Getting the physics engine to handle collisions with the tilemap was no easy task, but I’ll walk you through how I made it work. On top of that, I explore some game design, sketching out ideas for where the game is heading.

https://youtu.be/qKVcIFhsZY0

Last time I made a basic physics engine that could cope with collisions against different physics bodies. This time I’ve been adding the ability to have a level that is made from tiles, some of which are solid.

Making a tilemap for a game is a traditional way to represent the game’s background and scenery. Testing for collisions with tiles is quite an easy thing to do, but does require more care when a physics library is involved. Normally the sprites simply look up their position in the tilemap and if there’s a solid tile under them, the sprite system moves the sprite to the closest edge before drawing it.

With a physics engine the physics system also needs to know about the tilemap. However what I didn’t want to do was tightly couple the sprite system, physics system and tilemap system together. What I chose to do was make the sprite system in control of everything, and it works out when to call the physics code, or when to move the sprites out of collision with the tilemap.

After a few false starts that did have some amusing bugs I managed to make it work.

This is one of those programming challenges that seems impossible to achieve, and for a while I did wonder whether I’d created a mess that I couldn’t solve. However with some careful redesigning of the code I made it all work in a very satisfying manner.

To save a lot of time and effort I used the tile editing tool Tiled which exports its data as easy to read XML files

By reading this in with some custom Python code, I was able to create my own map data file format for reading into the game

The remaining task was to test it on the hardware. Unfortunately this is where I encountered several showstopping bugs to do with loading graphics which needed solving

and then a severe performance issue which lead me down the path of dirty rectangle optimisation.

By the end I had a robust and reasonably performant sprite system that had physics and a tilemap.

Now I have the majority of the basic game engine working, I can focus on designing an actual game, and then starting to make parts of it. It’s still a complete work in progress and I am sure things will continue to evolve over time.

Leave a Reply

Your email address will not be published. Required fields are marked *