# Score based on distance

Get help using Construct 2

### » Mon Feb 17, 2014 11:16 am

Hi,

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 ...

Thank you
B
8
S
1
Posts: 37
Reputation: 593

### » Mon Feb 17, 2014 11:21 am

something like:

every tick set score: player.x

or deducting the start x-position from player.x
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

### » Mon Feb 17, 2014 12:40 pm

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

Joskin2014-02-17 12:49:23
B
40
S
15
G
5
Posts: 295
Reputation: 6,129

### » Mon Feb 17, 2014 1:44 pm

On Every Tick> Add Player.speed *dt to totalDistance.
From Auto-Runner template. Have a look at it.
B
11
S
4
G
1
Posts: 272
Reputation: 1,643

### » Mon Feb 17, 2014 1:54 pm

Thanks you all for your help ... Will try it out .... :)
B
8
S
1
Posts: 37
Reputation: 593

### » Mon Feb 17, 2014 2:23 pm

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 ..
B
8
S
1
Posts: 37
Reputation: 593

### » Mon Feb 17, 2014 2:24 pm

I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

### » Mon Feb 17, 2014 2:27 pm

If the player speed is at 0 then nothing happen ... Don't get your problem.
B
40
S
15
G
5
Posts: 295
Reputation: 6,129

### » Mon Feb 17, 2014 3:40 pm

Global Var timer

Every Tick
----- 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.

B
101
S
32
G
12
Posts: 1,549
Reputation: 22,033