Game Development Reference
In-Depth Information
function AddSphere(scriptObject)
g_actorMgr:AddSphere(scriptObject);
end
function RemoveSphere(scriptObject)
g_actorMgr:RemoveSphere(scriptObject);
end
The first line calls require() , which executes the ActorManager.lua script if it
hasn
t already been executed. This is similar to C++ #include statements. The next
line instantiates a global ActorManager class. The rest of the file defines a number
of add and remove functions for various types of actors. These are called from the
XML-defined constructor and destructor for various game actors, as described at
the end of Chapter 12. It allows actors to be automatically added to and removed
from the Lua actor manager when they are created and destroyed.
'
The Actor Manager
Most of the action takes place in the actor manager. Here ' s the class definition:
ActorManager = class(nil,
{
_player = nil, -- this will be filled automatically when
-- player_teapot.xml is loaded
_enemies = {}, -- a map of enemy teapots; key = actor id
_spheres = {}, -- a map of spheres; key = actor id
-- processes
_enemyProcesses = nil;
_enemyHealer = nil, -- process that periodically heals all enemies
_enemyThinker = nil, -- process that causes enemies to make a new decision
_enemyUpdater = nil, -- process that updates all enemy states
});
The first three variables track the different types of actors in the world. The remain-
ing four handle special script processes that apply various gameplay effects, as
described in the comments next to each one.
When an AI teapot is created, the script component calls the constructor function,
which in turn calls ActorManager:AddEnemy() .
function ActorManager:AddEnemy(scriptObject)
-- add the enemy to the list of enemies
local actorId = scriptObject:GetActorId();
if (self._enemies[actorId]
= nil) then
˜
 
 
Search WWH ::




Custom Search