-1

I am programming a simple top-down car game on game-maker where the purpose of the game is to get as many points/laps by driving the car around the oval shaped track.

The car drives with speed = 5 and changes direction with the code direction = direction + 2; image_angle = direction;

If you couldn't tell already, i'm new to coding however i have been searching for a solution for at least a fortnight and haven't found anything- How can i make the game add a point every time that the car goes through the finish line? I suppose there would have to be a collision event between the car and the finish line but i do not understand the code that would take place in order to add a point and if I did code the game to add a point i anticipate that there will be a bug where by several points will be added (instead of 1) when the car goes over the finish line as it is "colliding" the whole way as it goes over. How can I make a point be added every time the car goes around the track? If you need any further information i'd be glad to help. Thank-you.

With Kake_Fisk's help i set up 3 midway lines around the track and created a collision event between the car and the midway lines: prntscr.com/c4uecl - the problem is that add_point doesn't actually do anything and i would be glad to have some help. Another problem i am encountering is that he car was originally meant to turn with the mouse button 1 but when i tried that the car only turned when i aimed on it if you get what i'm saying, do you have a solution for that also?

2 Answers2

0

First, you have an other problem you need to think about. What stops the player from just driving forth and back over the goal line? You would need to add invisible lines throughout the track. If all these lines have been passed, you know the player has driven the car through the whole track.

You want to trigger some code once, when the car hits the goal line. By utilizing the previous system, this can be done quite easily. In collision with goal line, use something like this:

// If all the invisible lines in the track has been visited
if (midway_lines == 3)
{
    // Sets the variable back to 0 so this piece of code only gets executed once
    midway_lines = 0;
    add_point();
}
Kake_Fisk
  • 1,107
  • 11
  • 22
  • Well there is no going backwards in this game (the car drives on it's own all you have to do is steer with space bar) but the car does start behind the finish line so i guess i would still need that. I'll try what you said and report back. Thanks. – AmericanSnake Aug 12 '16 at 13:29
  • Well, that sounds like a fun game. Hold space to drive on autopilot. Anyway, this piece of information should have been written in the original question. – Kake_Fisk Aug 12 '16 at 13:37
  • Alright so i have set up 3 midway lines around the track and created a collision event between the car and the midway lines: http://prntscr.com/c4uecl - the problem is that add_point isn't defined and i don't know how i'm supposed to define it, maybe a draw event or something, can you help me out? – AmericanSnake Aug 12 '16 at 13:40
  • The car was originally meant to turn with the mouse button 1 but when i tried that the car only turned when i aimed on it if you get what i'm saying, do you have a solution for that also? Lol yes it won't be a blast of fun but i just wanted to see what i could make it's pretty much a re-make of this http://td2tl.com/stay-on-the-road – AmericanSnake Aug 12 '16 at 13:43
0

obj_car:

creation event:
points = 0; //instance variable

step event:
if(place_meeting(x,y,obj_line)) {
 points += 1;
}

if(points == 3) {
 room_goto(rm_win);
}
Heavybrush
  • 79
  • 1
  • 10