user1947331
user1947331

Reputation: 47

Gamemaker points issue

I have spikes placed in front of me in an endless runner. Also if I jump higher but still over the spike it gives me less points. How do I fix this?

I have this code (in the spike step event) which allows gives me points whenever I jump over them BUT it gives me 13 when I just need 1 point.

if(collision_line(x, y, x, 0, obj_player, false, true)){
score += 1;
}

Upvotes: 0

Views: 139

Answers (3)

Tanay Karnik
Tanay Karnik

Reputation: 434

What you do is create a sprite of a green line which is the height of your room. Then create a new object and untick the box 'Visible' name it anything you like as this your game. In the create event of the spike object you execute the following piece of code:

spike_line = instance_create(Your line object name here)
spike_line.x = obj_spike.x; // obj_spike is the name of your spike object

Hope it works. Comment if you find any errors.

Upvotes: 2

Rob
Rob

Reputation: 4987

This is probably happening because the player is over the spikes for 13 steps, hence the 13 points.

If i were you, i would create a hidden object (a long black line) and spawn them at the same place as the spikes. Then if the player collides with it, you give 1 point and destroy the invisible line.

Upvotes: 0

gnysek
gnysek

Reputation: 318

There's a lot of ways to do, but simplest without changing your code a lot:

if(noPointsYet && collision_line(x, y, x, 0, obj_player, false, true)){
   score ++;
   noPointsYet = true;
}

Don't forget to set noPointsYet = false; in Create event.

Of course there are better ones like putting spikes x-pos into array/queue and checking that you already passed it with proper y-pos above, checking using instance_place, getting ID and checking that you're past it etc.

Upvotes: 2

Related Questions