From 9f2e91836ce520c83f01a4ddfcff5bcc3016fd53 Mon Sep 17 00:00:00 2001 From: Leen Dereu Date: Tue, 22 May 2018 16:01:14 +0200 Subject: [PATCH] Errors oplossen --- OGP1718-Worms/src/worms/model/Projectile.java | 25 ++++++++++++++----- .../worms/model/Part3_FullFacadeTest.java | 2 -- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/OGP1718-Worms/src/worms/model/Projectile.java b/OGP1718-Worms/src/worms/model/Projectile.java index 0b1a1dc..f841053 100644 --- a/OGP1718-Worms/src/worms/model/Projectile.java +++ b/OGP1718-Worms/src/worms/model/Projectile.java @@ -83,13 +83,19 @@ public abstract class Projectile extends GameObject { private double jumpVelocity() { 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; } } @@ -115,8 +122,14 @@ 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; } diff --git a/OGP1718-Worms/tests/worms/model/Part3_FullFacadeTest.java b/OGP1718-Worms/tests/worms/model/Part3_FullFacadeTest.java index 62c4e19..cbc11dc 100755 --- a/OGP1718-Worms/tests/worms/model/Part3_FullFacadeTest.java +++ b/OGP1718-Worms/tests/worms/model/Part3_FullFacadeTest.java @@ -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)