diff --git a/core/src/com/trs/game/StaticMath.java b/core/src/com/trs/game/StaticMath.java index d016ca2..51196d8 100644 --- a/core/src/com/trs/game/StaticMath.java +++ b/core/src/com/trs/game/StaticMath.java @@ -63,7 +63,7 @@ public class StaticMath { public static Polygon[] createCollisionPolygons(Polygon wall){ Polygon[] collisionPolygons = new Polygon[4]; - + // first line of polygon float[] newVertices = wall.getVertices(); @@ -83,7 +83,7 @@ public class StaticMath { collisionPolygons[2] = new Polygon(newVertices); // second line of polygon - newVertices = wall.getVertices(); + newVertices = wall.getVertices(); newVertices[0] = newVertices[2]; newVertices[1] = newVertices[3] + 1; @@ -100,6 +100,7 @@ public class StaticMath { newVertices[5] = newVertices[7] - 1; collisionPolygons[3] = new Polygon(newVertices); + return collisionPolygons; } diff --git a/core/src/com/trs/game/model/PermWall.java b/core/src/com/trs/game/model/PermWall.java index 74b48e4..0a71ca8 100644 --- a/core/src/com/trs/game/model/PermWall.java +++ b/core/src/com/trs/game/model/PermWall.java @@ -7,10 +7,12 @@ public class PermWall implements Wall { private double rotation; private Polygon polygon; + private Polygon[] collisionPolygons; public PermWall(double rotation, Polygon polygon){ this.rotation = rotation; this.polygon = polygon; + collisionPolygons = StaticMath.createCollisionPolygons(polygon); } @Override @@ -24,6 +26,11 @@ public class PermWall implements Wall { return Math.toDegrees(StaticMath.calculateAngle((int) vertices[0], (int) vertices[1], (int) vertices[6], (int) vertices[7])); } + @Override + public Polygon[] getCollisionPolygons() { + return collisionPolygons; + } + public void setRotation(double rotation) { this.rotation = rotation; } diff --git a/core/src/com/trs/game/model/Projectile.java b/core/src/com/trs/game/model/Projectile.java index e3518cd..1ddc079 100644 --- a/core/src/com/trs/game/model/Projectile.java +++ b/core/src/com/trs/game/model/Projectile.java @@ -57,10 +57,8 @@ public class Projectile { private void collision(Wall wall){ System.out.println("Collision"); - Polygon[] collisionPolygons = StaticMath.createCollisionPolygons(wall.getPolygon()); - double collisionAngle = 0; - for(Polygon collision : collisionPolygons){ + for(Polygon collision : wall.getCollisionPolygons()){ if(Intersector.overlapConvexPolygons(polygon, collision)){ float[] vertices = collision.getVertices(); collisionAngle = StaticMath.calculateAngle((int) vertices[0], (int) vertices[1], (int) vertices[6], (int) vertices[7]); diff --git a/core/src/com/trs/game/model/TempWall.java b/core/src/com/trs/game/model/TempWall.java index d754b8f..728b6ba 100644 --- a/core/src/com/trs/game/model/TempWall.java +++ b/core/src/com/trs/game/model/TempWall.java @@ -9,11 +9,13 @@ public class TempWall implements Wall { private double rotation; private Polygon polygon; private int lifetime; + private Polygon[] collisionPolygons; public TempWall(double rotation, Polygon polygon, int lifetime){ this.rotation = rotation; this.polygon = polygon; this.lifetime = lifetime; + collisionPolygons = StaticMath.createCollisionPolygons(polygon); } @Override @@ -27,6 +29,11 @@ public class TempWall implements Wall { return Math.toDegrees(StaticMath.calculateAngle((int) vertices[0], (int) vertices[1], (int) vertices[6], (int) vertices[7])); } + @Override + public Polygon[] getCollisionPolygons() { + return collisionPolygons; + } + public void setRotation(double rotation) { this.rotation = rotation; } diff --git a/core/src/com/trs/game/model/Wall.java b/core/src/com/trs/game/model/Wall.java index 4e108e9..0e3a139 100644 --- a/core/src/com/trs/game/model/Wall.java +++ b/core/src/com/trs/game/model/Wall.java @@ -6,4 +6,5 @@ public interface Wall { public Wall timerStep(); public Polygon getPolygon(); public double getRotation(); + public Polygon[] getCollisionPolygons(); }