diff options
-rw-r--r-- | src/RobotRace.java | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/RobotRace.java b/src/RobotRace.java index a7fc2e7..5d5a99c 100644 --- a/src/RobotRace.java +++ b/src/RobotRace.java @@ -287,17 +287,27 @@ public class RobotRace extends Base { * Draw all four robots in the robots array on the scene */ private void drawRobots() { - // Draw all four robots on the x-axis - for (int i = 0; i < 4; i++) { - gl.glPushMatrix(); + // laziness, save current positions because of translations + gl.glPushMatrix(); - // Place the robots on a line based on the current robot - gl.glTranslatef(-1.5f + i * 1f, 0f, 0f); + // Place the robots on a line based on the current robot. Robots are + // drawn with a distance of 1 meter between the middle of each robot, + // from left to right (seen from the robot's POV). First, set the + // starting point in a way such that the robot is drawn left of the + // axis (for an even number of robots). + gl.glTranslatef(.5f - robots.length / 2, 0f, 0f); + // Draw each robot on the X-axis + for (Robot robot: robots) { // Draw the current robot - robots[i].draw(gs.showStick); - gl.glPopMatrix(); + robot.draw(gs.showStick); + + // Position the next robot 1 meter away from the current one. + gl.glTranslatef(1f, 0f, 0f); } + + // restore positions + gl.glPopMatrix(); } /** |