This commit is contained in:
Jesper Lundin 2007-04-18 11:56:07 +00:00
parent 9324df29c7
commit 02316b71b3
4 changed files with 55 additions and 22 deletions

View file

@ -7,6 +7,7 @@ import ei.game.player.HumanPlayer;
import ei.game.player.PlayerHandler; import ei.game.player.PlayerHandler;
import ei.game.scene.Map; import ei.game.scene.Map;
import ei.game.scene.units.Tank; import ei.game.scene.units.Tank;
import ei.game.scene.weapons.WeaponHandler;
public class InGameState extends GameState{ public class InGameState extends GameState{
@ -33,6 +34,9 @@ public class InGameState extends GameState{
rootNode.add(player.getNode()); rootNode.add(player.getNode());
PlayerHandler.getInstance().addPlayer(player); PlayerHandler.getInstance().addPlayer(player);
rootNode.add(WeaponHandler.getInstance().getNode());
} }
/** /**
@ -47,6 +51,7 @@ public class InGameState extends GameState{
*/ */
public void update() { public void update() {
PlayerHandler.getInstance().update(); PlayerHandler.getInstance().update();
WeaponHandler.getInstance().update();
rootNode.update(); rootNode.update();
} }

View file

@ -58,7 +58,7 @@ public class InGameMouseInput extends MouseInput{
//selecting unit. //selecting unit.
if(event==RIGHT_MOUSE_BUTTON) { if(event==RIGHT_MOUSE_BUTTON) {
for(int i=0; i<selected.size(); i++) { for(int i=0; i<selected.size(); i++) {
selected.get(i).attack(new Vector2f(pos.getX(), pos.getY())); selected.get(i).attack(new Vector2i(pos.getX(), pos.getY()));
} }
} }
else if(!map.isPosEmpty(pos.getX(), pos.getY())){ else if(!map.isPosEmpty(pos.getX(), pos.getY())){

View file

@ -97,7 +97,7 @@ public abstract class Unit extends GameEntity{
* Lets a unit attack another unit or object in the world; * Lets a unit attack another unit or object in the world;
*/ */
public void attack(Vector2i target) { public void attack(Vector2i target) {
Weapon wep = new Weapon(10, new Vector2f(unitNode.getLocation().getX(), unitNode.getLocation().getY())); Weapon wep = new Weapon(10, new Vector2f(unitNode.getLocation().getX(), unitNode.getLocation().getY()), 4.0f);
wep.launch(target); wep.launch(target);
WeaponHandler.getInstance().addWeapon(wep); WeaponHandler.getInstance().addWeapon(wep);
} }

View file

@ -5,57 +5,85 @@ import ei.engine.math.Vector2f;
import ei.engine.math.Vector2i; import ei.engine.math.Vector2i;
import ei.engine.scene.Entity; import ei.engine.scene.Entity;
import ei.game.scene.Map; import ei.game.scene.Map;
/**
* The weapon class.
* @author Jesper Lundin
*
*/
public class Weapon { public class Weapon {
private int range; private int range;
private Vector2i target; private Vector2i target;
private int velocity; private float velocity;
private Particles part; private Particles part;
private Vector2f startPos; private Vector2f startPos;
public Weapon(int range, Vector2f startPos) { /**
* Constructor for the class Weapon. Initializes the weapon.
* @param range
* @param startPos
* @param velocity
*/
public Weapon(int range, Vector2f startPos, float velocity) {
this.range = range; this.range = range;
this.startPos = startPos; this.startPos = startPos;
this.velocity = velocity;
part = new Particles("weapon"); part = new Particles("weapon");
part.setLocation(startPos); part.setLocation(startPos);
part.MaxSpeedX=500; part.MaxSpeedX=500;
part.MaxSpeedY=400; part.MaxSpeedY=400;
part.MaxSpeedZ=600; part.MaxSpeedZ=600;
part.rainbow = true;
part.size=5; part.size=5;
part.reset();
} }
/**
* Launches the weapon type.
* @param target
*/
public void launch(Vector2i target) { public void launch(Vector2i target) {
this.target = target; this.target = target;
} }
/**
* updates the weapons movement and positions, also the behaviour of
* the weapon.
*
*/
public void update() { public void update() {
System.out.println("target getx :"+target.getX());
System.out.println("startpos getx :"+startPos.getX());
System.out.println("target getx :"+target.getY());
System.out.println("startpos gety :"+startPos.getY());
System.out.println("part getLoc: "+part.getLocation().getX());
Vector2f vect = Map.getPixelByPos(target.getX(), target.getY()); Vector2f vect = Map.getPixelByPos(target.getX(), target.getY());
float percentage = (vect.getX()-startPos.getX()) / (vect.getY()-startPos.getY()); float yVelocity = (Math.abs((vect.getY()-startPos.getY()) / velocity))/10;
System.out.println("Percentage; "+percentage); float xVelocity = (Math.abs((vect.getX()-startPos.getX()) / velocity))/10;
if(target.getX() > part.getLocation().getX()) { System.out.println("xVel: "+Math.abs(part.getLocation().getX()-vect.getX()));
part.getLocation().add(4f*percentage, 0f, 0f);
if(vect.getX() > part.getLocation().getX()) {
part.getLocation().add(xVelocity, 0f, 0f);
} }
if(target.getX() < part.getLocation().getX()) { if(vect.getX() < part.getLocation().getX()) {
part.getLocation().add(-4.0f*percentage, 0f, 0f); part.getLocation().add(-xVelocity, 0f, 0f);
} }
if(target.getY() > part.getLocation().getY()) { if(vect.getY() > part.getLocation().getY()) {
part.getLocation().add(0f, 4.0f, 0f); part.getLocation().add(0f, yVelocity, 0f);
} }
if(target.getY() < part.getLocation().getY()) { if(vect.getY() < part.getLocation().getY()) {
part.getLocation().add(0f, -4.0f, 0f); part.getLocation().add(0f, -yVelocity, 0f);
}
if(Math.abs(part.getLocation().getX()-vect.getX()) < 10 && Math.abs(part.getLocation().getY()-vect.getY()) < 10) {
part.regenerate = false;
if(part.isDead()) {
WeaponHandler.getInstance().removeWeapon(this);
}
} }
} }
/**
* Returns the node with the weapon.
* @return
*/
public Entity getNode() { public Entity getNode() {
return part; return part;
} }