diff --git a/core/src/com/trs/game/StaticMath.java b/core/src/com/trs/game/StaticMath.java index fd86503..21bc659 100644 --- a/core/src/com/trs/game/StaticMath.java +++ b/core/src/com/trs/game/StaticMath.java @@ -1,6 +1,9 @@ package com.trs.game; +import com.badlogic.gdx.math.Polygon; + public class StaticMath { + public static double calculateAngle(int xPos1, int yPos1, int xPos2, int yPos2){ float deltaX = xPos2 - xPos1; float deltaY = yPos2 - yPos1; @@ -37,4 +40,24 @@ public class StaticMath { return angle; } + public static Polygon createPolygon(int xPos, int yPos, double angle, double width, double length){ + float[] points = new float[8]; + + double d = Math.sin(Math.toRadians(angle)) * width; + double e = Math.cos(Math.toRadians(angle)) * width; + double f = Math.sin(Math.toRadians(angle)) * length; + double g = Math.cos(Math.toRadians(angle)) * length; + + points[0] = xPos; + points[1] = yPos; + points[2] = points[0] + (float) e; + points[3] = points[1] - (float) d; + points[4] = points[2] + (float) g; + points[5] = points[3] + (float) f; + points[6] = points[4] - (float) e; + points[7] = points[5] + (float) d; + + return new Polygon(points); + } + } diff --git a/core/src/com/trs/game/model/PermWall.java b/core/src/com/trs/game/model/PermWall.java index 9c4314f..37c0560 100644 --- a/core/src/com/trs/game/model/PermWall.java +++ b/core/src/com/trs/game/model/PermWall.java @@ -1,15 +1,15 @@ package com.trs.game.model; -import com.badlogic.gdx.math.Rectangle; +import com.badlogic.gdx.math.Polygon; public class PermWall implements Wall { private double rotation; - private Rectangle rect; + private Polygon polygon; - public PermWall(double rotation, Rectangle rect){ + public PermWall(double rotation, Polygon polygon){ this.rotation = rotation; - this.rect = rect; + this.polygon = polygon; } @Override @@ -25,12 +25,12 @@ public class PermWall implements Wall { this.rotation = rotation; } - public Rectangle getRect() { - return rect; + public Polygon getPolygon() { + return polygon; } - public void setRect(Rectangle rect) { - this.rect = rect; + public void setPolygon(Polygon polygon) { + this.polygon = polygon; } } diff --git a/core/src/com/trs/game/model/Projectile.java b/core/src/com/trs/game/model/Projectile.java index eeac25e..6b4b7ec 100644 --- a/core/src/com/trs/game/model/Projectile.java +++ b/core/src/com/trs/game/model/Projectile.java @@ -39,7 +39,7 @@ public class Projectile { private void checkCollision(ArrayList walls){ for(Wall wall : walls){ - if(Intersector.overlaps(circle, wall.getRect())){ + if(/*Intersector.overlaps(circle, wall.getPolygon())*/ false){ circle.x -= movementX; circle.y -= movementY; diff --git a/core/src/com/trs/game/model/TempWall.java b/core/src/com/trs/game/model/TempWall.java index ed171e5..7d7fbaa 100644 --- a/core/src/com/trs/game/model/TempWall.java +++ b/core/src/com/trs/game/model/TempWall.java @@ -1,17 +1,17 @@ package com.trs.game.model; -import com.badlogic.gdx.math.Rectangle; +import com.badlogic.gdx.math.Polygon; public class TempWall implements Wall { private double rotation; - private Rectangle rect; + private Polygon polygon; private int lifetime; - public TempWall(double rotation, Rectangle rect, int lifetime){ + public TempWall(double rotation, Polygon polygon, int lifetime){ this.rotation = rotation; - this.rect = rect; + this.polygon = polygon; this.lifetime = lifetime; } @@ -28,12 +28,12 @@ public class TempWall implements Wall { this.rotation = rotation; } - public Rectangle getRect() { - return rect; + public Polygon getPolygon() { + return polygon; } - public void setRect(Rectangle rect) { - this.rect = rect; + public void setPolygon(Polygon polygon) { + this.polygon = polygon; } public int getLifetime() { diff --git a/core/src/com/trs/game/model/Wall.java b/core/src/com/trs/game/model/Wall.java index 66d18fb..4e108e9 100644 --- a/core/src/com/trs/game/model/Wall.java +++ b/core/src/com/trs/game/model/Wall.java @@ -1,9 +1,9 @@ package com.trs.game.model; -import com.badlogic.gdx.math.Rectangle; +import com.badlogic.gdx.math.Polygon; public interface Wall { public Wall timerStep(); - public Rectangle getRect(); + public Polygon getPolygon(); public double getRotation(); }