This commit is contained in:
Jesper Lundin 2007-04-18 10:04:08 +00:00
parent 99a30c2e8d
commit 90d685195d
5 changed files with 160 additions and 4 deletions

View file

@ -13,6 +13,7 @@ import ei.game.gamestate.InGameState;
import ei.game.scene.GameEntity;
import ei.game.scene.Map;
import ei.game.scene.weapons.Weapon;
import ei.game.scene.weapons.WeaponHandler;
/**
* The Unit class, handles the units in the game.
@ -92,6 +93,14 @@ public abstract class Unit extends GameEntity{
setPos(temp.getX(), temp.getY());
}
}
/**
* Lets a unit attack another unit or object in the world;
*/
public void attack(Vector2i target) {
Weapon wep = new Weapon(10, new Vector2f(unitNode.getLocation().getX(), unitNode.getLocation().getY()));
wep.launch(target);
WeaponHandler.getInstance().addWeapon(wep);
}
/**
* Updating the unit
@ -100,13 +109,12 @@ public abstract class Unit extends GameEntity{
if(moveTo != null) {
Vector2i moveVect = new Vector2i((int)moveTo.getX(),(int)moveTo.getY());
//Vector2i currentVect = new Vector2i((int)unitNode.getLocation().getX(), (int)unitNode.getLocation().getY());
int moveXminus = moveVect.getX()-oldVect.getX();
int moveYminus = moveVect.getY()-oldVect.getY();
float divideY = (moveVect.getY()+1)/(oldVect.getY()+1);
float divideX = (moveVect.getX()+1)/(oldVect.getX()+1);
float divideY = (moveVect.getY()+2)/(oldVect.getY()+2);
float divideX = (moveVect.getX()+2)/(oldVect.getX()+2);
//The rotation animation is done here.
if(moveVect.getX() < oldVect.getX() && divideY==1) {