Added hud

This commit is contained in:
Ziver Koc 2007-04-23 16:26:39 +00:00
parent 7e309db351
commit 31692d8b4e
6 changed files with 110 additions and 64 deletions

View file

@ -108,9 +108,14 @@ public class BitmapText extends Entity{
} // Loop Until All 256 Are Built
}
/**
* Returns the bound of this class
*/
public Rectangle getBound() {
// TODO Auto-generated method stub
return null;
return new Rectangle(
(int)getLocation().getX(),
(int)getLocation().getY(),
16*(text!=null?text.length():0),16);
}
@Override

View file

@ -3,6 +3,7 @@ package ei.game.gamestate;
import ei.engine.scene.Node;
import ei.engine.sound.Sound;
import ei.engine.state.GameState;
import ei.game.hud.InGameHud;
import ei.game.input.InGameMouseInput;
import ei.game.player.HumanPlayer;
import ei.game.player.PlayerHandler;
@ -16,6 +17,7 @@ import ei.game.scene.weapons.WeaponHandler;
public class InGameState extends GameState{
private Node rootNode;
private InGameHud hud;
private static Map map;
private Sound music;
@ -49,6 +51,8 @@ public class InGameState extends GameState{
music = new Sound("music", "data/sounds/ei.ogg");
music.loop();
hud = new InGameHud(player);
rootNode.add(hud.getNode());
}
/**
@ -64,6 +68,7 @@ public class InGameState extends GameState{
public void update() {
PlayerHandler.getInstance().update();
WeaponHandler.getInstance().update();
hud.update();
rootNode.update();
}

View file

@ -0,0 +1,38 @@
package ei.game.hud;
import ei.engine.LWJGLGameWindow;
import ei.engine.effects.BitmapText;
import ei.engine.math.Vector2f;
import ei.engine.scene.Node;
import ei.game.player.Player;
public class InGameHud {
private Node hudNode;
private BitmapText money;
private Player player;
public InGameHud(Player p){
player = p;
hudNode = new Node("Hud");
money = new BitmapText("MoneyMeter");
money.setLocation(new Vector2f(LWJGLGameWindow.getWidth()-money.getBound().width,0));
hudNode.add(money);
}
public void update(){
money.setText(""+player.getKredits());
money.setLocation(new Vector2f(LWJGLGameWindow.getWidth()-money.getBound().width,0));
player.addKredits(100);
hudNode.setLocation(new Vector2f(
LWJGLGameWindow.getCamera().getLocation().getX(),
LWJGLGameWindow.getCamera().getLocation().getY()));
}
public Node getNode(){
return hudNode;
}
}

View file

@ -1,38 +1,18 @@
package ei.game.player;
import java.util.ArrayList;
import ei.engine.scene.Entity;
import ei.engine.scene.Node;
import ei.game.scene.GameEntity;
import ei.game.scene.units.Unit;
import ei.game.scene.buildings.Building;
/**
* Mother nature
*
* @author Ziver
*
*/
public class GaiaPlayer extends Player{
private ArrayList<GameEntity> units;
private Node unitsNode;
public GaiaPlayer(){
units = new ArrayList<GameEntity>();
unitsNode = new Node("GaiaPlayerNode");
}
public void addUnit(GameEntity u){
units.add(u);
unitsNode.add(u.getNode());
}
public void removeUnit(GameEntity u){
units.remove(u);
unitsNode.remove(u.getNode());
}
public Node getNode(){
return unitsNode;
@Override
public Building getCC() {
return null;
}
public void update() {
for(int i=0; i<units.size() ;i++){
units.get(i).update();
}
}
}

View file

@ -1,37 +1,18 @@
package ei.game.player;
import java.util.ArrayList;
import ei.engine.scene.Node;
import ei.game.scene.GameEntity;
import ei.game.scene.units.Unit;
import ei.game.scene.buildings.Building;
import ei.game.scene.buildings.CommandCenter;
public class HumanPlayer extends Player{
private ArrayList<GameEntity> units;
private Node unitsNode;
private CommandCenter cc;
public HumanPlayer(){
units = new ArrayList<GameEntity>();
unitsNode = new Node("HumanPlayerNode");
super();
cc = new CommandCenter(10,10,this);
}
public void addUnit(GameEntity u){
units.add(u);
unitsNode.add(u.getNode());
}
public void removeUnit(GameEntity u){
units.remove(u);
unitsNode.remove(u.getNode());
}
public Node getNode(){
return unitsNode;
public Building getCC() {
return cc;
}
public void update() {
for(int i=0; i<units.size() ;i++){
units.get(i).update();
}
}
}

View file

@ -1,16 +1,53 @@
package ei.game.player;
import java.util.ArrayList;
import ei.engine.scene.Node;
import ei.game.scene.GameEntity;
import ei.game.scene.units.Unit;
import ei.game.scene.buildings.Building;
public abstract class Player {
private ArrayList<GameEntity> units;
private Node unitsNode;
private int kredits;
public abstract void addUnit(GameEntity u);
public Player(){
units = new ArrayList<GameEntity>();
unitsNode = new Node("HumanPlayerNode");
kredits = 1000;
}
public abstract void removeUnit(GameEntity u);
public void setKredits(int k){
kredits = k;
}
public abstract Node getNode();
public int getKredits(){
return kredits;
}
public abstract void update();
public void addKredits(int add){
kredits += add;
}
public void addUnit(GameEntity u){
units.add(u);
unitsNode.add(u.getNode());
}
public void removeUnit(GameEntity u){
units.remove(u);
unitsNode.remove(u.getNode());
}
public Node getNode(){
return unitsNode;
}
public void update() {
for(int i=0; i<units.size() ;i++){
units.get(i).update();
}
}
public abstract Building getCC();
}