How Do I Make The Game Harder Without Need To Change Scene?

Hi guys, im really inspired from android game NinJump and im looking to make similar mechanism to my game. I want my game to be harder through the game as long as the player hasn't died yet (items spawn faster and different various items only appear when we survive the first few minutes).

What i have is like this atm:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
function spawn( objectType, x, y )
    if gameIsActive == true then
        bottle = display.newImage("bottle1.png")
        bottle.name = "bottle"
        bottle.x = math.random(320)
        bottle.y = -100
        bottle.rotation = 10
        physics.addBody(bottle, { density=2.0, friction=0.5, bounce=0.3})
 
        if bottle.y > display.contentHeight then
                print("failed")
        end
        end
end
timer.performWithDelay(2000,spawn,60000)

Hey,

Theres a fair few ways to go about doing that, one way would to just keep track of the elasped time, then edit variables accordingly. Another way is shown below.. I just knocked this up, so its probably a horrendous way of doing it, but it should give you some ideas at the very least.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
local staticTimerFunc --Forward declaration of the timer function...
local bottleSpawns = 0 --Variable to keep track of  bottle spawns...
 
function spawn( objectType, x, y )
    if gameIsActive == true then
        --Increase the variable each time one spawns..
        bottleSpawns = bottleSpawns + 1 
        
        bottle = display.newImage("bottle1.png")
        bottle.name = "bottle"
        bottle.x = math.random(320)
        bottle.y = -100
        bottle.rotation = 10
        physics.addBody(bottle, { density=2.0, friction=0.5, bounce=0.3})
 
        if bottle.y > display.contentHeight then
                print("failed")
        end
                
        --Check to see if enough bottles have spawned to start spawning "Bananas" aswell...
        if bottleSpawns > 60 then
             --Could also add 50/50 chance to call this function here too..
             createBanana() --Call your new spawn function.
        end
                
        --Call the timer function again to start a new spawn sequence... 
        staticTimerFunc()
    end
end
 
--The time for the first timer below is now slowly subtracted by the amount of bottles spawned*10.. Therefore lowering the time between spawns each time.
local function changingTime() local variableTimer = timer.performWithDelay(2000-(bottleSpawns*10),spawn,1); end
function staticTimerFunc() local staticTimer = timer.performWithDelay(50,changingTime,1); end
--Calls this function initially to start everything off.
staticTimerFunc() 

hi mate,

thank you so much.

it really works, thank you. However, im curious about something

1
2
local function changingTime() local variableTimer = timer.performWithDelay(2000-(bottleSpawns*10),spawn,1); end
function staticTimerFunc() local staticTimer = timer.performWithDelay(50,changingTime,1); end

Math!

Lets say using your example using timer delay.......

and you want to have 20 levels of play... Each level gets a little bit faster.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
local level = 1
local maxLevel = 20
local elapsedTime = 0
 
function spawn( objectType, x, y )
    elapsedTime = elapsedTime + 1
    if elapsedTime > (maxLevel - level) then
        if gameIsActive == true then
            bottle = display.newImage("bottle1.png")
            bottle.name = "bottle"
            bottle.x = math.random(320)
            bottle.y = -100
            bottle.rotation = 10
            physics.addBody(bottle, { density=2.0, friction=0.5, bounce=0.3})
 
            if bottle.y > display.contentHeight then
                print("failed")
            end
        end
        elapsedTime = 0
    end
end
timer.performWithDelay(100,spawn,1200000)

The reason they are both '1' is because in your spawn function, i have it calling staticTimerFunc() again. Therefore its essentially a never ending loop of spawning the item.

staticTimerFunc() calls changingTime() which calles spawn(), that in turn calls staticTimerFunc() again.

Robs way is also good, and probably better than me using timers again and again lol.

If it were me I wouldn't use a timer. Lots of overhead...

I'd setup an Runtime:addEventListener("enterFrame",spawn) gameLoop myself and knowing I'm getting called 30 times per second (or 60 depending on your setup), I'd use similar logic to spawn after X number of frames.

hi guys, thanks for the explanation. I will check these codes later tonight and will comment here back if i need anything else. Thanks!

views:1499 update:2012/1/13 9:04:04
corona forums © 2003-2011