Edit:
I was also curious on how to spawn multiple enemies.
Currently I have them set up like this. It also has a "state" to handle the animation that is played.
love.load
Code: Select all
enemy = {
hp = 100,
status = "ALIVE",
x = 600,
y = 150,
w = 14,
h = 16,
speed = 20,
}
enemy_state = enemy_anim.enemy_walkleft
Code: Select all
function love.draw()
enemy_state:draw(enemy.x, enemy.y)
end
Code: Select all
function CheckCollision(obj1, obj2)
if obj1.x > obj2.x + obj2.w - 1 or
obj1.y > obj2.y + obj2.h - 1 or
obj2.x > obj1.x + obj1.w - 1 or
obj2.y > obj1.y + obj1.h - 1
then
return false -- No collision. Yay!
else
return true -- Yes collision. Ouch!
end
end
function CheckDirection(obj1, obj2)
if obj1.x > obj2.x + obj2.w - 1 then
enemy_direction = "right"
return false
elseif obj1.y > obj2.y + obj2.h - 1 then
enemy_direction = "down"
return false
elseif obj2.x > obj1.x + obj1.w - 1 then
enemy_direction = "left"
return false
elseif obj2.y > obj1.y + obj1.h - 1 then
enemy_direction = "up"
return false
else
return true -- Yes collision. Ouch!
end
end