Rotation half fixed

This commit is contained in:
Jesper Lundin 2007-04-17 13:09:50 +00:00
parent adbfa34350
commit 347a269c4d

View file

@ -71,7 +71,8 @@ public abstract class Unit extends GameEntity{
InGameState.getMap().removePos(oldPos.getX(), oldPos.getY()); InGameState.getMap().removePos(oldPos.getX(), oldPos.getY());
} }
oldPos = new Vector2i(x, y); oldPos = new Vector2i(x, y);
InGameState.getMap().setPos(this, x, y); InGameState.getMap().setPos(this, x, y);
System.out.println(oldPos);
} }
/** /**
@ -97,29 +98,57 @@ public abstract class Unit extends GameEntity{
getSelection().setValue(getLife()); getSelection().setValue(getLife());
if(moveTo != null) { if(moveTo != null) {
Vector2i moveVect = Map.getPosByPixel(moveTo.getX(), moveTo.getY()); Vector2i moveVect = new Vector2i((int)moveTo.getX(),(int)moveTo.getY());
Vector2i currentVect = Map.getPosByPixel(unitNode.getLocation().getX(), unitNode.getLocation().getY()); Vector2i currentVect = new Vector2i((int)unitNode.getLocation().getX(), (int)unitNode.getLocation().getY());
Vector3f lastRotation = new Vector3f(0, 0, 0);
//The rotation animation is done here.
if(moveVect.getX() < currentVect.getX()) {
unitNode.get("Tank").setRotation(new Vector3f(0, 0, 90));
}
if(moveVect.getX() > currentVect.getX()){
unitNode.get("Tank").setRotation(new Vector3f(0, 0, -90));
}
if(moveVect.getY() < currentVect.getY()){
unitNode.get("Tank").setRotation(new Vector3f(0, 0, 180));
}
if(moveVect.getY() > currentVect.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);
float divideX = (moveVect.getX()+1)/(currentVect.getX()+1);
//The rotation animation is done here.
if(moveVect.getX() < currentVect.getX() && divideY==1) {
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)); unitNode.get("Tank").setRotation(new Vector3f(0, 0, 0));
} }
if(moveVect.getX() > currentVect.getX() && divideY==1) {
unitNode.get("Tank").setRotation(new Vector3f(0, 0, -90));
}
if(moveVect.getY() < currentVect.getY() && divideX==1) {
unitNode.get("Tank").setRotation(new Vector3f(0, 0, 180));
}
//Diagonally.
if(moveVect.getX() > currentVect.getX() && moveVect.getY() > currentVect.getY()
&& moveXminus>=2 && moveYminus>=2) {
unitNode.get("Tank").setRotation(new Vector3f(0, 0, -45));
}
if(moveVect.getX() < currentVect.getX() && moveVect.getY() < currentVect.getY()
&& moveXminus<=-2 && moveYminus<=-2) {
unitNode.get("Tank").setRotation(new Vector3f(0, 0, 135));
}
if(moveVect.getX() > currentVect.getX() && moveVect.getY() < currentVect.getY()
&& moveXminus>=2 && moveYminus<=-2) {
unitNode.get("Tank").setRotation(new Vector3f(0, 0, -135));
}
if(moveVect.getX() < currentVect.getX() && moveVect.getY() > currentVect.getY()
&& moveXminus<=-2 && moveYminus>=2) {
unitNode.get("Tank").setRotation(new Vector3f(0, 0, 45));
}
//System.out.println(unitNode.get("Tank").getRotation()); //System.out.println(unitNode.get("Tank").getRotation());
//The moving is done here. //The moving is done here.
if(moveTo.getX() > unitNode.getLocation().getX()) { if(moveTo.getX() > unitNode.getLocation().getX()) {
unitNode.getLocation().add(1.5f, 0f, 0f); unitNode.getLocation().add(1.5f, 0f, 0f);
@ -133,7 +162,7 @@ public abstract class Unit extends GameEntity{
if(moveTo.getY() < unitNode.getLocation().getY()) { if(moveTo.getY() < unitNode.getLocation().getY()) {
unitNode.getLocation().add(0f, -1.5f, 0f); unitNode.getLocation().add(0f, -1.5f, 0f);
} }
if(Math.abs(moveTo.getX() - unitNode.getLocation().getX()) < 2 if(Math.abs(moveTo.getX() - unitNode.getLocation().getX()) < 2
&& Math.abs(moveTo.getY() - unitNode.getLocation().getY())< 2 ){ && Math.abs(moveTo.getY() - unitNode.getLocation().getY())< 2 ){
if(path != null && !path.isEmpty()){ if(path != null && !path.isEmpty()){