Wrong creation of enemy bullets
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Wrong creation of enemy bullets
Trying to create enemies shooting, but in fact shooting only FIRST of enemies. Where is the mistake?
- Attachments
-
- Project.love
- (5.06 MiB) Downloaded 65 times
Re: Wrong creation of enemy bullets
Hi,
the problem was that you've created just one timer to spawn bullets from enemies. In fact each enemy need his own timer.
the problem was that you've created just one timer to spawn bullets from enemies. In fact each enemy need his own timer.
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
Re: Wrong creation of enemy bullets
Oh. I thought about it couple of hours ago, but totally forget 'till now ^~^
Thanks!
Thanks!
Who is online
Users browsing this forum: Ahrefs [Bot], Semrush [Bot] and 6 guests