Help: Spawning multiple enemies at set locations
Posted: Mon Mar 13, 2017 8:29 pm
Hello.
I am trying to learn love2d, and decided to follow a youtube tutorial (https://www.youtube.com/watch?v=FeLljv5clnw&t=689s). However, I cannot get multiple enemies to spawn, and I am pretty sure I am following the instructions correctly. Please take a look at my code and let me know what I am doing wrong. Thank you.
I am trying to learn love2d, and decided to follow a youtube tutorial (https://www.youtube.com/watch?v=FeLljv5clnw&t=689s). However, I cannot get multiple enemies to spawn, and I am pretty sure I am following the instructions correctly. Please take a look at my code and let me know what I am doing wrong. Thank you.
Code: Select all
enemy {}
enemies_controller = {}
enemies_controller.enemies = {}
function enemies_controller:spawnEnemy(x, y)
enemy = {}
enemy.x = x
enemy.y = y
enemy.bullets = {}
enemy.cooldown = 0
enemy.speed = 6
table.insert(self.enemies, enemy)
end
enemy = {}
enemies_controller:spawnEnemy(0, 0)
enemies_controller:spawnEnemy(100, 100)
function love.update(dt)
for _,e in pairs (enemies_controller.enemies) do
e.y = e.y + 1
end
end
function love.draw()
--draw enemy
love.graphics.setColor(255, 0 , 0)
for _,e in pairs(enemies_controller.enemies) do
love.graphics.rectangle("fill", e.x, e.y, 80, 20)
end
end