diff --git a/OGP1718-Worms/src/worms/model/Projectile.java b/OGP1718-Worms/src/worms/model/Projectile.java index cd7876f..0b1a1dc 100644 --- a/OGP1718-Worms/src/worms/model/Projectile.java +++ b/OGP1718-Worms/src/worms/model/Projectile.java @@ -4,6 +4,8 @@ import static java.lang.Math.*; import worms.util.Coordinate; +import java.util.List; + public abstract class Projectile extends GameObject { private static final int rho = 7800; @@ -111,7 +113,6 @@ public abstract class Projectile extends GameObject { throw new RuntimeException(); } } - return time; } @@ -127,10 +128,16 @@ public abstract class Projectile extends GameObject { double t = getJumpTime(jumpTimeStep); double a = getOrientation(); Coordinate newLocation; - - //TODO In case the initial position of a projectile already hits impassable terrain or a worm, the projectile will - //TODO jump over a distance of 0.0 m. + List worms = getWorld().getGameObjectsByClass(Worm.class); + + for (Worm worm: worms) { + if (this.getDistance(worm) < 0) { + newLocation = Coordinate.create(getLocation().getX(), getLocation().getY()); + setLocation(newLocation); + } + } + if (getWorld().isAdjacent(getLocation(),getRadius())) { newLocation = Coordinate.create(getLocation().getX(), getLocation().getY()); } diff --git a/OGP1718-Worms/src/worms/model/Worm.java b/OGP1718-Worms/src/worms/model/Worm.java index 8eb79e3..e6c82b8 100644 --- a/OGP1718-Worms/src/worms/model/Worm.java +++ b/OGP1718-Worms/src/worms/model/Worm.java @@ -1227,9 +1227,6 @@ public class Worm extends GameObject { public Projectile fire() { if (canFire()) { - - //TODO location overlaps with 1 or more projectiles => firing worm is hit by one overlapping projectile - //TODO => method returns null if (!getWorld().getGameObjectsByClass(Projectile.class).isEmpty()) { List projectiles = getWorld().getGameObjectsByClass(Projectile.class); for (Projectile project: projectiles) {