Fix this
This commit is contained in:
parent
921b30ca95
commit
6d2057f0c2
5 changed files with 60 additions and 13 deletions
|
|
@ -5,6 +5,7 @@ import ei.engine.math.Vector2i;
|
|||
import ei.engine.scene.Sprite;
|
||||
import ei.game.player.Player;
|
||||
import ei.game.scene.SelectBox;
|
||||
import ei.game.scene.weapons.BomberWeapon;
|
||||
import ei.game.scene.weapons.CannonBall;
|
||||
import ei.game.scene.weapons.Weapon;
|
||||
|
||||
|
|
@ -18,7 +19,7 @@ public class Bomber extends Unit{
|
|||
public Bomber(int x, int y, Player p){
|
||||
super(100, new Vector2i(x,y), p);
|
||||
this.sprite = new Sprite("Tank", "data/units/bomber/bomber0000.png");
|
||||
sprite.setSize(new Vector2f(40,40));
|
||||
sprite.setSize(new Vector2f(50,60));
|
||||
getNode().add(sprite);
|
||||
|
||||
selectionBox = new SelectBox(40,40,getMaxLife());
|
||||
|
|
@ -33,13 +34,20 @@ public class Bomber extends Unit{
|
|||
* of unit.
|
||||
*/
|
||||
public Weapon getWeapon(Vector2f startPos) {
|
||||
return new CannonBall(startPos);
|
||||
return new BomberWeapon(startPos);
|
||||
}
|
||||
/**
|
||||
* This unit type is now destroyed.
|
||||
*/
|
||||
public void destroyed(){
|
||||
|
||||
}
|
||||
/**
|
||||
* returns the velocity of the unit type.
|
||||
* @return
|
||||
*/
|
||||
public float getVelocity() {
|
||||
return 3;
|
||||
}
|
||||
/**
|
||||
* Manages the sprite connected to this unit.
|
||||
|
|
|
|||
|
|
@ -40,6 +40,13 @@ public class Tank extends Unit{
|
|||
*/
|
||||
public void destroyed(){
|
||||
|
||||
}
|
||||
/**
|
||||
* returns the velocity of the unit type.
|
||||
* @return
|
||||
*/
|
||||
public float getVelocity() {
|
||||
return 2;
|
||||
}
|
||||
/**
|
||||
* Manages the sprite connected to this unit.
|
||||
|
|
|
|||
|
|
@ -113,6 +113,8 @@ public abstract class Unit extends GameEntity{
|
|||
WeaponHandler.getInstance().addWeapon(wep);
|
||||
}
|
||||
public abstract Weapon getWeapon(Vector2f startPos);
|
||||
|
||||
public abstract float getVelocity();
|
||||
/**
|
||||
* Updating the unit
|
||||
*/
|
||||
|
|
@ -120,6 +122,7 @@ public abstract class Unit extends GameEntity{
|
|||
if(getLife()<=0) {
|
||||
unitNode.remove("Tank");
|
||||
getPlayer().removeUnit(this);
|
||||
InGameState.getMap().removePos(oldPos.getX(), oldPos.getY());
|
||||
}
|
||||
|
||||
else if(moveTo != null) {
|
||||
|
|
@ -175,20 +178,20 @@ public abstract class Unit extends GameEntity{
|
|||
|
||||
//The moving is done here.
|
||||
if(moveTo.getX() > unitNode.getLocation().getX()) {
|
||||
unitNode.getLocation().add(1.5f, 0f, 0f);
|
||||
unitNode.getLocation().add(getVelocity(), 0f, 0f);
|
||||
}
|
||||
if(moveTo.getX() < unitNode.getLocation().getX()) {
|
||||
unitNode.getLocation().add(-1.5f, 0f, 0f);
|
||||
unitNode.getLocation().add(-getVelocity(), 0f, 0f);
|
||||
}
|
||||
if(moveTo.getY() > unitNode.getLocation().getY()) {
|
||||
unitNode.getLocation().add(0f, 1.5f, 0f);
|
||||
unitNode.getLocation().add(0f, getVelocity(), 0f);
|
||||
}
|
||||
if(moveTo.getY() < unitNode.getLocation().getY()) {
|
||||
unitNode.getLocation().add(0f, -1.5f, 0f);
|
||||
unitNode.getLocation().add(0f, -getVelocity(), 0f);
|
||||
}
|
||||
|
||||
if(Math.abs(moveTo.getX() - unitNode.getLocation().getX()) < 2
|
||||
&& Math.abs(moveTo.getY() - unitNode.getLocation().getY())< 2 ){
|
||||
if(Math.abs(moveTo.getX() - unitNode.getLocation().getX()) < getVelocity()+1
|
||||
&& Math.abs(moveTo.getY() - unitNode.getLocation().getY())< getVelocity()+1 ){
|
||||
if(path != null && !path.isEmpty()){
|
||||
AStarNode temp = path.poll();
|
||||
if(InGameState.getMap().isPosEmpty(temp.getX(), temp.getY())){
|
||||
|
|
|
|||
|
|
@ -2,28 +2,54 @@ package ei.game.scene.weapons;
|
|||
|
||||
import ei.engine.effects.Particles;
|
||||
import ei.engine.math.Vector2f;
|
||||
import ei.engine.math.Vector2i;
|
||||
import ei.game.gamestate.InGameState;
|
||||
import ei.game.scene.Map;
|
||||
|
||||
public class BomberWeapon extends Weapon{
|
||||
private Particles part;
|
||||
private boolean hit;
|
||||
private Vector2i position;
|
||||
|
||||
public BomberWeapon(Vector2f startPos) {
|
||||
super(startPos);
|
||||
setVelocity(4);
|
||||
setRange(100);
|
||||
setDamage(10);
|
||||
hit = false;
|
||||
position = Map.getPosByPixel(startPos.getX(), startPos.getY());
|
||||
}
|
||||
public Particles getWeapon() {
|
||||
Particles part = new Particles("bomber");
|
||||
part = new Particles("bomber");
|
||||
part = new Particles("weapon");
|
||||
part.MaxSpeedX=500;
|
||||
part.MaxSpeedY=400;
|
||||
part.MaxSpeedZ=600;
|
||||
part.MaxSpeedX=700;
|
||||
part.MaxSpeedY=700;
|
||||
part.MaxSpeedZ=0;
|
||||
part.slowdown = 1;
|
||||
part.rainbow = false;
|
||||
part.size=10;
|
||||
part.regenerate = false;
|
||||
part.size=20;
|
||||
return part;
|
||||
}
|
||||
|
||||
public void update() {
|
||||
|
||||
if(!hit) {
|
||||
for(int i=position.getX()-1; i<=position.getX()+1; i++ ) {
|
||||
for(int j=position.getY()-1; i<=position.getY()+1; j++) {
|
||||
System.out.println("i :"+i+" j: "+j);
|
||||
if(InGameState.getMap().posExist(i, j)&& !InGameState.getMap().isPosEmpty(i, j)) {
|
||||
System.out.println("Damaged");
|
||||
InGameState.getMap().getPos(i, j).damaged(getDamage());
|
||||
}
|
||||
}
|
||||
}
|
||||
hit = true;
|
||||
}
|
||||
if(part.isDead()) {
|
||||
WeaponHandler.getInstance().removeWeapon(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,6 +47,9 @@ public abstract class Weapon {
|
|||
public void setDamage(int damage) {
|
||||
this.damage = damage;
|
||||
}
|
||||
public int getDamage() {
|
||||
return this.damage;
|
||||
}
|
||||
/**
|
||||
* Launches the weapon type.
|
||||
* @param target
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue