errors fixen
This commit is contained in:
@@ -4,6 +4,8 @@ import static java.lang.Math.*;
|
|||||||
|
|
||||||
import worms.util.Coordinate;
|
import worms.util.Coordinate;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public abstract class Projectile extends GameObject {
|
public abstract class Projectile extends GameObject {
|
||||||
|
|
||||||
private static final int rho = 7800;
|
private static final int rho = 7800;
|
||||||
@@ -79,7 +81,7 @@ public abstract class Projectile extends GameObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private double jumpVelocity() {
|
private double jumpVelocity() {
|
||||||
return getForce()/getMass() * FORCE_TIME;
|
return (getForce()/getMass()) * FORCE_TIME;
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getJumpTime(double jumpTimeStep) {
|
public double getJumpTime(double jumpTimeStep) {
|
||||||
@@ -94,12 +96,12 @@ public abstract class Projectile extends GameObject {
|
|||||||
while (true) {
|
while (true) {
|
||||||
time += 0.05;
|
time += 0.05;
|
||||||
double x = loc.getX() + v * time * cos(a);
|
double x = loc.getX() + v * time * cos(a);
|
||||||
double y = loc.getY() + v * time * sin(a) - (G * time * time) / 2.0;
|
double y = loc.getY() + v * time * sin(a) - (0.5 * G * time * time);
|
||||||
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 -= 0.01;
|
||||||
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) - (0.5 * G * time * time));
|
||||||
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)) {
|
||||||
break;
|
break;
|
||||||
@@ -111,7 +113,6 @@ public abstract class Projectile extends GameObject {
|
|||||||
throw new RuntimeException();
|
throw new RuntimeException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,21 +129,28 @@ public abstract class Projectile extends GameObject {
|
|||||||
double a = getOrientation();
|
double a = getOrientation();
|
||||||
Coordinate newLocation;
|
Coordinate newLocation;
|
||||||
|
|
||||||
|
List<Worm> worms = getWorld().getGameObjectsByClass(Worm.class);
|
||||||
|
|
||||||
|
for (Worm worm: worms) {
|
||||||
|
if (this.getDistance(worm) < 0) {
|
||||||
|
newLocation = Coordinate.create(getLocation().getX(), getLocation().getY());
|
||||||
|
setLocation(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.
|
|
||||||
if (getWorld().isAdjacent(getLocation(),getRadius())) {
|
if (getWorld().isAdjacent(getLocation(),getRadius())) {
|
||||||
newLocation = Coordinate.create(getLocation().getX(), getLocation().getY());
|
newLocation = Coordinate.create(getLocation().getX(), getLocation().getY());
|
||||||
|
setLocation(newLocation);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
newLocation = Coordinate.create(getLocation().getX() + v * t * cos(a), getLocation().getY() + v * t * sin(a) - (G * t * t) / 2.0);
|
newLocation = Coordinate.create(getLocation().getX() + v * t * cos(a), getLocation().getY() + v * t * sin(a) - (G * t * t) / 2.0);
|
||||||
|
setLocation(newLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! isValidLocation(newLocation)) {
|
if (! isValidLocation(newLocation)) {
|
||||||
terminate();
|
terminate();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setLocation(newLocation);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Coordinate calcLocation(Coordinate wormLocation, double wormOrientation, double wormRadius, double mass) {
|
private static Coordinate calcLocation(Coordinate wormLocation, double wormOrientation, double wormRadius, double mass) {
|
||||||
|
@@ -1226,9 +1226,6 @@ public class Worm extends GameObject {
|
|||||||
|
|
||||||
public Projectile fire() {
|
public Projectile fire() {
|
||||||
if (canFire()) {
|
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()) {
|
if (! getWorld().getGameObjectsByClass(Projectile.class).isEmpty()) {
|
||||||
List<Projectile> projectiles = getWorld().getGameObjectsByClass(Projectile.class);
|
List<Projectile> projectiles = getWorld().getGameObjectsByClass(Projectile.class);
|
||||||
for (Projectile project: projectiles) {
|
for (Projectile project: projectiles) {
|
||||||
|
Reference in New Issue
Block a user