Added hud

This commit is contained in:
Ziver Koc 2009-03-11 20:18:16 +00:00
parent b26ee23c41
commit fa72657e8f

View file

@ -16,14 +16,13 @@ import com.jme.scene.state.LightState;
import com.jme.system.DisplaySystem; import com.jme.system.DisplaySystem;
import com.jmex.game.state.CameraGameState; import com.jmex.game.state.CameraGameState;
import com.jmex.game.state.GameStateManager; import com.jmex.game.state.GameStateManager;
import com.jmex.game.state.load.LoadingGameState;
import com.jmex.physics.DynamicPhysicsNode; import com.jmex.physics.DynamicPhysicsNode;
import com.jmex.physics.PhysicsDebugger; import com.jmex.physics.PhysicsDebugger;
import com.jmex.physics.PhysicsSpace; import com.jmex.physics.PhysicsSpace;
import com.jmex.physics.StaticPhysicsNode; import com.jmex.physics.StaticPhysicsNode;
public class InGameState extends CameraGameState { public class InGameState extends CameraGameState {
/** The Keyboard/ mous input handler */ /** The Keyboard/ mouse input handler */
protected InputHandler input; protected InputHandler input;
/** The environment of the game */ /** The environment of the game */
protected Environment environment; protected Environment environment;
@ -36,10 +35,6 @@ public class InGameState extends CameraGameState {
public InGameState(String name) { public InGameState(String name) {
super(name); super(name);
LoadingGameState loader = new LoadingGameState(2);
GameStateManager.getInstance().attachChild(loader);
loader.setActive(true);
// ***************** Load the Game ********************************** // ***************** Load the Game **********************************
// Pass (render thingies) // Pass (render thingies)
@ -57,39 +52,47 @@ public class InGameState extends CameraGameState {
// environment // environment
environment = new Environment(rootNode); environment = new Environment(rootNode);
rootNode.attachChild(environment); rootNode.attachChild(environment);
loader.increment();
// ship // ship
Node ship = SGUtil.loadModel("sg/data/models/ships/G6.3ds"); Node ship = SGUtil.loadModel("sg/data/models/ships/G6.3ds");
ship.setLocalTranslation(new Vector3f( 0, 0, 40)); ship.setLocalTranslation(new Vector3f( 0, 0, 40));
rootNode.attachChild(ship); rootNode.attachChild(ship);
loader.increment();
// inputs // inputs
FirstPersonHandler first = new FirstPersonHandler( cam, 50, 1 ); FirstPersonHandler first = new FirstPersonHandler( cam, 50, 1 );
input = new InputHandler(); input = new InputHandler();
input.addToAttachedHandlers( first ); input.addToAttachedHandlers( first );
loader.increment();
// lights // lights
/** Set up a basic, default light. */ /** Set up a basic, default light. */
PointLight light = new PointLight(); PointLight light = new PointLight();
light.setDiffuse( new ColorRGBA( 0.75f, 0.75f, 0.75f, 0.75f ) ); light.setDiffuse( new ColorRGBA( 0.75f, 0.75f, 0.75f, 0.75f ) );
light.setAmbient( new ColorRGBA( 0.5f, 0.5f, 0.5f, 1.0f ) ); light.setAmbient( new ColorRGBA( 0.5f, 0.5f, 0.5f, 1.0f ) );
light.setLocation( new Vector3f( 100, 100, 100 ) ); light.setLocation( new Vector3f( 100, 100, 100 ) );
light.setEnabled( true ); light.setEnabled( true );
/** Attach the light to a lightState and the lightState to rootNode. */ /** Attach the light to a lightState and the lightState to rootNode. */
LightState lightState = DisplaySystem.getDisplaySystem().getRenderer().createLightState(); LightState lightState = DisplaySystem.getDisplaySystem().getRenderer().createLightState();
lightState.setEnabled( true ); lightState.setEnabled( true );
lightState.attach( light ); lightState.attach( light );
rootNode.setRenderState( lightState ); rootNode.setRenderState( lightState );
rootNode.updateRenderState(); rootNode.updateRenderState();
HudState hud = new HudState("hud");
GameStateManager.getInstance().attachChild(hud);
cam.setFrustumFar(5000);
// ***************** Done loading ********************************** // ***************** Done loading **********************************
loader.setActive(false); }
GameStateManager.getInstance().detachChild(loader);
this.setActive(true); public void onActivate(){
super.onActivate();
GameStateManager.getInstance().activateChildNamed("hud");
}
public void onDeactivate(){
super.onDeactivate();
GameStateManager.getInstance().deactivateChildNamed("hud");
} }
public void stateUpdate(float tpf) { public void stateUpdate(float tpf) {