improvements to jumpTime / jumpStep and...
This commit is contained in:
@@ -27,8 +27,8 @@ public class Worm {
|
|||||||
|
|
||||||
// jumping
|
// jumping
|
||||||
private Tuple<Double, Double> oldLocation;
|
private Tuple<Double, Double> oldLocation;
|
||||||
private double jumpForce;
|
|
||||||
private double jumpVelocity;
|
private double jumpVelocity;
|
||||||
|
private double jumpTime;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* this variable contains the orientation of the worm
|
* 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 = Tuple.create(this.location.item1 + numberSteps * distanceX,
|
||||||
this.location.item2 + numberSteps * distanceY);
|
this.location.item2 + numberSteps * distanceY);
|
||||||
subtractPoints(cost);
|
subtractPoints(cost);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
@@ -441,7 +440,7 @@ public class Worm {
|
|||||||
* |substractPoints(angle)
|
* |substractPoints(angle)
|
||||||
*/
|
*/
|
||||||
public void turn(double 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));
|
setOrientation((this.orientation + angle) % (2 * PI));
|
||||||
subtractPoints(angle);
|
subtractPoints(angle);
|
||||||
@@ -454,9 +453,7 @@ public class Worm {
|
|||||||
// region Jump
|
// region Jump
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
|
|
||||||
/**
|
/** this constant contains the gravity */
|
||||||
* this constant contains the gravity
|
|
||||||
*/
|
|
||||||
private final double G = 5.0;
|
private final double G = 5.0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -484,6 +481,7 @@ public class Worm {
|
|||||||
|
|
||||||
this.oldLocation = this.location;
|
this.oldLocation = this.location;
|
||||||
this.jumpVelocity = jumpVelocity();
|
this.jumpVelocity = jumpVelocity();
|
||||||
|
this.jumpTime = jumpTime();
|
||||||
this.location = Tuple.create(location.item1 + jumpDistance(this.jumpVelocity), location.item2);
|
this.location = Tuple.create(location.item1 + jumpDistance(this.jumpVelocity), location.item2);
|
||||||
this.points = 0;
|
this.points = 0;
|
||||||
}
|
}
|
||||||
@@ -508,16 +506,18 @@ public class Worm {
|
|||||||
*/
|
*/
|
||||||
public double jumpTime() {
|
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
|
* @param deltaTime ...
|
||||||
* @return
|
* @return Tuple<Double, Double>
|
||||||
*/
|
*/
|
||||||
public Tuple<Double, Double> jumpStep(double deltaTime) {
|
public Tuple<Double, Double> jumpStep(double deltaTime) {
|
||||||
if (Double.isNaN(deltaTime)) {
|
if (Double.isNaN(deltaTime) || deltaTime > this.jumpTime || deltaTime < 0) {
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user