package ei.game.scene.buildings; import java.util.LinkedList; import java.util.Queue; import ei.engine.math.Vector2i; import ei.engine.scene.Node; import ei.game.gamestate.InGameState; import ei.game.player.Player; import ei.game.scene.GameEntity; import ei.game.scene.Map; import ei.game.scene.units.Unit; public abstract class Building extends GameEntity{ private Queue buildQueue; private int buildTime; private Node unitNode; private Vector2i oldPos; private int size; public Building(int l, Vector2i pos, Player p, int size) { super(l, p); this.size = size; buildQueue = new LinkedList(); unitNode = new Node("UnitNode"); unitNode.setLocation(Map.getPixelByPos(pos.getX(), pos.getY(), this.size)); System.out.println("location: "+unitNode.getLocation()); setPos(pos.getX(), pos.getY(), this.size); } public void setSelected(boolean b) { if(b) { unitNode.add(getSelection().getSelectNode()); } else{ unitNode.remove(getSelection().getSelectNode()); } } public void setMouseOver(boolean b) { if(b) { unitNode.add(getSelection().getMouseOverNode()); } else{ unitNode.remove(getSelection().getMouseOverNode()); } } /** * Sets the size of the building. * @param size */ public void setSize(int size) { this.size = size; } /** * Returns the sprite for the unit * * @return The sprite for the unit */ public Node getNode(){ return unitNode; } /** * Changes the pos of the unit in the map * * @param x The x pos to move to * @param y The y pos to move to */ public void setPos(int x, int y, int size) { if(oldPos!=null) { InGameState.getMap().removeBuildPos(oldPos.getX(), oldPos.getY(), size); } oldPos = new Vector2i(x, y); InGameState.getMap().setBuildPos(this, x, y, size); } /** * Removes this building from the game. * */ public void removeBuilding(){ unitNode.remove(getSprite()); getPlayer().removeUnit(this); InGameState.getMap().removeBuildPos(oldPos.getX(), oldPos.getY(), this.size); } /** * Updating the unit */ public void update() { if(getLife()<=0) { removeBuilding(); } } }