29 lines
586 B
Lua
29 lines
586 B
Lua
-- helper functions
|
|
|
|
function lookAway(actor, pos)
|
|
y = actor.position.y - pos.y
|
|
x = actor.position.x - pos.x
|
|
rotation = math.atan(y, x)
|
|
actor.rotation = math.deg(rotation)
|
|
end
|
|
|
|
function distance(a, b)
|
|
return math.sqrt((math.abs(a.x - b.x)^2) + (math.abs(a.y - b.y)^2))
|
|
end
|
|
|
|
function idle(actor, target)
|
|
-- do nothing here for now
|
|
end
|
|
|
|
function patrol(actor, target)
|
|
-- do nothing for now
|
|
end
|
|
|
|
function alert(actor, target)
|
|
if target ~= nil then
|
|
lookAway(actor, target.position)
|
|
if distance(actor.position, target.position) < 250 then
|
|
actor:moveForward()
|
|
end
|
|
end
|
|
end
|