PDA

View Full Version : How many times has it passed?


Kirbya
10-23-2006, 09:46 AM
Im creating a racing game for my final project right now and I need to know how to check if the racecar has passed the flag twice, then when it has passed it for the third time so i can change the flag's accordingly.

Also if you could show me how to make it so the cars can't move until the text "GO!" shows up that would help greatly.

DrJim
10-23-2006, 07:16 PM
First of all - nice start. It looks good and the cars control well. :D

Re your two questions. First, you need a "lap counter" variable for each car and a monitor loop to increment the counter each time the car passes within a threshold of the flag.

For the second, you are going to have to change the while statements controlling the car from world events, like they are now to conditional loops inside a general "While race is on" loop in one of the top level methods. The condition "race is on" goes true when the GO shows up and stay true until one car passes the flag three times. When it's false, the key controls don't work and thus the cars can't be move. (Right now, there is nothing to stop them from moving any time the world is running.)

I know this is pretty sketchy :( but didn't have time to work out the details. Hope it helps at least a bit and good luck. :)

Kirbya
10-24-2006, 09:43 AM
How would I make a monitor loop?


EDIT: Nevermind, I figured it out, thanks
Now onto the second part...

Kirbya
10-24-2006, 10:04 AM
If you could explain your answer to the second answer a little more I would appreciate it, I can't figure out what you mean.

DrJim
10-24-2006, 11:36 AM
See attached - ugly code (mine, not yours), :p large file, only done for the "W" key and not really what I described ("Aside from that, Mrs. Lincoln, how did you like the play?") - but it may give you the general idea.

The event call will always happen when the world is running so you have to modify the "forward" command - in this case it only does something after GO was displayed and before the loop counter (you would replace that with the lap counter) reaches 4.

Kirbya
10-25-2006, 02:43 PM
I get what your saying now, I have it working great.

DrJim
10-25-2006, 07:22 PM
Glad you got it running :) - maybe you could post it in the share worlds section of this forum.