Reader small image

You're reading from  Learning Game AI Programming with Lua

Product typeBook
Published inNov 2014
Reading LevelBeginner
PublisherPackt
ISBN-139781783281336
Edition1st Edition
Languages
Right arrow
Author (1)
David Young
David Young
Right arrow

Handling auditory events


Handling auditory events requires you to add additional time-to-live information to each stored event. As a large number of bullet shots and impacts events are emitted, the time-to-live information will be used to prune out old events:

AgentSenses.lua:

local function HandleBulletImpactEvent(
    userData, eventType, event)
    
    local blackboard = userData.blackboard;
    local bulletImpacts = blackboard:Get("bulletImpacts") or {};
    
    table.insert(
        bulletImpacts,
        { position = event.position, ttl = 1000 });
    blackboard:Set("bulletImpacts", bulletImpacts);
end

local function HandleBulletShotEvent(userData, eventType, event)
    local blackboard = userData.blackboard;
    local bulletShots = blackboard:Get("bulletShots") or {};
    
    table.insert(
        bulletShots,
        { position = event.position, ttl = 1000 });
    blackboard:Set("bulletShots", bulletShots);
end

We can now add our auditory event handlers during the AgentSenses initialization...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Learning Game AI Programming with Lua
Published in: Nov 2014Publisher: PacktISBN-13: 9781783281336

Author (1)