From 8195a30ace6f6eedbc4e9e4d5a4a8e447bfb4c1f Mon Sep 17 00:00:00 2001 From: Arthur Bols Date: Wed, 7 Mar 2018 22:40:57 +0100 Subject: [PATCH] improvements to jumpTime / jumpStep and... --- OGP1718-Worms/src/worms/model/Worm.java | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/OGP1718-Worms/src/worms/model/Worm.java b/OGP1718-Worms/src/worms/model/Worm.java index 2a8df04..cb72c69 100644 --- a/OGP1718-Worms/src/worms/model/Worm.java +++ b/OGP1718-Worms/src/worms/model/Worm.java @@ -27,8 +27,8 @@ public class Worm { // jumping private Tuple oldLocation; - private double jumpForce; private double jumpVelocity; + private double jumpTime; /** * this variable contains the orientation of the worm @@ -415,7 +415,6 @@ public class Worm { this.location = Tuple.create(this.location.item1 + numberSteps * distanceX, this.location.item2 + numberSteps * distanceY); subtractPoints(cost); - } //=================================================================================== @@ -441,7 +440,7 @@ public class Worm { * |substractPoints(angle) */ public void turn(double angle) { - assert 0 <= angle && angle < (2 * PI); + assert 0 <= angle && angle < (2 * PI) && !Double.isNaN(angle); setOrientation((this.orientation + angle) % (2 * PI)); subtractPoints(angle); @@ -454,9 +453,7 @@ public class Worm { // region Jump //=================================================================================== - /** - * this constant contains the gravity - */ + /** this constant contains the gravity */ private final double G = 5.0; /** @@ -484,6 +481,7 @@ public class Worm { this.oldLocation = this.location; this.jumpVelocity = jumpVelocity(); + this.jumpTime = jumpTime(); this.location = Tuple.create(location.item1 + jumpDistance(this.jumpVelocity), location.item2); this.points = 0; } @@ -508,16 +506,18 @@ public class Worm { */ public double jumpTime() { - return jumpDistance(this.jumpVelocity) / (this.jumpVelocity * cos(this.orientation)); + if (this.orientation >= PI || this.points == 0) + throw new IllegalStateException(); + return jumpDistance(jumpVelocity()) / (jumpVelocity() * cos(this.orientation)); } /** * - * @param deltaTime - * @return + * @param deltaTime ... + * @return Tuple */ public Tuple jumpStep(double deltaTime) { - if (Double.isNaN(deltaTime)) { + if (Double.isNaN(deltaTime) || deltaTime > this.jumpTime || deltaTime < 0) { throw new IllegalArgumentException(); }