Increase difficulty in game

Hey guys

I’m trying to increase the difficulty in my game by increasing the amount of times the enemy is spawned every 15 seconds. at the moment it is spawing an enemy every 2.5 seconds, which is what i want it to do, but every 15 seconds, i want the amount spawned to be half a second short, making it to be spawned every 2 seconds, etc.I am having  a hard time doing this, can you help me out? here is my code.

local function spawnEnemy()     local enemyBalloon = display.newImage(Balloons,"Balloon.png") physics.addBody(enemyBalloon,"dynamic", physicsData:get("balloon") ) if math.random(2) == 1 then enemyBalloon.x = math.random(-100,-25) else enemyBalloon.x = math.random(display.contentWidth+25,display.contentWidth +100) end enemyBalloon.x = math.random(display.contentWidth) enemyBalloon.y = -60 end local spawnTimer = timer.performWithDelay(2500,spawnEnemy, 0 )  

Cheers Hazza.

can someone please help me, really need a reply to this topic

Harry,

If I understand your question correctly, this might work; or at least give you some starting point. Of course the spawn times I use here you should change to whatever times you want.

try this:

Add these 3 lines to top of the code:

local spawnTmr local spawnTime = 5000 local difficultyLevels = 4

Keep rest of the code as it is except the last line. Replace the last line with this :

&nbsp; &nbsp; &nbsp; &nbsp; local function increaseDifficulty() &nbsp; &nbsp; &nbsp; &nbsp; if spawnTmr ~= nil then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; timer.cancel(spawnTmr) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; spawnTmr = nil &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp;spawnTime = spawnTime - 1000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- just to be safe, set this to whatever spawn rate would be the &nbsp; &nbsp; &nbsp; &nbsp;-- fastest, so game never spawns to fast &nbsp; &nbsp; &nbsp; &nbsp;if spawnTime \< 1000 then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;spawnTime = 1000 &nbsp; &nbsp; &nbsp; &nbsp;end &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- spawn at this rate until this timer is canceled&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;spawnTmr = &nbsp;timer.performWithDelay(spawnTime, spawnEnemy, 0) &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; -- this timer loops only till spawning at most difficult speed is reached &nbsp; &nbsp; local difficultyTmr = &nbsp;timer.performWithDelay(15000, increaseDifficulty, difficultyLevels) &nbsp; &nbsp;
  1.  First series of spawns will be at 4 second intervals

  2.  15 seconds later, the spawns will be at 3 second intervals

  3.  15 seconds after that, at 2 second intervals

  4.  will never be faster then 1 second intervals

  5.  once at 1 second intervals, the spawning will continue to spawn till you call to cancel the spawnTmr

  6. difficultyTmr should only loop till it gets to the fastest speed.

  7. if all balloons are spawned/destroyed or wave is over… cancel both timers.

hope that helps.

Thanks helped a lot, appreciate it.:slight_smile:

can someone please help me, really need a reply to this topic

Harry,

If I understand your question correctly, this might work; or at least give you some starting point. Of course the spawn times I use here you should change to whatever times you want.

try this:

Add these 3 lines to top of the code:

local spawnTmr local spawnTime = 5000 local difficultyLevels = 4

Keep rest of the code as it is except the last line. Replace the last line with this :

&nbsp; &nbsp; &nbsp; &nbsp; local function increaseDifficulty() &nbsp; &nbsp; &nbsp; &nbsp; if spawnTmr ~= nil then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; timer.cancel(spawnTmr) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; spawnTmr = nil &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp;spawnTime = spawnTime - 1000 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- just to be safe, set this to whatever spawn rate would be the &nbsp; &nbsp; &nbsp; &nbsp;-- fastest, so game never spawns to fast &nbsp; &nbsp; &nbsp; &nbsp;if spawnTime \< 1000 then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;spawnTime = 1000 &nbsp; &nbsp; &nbsp; &nbsp;end &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- spawn at this rate until this timer is canceled&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;spawnTmr = &nbsp;timer.performWithDelay(spawnTime, spawnEnemy, 0) &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; -- this timer loops only till spawning at most difficult speed is reached &nbsp; &nbsp; local difficultyTmr = &nbsp;timer.performWithDelay(15000, increaseDifficulty, difficultyLevels) &nbsp; &nbsp;
  1.  First series of spawns will be at 4 second intervals

  2.  15 seconds later, the spawns will be at 3 second intervals

  3.  15 seconds after that, at 2 second intervals

  4.  will never be faster then 1 second intervals

  5.  once at 1 second intervals, the spawning will continue to spawn till you call to cancel the spawnTmr

  6. difficultyTmr should only loop till it gets to the fastest speed.

  7. if all balloons are spawned/destroyed or wave is over… cancel both timers.

hope that helps.

Thanks helped a lot, appreciate it.:slight_smile:

if it was a jigsaw puzzle game how would you give the option to choose the difficultly level?

if it was a jigsaw puzzle game how would you give the option to choose the difficultly level?