commit
41da1e8641
@ -1,4 +1,40 @@
|
|||||||
package com.trs.game;
|
package com.trs.game;
|
||||||
|
|
||||||
public class StaticMath {
|
public class StaticMath {
|
||||||
|
public static double calculateAngle(int xPos1, int yPos1, int xPos2, int yPos2){
|
||||||
|
float deltaX = xPos2 - xPos1;
|
||||||
|
float deltaY = yPos2 - yPos1;
|
||||||
|
|
||||||
|
double angle;
|
||||||
|
if(deltaY == 0){
|
||||||
|
if(deltaX < 0){
|
||||||
|
angle = Math.PI;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
angle = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(deltaX == 0 && deltaY >= 0){
|
||||||
|
angle = Math.PI / 2;
|
||||||
|
}
|
||||||
|
else if(deltaX == 0 && deltaY < 0){
|
||||||
|
angle = Math.PI / -2;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
angle = Math.abs(Math.atan(deltaY / deltaX));
|
||||||
|
|
||||||
|
if(deltaX < 0 && deltaY < 0){
|
||||||
|
angle = Math.PI + angle;
|
||||||
|
}
|
||||||
|
else if(deltaX < 0 && deltaY > 0){
|
||||||
|
angle = Math.PI - angle;
|
||||||
|
}
|
||||||
|
else if(deltaX > 0 && deltaY < 0){
|
||||||
|
angle = 2*Math.PI - angle;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return angle;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,45 @@
|
|||||||
package com.trs.game.model;
|
package com.trs.game.model;
|
||||||
|
|
||||||
|
import com.trs.game.StaticMath;
|
||||||
|
|
||||||
public class Monster {
|
public class Monster {
|
||||||
|
|
||||||
|
private final int SPEED = 3;
|
||||||
|
|
||||||
|
private int xPos;
|
||||||
|
private int yPos;
|
||||||
|
private double movementX;
|
||||||
|
private double movementY;
|
||||||
|
private int xPosTarget;
|
||||||
|
private int yPosTarget;
|
||||||
|
|
||||||
|
public Monster(int xPos, int yPos){
|
||||||
|
this.xPos = xPos;
|
||||||
|
this.yPos = yPos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void move(){
|
||||||
|
this.xPos += this.movementX;
|
||||||
|
this.yPos += this.movementY;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkTarget(){
|
||||||
|
if(this.xPos == this.xPosTarget && this.yPos == this.yPosTarget){
|
||||||
|
this.generateNewTarget();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void generateNewTarget(){
|
||||||
|
// TODO: generate new target coordinates
|
||||||
|
|
||||||
|
calculateMovement();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void calculateMovement(){
|
||||||
|
double angle = StaticMath.calculateAngle(this.xPos, this.yPos, this.xPosTarget, this.yPosTarget);
|
||||||
|
|
||||||
|
movementX = Math.cos(angle) * SPEED;
|
||||||
|
movementY = Math.sin(angle) * SPEED;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,33 @@
|
|||||||
package com.trs.game.model;
|
package com.trs.game.model;
|
||||||
|
|
||||||
|
import com.trs.game.StaticMath;
|
||||||
|
|
||||||
public class Projectile {
|
public class Projectile {
|
||||||
|
|
||||||
|
private final int SPEED = 3;
|
||||||
|
|
||||||
|
private int xPos;
|
||||||
|
private int yPos;
|
||||||
|
private double movementX;
|
||||||
|
private double movementY;
|
||||||
|
|
||||||
|
public Projectile(int xPos, int yPos, int xPosMonster, int yPosMonster){
|
||||||
|
this.xPos = xPos;
|
||||||
|
this.yPos = yPos;
|
||||||
|
|
||||||
|
// calculating values for movementX and movementY
|
||||||
|
double angle = StaticMath.calculateAngle(this.xPos, this.yPos, xPosMonster, yPosMonster);
|
||||||
|
|
||||||
|
movementX = Math.cos(angle) * SPEED;
|
||||||
|
movementY = Math.sin(angle) * SPEED;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void collision(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void move(){
|
||||||
|
this.xPos += this.movementX;
|
||||||
|
this.yPos += this.movementY;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in new issue