Increase difficulty based on score

Hey there,

I’ve just finished the “Getting Started” guide and was trying to get the game a bit more hard to play

So i’ve reduced the gameLoopTimer = timer.performWithDelay( 500, gameLoop, 0 ) to 250

And was actually wondering if there’s a way to keep decreasing that value based on the Score, in a way that the higher the player score is the faster the asteroids respawn.

Have tried to do this via the “if/then” command, but had no luck doing so …

Thanks in advance !

Instead of using a timer, use an enterFrame listener which checks the time elapsed since the last spawn on every frame, comparing system.getTimer() against the last spawn time. When it reaches your threshold ( which you can also decrease over time to increase difficulty), launch the spawn function and store the spawn time.

First all thank you for your tips nick ! I’ll try all those tips today and come back with my results

Do you have any extra information concerning these commands? i’ve been trying to apply them on my actual code and I haven’t been able to recreate the same thing my Timer does right now and add a kind of evolution in the parameters :confused:

Something like this:

[lua]

local threshold = 500

local reduce = 0.01

local lastSpawn = system.getTimer()

local spawnFunction = function ()

  print (“SPAWN CODE HERE”)

end

local gameLoop = function ()

  local t = system.getTimer()

  if t - lastSpawn > threshold then

    spawnFunction()

    lastSpawn = system.getTimer()

  end

  threshold = threshold - reduce

end

Runtime:addEventListener(“enterFrame”, gameLoop)

[/lua]

Instead of using a timer, use an enterFrame listener which checks the time elapsed since the last spawn on every frame, comparing system.getTimer() against the last spawn time. When it reaches your threshold ( which you can also decrease over time to increase difficulty), launch the spawn function and store the spawn time.

First all thank you for your tips nick ! I’ll try all those tips today and come back with my results

Do you have any extra information concerning these commands? i’ve been trying to apply them on my actual code and I haven’t been able to recreate the same thing my Timer does right now and add a kind of evolution in the parameters :confused:

Something like this:

[lua]

local threshold = 500

local reduce = 0.01

local lastSpawn = system.getTimer()

local spawnFunction = function ()

  print (“SPAWN CODE HERE”)

end

local gameLoop = function ()

  local t = system.getTimer()

  if t - lastSpawn > threshold then

    spawnFunction()

    lastSpawn = system.getTimer()

  end

  threshold = threshold - reduce

end

Runtime:addEventListener(“enterFrame”, gameLoop)

[/lua]