summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <lekensteyn@gmail.com>2014-01-09 14:34:13 +0100
committerPeter Wu <lekensteyn@gmail.com>2014-01-09 15:20:49 +0100
commit3ba821abd5ab9c0e40ab5252d7221ff9d3052b12 (patch)
tree3021d3d0e2a61b296cae7461cd52feafe0f3503b
parent1a18507da4d04b2e26b6cad73b76f4bd6ba2f2d2 (diff)
download2iv60-robots-3ba821abd5ab9c0e40ab5252d7221ff9d3052b12.tar.gz
Fix reset button
-rw-r--r--src/Robot.java7
-rw-r--r--src/RobotRace.java10
2 files changed, 17 insertions, 0 deletions
diff --git a/src/Robot.java b/src/Robot.java
index de7943f..b0bca1a 100644
--- a/src/Robot.java
+++ b/src/Robot.java
@@ -501,6 +501,13 @@ class Robot extends BetterBase {
}
/**
+ * Resets the position on the track to the begin.
+ */
+ public void resetPosition() {
+ robot_time_pos = 0;
+ }
+
+ /**
* Returns the lane number on which the robot should walk.
*/
public int getLane() {
diff --git a/src/RobotRace.java b/src/RobotRace.java
index ee8abb5..622f82b 100644
--- a/src/RobotRace.java
+++ b/src/RobotRace.java
@@ -372,6 +372,16 @@ public class RobotRace extends Base {
*/
private void calculateRobotSpeedAndLocation() {
double current_t = gs.tAnim;
+ // on reset, position the robots on the begin
+ if (current_t < last_speed_update) {
+ last_speed_update = 0;
+ last_t = 0;
+ for (Robot robot : robots) {
+ robot.setSpeed(0);
+ robot.resetPosition();
+ }
+ }
+
double last_speed_update_t_diff = current_t - last_speed_update;
if (last_speed_update_t_diff >= SPEED_RECALC_INTERVAL) {
for (Robot robot : robots) {