diff --git a/src/ei/game/gamestate/InGameState.java b/src/ei/game/gamestate/InGameState.java index df53ae3..a0cd580 100644 --- a/src/ei/game/gamestate/InGameState.java +++ b/src/ei/game/gamestate/InGameState.java @@ -3,7 +3,8 @@ package ei.game.gamestate; import ei.engine.scene.Node; import ei.engine.state.GameState; import ei.game.input.InGameMouseInput; -import ei.game.player.Human; +import ei.game.player.HumanPlayer; +import ei.game.player.PlayerHandler; import ei.game.scene.Map; import ei.game.scene.units.Tank; @@ -11,7 +12,6 @@ import ei.game.scene.units.Tank; public class InGameState extends GameState{ private Node rootNode; private static Map map; - private static Human player; public InGameState(String name){ super(name); @@ -22,24 +22,32 @@ public class InGameState extends GameState{ InGameMouseInput mouse = new InGameMouseInput(map); super.getInput().addInput(mouse); - - player = new Human(); + HumanPlayer player = new HumanPlayer(); + player.addUnit(new Tank()); rootNode.add(player.getNode()); - Tank tank = new Tank(); - player.addUnit(tank); - //tank.move(10, 3); - } - public static Human getHuman(){ - return player; + PlayerHandler.getInstance().addPlayer(player); } + /** + * Renders the gamestate + */ public void render() { rootNode.render(); } + /** + * Updates the gamestate + */ public void update() { + PlayerHandler.getInstance().update(); rootNode.update(); } + + /** + *Returns the map of the game + * + * @return The map of the game + */ public static Map getMap() { return map; } diff --git a/src/ei/game/player/Human.java b/src/ei/game/player/HumanPlayer.java similarity index 72% rename from src/ei/game/player/Human.java rename to src/ei/game/player/HumanPlayer.java index 785bc72..a47816b 100644 --- a/src/ei/game/player/Human.java +++ b/src/ei/game/player/HumanPlayer.java @@ -6,11 +6,11 @@ import ei.engine.scene.Node; import ei.game.scene.GameEntity; import ei.game.scene.units.Unit; -public class Human { +public class HumanPlayer extends Player{ private ArrayList units; private Node unitsNode; - public Human(){ + public HumanPlayer(){ units = new ArrayList(); unitsNode = new Node("UnitsNode"); } @@ -28,4 +28,10 @@ public class Human { public Node getNode(){ return unitsNode; } + + public void update() { + for(int i=0; i players; + + /** + * Creates a PlayerHandler + * + */ + public PlayerHandler(){ + players = new ArrayList(); + } + + /** + * Add a player to the handler + * + * @param p The player to add to the handler + * @return true if added else false + */ + public boolean addPlayer(Player p){ + if(!players.contains(p)){ + players.add(p); + return true; + } + return false; + } + + /** + * Removes a player from the handler + * @param p The player to remove + * @return true if succesful else false + */ + public boolean removePlayer(Player p){ + if(players.contains(p)){ + players.remove(p); + return true; + } + return false; + } + + public void update(){ + for(int i=0; i looks.getLocation().getX()) { + looks.getLocation().add(1.5f, 0f, 0f); + } + if(moveTo.getX() < looks.getLocation().getX()) { + looks.getLocation().add(-1.5f, 0f, 0f); + } + if(moveTo.getY() > looks.getLocation().getY()) { + looks.getLocation().add(0f, 1.5f, 0f); + } + if(moveTo.getY() < looks.getLocation().getY()) { + looks.getLocation().add(0f, -1.5f, 0f); + } + + if(moveTo.getX() == looks.getLocation().getX() + && moveTo.getY() == looks.getLocation().getY()) { + moveTo = null; + } + } + } }