From 6d2057f0c2febf2aff93e5b5aedd14d7a04dbc00 Mon Sep 17 00:00:00 2001 From: Jesper Lundin Date: Wed, 18 Apr 2007 17:13:29 +0000 Subject: [PATCH] Fix this --- src/ei/game/scene/units/Bomber.java | 12 +++++-- src/ei/game/scene/units/Tank.java | 7 ++++ src/ei/game/scene/units/Unit.java | 15 +++++---- src/ei/game/scene/weapons/BomberWeapon.java | 36 ++++++++++++++++++--- src/ei/game/scene/weapons/Weapon.java | 3 ++ 5 files changed, 60 insertions(+), 13 deletions(-) diff --git a/src/ei/game/scene/units/Bomber.java b/src/ei/game/scene/units/Bomber.java index f9deb46..e207e97 100644 --- a/src/ei/game/scene/units/Bomber.java +++ b/src/ei/game/scene/units/Bomber.java @@ -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. diff --git a/src/ei/game/scene/units/Tank.java b/src/ei/game/scene/units/Tank.java index 8a70e3a..64e3069 100644 --- a/src/ei/game/scene/units/Tank.java +++ b/src/ei/game/scene/units/Tank.java @@ -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. diff --git a/src/ei/game/scene/units/Unit.java b/src/ei/game/scene/units/Unit.java index bd80b1e..0283c57 100644 --- a/src/ei/game/scene/units/Unit.java +++ b/src/ei/game/scene/units/Unit.java @@ -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())){ diff --git a/src/ei/game/scene/weapons/BomberWeapon.java b/src/ei/game/scene/weapons/BomberWeapon.java index 0b11163..b2d5c49 100644 --- a/src/ei/game/scene/weapons/BomberWeapon.java +++ b/src/ei/game/scene/weapons/BomberWeapon.java @@ -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); + } + } } diff --git a/src/ei/game/scene/weapons/Weapon.java b/src/ei/game/scene/weapons/Weapon.java index 496ece5..ae11805 100644 --- a/src/ei/game/scene/weapons/Weapon.java +++ b/src/ei/game/scene/weapons/Weapon.java @@ -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