diff --git a/src/data/sounds/APUattack.wav b/src/data/sounds/APUattack.wav new file mode 100644 index 0000000..75d6422 Binary files /dev/null and b/src/data/sounds/APUattack.wav differ diff --git a/src/data/sounds/APUmove1.wav b/src/data/sounds/APUmove1.wav new file mode 100644 index 0000000..6866aca Binary files /dev/null and b/src/data/sounds/APUmove1.wav differ diff --git a/src/data/sounds/APUselect.wav b/src/data/sounds/APUselect.wav new file mode 100644 index 0000000..0e2c887 Binary files /dev/null and b/src/data/sounds/APUselect.wav differ diff --git a/src/data/sounds/APUyes.wav b/src/data/sounds/APUyes.wav new file mode 100644 index 0000000..841bb30 Binary files /dev/null and b/src/data/sounds/APUyes.wav differ diff --git a/src/data/sounds/BOMBERattack.wav b/src/data/sounds/BOMBERattack.wav new file mode 100644 index 0000000..d59ebc3 Binary files /dev/null and b/src/data/sounds/BOMBERattack.wav differ diff --git a/src/data/sounds/BOMBERmove1.wav b/src/data/sounds/BOMBERmove1.wav new file mode 100644 index 0000000..e886af8 Binary files /dev/null and b/src/data/sounds/BOMBERmove1.wav differ diff --git a/src/data/sounds/BOMBERmove2.wav b/src/data/sounds/BOMBERmove2.wav new file mode 100644 index 0000000..f6beb70 Binary files /dev/null and b/src/data/sounds/BOMBERmove2.wav differ diff --git a/src/data/sounds/BOMBERselect.wav b/src/data/sounds/BOMBERselect.wav new file mode 100644 index 0000000..85f5dc3 Binary files /dev/null and b/src/data/sounds/BOMBERselect.wav differ diff --git a/src/data/sounds/machinegun.wav b/src/data/sounds/machinegun.wav new file mode 100644 index 0000000..e3f2a75 Binary files /dev/null and b/src/data/sounds/machinegun.wav differ diff --git a/src/ei/game/gamestate/InGameState.java b/src/ei/game/gamestate/InGameState.java index 2229467..4e781c6 100644 --- a/src/ei/game/gamestate/InGameState.java +++ b/src/ei/game/gamestate/InGameState.java @@ -6,6 +6,7 @@ import ei.game.input.InGameMouseInput; import ei.game.player.HumanPlayer; import ei.game.player.PlayerHandler; import ei.game.scene.Map; +import ei.game.scene.buildings.CommandCenter; import ei.game.scene.units.APU; import ei.game.scene.units.Bomber; import ei.game.scene.units.Tank; @@ -35,6 +36,8 @@ public class InGameState extends GameState{ player.addUnit(new Tank(2,0, player)); player.addUnit(new Bomber(3, 0, player)); player.addUnit(new APU(4, 0, player)); + player.addUnit(new APU(5, 0, player)); + player.addUnit(new CommandCenter(10, 10, player)); PlayerHandler.getInstance().addPlayer(player); diff --git a/src/ei/game/player/GaiaPlayer.java b/src/ei/game/player/GaiaPlayer.java index 1387e5c..2005b08 100644 --- a/src/ei/game/player/GaiaPlayer.java +++ b/src/ei/game/player/GaiaPlayer.java @@ -2,6 +2,7 @@ package ei.game.player; import java.util.ArrayList; +import ei.engine.scene.Entity; import ei.engine.scene.Node; import ei.game.scene.GameEntity; import ei.game.scene.units.Unit; @@ -15,12 +16,12 @@ public class GaiaPlayer extends Player{ unitsNode = new Node("GaiaPlayerNode"); } - public void addUnit(Unit u){ + public void addUnit(GameEntity u){ units.add(u); unitsNode.add(u.getNode()); } - public void removeUnit(Unit u){ + public void removeUnit(GameEntity u){ units.remove(u); unitsNode.remove(u.getNode()); } diff --git a/src/ei/game/player/HumanPlayer.java b/src/ei/game/player/HumanPlayer.java index 5edf066..7233b87 100644 --- a/src/ei/game/player/HumanPlayer.java +++ b/src/ei/game/player/HumanPlayer.java @@ -15,12 +15,12 @@ public class HumanPlayer extends Player{ unitsNode = new Node("HumanPlayerNode"); } - public void addUnit(Unit u){ + public void addUnit(GameEntity u){ units.add(u); unitsNode.add(u.getNode()); } - public void removeUnit(Unit u){ + public void removeUnit(GameEntity u){ units.remove(u); unitsNode.remove(u.getNode()); } diff --git a/src/ei/game/player/Player.java b/src/ei/game/player/Player.java index 29f73ea..bcb286d 100644 --- a/src/ei/game/player/Player.java +++ b/src/ei/game/player/Player.java @@ -1,13 +1,14 @@ package ei.game.player; import ei.engine.scene.Node; +import ei.game.scene.GameEntity; import ei.game.scene.units.Unit; public abstract class Player { - public abstract void addUnit(Unit u); + public abstract void addUnit(GameEntity u); - public abstract void removeUnit(Unit u); + public abstract void removeUnit(GameEntity u); public abstract Node getNode(); diff --git a/src/ei/game/scene/Map.java b/src/ei/game/scene/Map.java index 9b58269..2050247 100644 --- a/src/ei/game/scene/Map.java +++ b/src/ei/game/scene/Map.java @@ -199,6 +199,21 @@ public class Map { float yf = (POS_SIZE*y); return new Vector2f(xf,yf); } + public static Vector2f getPixelByPos(int x, int y, int size){ + if(size%2!=0) { + size = (size/2)+1; + float xf = (POS_SIZE)*(x+size); + float yf = (POS_SIZE)*(y+size); + return new Vector2f(xf,yf); + } + size = (size/2)-1; + float xDiff = Math.abs((getPixelByPos(x+size, 0).getX())-(getPixelByPos(size+x+1, 0).getX()))/2; + float yDiff = Math.abs((getPixelByPos(0, size+y).getY())-(getPixelByPos(0, size+y+1).getY()))/2; + + return new Vector2f(getPixelByPos(x+size, 0).getX()+xDiff, getPixelByPos(0, y+size).getY()+yDiff); + + + } /** * Returns if the pos inthe map is empty @@ -213,6 +228,24 @@ public class Map { } return false; } + /** + * Returns true if the pos in the map is empty + * @param x pos + * @param y pos + * @param size, size to check + * @return true if pos is empty, else false + */ + public boolean isPosEmpty(int x, int y, int size) { + for(int i=x; i availableUnits; private Queue buildQueue; + private Node unitNode; + private Vector2i oldPos; + private int size; + + + public Building(int l, Vector2i pos, Player p, int size) { + super(l, p); + this.size = size; + unitNode = new Node("UnitNode"); + unitNode.setLocation(Map.getPixelByPos(pos.getX(), pos.getY(), this.size)); + System.out.println("location: "+unitNode.getLocation()); + setPos(pos.getX(), pos.getY(), this.size); + } - public Building(int l, Player p) { - super(l,p); - // TODO Auto-generated constructor stub + public void setSelected(boolean b) { + if(b) { + unitNode.add(getSelection().getSelectNode()); + } + else{ + unitNode.remove(getSelection().getSelectNode()); + } + } + + public void setMouseOver(boolean b) { + if(b) { + unitNode.add(getSelection().getMouseOverNode()); + } + else{ + unitNode.remove(getSelection().getMouseOverNode()); + } + } + /** + * Sets the size of the building. + * @param size + */ + public void setSize(int size) { + this.size = size; + } + /** + * Returns the sprite for the unit + * + * @return The sprite for the unit + */ + public Node getNode(){ + return unitNode; + } + + /** + * Changes the pos of the unit in the map + * + * @param x The x pos to move to + * @param y The y pos to move to + */ + public void setPos(int x, int y, int size) { + if(oldPos!=null) { + InGameState.getMap().removeBuildPos(oldPos.getX(), oldPos.getY(), size); + } + oldPos = new Vector2i(x, y); + InGameState.getMap().setBuildPos(this, x, y, size); } + + /** + * Removes this unit from the game. + * + */ + public void removeUnit(){ + unitNode.remove(getSprite()); + getPlayer().removeUnit(this); + InGameState.getMap().removePos(oldPos.getX(), oldPos.getY()); + } + + /** + * Updating the unit + */ + public void update() { + + if(getLife()<=0) { + removeUnit(); + } + + } } + diff --git a/src/ei/game/scene/buildings/CommandCenter.java b/src/ei/game/scene/buildings/CommandCenter.java new file mode 100644 index 0000000..9c56d3f --- /dev/null +++ b/src/ei/game/scene/buildings/CommandCenter.java @@ -0,0 +1,55 @@ +package ei.game.scene.buildings; + +import ei.engine.math.Vector2f; +import ei.engine.math.Vector2i; +import ei.engine.scene.Sprite; +import ei.game.player.Player; +import ei.game.scene.SelectBox; + +public class CommandCenter extends Building{ + private SelectBox selectionBox; + private Sprite sprite; + public CommandCenter(Player p) { + this(0, 0, p); + } + + public CommandCenter(int x, int y, Player p){ + super(1000, new Vector2i(x,y), p, 4); + this.sprite = new Sprite("APU", "data/buildings/commandcenter.png"); + sprite.setSize(new Vector2f(200,200)); + getNode().add(sprite); + + selectionBox = new SelectBox(200,200,getMaxLife()); + } + + protected SelectBox getSelection() { + return selectionBox; + } + /** + * This unit type is now destroyed. + */ + public void destroyed(){ + + } + /** + * Doesnt matter anyway. Since buildings cant attack. + */ + public void attack(Vector2i target) { + + } + /** + * Manages the sprite connected to this unit. + * @param s + */ + public void setSprite(Sprite s) { + this.sprite = s; + } + /** + * returns the sprite connected to this type + * of unit. + * @return + */ + public Sprite getSprite() { + return this.sprite; + } +} diff --git a/src/ei/game/scene/units/APU.java b/src/ei/game/scene/units/APU.java index 7831ad8..de1e524 100644 --- a/src/ei/game/scene/units/APU.java +++ b/src/ei/game/scene/units/APU.java @@ -3,6 +3,7 @@ package ei.game.scene.units; import ei.engine.math.Vector2f; import ei.engine.math.Vector2i; import ei.engine.scene.Sprite; +import ei.engine.sound.Sound; import ei.game.player.Player; import ei.game.scene.SelectBox; import ei.game.scene.weapons.MachineGun; @@ -11,6 +12,12 @@ import ei.game.scene.weapons.Weapon; public class APU extends Unit{ private SelectBox selectionBox; private Sprite sprite; + + private Sound gunSound; + private Sound moveSound; + private Sound attackSound; + private Sound selectSound; + public APU(Player p) { this(0, 0, p); } @@ -20,6 +27,9 @@ public class APU extends Unit{ this.sprite = new Sprite("APU", "data/units/apu/apu0000.png"); sprite.setSize(new Vector2f(40,40)); getNode().add(sprite); + gunSound = new Sound("gunSound", "data/sounds/machinegun.wav"); + moveSound = new Sound("moveSound", "data/sounds/APUmove1.wav"); + selectSound = new Sound("selectSound", "data/sounds/APUselect.wav"); selectionBox = new SelectBox(40,40,getMaxLife()); setLife(50); @@ -40,6 +50,15 @@ public class APU extends Unit{ */ public void destroyed(){ + } + public Sound getGunSound() { + return gunSound; + } + public Sound getMoveSound() { + return moveSound; + } + public Sound getSelectSound() { + return selectSound; } /** * returns the velocity of the unit type. diff --git a/src/ei/game/scene/units/Bomber.java b/src/ei/game/scene/units/Bomber.java index 6618451..ba00fdb 100644 --- a/src/ei/game/scene/units/Bomber.java +++ b/src/ei/game/scene/units/Bomber.java @@ -3,6 +3,7 @@ package ei.game.scene.units; import ei.engine.math.Vector2f; import ei.engine.math.Vector2i; import ei.engine.scene.Sprite; +import ei.engine.sound.Sound; import ei.game.player.Player; import ei.game.scene.SelectBox; import ei.game.scene.weapons.BomberWeapon; @@ -11,6 +12,12 @@ import ei.game.scene.weapons.Weapon; public class Bomber extends Unit{ private SelectBox selectionBox; private Sprite sprite; + + private Sound gunSound; + private Sound[] moveSound = new Sound[2]; + private Sound attackSound; + private Sound selectSound; + public Bomber(Player p) { this(0, 0, p); } @@ -20,6 +27,10 @@ public class Bomber extends Unit{ this.sprite = new Sprite("Bomber", "data/units/bomber/bomber0000.png"); sprite.setSize(new Vector2f(50,60)); getNode().add(sprite); + gunSound = new Sound("gunSound", "data/sounds/machinegun.wav"); + moveSound[0] = new Sound("moveSound", "data/sounds/BOMBERmove1.wav"); + moveSound[1] = new Sound("moveSound", "data/sounds/BOMBERmove2.wav"); + selectSound = new Sound("selectSound", "data/sounds/BOMBERselect.wav"); selectionBox = new SelectBox(40,40,getMaxLife()); setLife(180); @@ -40,6 +51,15 @@ public class Bomber extends Unit{ */ public void destroyed(){ + } + public Sound getGunSound() { + return gunSound; + } + public Sound getMoveSound() { + return moveSound[(int)(Math.random()*2)]; + } + public Sound getSelectSound() { + return selectSound; } /** * returns the velocity of the unit type. diff --git a/src/ei/game/scene/units/Unit.java b/src/ei/game/scene/units/Unit.java index 0bc6563..8c17a83 100644 --- a/src/ei/game/scene/units/Unit.java +++ b/src/ei/game/scene/units/Unit.java @@ -7,6 +7,7 @@ import ei.engine.math.Vector2f; import ei.engine.math.Vector2i; import ei.engine.math.Vector3f; import ei.engine.scene.Node; +import ei.engine.sound.Sound; import ei.game.algo.AStar; import ei.game.algo.AStarNode; import ei.game.gamestate.InGameState; @@ -35,6 +36,7 @@ public abstract class Unit extends GameEntity{ private int weponTimer; // The path to travel private LinkedList path; + private Vector2i target; /** * Creates a empty unit @@ -50,6 +52,7 @@ public abstract class Unit extends GameEntity{ public void setSelected(boolean b) { if(b) { + getSelectSound().play(); unitNode.add(getSelection().getSelectNode()); } else{ @@ -97,6 +100,7 @@ public abstract class Unit extends GameEntity{ * @param y The y pos to move to */ public void move(int x, int y){ + getMoveSound().play(); move(x,y,true); } @@ -125,6 +129,7 @@ public abstract class Unit extends GameEntity{ * Lets a unit attack another unit or object in the world; */ public void attack(Vector2i target) { + this.target = target; attack = InGameState.getMap().getPos(target.getX(),target.getY()); } @@ -132,6 +137,12 @@ public abstract class Unit extends GameEntity{ public abstract float getVelocity(); + public abstract Sound getGunSound(); + + public abstract Sound getSelectSound(); + + public abstract Sound getMoveSound(); + public void removeUnit(){ unitNode.remove(getSprite()); getPlayer().removeUnit(this); @@ -236,7 +247,15 @@ public abstract class Unit extends GameEntity{ } else if(attack != null){ Weapon wepon = getWeapon(new Vector2f(unitNode.getLocation().getX(), unitNode.getLocation().getY())); - Vector2i enamyPos = InGameState.getMap().getPosIndex(attack); + Vector2i enamyPos; + if(InGameState.getMap().getPos(target.getX(), target.getY())!=attack) { + enamyPos = InGameState.getMap().getPosIndex(attack); + } + else{ + enamyPos = target.getCopy(); + } + + if(attack.getLife() <= 0 || enamyPos == null){ attack = null; } @@ -244,6 +263,7 @@ public abstract class Unit extends GameEntity{ if(wepon.onRange(new Vector2f(attack.getNode().getLocation().getX(), attack.getNode().getLocation().getY()))){ if(weponTimer >= wepon.getReload()){ wepon.launch(enamyPos); + getGunSound().play(); WeaponHandler.getInstance().addWeapon(wepon); weponTimer = 0; } diff --git a/src/ei/game/scene/weapons/MachineGun.java b/src/ei/game/scene/weapons/MachineGun.java index 52c78ea..bfbfb6e 100644 --- a/src/ei/game/scene/weapons/MachineGun.java +++ b/src/ei/game/scene/weapons/MachineGun.java @@ -10,7 +10,7 @@ public class MachineGun extends Weapon{ setVelocity(4); setRange(500); setDamage(2); - setReload(10); + setReload(20); } public Particles getWeapon() { Particles part = new Particles("cannon");