2007-03-29 23:21:00 +00:00
|
|
|
package ei.game.scene.buildings;
|
|
|
|
|
|
2007-04-23 13:58:47 +00:00
|
|
|
import java.util.LinkedList;
|
2007-04-04 14:45:44 +00:00
|
|
|
import java.util.Queue;
|
2007-03-29 23:21:00 +00:00
|
|
|
|
2007-04-23 13:58:47 +00:00
|
|
|
import ei.engine.math.Vector2i;
|
|
|
|
|
import ei.engine.scene.Node;
|
|
|
|
|
import ei.game.gamestate.InGameState;
|
2007-04-18 17:02:58 +00:00
|
|
|
import ei.game.player.Player;
|
2007-03-29 23:21:00 +00:00
|
|
|
import ei.game.scene.GameEntity;
|
2007-04-23 13:58:47 +00:00
|
|
|
import ei.game.scene.Map;
|
2007-03-29 23:21:00 +00:00
|
|
|
import ei.game.scene.units.Unit;
|
|
|
|
|
|
2007-04-24 12:57:38 +00:00
|
|
|
/**
|
|
|
|
|
* The Building class, handles buildings, this case CommandCenter class.
|
|
|
|
|
* @author Jesper Lundin
|
|
|
|
|
*
|
|
|
|
|
*/
|
2007-03-29 23:21:00 +00:00
|
|
|
public abstract class Building extends GameEntity{
|
2007-04-04 14:45:44 +00:00
|
|
|
private Queue<Unit> buildQueue;
|
2007-04-23 20:58:24 +00:00
|
|
|
private int buildTime;
|
2007-04-23 13:58:47 +00:00
|
|
|
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;
|
2007-04-23 20:58:24 +00:00
|
|
|
buildQueue = new LinkedList<Unit>();
|
2007-04-23 13:58:47 +00:00
|
|
|
unitNode = new Node("UnitNode");
|
|
|
|
|
unitNode.setLocation(Map.getPixelByPos(pos.getX(), pos.getY(), this.size));
|
|
|
|
|
setPos(pos.getX(), pos.getY(), this.size);
|
|
|
|
|
}
|
2007-03-29 23:21:00 +00:00
|
|
|
|
2007-04-23 13:58:47 +00:00
|
|
|
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);
|
2007-03-29 23:21:00 +00:00
|
|
|
}
|
|
|
|
|
|
2007-04-23 13:58:47 +00:00
|
|
|
|
|
|
|
|
/**
|
2007-04-23 16:25:27 +00:00
|
|
|
* Removes this building from the game.
|
2007-04-23 13:58:47 +00:00
|
|
|
*
|
|
|
|
|
*/
|
2007-04-23 16:25:27 +00:00
|
|
|
public void removeBuilding(){
|
2007-04-23 13:58:47 +00:00
|
|
|
unitNode.remove(getSprite());
|
|
|
|
|
getPlayer().removeUnit(this);
|
2007-04-23 16:25:27 +00:00
|
|
|
InGameState.getMap().removeBuildPos(oldPos.getX(), oldPos.getY(), this.size);
|
2007-04-23 13:58:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Updating the unit
|
|
|
|
|
*/
|
|
|
|
|
public void update() {
|
|
|
|
|
|
|
|
|
|
if(getLife()<=0) {
|
2007-04-23 16:25:27 +00:00
|
|
|
removeBuilding();
|
2007-04-23 13:58:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2007-03-29 23:21:00 +00:00
|
|
|
}
|
2007-04-23 13:58:47 +00:00
|
|
|
|