I have a program meant to simulate traffic and all process (movement, drawing new cars, responding to traffic lights) except tracking movement are working.
I have used getter methods
float getXposition(){
return x;
}
float getYposition(){
return y;
}
to determine the location of my sprite but my problem is with conditions relating to the position. For example, my do while loop
do {
topcar.setYvelocity((topcar.getYvelocity()/2));
}while(topcar.getYposition() < 275);
is always bypassed.
Update method(s)
public void update() { // update position and velocity every n milliSec
// default - just move at constant velocity
x += dx; // velocity in x direction
y += dy; // velocity in y direction
}
public void actionPerformed(ActionEvent arg0) {
// called by Timer every 50 milliseconds
for (SimpleSprite s : SimpleSprite.sprites)
s.update(); // update positions of all sprites
repaint();
}
What I wanted to do was make it so that when the light turns red the car sprite should slow down to half speed until it reaches y coordinate 275 and then stop, but instead my sprite will abruptly stop as soon as the light turns red