I have a problem with a traffic simulator I am trying to build where the cars that spawn at the edges of the world all turn to the right side of the world. My code appears to be wrong in some way though I can't seem to figure out what is wrong.
This is my code to turn left.
This is my code to turn right.
Would anyone with experience please tell me what I have wrong?
private void turnLeft(Actor i) {
if(this.getRotation() == RIGHT && this.getX() == i.getX()+15){
this.setRotation(UP);
}
else if(this.getRotation() == DOWN && this.getY() == i.getY()+15){
this.setRotation(RIGHT);
}
else if(this.getRotation() == LEFT && this.getX() == i.getX()-15){
this.setRotation(DOWN);
}
else if(this.getRotation() == UP && this.getY() == i.getY()-15){
this.setRotation(LEFT);
}
}private void turnRight(Actor i) {
if(this.getRotation() == RIGHT && this.getX() == i.getX()-15){
this.setRotation(DOWN);
}
else if(this.getRotation() == DOWN && this.getY() == i.getY()-15){
this.setRotation(LEFT);
}
else if(this.getRotation() == LEFT && this.getX() == i.getX()+15){
this.setRotation(UP);
}
else if(this.getRotation() == UP && this.getY() == i.getY()+15){
this.setRotation(RIGHT);
}
}
