fixed
This commit is contained in:
parent
8ff57fda63
commit
98cd3b8287
1 changed files with 26 additions and 20 deletions
|
|
@ -27,6 +27,7 @@ public abstract class Unit extends GameEntity{
|
||||||
private Weapon weapon;
|
private Weapon weapon;
|
||||||
// Som temp pos for moving the unit
|
// Som temp pos for moving the unit
|
||||||
private Vector2i oldPos;
|
private Vector2i oldPos;
|
||||||
|
private Vector2i oldVect;
|
||||||
private Vector2f moveTo;
|
private Vector2f moveTo;
|
||||||
private LinkedList<AStarNode> path;
|
private LinkedList<AStarNode> path;
|
||||||
|
|
||||||
|
|
@ -86,6 +87,7 @@ public abstract class Unit extends GameEntity{
|
||||||
|
|
||||||
if(path != null && !path.isEmpty() && moveTo == null){
|
if(path != null && !path.isEmpty() && moveTo == null){
|
||||||
AStarNode temp = path.poll();
|
AStarNode temp = path.poll();
|
||||||
|
oldVect = new Vector2i((int)unitNode.getLocation().getX(), (int)unitNode.getLocation().getY());
|
||||||
moveTo = Map.getPixelByPos(temp.getX(), temp.getY());
|
moveTo = Map.getPixelByPos(temp.getX(), temp.getY());
|
||||||
setPos(temp.getX(), temp.getY());
|
setPos(temp.getX(), temp.getY());
|
||||||
}
|
}
|
||||||
|
|
@ -99,49 +101,52 @@ public abstract class Unit extends GameEntity{
|
||||||
|
|
||||||
if(moveTo != null) {
|
if(moveTo != null) {
|
||||||
Vector2i moveVect = new Vector2i((int)moveTo.getX(),(int)moveTo.getY());
|
Vector2i moveVect = new Vector2i((int)moveTo.getX(),(int)moveTo.getY());
|
||||||
Vector2i currentVect = new Vector2i((int)unitNode.getLocation().getX(), (int)unitNode.getLocation().getY());
|
//Vector2i currentVect = new Vector2i((int)unitNode.getLocation().getX(), (int)unitNode.getLocation().getY());
|
||||||
|
|
||||||
int moveXminus = moveVect.getX()-currentVect.getX();
|
|
||||||
int moveYminus = moveVect.getY()-currentVect.getY();
|
|
||||||
System.out.println(moveVect.getY());
|
|
||||||
System.out.println(currentVect);
|
|
||||||
|
|
||||||
float divideY = (moveVect.getY()+1)/(currentVect.getY()+1);
|
int moveXminus = moveVect.getX()-oldVect.getX();
|
||||||
float divideX = (moveVect.getX()+1)/(currentVect.getX()+1);
|
int moveYminus = moveVect.getY()-oldVect.getY();
|
||||||
|
System.out.println("moveVect: "+moveVect);
|
||||||
|
//System.out.println("currentVect: "+currentVect);
|
||||||
|
|
||||||
|
float divideY = (moveVect.getY()+1)/(oldVect.getY()+1);
|
||||||
|
float divideX = (moveVect.getX()+1)/(oldVect.getX()+1);
|
||||||
|
|
||||||
//The rotation animation is done here.
|
//The rotation animation is done here.
|
||||||
if(moveVect.getX() < currentVect.getX() && divideY==1) {
|
if(moveVect.getX() < oldVect.getX() && divideY==1) {
|
||||||
unitNode.get("Tank").setRotation(new Vector3f(0, 0, 90));
|
unitNode.get("Tank").setRotation(new Vector3f(0, 0, 90));
|
||||||
}
|
}
|
||||||
if(moveVect.getY() > currentVect.getY() && divideX==1) {
|
|
||||||
unitNode.get("Tank").setRotation(new Vector3f(0, 0, 0));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(moveVect.getX() > currentVect.getX() && divideY==1) {
|
if(moveVect.getX() > oldVect.getX() && divideY==1) {
|
||||||
unitNode.get("Tank").setRotation(new Vector3f(0, 0, -90));
|
unitNode.get("Tank").setRotation(new Vector3f(0, 0, -90));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(moveVect.getY() < currentVect.getY() && divideX==1) {
|
if(moveVect.getY() < oldVect.getY() && divideX==1) {
|
||||||
unitNode.get("Tank").setRotation(new Vector3f(0, 0, 180));
|
unitNode.get("Tank").setRotation(new Vector3f(0, 0, 180));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(moveVect.getY() > oldVect.getY() && divideX==1) {
|
||||||
|
unitNode.get("Tank").setRotation(new Vector3f(0, 0, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//Diagonally.
|
//Diagonally.
|
||||||
if(moveVect.getX() > currentVect.getX() && moveVect.getY() > currentVect.getY()
|
if(moveVect.getX() > oldVect.getX() && moveVect.getY() > oldVect.getY()
|
||||||
&& moveXminus>=2 && moveYminus>=2) {
|
&& moveXminus>=2 && moveYminus>=2) {
|
||||||
unitNode.get("Tank").setRotation(new Vector3f(0, 0, -45));
|
unitNode.get("Tank").setRotation(new Vector3f(0, 0, -45));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(moveVect.getX() < currentVect.getX() && moveVect.getY() < currentVect.getY()
|
if(moveVect.getX() < oldVect.getX() && moveVect.getY() < oldVect.getY()
|
||||||
&& moveXminus<=-2 && moveYminus<=-2) {
|
&& moveXminus<=-2 && moveYminus<=-2) {
|
||||||
unitNode.get("Tank").setRotation(new Vector3f(0, 0, 135));
|
unitNode.get("Tank").setRotation(new Vector3f(0, 0, 135));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(moveVect.getX() > currentVect.getX() && moveVect.getY() < currentVect.getY()
|
if(moveVect.getX() > oldVect.getX() && moveVect.getY() < oldVect.getY()
|
||||||
&& moveXminus>=2 && moveYminus<=-2) {
|
&& moveXminus>=2 && moveYminus<=-2) {
|
||||||
unitNode.get("Tank").setRotation(new Vector3f(0, 0, -135));
|
unitNode.get("Tank").setRotation(new Vector3f(0, 0, -135));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(moveVect.getX() < currentVect.getX() && moveVect.getY() > currentVect.getY()
|
if(moveVect.getX() < oldVect.getX() && moveVect.getY() > oldVect.getY()
|
||||||
&& moveXminus<=-2 && moveYminus>=2) {
|
&& moveXminus<=-2 && moveYminus>=2) {
|
||||||
unitNode.get("Tank").setRotation(new Vector3f(0, 0, 45));
|
unitNode.get("Tank").setRotation(new Vector3f(0, 0, 45));
|
||||||
}
|
}
|
||||||
|
|
@ -168,6 +173,7 @@ public abstract class Unit extends GameEntity{
|
||||||
if(path != null && !path.isEmpty()){
|
if(path != null && !path.isEmpty()){
|
||||||
AStarNode temp = path.poll();
|
AStarNode temp = path.poll();
|
||||||
if(InGameState.getMap().isPosEmpty(temp.getX(), temp.getY())){
|
if(InGameState.getMap().isPosEmpty(temp.getX(), temp.getY())){
|
||||||
|
oldVect = new Vector2i((int)moveTo.getX(), (int)moveTo.getY());
|
||||||
moveTo = Map.getPixelByPos(temp.getX(), temp.getY());
|
moveTo = Map.getPixelByPos(temp.getX(), temp.getY());
|
||||||
setPos(temp.getX(), temp.getY());
|
setPos(temp.getX(), temp.getY());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue