Created
November 17, 2013 04:49
-
-
Save danhp/7509395 to your computer and use it in GitHub Desktop.
Mariachi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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