Polygon draw method added

master
Jonathan Hager 5 years ago
parent befc5ed380
commit 67af4e97f1

@ -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);
}
}

@ -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;
}
}

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

@ -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() {

@ -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();
}

Loading…
Cancel
Save