Distance counter

Hello!

I'm trying to make a game on which we must escape some enemies who are on a pursuit. The longer you survive, more you score.

The problem is I can't find a way to count the distance (or even the pixels) we travelled on the game.

I searched lots of tutorials on YouTube or even texts on GMS2, but didn't find anything that could help me. Could you please help?

Thanks and sorry for my rusty English
 

Ommn

Member
you can determine distance by value of X or by calculating the incremental value of the velocity.

We need more information about the movement mechanism you use in your game to help you better!!
 
Guys, so sorry! On the last week I was busy with a job and couldn't answer here!

@Ommn, here is the code of movement

//move
right = keyboard_check(ord("D"));

if keyboard_check(ord("D")) {
sprite_index = spr_dog_direita;
}

left = keyboard_check(ord("A"));

if keyboard_check(ord("A")) {
sprite_index = spr_dog_esquerda;
}

up = keyboard_check(ord("W"));

if keyboard_check(ord("W")) {
sprite_index = spr_dog_cima;
}

down = keyboard_check(ord("S"));

if keyboard_check(ord("S")) {
sprite_index = spr_dog_baixo;
}

if hveloc = 0 and veloc = 0 {
sprite_index = spr_dog_idle;
}

hveloc = (right - left) * veloc;

// collision

if place_meeting(x + hveloc, y, obj_collision){
while !place_meeting(x + sign(hveloc), y, obj_collision){
x += sign(hveloc);
}

hveloc = 0;
}

x += hveloc;

vveloc = (down - up) * veloc;

if place_meeting(x, y + vveloc, obj_collision){
while !place_meeting(x, y + sign(vveloc), obj_collision){
y += sign(vveloc);
}
vveloc = 0;
}

y += vveloc;
 

Ommn

Member
Guys, so sorry! On the last week I was busy with a job and couldn't answer here!

@Ommn, here is the code of movement

//move
right = keyboard_check(ord("D"));

if keyboard_check(ord("D")) {
sprite_index = spr_dog_direita;
}

left = keyboard_check(ord("A"));

if keyboard_check(ord("A")) {
sprite_index = spr_dog_esquerda;
}

up = keyboard_check(ord("W"));

if keyboard_check(ord("W")) {
sprite_index = spr_dog_cima;
}

down = keyboard_check(ord("S"));

if keyboard_check(ord("S")) {
sprite_index = spr_dog_baixo;
}

if hveloc = 0 and veloc = 0 {
sprite_index = spr_dog_idle;
}

hveloc = (right - left) * veloc;

// collision

if place_meeting(x + hveloc, y, obj_collision){
while !place_meeting(x + sign(hveloc), y, obj_collision){
x += sign(hveloc);
}

hveloc = 0;
}

x += hveloc;

vveloc = (down - up) * veloc;

if place_meeting(x, y + vveloc, obj_collision){
while !place_meeting(x, y + sign(vveloc), obj_collision){
y += sign(vveloc);
}
vveloc = 0;
}

y += vveloc;
you should try code @chamaeleon
this is really easy way to counter distance
 
Top