Game Development Reference
In-Depth Information
The reload action
Reloading is the first action that requires an animation to complete before we can consider
the action complete, as the behavior will refill our agent's current ammunition count. As
our animation controller is queue-based, the action itself never knows how many com-
mands must be processed before the reload command has finished executing.
To account for this during the update loop of our action, we wait till the command queue is
empty, as the reload action will be the last command that will be added to the queue. Once
the queue is empty, we can terminate the action and allow the cleanup function to award
the ammo:
SoldierActions.lua :
function SoldierActions_ReloadCleanUp(userData)
userData.ammo = userData.maxAmmo;
end
function SoldierActions_ReloadInitialize(userData)
userData.controller:QueueCommand(
userData.agent,
SoldierController.Commands.RELOAD);
return Action.Status.RUNNING;
end
function SoldierActions_ReloadUpdate(deltaTimeInMillis,
userData)
if (userData.controller:QueueLength() > 0) then
return Action.Status.RUNNING;
end
return Action.Status.TERMINATED;
end
SoldierLogic.lua :
local function ReloadAction(userData)
return Action.new(
"reload",
Search WWH ::




Custom Search