Skip to content

Instantly share code, notes, and snippets.

@kevinw
Created January 30, 2013 11:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kevinw/4672555 to your computer and use it in GitHub Desktop.
Save kevinw/4672555 to your computer and use it in GitHub Desktop.
local NUM_BULLETS = 10
return {
startState = 'wandering',
states = {
wandering = function()
while true do
walk(chooseRandomDirection())
wait(1)
end
end,
noticePlayer = function(player)
disableTrigger('onPlayerSeen')
stop()
lookAt(player)
pulse {time=.3}
wait(.15)
ai:gotoState('firing', vecTo(player))
end,
firing = function(dir)
for x=0, NUM_BULLETS - 1 do
local phi = x / NUM_BULLETS * (math.pi/2) - (math.pi/4)
local v = vector.new(dir.x, dir.y):rotate_inplace(phi)
entity:trigger('fireBullet', v)
wait(.05)
end
after(2, function() enableTrigger('onPlayerSeen') end)
ai:gotoState('wandering')
end
},
triggers = {
onPlayerSeen = {
sightDistance = 50,
func = function(ai, player)
ai:gotoState('noticePlayer', player)
end
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment