evil-inside/src/ei/game/scene/units/Unit.java

102 lines
2.2 KiB
Java
Raw Normal View History

package ei.game.scene.units;
2007-04-04 18:16:37 +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;
import ei.game.scene.GameEntity;
2007-04-04 14:44:25 +00:00
import ei.game.scene.weapons.Weapon;
public abstract class Unit extends GameEntity{
// The texture
2007-04-04 14:44:25 +00:00
private Sprite looks;
// The wepon of the unit
2007-04-04 14:44:25 +00:00
private Weapon weapon;
// Som temp pos for moving the unit
2007-04-04 16:28:57 +00:00
private Vector2i oldPos;
private Vector2f moveTo;
/**
* Creates a empty unit
*
* @param l The max life of the unit
*/
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-04-04 14:44:25 +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;
}
/**
* 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;
}
/**
* 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);
}
/**
* 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);
moveTo = InGameState.getMap().getPixelByPos((int)x, (int)y);
2007-04-04 16:28:57 +00:00
oldPos = new Vector2i(x, y);
}
/**
* 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;
}
}
}
}