Errors oplossen

This commit is contained in:
Leen Dereu
2018-05-22 16:01:14 +02:00
parent 119a112555
commit 9f2e91836c
2 changed files with 19 additions and 8 deletions

View File

@@ -84,12 +84,18 @@ public abstract class Projectile extends GameObject {
return getForce() / (getMass() / 1000) * FORCE_TIME;
}
//TODO jumpTimeStep moet nog toegepast worden!
public double getJumpTime(double jumpTimeStep) {
double v = jumpVelocity();
double time = jumpTimeStep;
World world = getWorld();
if (world == null) {
throw new IllegalStateException("World cannot be null");
}
double v = jumpVelocity();
double time = 0;
double a = getOrientation();
Coordinate loc = getLocation();
World world = getWorld();
double radius = getRadius();
Coordinate newLoc;
@@ -104,6 +110,7 @@ public abstract class Projectile extends GameObject {
newLoc = Coordinate.create(loc.getX() + v * time * cos(a), loc.getY() + v * time * sin(a) - (G * time * time) / 2.0);
if (newLoc.getX() < 0 || newLoc.getY() < 0 || newLoc.getX() > getWorld().getWidth() ||
newLoc.getY() > world.getHeight() || world.isAdjacent(newLoc, radius)) {
if (getDistance(loc, newLoc) < getRadius()) throw new IllegalStateException();
break;
}
}
@@ -116,7 +123,13 @@ public abstract class Projectile extends GameObject {
return time;
}
private boolean canJump() {
public double getDistance(Coordinate start, Coordinate end) {
return Math.sqrt(Math.pow(Math.abs(start.getX() - end.getX()), 2) +
Math.pow(Math.abs(start.getY() - end.getY()), 2));
}
private boolean canJump() {
return getOrientation() < PI;
}

View File

@@ -2439,8 +2439,6 @@ public class Part3_FullFacadeTest {
double[] expectedBazookaLocation = new double[] { 6.114, 3.875 };
System.out.println(projectile instanceof Rifle);
assertEquals("Result must have exactly 2 coordinates", 2, stepLocation.length);
System.out.println(stepLocation[0] + " " + stepLocation[1]);
System.out.println(projectile.getLocationArray()[0] + " " + projectile.getLocationArray()[1]);
assertTrue((Math.abs(stepLocation[0] - expectedRifleLocation[0]) < 0.01)
|| (Math.abs(stepLocation[0] - expectedBazookaLocation[0]) < 0.01));
assertTrue((Math.abs(stepLocation[1] - expectedRifleLocation[1]) < 0.01)