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();
// DRAW MONSTER
model.getMonster().drawMonster(renderer,polygonSpriteBatch);
//model.getMonster().drawMonster(renderer,polygonSpriteBatch);
}
}

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

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

Loading…
Cancel
Save