public void act() { super.act(); switch (intersectionState) { case APPROACHING: this.speed = Speed.HALF_SPEED; hasTurned = false; break; case IN: if (intersection.getSignal(this.heading).getState() == State.RED) { this.speed = Speed.STOP; } else { this.speed = Speed.HALF_SPEED; } break; case LEAVING: if (intersection.getSignal(this.heading).getState() != State.RED) { this.speed = Speed.HALF_SPEED; if (!hasTurned) { if (turn == Turn.LEFT) { hasTurned = turnLeft(intersection); if (hasTurned) { turn = Turn.RIGHT; } } else if (turn == Turn.RIGHT) { hasTurned = turnRight(intersection); if (hasTurned) { turn = Turn.LEFT; } } else { this.speed = Speed.FULL_SPEED; } } else { this.speed = Speed.FULL_SPEED; } } break; } move(speed.ordinal()); }
public void act() { super.act(); move(MOVE_AMOUNT); if (this.getY() < TrafficWorld.WIDTH / 2 && this.isAtEdge()) { this.setLocation(this.getX(), TrafficWorld.WIDTH); } else if (this.getY() > TrafficWorld.WIDTH / 2 && this.isAtEdge()) { this.setLocation(this.getX(), 0); } switch (state) { case "INSIDE": MOVE_AMOUNT = 3; break; case "APPROACHING": if (i.verticalColor == TrafficLights.Color.GREEN) { MOVE_AMOUNT = 2; } else if (i.verticalColor == TrafficLights.Color.YELLOW) { MOVE_AMOUNT = 1; } else if (i.verticalColor == TrafficLights.Color.RED) { if (this.isTouching(Intersection.class)) { MOVE_AMOUNT = 0; } } } }