Merge branch 'master' of https://gitlab.principis.be/OGP/worms
This commit is contained in:
@@ -147,7 +147,11 @@ public class Facade implements IFacade {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public double getJumpTime(Worm worm, double deltaT) throws ModelException {
|
public double getJumpTime(Worm worm, double deltaT) throws ModelException {
|
||||||
return worm.jumpTime();
|
try {
|
||||||
|
return worm.jumpTime();
|
||||||
|
} catch(IllegalStateException e){
|
||||||
|
throw new ModelException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
// /**
|
||||||
|
@@ -9,5 +9,6 @@ public class Food extends GameObject {
|
|||||||
setRadius(0.2);
|
setRadius(0.2);
|
||||||
final double rho = 150;
|
final double rho = 150;
|
||||||
setMass(getRadius(), rho);
|
setMass(getRadius(), rho);
|
||||||
|
world.addFood(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -142,14 +142,14 @@ public class World {
|
|||||||
public boolean isPassable(double[] center, double radius) {
|
public boolean isPassable(double[] center, double radius) {
|
||||||
|
|
||||||
for (double i = 0; i < 2 * Math.PI; i += Math.PI / 180) {
|
for (double i = 0; i < 2 * Math.PI; i += Math.PI / 180) {
|
||||||
double lenX = Math.round((center[0] + radius * Math.cos(i)) * 10000) / 10000;
|
double lenX = center[0] + radius * Math.cos(i);
|
||||||
double lenY = Math.round((center[1] + radius * Math.sin(i)) * 10000) / 10000;
|
double lenY = center[1] + radius * Math.sin(i);
|
||||||
|
|
||||||
if (i < 1.58 && i > 1.57) {
|
if (i < 1.58 && i > 1.57) {
|
||||||
lenY -= 0.00001;
|
lenY -= 0.0000000001;
|
||||||
}
|
}
|
||||||
else if (i < 0.79 && i > 0.78 ) {
|
else if (i < 0.79 && i > 0.78 ) {
|
||||||
lenX -= 0.00001;
|
lenX -= 0.0000000001;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isPassable(lenX, lenY)) {
|
if (!isPassable(lenX, lenY)) {
|
||||||
@@ -158,46 +158,6 @@ public class World {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isUnderCircle(Coordinate square, Coordinate center, double radius) {
|
|
||||||
|
|
||||||
double angle = Math.atan2(center.getY() - square.getY(), square.getX() - center.getX());
|
|
||||||
if (angle < Math.PI && angle > Math.PI / 2) {
|
|
||||||
square = Coordinate.create(square.getX() + 1, square.getY() + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
else if (angle < Math.PI / 2 && angle > 0) angle = Math.PI / 4;
|
|
||||||
else if (angle < 0 && angle > -Math.PI / 2) angle = -Math.PI / 4;
|
|
||||||
else if (angle < 0 && angle > -Math.PI) angle = -3* Math.PI / 4;
|
|
||||||
|
|
||||||
if (square.getX() == center.getX() && square.getY() == center.getY()) return true;
|
|
||||||
|
|
||||||
double x = Math.abs(radius * Math.cos(angle) + center.getX());
|
|
||||||
double y = Math.abs(radius * Math.sin(angle) + center.getY());
|
|
||||||
|
|
||||||
return Math.floor(square.getX() / getLengthX()) - Math.floor(x / getLengthX()) == 0 &&
|
|
||||||
Math.floor(square.getY() / getLengthY()) - Math.floor(y / getLengthY()) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<Coordinate> getCircleList(Coordinate center, double radius) {
|
|
||||||
|
|
||||||
double[] pos = {Math.floor(center.getX() - radius), Math.floor(center.getY() - radius)};
|
|
||||||
ArrayList<Coordinate> circle = new ArrayList<Coordinate>();
|
|
||||||
int partsX = (int) Math.ceil(center.getX() + radius / getLengthX()) - (int) Math.floor((center.getX() - radius) / getLengthX());
|
|
||||||
int partsY = (int) Math.ceil(center.getY() + radius / getLengthY()) - (int) Math.floor((center.getY() - radius) / getLengthY());
|
|
||||||
|
|
||||||
for (int x = 0; x < partsX; x++) {
|
|
||||||
for (int y = 0; y < partsY; y++) {
|
|
||||||
Coordinate temp = Coordinate.create(pos[0] + x * getLengthX(), pos[1] + y * getLengthY());
|
|
||||||
if (isUnderCircle(temp, center, radius)) {
|
|
||||||
circle.add(temp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return circle;
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param center ...
|
* @param center ...
|
||||||
@@ -236,10 +196,10 @@ public class World {
|
|||||||
int yCoord = map.length - 1 - (int) Math.floor(y / lengthY);
|
int yCoord = map.length - 1 - (int) Math.floor(y / lengthY);
|
||||||
|
|
||||||
if (yCoord < 0 || yCoord >= map.length) {
|
if (yCoord < 0 || yCoord >= map.length) {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
if (xCoord < 0 || xCoord >= map[0].length) {
|
if (xCoord < 0 || xCoord >= map[0].length) {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return getMap()[yCoord][xCoord];
|
return getMap()[yCoord][xCoord];
|
||||||
@@ -252,8 +212,6 @@ public class World {
|
|||||||
// region objects
|
// region objects
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public Collection<Object> getAllItems() {
|
public Collection<Object> getAllItems() {
|
||||||
Set<Object> all = new HashSet<Object>();
|
Set<Object> all = new HashSet<Object>();
|
||||||
all.add(getWormList());
|
all.add(getWormList());
|
||||||
@@ -278,9 +236,9 @@ public class World {
|
|||||||
|
|
||||||
public void addWorm(Worm worm) throws IllegalArgumentException, NullPointerException, IllegalStateException {
|
public void addWorm(Worm worm) throws IllegalArgumentException, NullPointerException, IllegalStateException {
|
||||||
|
|
||||||
if (hasActiveGame()) throw new IllegalStateException();
|
if (hasActiveGame() || hasAsWorm(worm)) throw new IllegalStateException();
|
||||||
if (hasAsWorm(worm)) throw new IllegalArgumentException();
|
|
||||||
getWormList().add(worm);
|
getWormList().add(worm);
|
||||||
|
worm.setWorld(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeWorm(Worm worm) throws IllegalArgumentException, NullPointerException {
|
public void removeWorm(Worm worm) throws IllegalArgumentException, NullPointerException {
|
||||||
|
@@ -134,6 +134,7 @@ public class Worm extends GameObject {
|
|||||||
this(Coordinate.create(location), direction, name, radius, 0.25);
|
this(Coordinate.create(location), direction, name, radius, 0.25);
|
||||||
setWorld(world);
|
setWorld(world);
|
||||||
setTeam(team);
|
setTeam(team);
|
||||||
|
world.addWorm(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
//===================================================================================
|
//===================================================================================
|
||||||
|
Reference in New Issue
Block a user