|
|
|
@@ -142,14 +142,14 @@ public class World {
|
|
|
|
|
public boolean isPassable(double[] center, double radius) {
|
|
|
|
|
|
|
|
|
|
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 lenY = Math.round((center[1] + radius * Math.sin(i)) * 10000) / 10000;
|
|
|
|
|
double lenX = center[0] + radius * Math.cos(i);
|
|
|
|
|
double lenY = center[1] + radius * Math.sin(i);
|
|
|
|
|
|
|
|
|
|
if (i < 1.58 && i > 1.57) {
|
|
|
|
|
lenY -= 0.00001;
|
|
|
|
|
lenY -= 0.0000000001;
|
|
|
|
|
}
|
|
|
|
|
else if (i < 0.79 && i > 0.78 ) {
|
|
|
|
|
lenX -= 0.00001;
|
|
|
|
|
lenX -= 0.0000000001;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!isPassable(lenX, lenY)) {
|
|
|
|
@@ -158,46 +158,6 @@ public class World {
|
|
|
|
|
}
|
|
|
|
|
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 ...
|
|
|
|
@@ -236,10 +196,10 @@ public class World {
|
|
|
|
|
int yCoord = map.length - 1 - (int) Math.floor(y / lengthY);
|
|
|
|
|
|
|
|
|
|
if (yCoord < 0 || yCoord >= map.length) {
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (xCoord < 0 || xCoord >= map[0].length) {
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return getMap()[yCoord][xCoord];
|
|
|
|
@@ -252,8 +212,6 @@ public class World {
|
|
|
|
|
// region objects
|
|
|
|
|
//===================================================================================
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Collection<Object> getAllItems() {
|
|
|
|
|
Set<Object> all = new HashSet<Object>();
|
|
|
|
|
all.add(getWormList());
|
|
|
|
@@ -278,9 +236,9 @@ public class World {
|
|
|
|
|
|
|
|
|
|
public void addWorm(Worm worm) throws IllegalArgumentException, NullPointerException, IllegalStateException {
|
|
|
|
|
|
|
|
|
|
if (hasActiveGame()) throw new IllegalStateException();
|
|
|
|
|
if (hasAsWorm(worm)) throw new IllegalArgumentException();
|
|
|
|
|
if (hasActiveGame() || hasAsWorm(worm)) throw new IllegalStateException();
|
|
|
|
|
getWormList().add(worm);
|
|
|
|
|
worm.setWorld(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void removeWorm(Worm worm) throws IllegalArgumentException, NullPointerException {
|
|
|
|
|