evil-inside/src/ei/game/scene/weapons/Weapon.java

92 lines
2.2 KiB
Java
Raw Normal View History

package ei.game.scene.weapons;
2007-04-18 10:04:08 +00:00
import ei.engine.effects.Particles;
import ei.engine.math.Vector2f;
import ei.engine.math.Vector2i;
import ei.engine.scene.Entity;
import ei.game.scene.Map;
2007-04-18 11:56:07 +00:00
/**
* The weapon class.
* @author Jesper Lundin
*
*/
2007-04-18 10:04:08 +00:00
public class Weapon {
private int range;
private Vector2i target;
2007-04-18 11:56:07 +00:00
private float velocity;
2007-04-18 10:04:08 +00:00
private Particles part;
private Vector2f startPos;
2007-04-18 11:56:07 +00:00
/**
* Constructor for the class Weapon. Initializes the weapon.
* @param range
* @param startPos
* @param velocity
*/
public Weapon(int range, Vector2f startPos, float velocity) {
2007-04-18 10:04:08 +00:00
this.range = range;
this.startPos = startPos;
2007-04-18 11:56:07 +00:00
this.velocity = velocity;
2007-04-18 10:04:08 +00:00
part = new Particles("weapon");
part.setLocation(startPos);
part.MaxSpeedX=500;
part.MaxSpeedY=400;
part.MaxSpeedZ=600;
2007-04-18 11:56:07 +00:00
part.rainbow = true;
2007-04-18 10:04:08 +00:00
part.size=5;
2007-04-18 11:56:07 +00:00
part.reset();
2007-04-18 10:04:08 +00:00
}
2007-04-18 11:56:07 +00:00
/**
* Launches the weapon type.
* @param target
*/
2007-04-18 10:04:08 +00:00
public void launch(Vector2i target) {
this.target = target;
}
2007-04-18 11:56:07 +00:00
/**
* updates the weapons movement and positions, also the behaviour of
* the weapon.
*
*/
2007-04-18 10:04:08 +00:00
public void update() {
Vector2f vect = Map.getPixelByPos(target.getX(), target.getY());
2007-04-18 11:56:07 +00:00
float yVelocity = (Math.abs((vect.getY()-startPos.getY()) / velocity))/10;
float xVelocity = (Math.abs((vect.getX()-startPos.getX()) / velocity))/10;
System.out.println("xVel: "+Math.abs(part.getLocation().getX()-vect.getX()));
2007-04-18 10:04:08 +00:00
2007-04-18 11:56:07 +00:00
if(vect.getX() > part.getLocation().getX()) {
part.getLocation().add(xVelocity, 0f, 0f);
2007-04-18 10:04:08 +00:00
}
2007-04-18 11:56:07 +00:00
if(vect.getX() < part.getLocation().getX()) {
part.getLocation().add(-xVelocity, 0f, 0f);
2007-04-18 10:04:08 +00:00
}
2007-04-18 11:56:07 +00:00
if(vect.getY() > part.getLocation().getY()) {
part.getLocation().add(0f, yVelocity, 0f);
2007-04-18 10:04:08 +00:00
}
2007-04-18 11:56:07 +00:00
if(vect.getY() < part.getLocation().getY()) {
part.getLocation().add(0f, -yVelocity, 0f);
2007-04-18 10:04:08 +00:00
}
2007-04-18 11:56:07 +00:00
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);
}
}
2007-04-18 10:04:08 +00:00
}
2007-04-18 11:56:07 +00:00
/**
* Returns the node with the weapon.
* @return
*/
2007-04-18 10:04:08 +00:00
public Entity getNode() {
return part;
}
}