k
This commit is contained in:
parent
380415f035
commit
79ae1d0dcc
3 changed files with 27 additions and 5 deletions
|
|
@ -78,7 +78,7 @@ public class Node extends Sprite {
|
|||
super.setTranslationGL();
|
||||
//the rotation
|
||||
Rectangle rect = getBound();
|
||||
super.setRotationGL(rect.width/2,rect.height/2);
|
||||
//super.setRotationGL(rect.width/2,rect.height/2);
|
||||
//Sets the scale of the sprite
|
||||
super.setScaleGL();
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ public class Map {
|
|||
* @param y y pixels
|
||||
* @return The pos thats in the coordinates
|
||||
*/
|
||||
public Vector2i getPosByPixel(float x, float y){
|
||||
public static Vector2i getPosByPixel(float x, float y){
|
||||
x = x/POS_SIZE;
|
||||
y = y/POS_SIZE;
|
||||
return new Vector2i((int)x, (int)y);
|
||||
|
|
@ -52,7 +52,7 @@ public class Map {
|
|||
* @param y y pos
|
||||
* @return The coordinate of the pos
|
||||
*/
|
||||
public Vector2f getPixelByPos(int x, int y){
|
||||
public static Vector2f getPixelByPos(int x, int y){
|
||||
float xf = (POS_SIZE*x);
|
||||
float yf = (POS_SIZE*y);
|
||||
return new Vector2f(xf,yf);
|
||||
|
|
|
|||
|
|
@ -3,10 +3,12 @@ package ei.game.scene.units;
|
|||
|
||||
import ei.engine.math.Vector2f;
|
||||
import ei.engine.math.Vector2i;
|
||||
import ei.engine.math.Vector3f;
|
||||
import ei.engine.scene.Node;
|
||||
import ei.engine.scene.Sprite;
|
||||
import ei.game.gamestate.InGameState;
|
||||
import ei.game.scene.GameEntity;
|
||||
import ei.game.scene.Map;
|
||||
import ei.game.scene.weapons.Weapon;
|
||||
|
||||
/**
|
||||
|
|
@ -74,7 +76,7 @@ public abstract class Unit extends GameEntity{
|
|||
InGameState.getMap().removePos(oldPos.getX(), oldPos.getY());
|
||||
}
|
||||
setPos(x, y);
|
||||
moveTo = InGameState.getMap().getPixelByPos((int)x, (int)y);
|
||||
moveTo = Map.getPixelByPos((int)x, (int)y);
|
||||
oldPos = new Vector2i(x, y);
|
||||
}
|
||||
|
||||
|
|
@ -83,6 +85,26 @@ public abstract class Unit extends GameEntity{
|
|||
*/
|
||||
public void update() {
|
||||
if(moveTo!=null) {
|
||||
Vector2i moveVect = Map.getPosByPixel(moveTo.getX(), moveTo.getY());
|
||||
Vector2i currentVect = Map.getPosByPixel(unitNode.getLocation().getX(), unitNode.getLocation().getY());
|
||||
//System.out.println("going to: "+moveVect);
|
||||
//System.out.println("from: "+currentVect);
|
||||
Vector3f currentRot = null;
|
||||
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()) {
|
||||
unitNode.get("Tank").setRotation(new Vector3f(0, 0, 0));
|
||||
}
|
||||
//System.out.println(unitNode.get("Tank").getRotation());
|
||||
|
||||
if(moveTo.getX() > unitNode.getLocation().getX()) {
|
||||
unitNode.getLocation().add(1.5f, 0f, 0f);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue