2007-03-29 23:21:00 +00:00
|
|
|
package ei.game.scene.units;
|
|
|
|
|
|
2007-04-04 18:16:37 +00:00
|
|
|
|
2007-04-05 12:45:22 +00:00
|
|
|
import ei.engine.math.Vector2f;
|
2007-04-04 14:44:25 +00:00
|
|
|
import ei.engine.math.Vector2i;
|
|
|
|
|
import ei.engine.scene.Sprite;
|
2007-04-04 16:28:57 +00:00
|
|
|
import ei.game.gamestate.InGameState;
|
2007-03-29 23:21:00 +00:00
|
|
|
import ei.game.scene.GameEntity;
|
2007-04-04 14:44:25 +00:00
|
|
|
import ei.game.scene.weapons.Weapon;
|
2007-03-29 23:21:00 +00:00
|
|
|
|
|
|
|
|
public abstract class Unit extends GameEntity{
|
2007-04-05 12:45:22 +00:00
|
|
|
// The texture
|
2007-04-04 14:44:25 +00:00
|
|
|
private Sprite looks;
|
2007-04-05 12:45:22 +00:00
|
|
|
// The wepon of the unit
|
2007-04-04 14:44:25 +00:00
|
|
|
private Weapon weapon;
|
2007-04-05 12:45:22 +00:00
|
|
|
// Som temp pos for moving the unit
|
2007-04-04 16:28:57 +00:00
|
|
|
private Vector2i oldPos;
|
2007-04-05 12:45:22 +00:00
|
|
|
private Vector2f moveTo;
|
2007-03-29 23:21:00 +00:00
|
|
|
|
2007-04-05 12:45:22 +00:00
|
|
|
/**
|
|
|
|
|
* Creates a empty unit
|
|
|
|
|
*
|
|
|
|
|
* @param l The max life of the unit
|
|
|
|
|
*/
|
2007-03-29 23:21:00 +00:00
|
|
|
public Unit(int l) {
|
|
|
|
|
super(l);
|
2007-04-04 16:28:57 +00:00
|
|
|
looks = new Sprite("none");
|
2007-04-04 18:15:11 +00:00
|
|
|
setPos(0, 0);
|
2007-03-29 23:21:00 +00:00
|
|
|
}
|
2007-04-04 14:44:25 +00:00
|
|
|
|
2007-04-05 12:45:22 +00:00
|
|
|
/**
|
|
|
|
|
* Returns the sprite for the unit
|
|
|
|
|
*
|
|
|
|
|
* @return The sprite for the unit
|
|
|
|
|
*/
|
2007-04-04 14:44:25 +00:00
|
|
|
public Sprite getSprite(){
|
|
|
|
|
return looks;
|
|
|
|
|
}
|
2007-04-05 12:45:22 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the sprite for the unit
|
|
|
|
|
*
|
|
|
|
|
* @param image The sprite for the unit
|
|
|
|
|
*/
|
2007-04-04 14:44:25 +00:00
|
|
|
public void setSprite(Sprite image) {
|
|
|
|
|
looks = image;
|
|
|
|
|
}
|
2007-04-05 12:45:22 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Sets the pos of the unit whitout removing it from the old
|
|
|
|
|
*
|
|
|
|
|
* @param x The x pos to move to
|
|
|
|
|
* @param y The y pos to move to
|
|
|
|
|
*/
|
2007-04-04 16:28:57 +00:00
|
|
|
public void setPos(int x, int y) {
|
|
|
|
|
oldPos = new Vector2i(x, y);
|
|
|
|
|
InGameState.getMap().setPos(this, x, y);
|
|
|
|
|
|
|
|
|
|
}
|
2007-04-05 12:45:22 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Moving a unit to the given pos
|
|
|
|
|
*
|
|
|
|
|
* @param x The x pos to move to
|
|
|
|
|
* @param y The y pos to move to
|
|
|
|
|
*/
|
2007-04-04 16:28:57 +00:00
|
|
|
public void move(int x, int y) {
|
|
|
|
|
if(oldPos!=null) {
|
|
|
|
|
InGameState.getMap().removePos(oldPos.getX(), oldPos.getY());
|
|
|
|
|
}
|
|
|
|
|
setPos(x, y);
|
2007-04-05 12:45:22 +00:00
|
|
|
moveTo = InGameState.getMap().getPixelByPos((int)x, (int)y);
|
2007-04-04 16:28:57 +00:00
|
|
|
oldPos = new Vector2i(x, y);
|
|
|
|
|
}
|
2007-04-05 12:45:22 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Updating the unit
|
|
|
|
|
*/
|
|
|
|
|
public void update() {
|
|
|
|
|
if(moveTo!=null) {
|
|
|
|
|
if(moveTo.getX() > looks.getLocation().getX()) {
|
|
|
|
|
looks.getLocation().add(1.5f, 0f, 0f);
|
|
|
|
|
}
|
|
|
|
|
if(moveTo.getX() < looks.getLocation().getX()) {
|
|
|
|
|
looks.getLocation().add(-1.5f, 0f, 0f);
|
|
|
|
|
}
|
|
|
|
|
if(moveTo.getY() > looks.getLocation().getY()) {
|
|
|
|
|
looks.getLocation().add(0f, 1.5f, 0f);
|
|
|
|
|
}
|
|
|
|
|
if(moveTo.getY() < looks.getLocation().getY()) {
|
|
|
|
|
looks.getLocation().add(0f, -1.5f, 0f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(moveTo.getX() == looks.getLocation().getX()
|
|
|
|
|
&& moveTo.getY() == looks.getLocation().getY()) {
|
|
|
|
|
moveTo = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2007-03-29 23:21:00 +00:00
|
|
|
|
|
|
|
|
}
|