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

@ -5,57 +5,85 @@ import ei.engine.math.Vector2f;
import ei.engine.math.Vector2i;
import ei.engine.scene.Entity;
import ei.game.scene.Map;
/**
* The weapon class.
* @author Jesper Lundin
*
*/
public class Weapon {
private int range;
private Vector2i target;
private int velocity;
private float velocity;
private Particles part;
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.startPos = startPos;
this.velocity = velocity;
part = new Particles("weapon");
part.setLocation(startPos);
part.MaxSpeedX=500;
part.MaxSpeedY=400;
part.MaxSpeedZ=600;
part.rainbow = true;
part.size=5;
part.reset();
}
/**
* Launches the weapon type.
* @param target
*/
public void launch(Vector2i target) {
this.target = target;
}
/**
* updates the weapons movement and positions, also the behaviour of
* the weapon.
*
*/
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());
float percentage = (vect.getX()-startPos.getX()) / (vect.getY()-startPos.getY());
System.out.println("Percentage; "+percentage);
float yVelocity = (Math.abs((vect.getY()-startPos.getY()) / velocity))/10;
float xVelocity = (Math.abs((vect.getX()-startPos.getX()) / velocity))/10;
if(target.getX() > part.getLocation().getX()) {
part.getLocation().add(4f*percentage, 0f, 0f);
System.out.println("xVel: "+Math.abs(part.getLocation().getX()-vect.getX()));
if(vect.getX() > part.getLocation().getX()) {
part.getLocation().add(xVelocity, 0f, 0f);
}
if(target.getX() < part.getLocation().getX()) {
part.getLocation().add(-4.0f*percentage, 0f, 0f);
if(vect.getX() < part.getLocation().getX()) {
part.getLocation().add(-xVelocity, 0f, 0f);
}
if(target.getY() > part.getLocation().getY()) {
part.getLocation().add(0f, 4.0f, 0f);
if(vect.getY() > part.getLocation().getY()) {
part.getLocation().add(0f, yVelocity, 0f);
}
if(target.getY() < part.getLocation().getY()) {
part.getLocation().add(0f, -4.0f, 0f);
if(vect.getY() < part.getLocation().getY()) {
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() {
return part;
}