Skip to content

Instantly share code, notes, and snippets.

@danhp
Created November 17, 2013 04:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danhp/7509395 to your computer and use it in GitHub Desktop.
Save danhp/7509395 to your computer and use it in GitHub Desktop.
Mariachi
update = function( dt, enemy, player, level )
if enemy.dead then return end
local direction
if enemy.hp < 16 and math.abs(enemy.position.x - player.position.x) < 250 then
enemy.idletime = enemy.idletime + dt
if math.abs(enemy.position.x - player.position.x) < 2 then
--stay put
elseif enemy.position.x < player.position.x then
enemy.direction = 'right'
elseif enemy.position.x + enemy.props.width > player.position.x + player.width then
enemy.direction = 'left'
end
direction = enemy.direction == 'left' and 1 or -1
enemy.velocity.x = 90 * direction
if enemy.idletime >= 3 then
enemy.props.pushattack(enemy)
enemy.idletime = 0
end
else
if enemy.position.x > enemy.maxx and enemy.state ~= 'attack' then
enemy.direction = 'left'
elseif enemy.position.x < enemy.minx and enemy.state ~= 'attack'then
enemy.direction = 'right'
end
direction = enemy.direction == 'left' and 1 or -1
enemy.velocity.x = 40 * direction
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment