69 lines
1.6 KiB
Java
69 lines
1.6 KiB
Java
package ei.game.scene;
|
|
|
|
import ei.engine.math.Vector2f;
|
|
import ei.engine.math.Vector4f;
|
|
import ei.engine.scene.Box;
|
|
import ei.engine.scene.Node;
|
|
import ei.engine.scene.Sprite;
|
|
import ei.engine.texture.Texture;
|
|
|
|
public class SelectBox {
|
|
private Node selectNode;
|
|
private Sprite value;
|
|
private int max;
|
|
private float width;
|
|
private static final float height = 3;
|
|
|
|
/**
|
|
* Creates a selection box with health bar
|
|
*
|
|
* @param x The size of the selection box
|
|
* @param y The size of the selection box
|
|
* @param max The max health of the object
|
|
*/
|
|
public SelectBox(float x, float y, int max){
|
|
this.max = max;
|
|
this.width = x;
|
|
selectNode = new Node("SelectionNode");
|
|
|
|
Texture tex = new Texture();
|
|
tex.setColor(new Vector4f(0.5f, 1.0f, 0.5f,1));
|
|
|
|
Texture tex2 = new Texture();
|
|
tex2.setColor(new Vector4f(0.3f, 1.0f, 0.3f, 0.6f));
|
|
|
|
value = new Sprite("Healthvalue",tex2);
|
|
value.setSize(new Vector2f(x,height));
|
|
value.setLocation(new Vector2f(0,-x/2+height/2));
|
|
selectNode.add(value);
|
|
|
|
Box bar = new Box("bar",tex);
|
|
bar.setSize(new Vector2f(x,height));
|
|
bar.setLocation(new Vector2f(0,-x/2+height/2));
|
|
selectNode.add(bar);
|
|
|
|
Box select = new Box("select",tex);
|
|
select.setSize(new Vector2f(x,y));
|
|
selectNode.add(select);
|
|
|
|
|
|
}
|
|
|
|
/**
|
|
* Returns the node of the selection
|
|
*
|
|
* @return The node of the selection
|
|
*/
|
|
public Node getNode(){
|
|
return selectNode;
|
|
}
|
|
|
|
/**
|
|
* Sets the value of the health bar
|
|
*
|
|
* @param v The value of the health bar
|
|
*/
|
|
public void setValue(int v){
|
|
value.setSize(new Vector2f((v/max)*width,height));
|
|
}
|
|
}
|