Polygon draw method added

master
Jonathan Hager 5 years ago
parent befc5ed380
commit 67af4e97f1

@ -1,6 +1,9 @@
package com.trs.game; package com.trs.game;
import com.badlogic.gdx.math.Polygon;
public class StaticMath { public class StaticMath {
public static double calculateAngle(int xPos1, int yPos1, int xPos2, int yPos2){ public static double calculateAngle(int xPos1, int yPos1, int xPos2, int yPos2){
float deltaX = xPos2 - xPos1; float deltaX = xPos2 - xPos1;
float deltaY = yPos2 - yPos1; float deltaY = yPos2 - yPos1;
@ -37,4 +40,24 @@ public class StaticMath {
return angle; 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);
}
} }

@ -1,15 +1,15 @@
package com.trs.game.model; package com.trs.game.model;
import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Polygon;
public class PermWall implements Wall { public class PermWall implements Wall {
private double rotation; 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.rotation = rotation;
this.rect = rect; this.polygon = polygon;
} }
@Override @Override
@ -25,12 +25,12 @@ public class PermWall implements Wall {
this.rotation = rotation; this.rotation = rotation;
} }
public Rectangle getRect() { public Polygon getPolygon() {
return rect; return polygon;
} }
public void setRect(Rectangle rect) { public void setPolygon(Polygon polygon) {
this.rect = rect; this.polygon = polygon;
} }
} }

@ -39,7 +39,7 @@ public class Projectile {
private void checkCollision(ArrayList<Wall> walls){ private void checkCollision(ArrayList<Wall> walls){
for(Wall wall : walls){ for(Wall wall : walls){
if(Intersector.overlaps(circle, wall.getRect())){ if(/*Intersector.overlaps(circle, wall.getPolygon())*/ false){
circle.x -= movementX; circle.x -= movementX;
circle.y -= movementY; circle.y -= movementY;

@ -1,17 +1,17 @@
package com.trs.game.model; package com.trs.game.model;
import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Polygon;
public class TempWall implements Wall { public class TempWall implements Wall {
private double rotation; private double rotation;
private Rectangle rect; private Polygon polygon;
private int lifetime; private int lifetime;
public TempWall(double rotation, Rectangle rect, int lifetime){ public TempWall(double rotation, Polygon polygon, int lifetime){
this.rotation = rotation; this.rotation = rotation;
this.rect = rect; this.polygon = polygon;
this.lifetime = lifetime; this.lifetime = lifetime;
} }
@ -28,12 +28,12 @@ public class TempWall implements Wall {
this.rotation = rotation; this.rotation = rotation;
} }
public Rectangle getRect() { public Polygon getPolygon() {
return rect; return polygon;
} }
public void setRect(Rectangle rect) { public void setPolygon(Polygon polygon) {
this.rect = rect; this.polygon = polygon;
} }
public int getLifetime() { public int getLifetime() {

@ -1,9 +1,9 @@
package com.trs.game.model; package com.trs.game.model;
import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Polygon;
public interface Wall { public interface Wall {
public Wall timerStep(); public Wall timerStep();
public Rectangle getRect(); public Polygon getPolygon();
public double getRotation(); public double getRotation();
} }

Loading…
Cancel
Save