Book Image

Learning Game AI Programming with Lua

By : David Young
Book Image

Learning Game AI Programming with Lua

By: David Young

Overview of this book

Table of Contents (16 chapters)
Learning Game AI Programming with Lua
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Free Chapter
1
Getting Started with AI Sandbox
Index

Running the obstacle course


Now that we've implemented both approaches to animation control, it's time to create both of these agent types within the obstacle course. As there's no actual agent decision-making logic, we'll be binding each different state to a keyboard hotkey so that we can influence what actions the agents perform. Here, we can see a few agents running the obstacle course:

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 direct 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...