Wrong creation of enemy bullets
Posted: Wed Sep 23, 2015 9:49 am
Trying to create enemies shooting, but in fact shooting only FIRST of enemies. Where is the mistake?
Code: Select all
--Check Shooting
for i, enemy in ipairs(enemies) do
-- Update Shooting interval timer --
enemy.timer = enemy.timer - (1*dt)
if enemy.timer < 0 then
enemy.canShoot = true
end
-- Spawn Bullet --
if enemy.canShoot then
newEnemyBullet = { x = enemy.x + enemy.sprite:getWidth()/2 - enemyBulletSprite:getWidth()/2, y = enemy.y + enemy.sprite:getHeight() - enemyBulletSprite:getHeight(), sprite = enemyBulletSprite}
table.insert(enemyBullets, newEnemyBullet)
enemy.canShoot = false
enemy.timer = canShootEnemyTimerMax
end