Did some stuff
This commit is contained in:
parent
c6ba0ea532
commit
af1a23b5af
6 changed files with 142 additions and 64 deletions
|
|
@ -10,8 +10,10 @@ import ei.engine.scene.Node;
|
|||
import ei.game.algo.AStar;
|
||||
import ei.game.algo.AStarNode;
|
||||
import ei.game.gamestate.InGameState;
|
||||
import ei.game.player.Player;
|
||||
import ei.game.scene.GameEntity;
|
||||
import ei.game.scene.Map;
|
||||
import ei.game.scene.weapons.CannonBall;
|
||||
import ei.game.scene.weapons.Weapon;
|
||||
import ei.game.scene.weapons.WeaponHandler;
|
||||
|
||||
|
|
@ -37,8 +39,8 @@ public abstract class Unit extends GameEntity{
|
|||
*
|
||||
* @param l The max life of the unit
|
||||
*/
|
||||
public Unit(int l, Vector2i pos) {
|
||||
super(l);
|
||||
public Unit(int l, Vector2i pos, Player p) {
|
||||
super(l, p);
|
||||
unitNode = new Node("unit");
|
||||
unitNode.setLocation(Map.getPixelByPos(pos.getX(), pos.getY()));
|
||||
setPos(pos.getX(), pos.getY());
|
||||
|
|
@ -85,6 +87,7 @@ public abstract class Unit extends GameEntity{
|
|||
System.out.println(oldPos);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Moving a unit to the given pos
|
||||
*
|
||||
|
|
@ -105,17 +108,21 @@ public abstract class Unit extends GameEntity{
|
|||
* 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()), 4.0f);
|
||||
Weapon wep = getWeapon(new Vector2f(unitNode.getLocation().getX(), unitNode.getLocation().getY()));
|
||||
wep.launch(target);
|
||||
WeaponHandler.getInstance().addWeapon(wep);
|
||||
}
|
||||
|
||||
public abstract Weapon getWeapon(Vector2f startPos);
|
||||
/**
|
||||
* Updating the unit
|
||||
*/
|
||||
public void update() {
|
||||
if(getLife()<=0) {
|
||||
unitNode.remove("Tank");
|
||||
getPlayer().removeUnit(this);
|
||||
}
|
||||
|
||||
if(moveTo != null) {
|
||||
else if(moveTo != null) {
|
||||
Vector2i moveVect = new Vector2i((int)moveTo.getX(),(int)moveTo.getY());
|
||||
|
||||
int moveXminus = moveVect.getX()-oldVect.getX();
|
||||
|
|
@ -126,19 +133,19 @@ public abstract class Unit extends GameEntity{
|
|||
|
||||
//The rotation animation is done here.
|
||||
if(moveVect.getX() < oldVect.getX() && divideY==1) {
|
||||
unitNode.get("Tank").setRotation(new Vector3f(0, 0, 90));
|
||||
getSprite().setRotation(new Vector3f(0, 0, 90));
|
||||
}
|
||||
|
||||
if(moveVect.getX() > oldVect.getX() && divideY==1) {
|
||||
unitNode.get("Tank").setRotation(new Vector3f(0, 0, -90));
|
||||
getSprite().setRotation(new Vector3f(0, 0, -90));
|
||||
}
|
||||
|
||||
if(moveVect.getY() < oldVect.getY() && divideX==1) {
|
||||
unitNode.get("Tank").setRotation(new Vector3f(0, 0, 180));
|
||||
getSprite().setRotation(new Vector3f(0, 0, 180));
|
||||
}
|
||||
|
||||
if(moveVect.getY() > oldVect.getY() && divideX==1) {
|
||||
unitNode.get("Tank").setRotation(new Vector3f(0, 0, 0));
|
||||
getSprite().setRotation(new Vector3f(0, 0, 0));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue