Collision working

master
Jonathan Hager 5 years ago
parent ba2e228919
commit 72e091610b

@ -127,7 +127,7 @@ public class Controller extends ApplicationAdapter implements InputProcessor {
renderer.end(); renderer.end();
// DRAW MONSTER // DRAW MONSTER
model.getMonster().drawMonster(renderer,polygonSpriteBatch); //model.getMonster().drawMonster(renderer,polygonSpriteBatch);
} }
} }

@ -1,7 +1,5 @@
package com.trs.game.model; package com.trs.game.model;
import com.badlogic.gdx.math.Rectangle;
import com.trs.game.StaticMath; import com.trs.game.StaticMath;
import java.util.ArrayList; import java.util.ArrayList;
@ -14,10 +12,10 @@ public class Model {
public Model(){ public Model(){
monster = new Monster(250,150); monster = new Monster(250,150);
walls = new ArrayList<>(); walls = new ArrayList<>();
walls.add(new PermWall(20, StaticMath.createPolygon(250,250,30,25, 100))); walls.add(new PermWall(60, StaticMath.createPolygon(250,250, 60,25, 100)));
projectiles = new ArrayList<>(); projectiles = new ArrayList<>();
projectiles.add(new Projectile(200, 200, 1000, 600)); projectiles.add(new Projectile(315, 500, 315, 0));
} }
public void timerStep(){ public void timerStep(){

@ -1,5 +1,6 @@
package com.trs.game.model; package com.trs.game.model;
import com.badlogic.gdx.math.Intersector;
import com.badlogic.gdx.math.Polygon; import com.badlogic.gdx.math.Polygon;
import com.trs.game.StaticMath; import com.trs.game.StaticMath;
@ -7,7 +8,7 @@ import java.util.ArrayList;
public class Projectile { public class Projectile {
private final int SPEED = 3; private final double SPEED = 3;
private double movementX; private double movementX;
private double movementY; private double movementY;
@ -46,7 +47,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.getPolygon())*/ false){ if(Intersector.overlapConvexPolygons(polygon, wall.getPolygon())){
setxPos((int) (getxPos() - this.movementX)); setxPos((int) (getxPos() - this.movementX));
setyPos((int) (getyPos() - this.movementY)); setyPos((int) (getyPos() - this.movementY));
@ -78,17 +79,25 @@ public class Projectile {
} }
public void setxPos(int xPos){ public void setxPos(int xPos){
polygon.getVertices()[0] = xPos; float[] positions = polygon.getVertices();
polygon.getVertices()[2] = xPos + 5;
polygon.getVertices()[4] = xPos + 5; positions[0] = xPos;
polygon.getVertices()[6] = xPos; positions[2] = xPos + 5;
positions[4] = xPos + 5;
positions[6] = xPos;
polygon.setVertices(positions);
} }
public void setyPos(int yPos){ public void setyPos(int yPos){
polygon.getVertices()[1] = yPos; float[] positions = polygon.getVertices();
polygon.getVertices()[3] = yPos;
polygon.getVertices()[5] = yPos + 5; positions[1] = yPos;
polygon.getVertices()[7] = yPos + 5; positions[3] = yPos;
positions[5] = yPos + 5;
positions[7] = yPos + 5;
polygon.setVertices(positions);
} }
public int getRadius(){ public int getRadius(){

Loading…
Cancel
Save