package ei.game.scene.units; import ei.engine.math.Vector2f; import ei.engine.math.Vector2i; import ei.engine.scene.Sprite; import ei.game.gamestate.InGameState; import ei.game.scene.GameEntity; import ei.game.scene.weapons.Weapon; public abstract class Unit extends GameEntity{ // The texture private Sprite looks; // The wepon of the unit private Weapon weapon; // Som temp pos for moving the unit private Vector2i oldPos; private Vector2f moveTo; /** * Creates a empty unit * * @param l The max life of the unit */ public Unit(int l) { super(l); looks = new Sprite("none"); setPos(0, 0); } /** * Returns the sprite for the unit * * @return The sprite for the unit */ public Sprite getSprite(){ return looks; } /** * Set the sprite for the unit * * @param image The sprite for the unit */ public void setSprite(Sprite image) { looks = image; } /** * Sets the pos of the unit whitout removing it from the old * * @param x The x pos to move to * @param y The y pos to move to */ public void setPos(int x, int y) { oldPos = new Vector2i(x, y); InGameState.getMap().setPos(this, x, y); } /** * Moving a unit to the given pos * * @param x The x pos to move to * @param y The y pos to move to */ public void move(int x, int y) { if(oldPos!=null) { InGameState.getMap().removePos(oldPos.getX(), oldPos.getY()); } setPos(x, y); moveTo = InGameState.getMap().getPixelByPos((int)x, (int)y); oldPos = new Vector2i(x, y); } /** * Updating the unit */ public void update() { if(moveTo!=null) { if(moveTo.getX() > looks.getLocation().getX()) { looks.getLocation().add(1.5f, 0f, 0f); } if(moveTo.getX() < looks.getLocation().getX()) { looks.getLocation().add(-1.5f, 0f, 0f); } if(moveTo.getY() > looks.getLocation().getY()) { looks.getLocation().add(0f, 1.5f, 0f); } if(moveTo.getY() < looks.getLocation().getY()) { looks.getLocation().add(0f, -1.5f, 0f); } if(moveTo.getX() == looks.getLocation().getX() && moveTo.getY() == looks.getLocation().getY()) { moveTo = null; } } } }