2007-03-12 19:13:08 +00:00
|
|
|
package ei.game.gamestate;
|
|
|
|
|
|
|
|
|
|
import ei.engine.scene.Node;
|
2007-04-23 15:24:59 +00:00
|
|
|
import ei.engine.sound.Sound;
|
2007-04-30 15:17:15 +00:00
|
|
|
import ei.engine.sound.SoundManager;
|
2007-03-12 19:13:08 +00:00
|
|
|
import ei.engine.state.GameState;
|
2007-04-23 16:26:39 +00:00
|
|
|
import ei.game.hud.InGameHud;
|
2007-04-28 22:09:39 +00:00
|
|
|
import ei.game.input.InGameKeyboardInput;
|
2007-03-29 23:21:00 +00:00
|
|
|
import ei.game.input.InGameMouseInput;
|
2007-05-06 20:35:09 +00:00
|
|
|
import ei.game.player.AiPlayer;
|
2007-04-05 12:45:22 +00:00
|
|
|
import ei.game.player.HumanPlayer;
|
|
|
|
|
import ei.game.player.PlayerHandler;
|
2007-03-29 23:21:00 +00:00
|
|
|
import ei.game.scene.Map;
|
2007-04-19 12:30:43 +00:00
|
|
|
import ei.game.scene.units.APU;
|
2007-04-04 16:28:57 +00:00
|
|
|
import ei.game.scene.units.Tank;
|
2007-04-18 11:56:07 +00:00
|
|
|
import ei.game.scene.weapons.WeaponHandler;
|
2007-03-12 19:13:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
public class InGameState extends GameState{
|
|
|
|
|
private Node rootNode;
|
2007-04-23 16:26:39 +00:00
|
|
|
private InGameHud hud;
|
2007-04-04 16:28:57 +00:00
|
|
|
private static Map map;
|
2007-04-23 15:24:59 +00:00
|
|
|
private Sound music;
|
2007-05-07 11:53:54 +00:00
|
|
|
private static InGameMouseInput mouse;
|
|
|
|
|
private static InGameKeyboardInput keyboard;
|
2007-03-12 19:13:08 +00:00
|
|
|
|
|
|
|
|
public InGameState(String name){
|
|
|
|
|
super(name);
|
2007-04-28 22:09:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void init() {
|
|
|
|
|
PlayerHandler.getInstance().clear();
|
|
|
|
|
WeaponHandler.getInstance().clear();
|
2007-04-30 15:17:15 +00:00
|
|
|
SoundManager.getInstnace().clear();
|
2007-04-28 22:09:39 +00:00
|
|
|
|
2007-03-12 19:13:08 +00:00
|
|
|
rootNode = new Node("InGameNode");
|
2007-05-06 20:35:09 +00:00
|
|
|
|
2007-03-29 23:21:00 +00:00
|
|
|
map = new Map(20,20);
|
2007-04-23 13:49:48 +00:00
|
|
|
map.init("data/map/default");
|
2007-05-06 20:35:09 +00:00
|
|
|
|
|
|
|
|
HumanPlayer player = new HumanPlayer();
|
2007-05-07 11:53:54 +00:00
|
|
|
mouse = new InGameMouseInput(map,player);
|
|
|
|
|
keyboard = new InGameKeyboardInput();
|
2007-05-06 20:35:09 +00:00
|
|
|
super.getInput().addInput(mouse);
|
2007-04-28 22:09:39 +00:00
|
|
|
super.getInput().addInput(keyboard);
|
2007-04-04 16:00:09 +00:00
|
|
|
|
2007-05-06 20:35:09 +00:00
|
|
|
player.addUnit(new Tank(0, 0, player));
|
|
|
|
|
player.addUnit(new Tank(1,0, player));
|
2007-04-18 16:08:10 +00:00
|
|
|
player.addUnit(new Tank(2,0, player));
|
2007-04-19 12:30:43 +00:00
|
|
|
player.addUnit(new APU(4, 0, player));
|
2007-05-06 20:35:09 +00:00
|
|
|
player.addUnit(new APU(5, 0, player));
|
2007-04-05 12:45:22 +00:00
|
|
|
PlayerHandler.getInstance().addPlayer(player);
|
2007-04-18 11:56:07 +00:00
|
|
|
|
2007-05-06 20:35:09 +00:00
|
|
|
AiPlayer ai = new AiPlayer();
|
2007-05-07 18:18:22 +00:00
|
|
|
ai.addUnit(new Tank(29,33, ai));
|
|
|
|
|
ai.addUnit(new Tank(30,33, ai));
|
|
|
|
|
ai.addUnit(new APU(31, 33, ai));
|
|
|
|
|
ai.addUnit(new APU(32, 33, ai));
|
2007-05-06 20:35:09 +00:00
|
|
|
PlayerHandler.getInstance().addPlayer(ai);
|
|
|
|
|
|
2007-04-21 21:18:27 +00:00
|
|
|
rootNode.add(map.getMapNode());
|
|
|
|
|
rootNode.add(PlayerHandler.getInstance().getNode());
|
2007-04-18 11:56:07 +00:00
|
|
|
rootNode.add(WeaponHandler.getInstance().getNode());
|
|
|
|
|
|
2007-04-23 16:26:39 +00:00
|
|
|
hud = new InGameHud(player);
|
2007-04-24 21:41:31 +00:00
|
|
|
mouse.setHud(hud);
|
2007-04-23 16:26:39 +00:00
|
|
|
rootNode.add(hud.getNode());
|
2007-04-24 21:41:31 +00:00
|
|
|
|
|
|
|
|
music = new Sound("music", "data/sounds/ei.ogg");
|
2007-04-28 22:09:39 +00:00
|
|
|
music.loop();
|
2007-03-12 19:13:08 +00:00
|
|
|
}
|
|
|
|
|
|
2007-04-05 12:45:22 +00:00
|
|
|
/**
|
|
|
|
|
* Renders the gamestate
|
|
|
|
|
*/
|
2007-03-12 19:13:08 +00:00
|
|
|
public void render() {
|
|
|
|
|
rootNode.render();
|
|
|
|
|
}
|
|
|
|
|
|
2007-04-05 12:45:22 +00:00
|
|
|
/**
|
|
|
|
|
* Updates the gamestate
|
|
|
|
|
*/
|
2007-03-12 19:13:08 +00:00
|
|
|
public void update() {
|
2007-04-05 12:45:22 +00:00
|
|
|
PlayerHandler.getInstance().update();
|
2007-04-18 11:56:07 +00:00
|
|
|
WeaponHandler.getInstance().update();
|
2007-04-23 16:26:39 +00:00
|
|
|
hud.update();
|
2007-03-15 19:26:15 +00:00
|
|
|
rootNode.update();
|
2007-03-12 19:13:08 +00:00
|
|
|
}
|
2007-04-05 12:45:22 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*Returns the map of the game
|
|
|
|
|
*
|
|
|
|
|
* @return The map of the game
|
|
|
|
|
*/
|
2007-04-04 16:28:57 +00:00
|
|
|
public static Map getMap() {
|
|
|
|
|
return map;
|
|
|
|
|
}
|
2007-05-07 11:53:54 +00:00
|
|
|
|
2007-05-07 13:46:41 +00:00
|
|
|
public static void input(boolean b){
|
2007-05-07 11:53:54 +00:00
|
|
|
mouse.setEnabled(b);
|
|
|
|
|
keyboard.setEnabled(b);
|
|
|
|
|
}
|
2007-03-12 19:13:08 +00:00
|
|
|
}
|