Could anyone tell me how to give the player score based on how far the player has travelled... Just like in a runner's game ...
every tick set score: player.x
or deducting the start x-position from player.x
You can easily calculate the distance between 2 points or to objects with the system expression "distance".
From the manual :
distance(x1, y1, x2, y2) Calculate distance between to points
So at the end of the run, just get the distance between the player and the start : distance(start.x, start.y, player.x, player.y).
Edit : This can work if you are moving the start point or the player.
Else, you can increment a variable called for example "distanceTravelled" every tick.
Every tick -> add (dt * variable) to distanceTravelled
On Every Tick> Add Player.speed *dt to totalDistance.
From Auto-Runner template. Have a look at it.
Thanks you all for your help ... Will try it out .... :)
Develop games in your browser. Powerful, performant & highly capable.
I cant use the last one which is the auto runner one... because since its based on every tick ... so when the player collides with the block. it still counts till the player is dead ..
Time to add another condition.
If the player speed is at 0 then nothing happen ... Don't get your problem.
Global Var timer
----- Add dt to timer
----- Show int(timer) in a text object
Put above in a group
If you want the timer to pause, deactivate the above group.
When you die deactivate the group and set timer to 0
Reactivate group when you are ready for the timer to start going up again.