Category Archives: Programming

Programming related stuff

Resource manager in Adolfish

When I started Adolfish I choose C++ as my project language and the SDL as my 2D library. At first I thought that the SDL library had some sort of resource management, but I was wrong! For our first demo levels this was not a problem, but as long as we started making longer levels this became a nightmare. In a simple level we had several enemies, something like 20 or 30, and for each of them the engine had to waste time loading the data and memory loading its texture, so I came up with a simple solution. The first thing was to get the filename of the resource (the filename is used as is unique to each resource) and check whether it existed in a “resource” list, if not it gets loaded and its name added to the list, otherwise the function returned just a reference of the resource. After a few tries, it worked! But what happens if we release the memory of a dead enemy? The whole level crashed! So the solution was to check if there were other enemies using those resources and to do so I added a reference counter in the resource list. When the counter goes to 0, we can safely remove the resource from the memory. Here it is a pseudo-code of the resource loader:

and a pseudo-code to release the memory:

Building a game editor

Today I want to talk a little about the process behind Adolfish. Well, the most important part of a game is the game editor, so the first thing I did when I started Adolfish was using a game engine I knew, Irrlicht, to build up an editor from scratch. Maybe Irrlicht wasn’t so great for a simple 2D game, but it had a feature I really liked at the time, a simple in-game GUI.

Building up the editor is like building up the game itself with all the needed features, like the bullet system, the physics, the animation system and all the stuff. Well, where is the editor, you might say? In Adolfish, every level is built up of several enemies, called entities inside the editor, each with a different AI attached using an external LUA script, several skins to create the world you see and several vertices for the physics. Let me explain with a picture:

Adolfish Game Editor – Level0 Wireframe


As you can see, this is level0, the first level you play in Adolfish, and all that purple lines are the vertices I was talking about. When building a level, the level designer places as many vertices as he wants and then presses the button “New Object”, this command connects all the vertices togheter and create a new object in the physics system. Ok, now let’s see level0 complete with all the skins and entities placed:

Adolfish Game Editor – Level0 Complete

The level is now complete, but the entities don’t move! In the level0 directory there’s an AI script for every entity, but completely void. Now the developer can write the AI as a finite state machine and pack it all togheter to build the final level.

There’s a lot more then this in the editor, but that’s all for now!

…Are you ready to play?

A day in the life of a bomb

Hello there! We have been really busy doing levels and testing the new functions of the game.

Today I want to show you a technical stuff: the AI.
Every enemy in the game is called internally “Entity”, it stores the position (x,y), the direction (xd, yd), the physical properties (friction, density, dimension…), the status, the life and few others.

The AI is attached to a LUA interpreter and each “Entity” has its own instance and a script file defining its behaviour.

Let’s take a look to a simple script for a bomb:

coord_x = 53.801708
coord_y = 60.000000
enemy = "bomb"
direction = "UP"
status = "IDLE"
path = 9.2

function OnIdle()
if (GetMyY() > coord_y) then
if (GetMyY() < coord_y-path) then

if (direction=="DOWN") then

function OnRage(distance)

function OnCollision(object)
if (object=="Player") then

function OnDeath()

As you can see it’s a state-machine, starting from the IDLE state. When the player hit the bomb a signal is sent to the AI, moving to the DEATH-state, determining the explosion of the bomb.

But what if the player doesn’t hit it? Simple, the bomb stays in IDLE-state, moving UP for a certain amount (the path variable) and then switching to DOWN (the direction variable).

There are other functions: GetMyX(), GetMyY(), ApplyForce(); These are internal functions written in the game engine and called from the script, their names are self-explainatory.

See you next time!