Added so that the unit now follows the enamy unit and i added a reload timmer
This commit is contained in:
parent
6d06a75144
commit
b97df125dd
8 changed files with 83 additions and 24 deletions
|
|
@ -4,7 +4,6 @@ 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;
|
||||
/**
|
||||
|
|
@ -22,6 +21,7 @@ public abstract class Weapon {
|
|||
private boolean hit;
|
||||
private Particles part;
|
||||
private Vector2f startPos;
|
||||
private int reload;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -38,26 +38,46 @@ public abstract class Weapon {
|
|||
part.setLocation(startPos);
|
||||
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;
|
||||
}
|
||||
|
||||
public int getDamage() {
|
||||
return this.damage;
|
||||
}
|
||||
|
||||
public void setReload(int r){
|
||||
reload = r;
|
||||
}
|
||||
|
||||
public int getReload(){
|
||||
return reload;
|
||||
}
|
||||
|
||||
/**
|
||||
* Launches the weapon type.
|
||||
* @param target
|
||||
*/
|
||||
public void launch(Vector2i target) {
|
||||
this.target = target;
|
||||
|
||||
|
||||
this.target = target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the wepon is on range else false
|
||||
* @param vect The position to attack
|
||||
* @return True if the wepon is on range else false
|
||||
*/
|
||||
public boolean onRange(Vector2f vect){
|
||||
return Math.sqrt(Math.pow((vect.getX()-startPos.getX()), 2) + Math.pow((vect.getY()-startPos.getY()), 2))<=range;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -68,10 +88,9 @@ public abstract class Weapon {
|
|||
public void update() {
|
||||
Vector2f vect = Map.getPixelByPos(target.getX(), target.getY());
|
||||
|
||||
if(Math.sqrt(Math.pow((vect.getX()-startPos.getX()), 2) + Math.pow((vect.getY()-startPos.getY()), 2))<=range) {
|
||||
if(onRange(vect)) {
|
||||
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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue