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 .
HedgeHog builder
Prole
Posts: 15 Joined: Sat Aug 19, 2017 9:13 am
Post
by HedgeHog builder » Mon Oct 09, 2017 10:03 am
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
Attachments
main.lua
(2.22 KiB) Downloaded 84 times
Teptai
Prole
Posts: 3 Joined: Sun Oct 08, 2017 8:12 am
Post
by Teptai » Mon Oct 09, 2017 1:29 pm
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
...
Users browsing this forum: Bing [Bot] and 4 guests