Page 1 of 1

Deleting enemies if too much

Posted: Mon Oct 09, 2017 10:03 am
by HedgeHog builder
I wish to stop enemies spawning when there are over 5 enemies, keeping the number of enemies at 5


I however have no idea how to do this properly, and as a result the enemies keep spawning and do not stop

Might be good to look at:

Code: Select all

			if timer < 1 and MaxPens < 5 then
				Enemy_Pen_Spawn(randomX,randomY,20,20)
				MaxPens = MaxPens + 1
				end
I actually have no idea why this does not work at stopping the enemies from spawning even if the enemies are far above 10.

You can make the "newTimer" a lower number so you can see the enemies flood the screen if you wish to test it

Re: Deleting enemies if too much

Posted: Mon Oct 09, 2017 1:29 pm
by Teptai
You got local MaxPens = 0 in your love.update(dt) so it resets MaxPen to 0 every frame(?). Put it in love.load() or elsewhere.

Code: Select all

function love.update(dt)
-- local variables here
local randomX = math.random(0,800)
local randomY = math.random(0,800)
local MaxPens = 0
SpawnNew_Units(pen.x,pen.y) -- block spawner
local speed = 170
-- Player Pen control
...