Errors projectile

This commit is contained in:
Leen Dereu
2018-05-22 22:08:19 +02:00
parent 5e9c6b25d9
commit 12defdc769
3 changed files with 11 additions and 4 deletions

View File

@@ -26,6 +26,8 @@ public class Bazooka extends Projectile {
if (value == 0) value++; if (value == 0) value++;
else value--; else value--;
} }
double force = getForce();
value = value* (int) force;
super.hitPoints = value; super.hitPoints = value;
} }

View File

@@ -83,7 +83,6 @@ public abstract class Projectile extends GameObject {
return getForce() / (getMass() / 1000) * FORCE_TIME; return getForce() / (getMass() / 1000) * FORCE_TIME;
} }
//TODO jumpTimeStep moet nog toegepast worden!
public double getJumpTime(double jumpTimeStep) { public double getJumpTime(double jumpTimeStep) {
World world = getWorld(); World world = getWorld();
@@ -105,7 +104,7 @@ public abstract class Projectile extends GameObject {
newLoc = Coordinate.create(x, y); newLoc = Coordinate.create(x, y);
if (! world.isPassable(newLoc, radius) || x < 0 || y < 0 || x > world.getWidth() || y > world.getHeight()) { if (! world.isPassable(newLoc, radius) || x < 0 || y < 0 || x > world.getWidth() || y > world.getHeight()) {
while (true) { while (true) {
time -= 0.01; time -= jumpTimeStep;
newLoc = Coordinate.create(loc.getX() + v * time * cos(a), loc.getY() + v * time * sin(a) - (G * time * time) / 2.0); 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() || if (newLoc.getX() < 0 || newLoc.getY() < 0 || newLoc.getX() > getWorld().getWidth() ||
newLoc.getY() > world.getHeight() || world.isAdjacent(newLoc, radius)) { newLoc.getY() > world.getHeight() || world.isAdjacent(newLoc, radius)) {
@@ -161,7 +160,14 @@ public abstract class Projectile extends GameObject {
terminate(); terminate();
return; return;
} }
setLocation(newLocation); setLocation(newLocation);
for (Worm worm: worms) {
if (this.getDistance(worm) < 0) {
hit(worm);
}
}
} }
private static Coordinate calcLocation(Coordinate wormLocation, double wormOrientation, double wormRadius, double mass) { private static Coordinate calcLocation(Coordinate wormLocation, double wormOrientation, double wormRadius, double mass) {

View File

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