before change to polygon

master
Jonathan Hager 5 years ago
parent 1a4793d22f
commit baeba0c9fc

@ -20,10 +20,10 @@ public class Model {
}
public void timerStep(){
monster.move();
monster.move(walls);
for(Projectile projectile : projectiles){
projectile.move();
projectile.move(walls);
}
}

@ -4,6 +4,8 @@ import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import com.trs.game.StaticMath;
import java.util.ArrayList;
public class Monster {
private final int SPEED = 3;
@ -42,7 +44,7 @@ public class Monster {
renderer.end();
}
public void move(){
public void move(ArrayList<Wall> walls){
checkTarget();
this.xPos += this.movementX;

@ -1,8 +1,14 @@
package com.trs.game.model;
import com.badlogic.gdx.math.Circle;
import com.badlogic.gdx.math.Intersector;
import com.badlogic.gdx.math.Polygon;
import com.badlogic.gdx.math.Rectangle;
import com.trs.game.StaticMath;
import java.lang.reflect.Array;
import java.util.ArrayList;
public class Projectile {
private final int SPEED = 3;
@ -22,15 +28,40 @@ public class Projectile {
movementY = Math.sin(angle) * SPEED;
}
public void collision(){
}
public void move(){
public void move(ArrayList<Wall> walls){
checkCollision(walls);
circle.x += this.movementX;
circle.y += this.movementY;
}
private void checkCollision(ArrayList<Wall> walls){
for(Wall wall : walls){
if(Intersector.overlaps(circle, wall.getRect())){
circle.x -= movementX;
circle.y -= movementY;
collision(wall);
break;
}
}
}
private void collision(Wall wall){
System.out.println("Collision");
double alpha = Math.atan(movementY/movementX);
double delta = (Math.PI / 2) - Math.toRadians(wall.getRotation());
double beta = +((Math.PI / 2) - alpha - delta);
double phi = beta + Math.toRadians(wall.getRotation());
movementX = Math.cos(phi) * SPEED;
movementY = Math.sin(phi) * SPEED;
}
public int getxPos() {
return (int) circle.x;
}

Loading…
Cancel
Save