Added health bar

This commit is contained in:
Ziver Koc 2007-04-17 12:51:26 +00:00
parent f7c3a895f0
commit adbfa34350
4 changed files with 113 additions and 26 deletions

View file

@ -2,14 +2,11 @@ package ei.game.scene.units;
import ei.engine.math.Vector2f;
import ei.engine.math.Vector2i;
import ei.engine.math.Vector4f;
import ei.engine.scene.Box;
import ei.engine.scene.Entity;
import ei.engine.scene.Sprite;
import ei.engine.texture.Texture;
import ei.game.scene.SelectBox;
public class Tank extends Unit{
private Box box;
private SelectBox selectionBox;
public Tank() {
this(0, 0);
}
@ -19,17 +16,12 @@ public class Tank extends Unit{
Sprite sp = new Sprite("Tank", "data/units/tank.png");
sp.setSize(new Vector2f(50,37));
getNode().add(sp);
Texture tex = new Texture();
tex.setColor(new Vector4f(0.5f, 1.0f, 0.5f,1));
box = new Box("selectionBox",tex);
box.setSize(new Vector2f(40,40));
selectionBox = new SelectBox(40,40,getMaxLife());
}
protected Entity getSelection() {
return box;
protected SelectBox getSelection() {
return selectionBox;
}

View file

@ -45,10 +45,10 @@ public abstract class Unit extends GameEntity{
public void setSelected(boolean b) {
super.setSelected(b);
if(b) {
unitNode.add(getSelection());
unitNode.add(getSelection().getNode());
}
else{
unitNode.remove(getSelection());
unitNode.remove(getSelection().getNode());
}
}
@ -94,6 +94,8 @@ public abstract class Unit extends GameEntity{
* Updating the unit
*/
public void update() {
getSelection().setValue(getLife());
if(moveTo != null) {
Vector2i moveVect = Map.getPosByPixel(moveTo.getX(), moveTo.getY());
Vector2i currentVect = Map.getPosByPixel(unitNode.getLocation().getX(), unitNode.getLocation().getY());