PDA

View Full Version : Stop my car


pedrodantas
11-30-2011, 05:09 PM
Well i am doing this game that the user control a car that moves at a constant speed. I put the car to move when the user presses enter and i put the duration infinite so it never stops moving. The problem is: how do i make it stop when you reach the finish line. Ive tried putting a distance to function in a while something is true but it doesnt work... Help!

davidghemer
11-30-2011, 05:43 PM
Attached is a partial solution to this problem.
I've used a while something is true event to drive the car until it passes a fire hydrant.
You can also use the spacebar to start/stop the car.
A boolean valued variable, stopped, is used to indicate whether or not the car is stopped - this is toggled when you press the spacebar and set to true when you pass the fire hydrant.

pedrodantas
11-30-2011, 08:36 PM
I got it! Thank you very very much... but now I have another problem. I want so that the car can not go on the grass... take a look at my code

(remember it is just a simple game for 7 year old kids so it doesnt need to be all sphisticated)

davidghemer
11-30-2011, 09:35 PM
To make sure the car doesn't go off of the road you could place a dummy object on the edge of each side of the first road. Then put your move left and move right commands inside of an if condition. Use the "is to left of" function to check that the convertible is to the left of the dummy object on the right hand side. Similar for the other side.

I also suggest changing your left and right movement events to while key is pressed events. This will give much smoother movement. Also decrease the distance in your left and right move methods (1 metre will be enough).

Finally, you might want to change the vehicle for the camera (look under properties) to the convertible. That way the camera follows the vehicle. You can do this instead of moving the camera forward.

Other than those changes it looks good.