improvements to jumpTime / jumpStep and...

This commit is contained in:
2018-03-07 22:40:57 +01:00
parent 3c8da5825f
commit 8195a30ace

View File

@@ -27,8 +27,8 @@ public class Worm {
// jumping
private Tuple<Double, Double> 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<Double, Double>
*/
public Tuple<Double, Double> jumpStep(double deltaTime) {
if (Double.isNaN(deltaTime)) {
if (Double.isNaN(deltaTime) || deltaTime > this.jumpTime || deltaTime < 0) {
throw new IllegalArgumentException();
}