Wrong creation of enemy bullets

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
LavX64
Prole
Posts: 8
Joined: Wed Sep 23, 2015 9:44 am

Wrong creation of enemy bullets

Post by LavX64 »

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
User avatar
MadByte
Party member
Posts: 533
Joined: Fri May 03, 2013 6:42 pm
Location: Braunschweig, Germany

Re: Wrong creation of enemy bullets

Post 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
LavX64
Prole
Posts: 8
Joined: Wed Sep 23, 2015 9:44 am

Re: Wrong creation of enemy bullets

Post by LavX64 »

Oh. I thought about it couple of hours ago, but totally forget 'till now ^~^
Thanks!
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 1 guest