cant make my cars to slow down.

Hi!

I'm making a race game.
This is how it should look.

the cars accelerate with a random speed from 1 to 10.
when they reach lets say 20 they need to slow down with a random nr from 1 to 5.

there is my problem, I'm done with the acceleration part but i have no idea how to make them stop, been trying for the past 3 hours without any luck..

my main
http://pastebin.com/nzc1Lzg3
cpp
http://pastebin.com/W8JwYmNZ
header
http://pastebin.com/amesCJza

Would be very nice if someone could help me out.

best regards
Last edited on
Without looking at your code, I'm sure your cars slow down. Suppose they reach a speed -- let's say 20. You make them slow down by 5. Now they are at 15. Did you make sure to slow them down further, are they accelerating again or did you simply let them continue at 15?

Edit: At first glance, it appears to me that your code in `raceDone()' and `main()' suggests that your logic is backward:

from `raceDone()' -
1
2
if(cars[i].getVelocity()>=velocity)
  return true;


from `main()' -
1
2
3
4
5
6
while(raceDone(cars,n,stop)!=true)
  {
    stopAllCars(cars, n);
    showCars(cars, n);
    system("pause");
  }


You're saying that if a car's velocity is greater than stop (0), it should exit the slow-down loop. Try changing it from >= to <= in `raceDone()'.
Last edited on
I want to make the cars slow down by a random nr from 1 to 5 until velocity=0,
something like a for-loop or a while that looks something like
while(velocity!=0)
{
stopAllCars(cars,n);
showCars(cars,n);//not needed, the cars need to slow down but not to be show on the screen
system("pause");//its only for me so i see that they really slow down.
}

I know that this kind of while wont work but thats what i would like to accomplish.

The thing you wanted me to change makes the program end, wont even start increasing the speed to "20", like before.
Topic archived. No new replies allowed.