Monthly Archives: October 2014

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
direction="UP"
end
if (GetMyY() < coord_y-path) then
direction="DOWN"
end

if (direction=="DOWN") then
ApplyForce(0,1)
else
ApplyForce(0,-1)
end
end

function OnRage(distance)
end

function OnCollision(object)
if (object=="Player") then
status="DEATH"
end
end

function OnDeath()
end

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!