Check it out, I have a new demo of the AI system. The demo is a simple Asteroids-like game.
The arrow keys move your little ship and Z shoots.
Enemy AI code:
Code: Select all
local hit = ai:Sequence ( false )
hit:Push ( ai:ReceiveMSG ( "shot" ) )
hit:Push ( ai:MoveTo ( x, y ) )
local goal = ai:Parallel ( true )
goal:Push ( ai:MoveTo ( 0, 10, speed, id ) )
goal:Push ( ai:RotateTo ( 0, 0, turnRate, playerID ) )
goal:Push ( hit )
Basically, the enemies are rotating towards the player and moving forward at the same time.
MoveTo moves the enemy to a given point: 0, 10 (in this case, a position relative to their own heading).
RotateTo rotates the enemy to a given point: 0, 0 (relative to the position of another object - playerID).
Whenever an enemy receives the "shot" message, he moves to x, y which is his initial position (in world coordinates).
Notice that since no speed is specified in the latter case, the enemy is teleported to his initial position.
Bullet AI:
Code: Select all
local move = ai:Sequence ( false )
move:Push ( ai:MoveTo ( x, y, speed ) )
move:Push ( ai:Function ( "DestroyObject", id ) )
local goal = ai:Parallel ( false )
goal:Push ( move )
goal:Push ( ai:SendMSG ( "contacts", "shot" ) )
Bullets move in a straight line and notify all of their contacts of being "shot".
Upon reaching its destination point, each bullet destroys itself.
The AI system is pretty efficient and seems to work pretty smooth with up to 2000 enemies.
You can adjust the number of enemies on the following line:
Code: Select all
-- create enemies
for i = 1, 20, 1 do
I might write a full article on this later on.