Page 1 of 1

Wrong creation of enemy bullets

Posted: Wed Sep 23, 2015 9:49 am
by LavX64
Trying to create enemies shooting, but in fact shooting only FIRST of enemies. Where is the mistake?

Re: Wrong creation of enemy bullets

Posted: Wed Sep 23, 2015 10:15 am
by MadByte
Hi,

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

Posted: Wed Sep 23, 2015 10:22 am
by LavX64
Oh. I thought about it couple of hours ago, but totally forget 'till now ^~^
Thanks!