Fixed with nodes and selection
This commit is contained in:
parent
c1e3fcdf9e
commit
1cb10a3166
5 changed files with 75 additions and 29 deletions
|
|
@ -3,14 +3,20 @@ package ei.game.scene.units;
|
|||
|
||||
import ei.engine.math.Vector2f;
|
||||
import ei.engine.math.Vector2i;
|
||||
import ei.engine.scene.Node;
|
||||
import ei.engine.scene.Sprite;
|
||||
import ei.game.gamestate.InGameState;
|
||||
import ei.game.scene.GameEntity;
|
||||
import ei.game.scene.weapons.Weapon;
|
||||
|
||||
/**
|
||||
* The Unit class, handles the units in the game.
|
||||
* @author Jesper Lundin
|
||||
*
|
||||
*/
|
||||
public abstract class Unit extends GameEntity{
|
||||
// The texture
|
||||
private Sprite looks;
|
||||
private Node unitNode;
|
||||
// The wepon of the unit
|
||||
private Weapon weapon;
|
||||
// Som temp pos for moving the unit
|
||||
|
|
@ -24,28 +30,27 @@ public abstract class Unit extends GameEntity{
|
|||
*/
|
||||
public Unit(int l) {
|
||||
super(l);
|
||||
looks = new Sprite("none");
|
||||
unitNode = new Node("unit");
|
||||
setPos(0, 0);
|
||||
}
|
||||
public void setSelected(boolean b) {
|
||||
super.setSelected(b);
|
||||
if(b) {
|
||||
unitNode.add(getSelection());
|
||||
}
|
||||
else{
|
||||
unitNode.remove(getSelection());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sprite for the unit
|
||||
*
|
||||
* @return The sprite for the unit
|
||||
*/
|
||||
public Sprite getSprite(){
|
||||
return looks;
|
||||
public Node getNode(){
|
||||
return unitNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the sprite for the unit
|
||||
*
|
||||
* @param image The sprite for the unit
|
||||
*/
|
||||
public void setSprite(Sprite image) {
|
||||
looks = image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the pos of the unit whitout removing it from the old
|
||||
*
|
||||
|
|
@ -78,21 +83,21 @@ public abstract class Unit extends GameEntity{
|
|||
*/
|
||||
public void update() {
|
||||
if(moveTo!=null) {
|
||||
if(moveTo.getX() > looks.getLocation().getX()) {
|
||||
looks.getLocation().add(1.5f, 0f, 0f);
|
||||
if(moveTo.getX() > unitNode.getLocation().getX()) {
|
||||
unitNode.getLocation().add(1.5f, 0f, 0f);
|
||||
}
|
||||
if(moveTo.getX() < looks.getLocation().getX()) {
|
||||
looks.getLocation().add(-1.5f, 0f, 0f);
|
||||
if(moveTo.getX() < unitNode.getLocation().getX()) {
|
||||
unitNode.getLocation().add(-1.5f, 0f, 0f);
|
||||
}
|
||||
if(moveTo.getY() > looks.getLocation().getY()) {
|
||||
looks.getLocation().add(0f, 1.5f, 0f);
|
||||
if(moveTo.getY() > unitNode.getLocation().getY()) {
|
||||
unitNode.getLocation().add(0f, 1.5f, 0f);
|
||||
}
|
||||
if(moveTo.getY() < looks.getLocation().getY()) {
|
||||
looks.getLocation().add(0f, -1.5f, 0f);
|
||||
if(moveTo.getY() < unitNode.getLocation().getY()) {
|
||||
unitNode.getLocation().add(0f, -1.5f, 0f);
|
||||
}
|
||||
|
||||
if(moveTo.getX() == looks.getLocation().getX()
|
||||
&& moveTo.getY() == looks.getLocation().getY()) {
|
||||
if(moveTo.getX() == unitNode.getLocation().getX()
|
||||
&& moveTo.getY() == unitNode.getLocation().getY()) {
|
||||
moveTo = null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue