Game Development Reference
In-Depth Information
Creating a direct control agent
As all the animation control for our direct control agents exists within the agent Lua script,
all that remains is setting the soldier's state based on hotkeys. Note that as we have no dir-
ect change state, we handle this completely within the hotkey itself:
DirectSoldierAgent.lua :
local function _IsNumKey(key, numKey)
-- Match both numpad keys and numeric keys.
return string.find(
key, string.format("^[numpad_]*%d_key$", numKey));
end
function Agent_HandleEvent(agent, event)
if (event.source == "keyboard" and event.pressed) then
-- Ignore new state requests if the agent is dead or
about
-- to die.
if (_soldierState == _soldierStates.DEATH or
_soldierState == _soldierStates.FALLING) then
return;
end
-- Immediately switch the current state of the
soldier.
if (_IsNumKey(event.key, 1)) then
_soldierState = _soldierStates.IDLE;
elseif (_IsNumKey(event.key, 2)) then
_soldierState = _soldierStates.SHOOTING;
elseif (_IsNumKey(event.key, 3)) then
_soldierState = _soldierStates.MOVING;
elseif (_IsNumKey(event.key, 4)) then
_soldierState = _soldierStates.DEATH;
elseif (_IsNumKey(event.key, 5)) then
-- Immediately switch the stance of the soldier,
does
-- not switch the current state of the soldier.
Search WWH ::




Custom Search