Did some stuff
This commit is contained in:
parent
c6ba0ea532
commit
af1a23b5af
6 changed files with 142 additions and 64 deletions
|
|
@ -4,6 +4,8 @@ import ei.engine.effects.Particles;
|
|||
import ei.engine.math.Vector2f;
|
||||
import ei.engine.math.Vector2i;
|
||||
import ei.engine.scene.Entity;
|
||||
import ei.engine.scene.Node;
|
||||
import ei.game.gamestate.InGameState;
|
||||
import ei.game.scene.Map;
|
||||
/**
|
||||
* The weapon class.
|
||||
|
|
@ -11,11 +13,13 @@ import ei.game.scene.Map;
|
|||
*
|
||||
*/
|
||||
|
||||
public class Weapon {
|
||||
public abstract class Weapon {
|
||||
private int range;
|
||||
private int damage;
|
||||
private Vector2i target;
|
||||
private float velocity;
|
||||
private float minVelocity;
|
||||
private boolean hit;
|
||||
private Particles part;
|
||||
private Vector2f startPos;
|
||||
|
||||
|
|
@ -26,20 +30,22 @@ public class Weapon {
|
|||
* @param startPos
|
||||
* @param velocity
|
||||
*/
|
||||
public Weapon(int range, Vector2f startPos, float velocity) {
|
||||
this.range = range;
|
||||
public Weapon(Vector2f startPos) {
|
||||
this.startPos = startPos;
|
||||
this.velocity = velocity;
|
||||
this.minVelocity = 5;
|
||||
part = new Particles("weapon");
|
||||
this.hit = false;
|
||||
part = getWeapon();
|
||||
part.setLocation(startPos);
|
||||
part.MaxSpeedX=500;
|
||||
part.MaxSpeedY=400;
|
||||
part.MaxSpeedZ=600;
|
||||
part.rainbow = false;
|
||||
part.size=5;
|
||||
part.reset();
|
||||
|
||||
}
|
||||
public void setRange(int range) {
|
||||
this.range = range;
|
||||
}
|
||||
public void setVelocity(float velocity) {
|
||||
this.velocity = velocity;
|
||||
}
|
||||
public void setDamage(int damage) {
|
||||
this.damage = damage;
|
||||
}
|
||||
/**
|
||||
* Launches the weapon type.
|
||||
|
|
@ -50,46 +56,55 @@ public class Weapon {
|
|||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* updates the weapons movement and positions, also the behaviour of
|
||||
* the weapon.
|
||||
*
|
||||
*/
|
||||
public void update() {
|
||||
|
||||
Vector2f vect = Map.getPixelByPos(target.getX(), target.getY());
|
||||
float yVelocity = (Math.abs((vect.getY()-startPos.getY()) / velocity))/10;
|
||||
float xVelocity = (Math.abs((vect.getX()-startPos.getX()) / velocity))/10;
|
||||
System.out.println("xVel: "+xVelocity);
|
||||
|
||||
//System.out.println("xVel: "+Math.abs(part.getLocation().getX()-vect.getX()));
|
||||
if(xVelocity < minVelocity && xVelocity < yVelocity) {
|
||||
yVelocity = (yVelocity/xVelocity)*minVelocity;
|
||||
xVelocity = minVelocity;
|
||||
}
|
||||
if(yVelocity < minVelocity && yVelocity < xVelocity) {
|
||||
xVelocity = (xVelocity/yVelocity)*minVelocity;
|
||||
yVelocity = minVelocity;
|
||||
}
|
||||
if(vect.getX() > part.getLocation().getX()) {
|
||||
part.getLocation().add(xVelocity, 0f, 0f);
|
||||
}
|
||||
if(vect.getX() < part.getLocation().getX()) {
|
||||
part.getLocation().add(-xVelocity, 0f, 0f);
|
||||
}
|
||||
if(vect.getY() > part.getLocation().getY()) {
|
||||
part.getLocation().add(0f, yVelocity, 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);
|
||||
if(Math.sqrt(Math.pow((vect.getX()-startPos.getX()), 2) + Math.pow((vect.getY()-startPos.getY()), 2))<=range) {
|
||||
float yVelocity = (Math.abs((vect.getY()-startPos.getY()) / velocity))/10;
|
||||
float xVelocity = (Math.abs((vect.getX()-startPos.getX()) / velocity))/10;
|
||||
System.out.println("xVel: "+xVelocity);
|
||||
|
||||
//System.out.println("xVel: "+Math.abs(part.getLocation().getX()-vect.getX()));
|
||||
if(xVelocity < minVelocity && xVelocity < yVelocity) {
|
||||
yVelocity = (yVelocity/xVelocity)*minVelocity;
|
||||
xVelocity = minVelocity;
|
||||
}
|
||||
if(yVelocity < minVelocity && yVelocity < xVelocity) {
|
||||
xVelocity = (xVelocity/yVelocity)*minVelocity;
|
||||
yVelocity = minVelocity;
|
||||
}
|
||||
if(vect.getX() > part.getLocation().getX()) {
|
||||
part.getLocation().add(xVelocity, 0f, 0f);
|
||||
}
|
||||
if(vect.getX() < part.getLocation().getX()) {
|
||||
part.getLocation().add(-xVelocity, 0f, 0f);
|
||||
}
|
||||
if(vect.getY() > part.getLocation().getY()) {
|
||||
part.getLocation().add(0f, yVelocity, 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(!hit) {
|
||||
InGameState.getMap().getPos(target.getX(), target.getY()).damaged(damage);
|
||||
hit = true;
|
||||
}
|
||||
if(part.isDead()) {
|
||||
WeaponHandler.getInstance().removeWeapon(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else{
|
||||
WeaponHandler.getInstance().removeWeapon(this);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Returns the node with the weapon.
|
||||
|
|
@ -98,5 +113,7 @@ public class Weapon {
|
|||
public Entity getNode() {
|
||||
return part;
|
||||
}
|
||||
|
||||
protected abstract Particles getWeapon();
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue