package ei.game.gamestate;

import ei.engine.scene.Node;
import ei.engine.state.GameState;
import ei.game.input.InGameMouseInput;
import ei.game.player.HumanPlayer;
import ei.game.player.PlayerHandler;
import ei.game.scene.Map;
import ei.game.scene.units.APU;
import ei.game.scene.units.Bomber;
import ei.game.scene.units.Tank;
import ei.game.scene.weapons.WeaponHandler;


public class InGameState extends GameState{
	private Node rootNode;
	private static Map map;
	
	public InGameState(String name){
		super(name);
		rootNode = new Node("InGameNode");

		map = new Map(20,20);
		rootNode.add(map.getMapNode());
		InGameMouseInput mouse = new InGameMouseInput(map);
		super.getInput().addInput(mouse);
		
		HumanPlayer player = new HumanPlayer();
		Tank t1 = new Tank(player);
		t1.setLife(10);
		player.addUnit(t1);
		Tank t2 = new Tank(1,0, player);
		t2.setLife(30);
		player.addUnit(t2);
		player.addUnit(new Tank(2,0, player));
		player.addUnit(new Bomber(3, 0, player));
		player.addUnit(new APU(4, 0, player));
		
		rootNode.add(player.getNode());
		PlayerHandler.getInstance().addPlayer(player);
		
		rootNode.add(WeaponHandler.getInstance().getNode());
		
	}
	
	/**
	 * Renders the gamestate
	 */
	public void render() {
		rootNode.render();
	}

	/**
	 * Updates the gamestate
	 */
	public void update() {
		PlayerHandler.getInstance().update();
		WeaponHandler.getInstance().update();
		rootNode.update();
	}
	
	/**
	 *Returns the map  of the game
	 *
	 * @return The map  of the game
	 */
	public static Map getMap() {
		return map;
	}

}
