Added states to the game and Empty input handlers :)
This commit is contained in:
parent
5514b96257
commit
e3cc55162f
8 changed files with 311 additions and 2 deletions
84
src/sg/states/InGameState.java
Normal file
84
src/sg/states/InGameState.java
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
package sg.states;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import sg.env.Environment;
|
||||
import sg.util.SGUtil;
|
||||
|
||||
import com.jme.input.InputHandler;
|
||||
import com.jme.input.ThirdPersonHandler;
|
||||
import com.jme.math.Vector3f;
|
||||
import com.jme.renderer.Renderer;
|
||||
import com.jme.scene.Node;
|
||||
import com.jme.system.DisplaySystem;
|
||||
import com.jmex.game.state.CameraGameState;
|
||||
import com.jmex.game.state.load.LoadingGameState;
|
||||
import com.jmex.physics.DynamicPhysicsNode;
|
||||
import com.jmex.physics.PhysicsDebugger;
|
||||
import com.jmex.physics.PhysicsSpace;
|
||||
import com.jmex.physics.StaticPhysicsNode;
|
||||
|
||||
public class InGameState extends CameraGameState {
|
||||
/** The Keyboard/ mous input handler */
|
||||
protected InputHandler input;
|
||||
/** The environment of the game */
|
||||
protected Environment environment;
|
||||
/** The physics space */
|
||||
private PhysicsSpace physicsSpace;
|
||||
/** The Speed of the physics */
|
||||
private float physicsSpeed = 1;
|
||||
|
||||
public InGameState(String name) {
|
||||
super(name);
|
||||
|
||||
LoadingGameState loader = new LoadingGameState(2);
|
||||
loader.setActive(true);
|
||||
// ***************** Load the Game **********************************
|
||||
|
||||
//physics
|
||||
physicsSpace = PhysicsSpace.create();
|
||||
|
||||
physicsSpace.setDirectionalGravity(new Vector3f(0f, 0f, 0f));
|
||||
StaticPhysicsNode staticNode = physicsSpace.createStaticNode();
|
||||
DynamicPhysicsNode dynamicNode = physicsSpace.createDynamicNode();
|
||||
rootNode.attachChild(dynamicNode);
|
||||
rootNode.attachChild(staticNode);
|
||||
|
||||
// environment
|
||||
environment = new Environment();
|
||||
rootNode.attachChild(environment);
|
||||
loader.increment();
|
||||
|
||||
// ship
|
||||
Node ship = SGUtil.loadModel("sg/data/models/ships/G6.3ds");
|
||||
ship.setLocalTranslation(new Vector3f(0,0,-40));
|
||||
//ship.setLocalScale(0.01f);
|
||||
rootNode.attachChild(ship);
|
||||
loader.increment();
|
||||
|
||||
// inputs
|
||||
input = new ThirdPersonHandler(ship, cam);
|
||||
loader.increment();
|
||||
|
||||
// ***************** Done loading **********************************
|
||||
loader.setActive(false);
|
||||
this.setActive(true);
|
||||
}
|
||||
|
||||
public void stateUpdate(float tpf) {
|
||||
input.update(tpf);
|
||||
|
||||
environment.update();
|
||||
|
||||
if ( tpf > 0.2 || Float.isNaN( tpf ) ) {
|
||||
Logger.getLogger( PhysicsSpace.LOGGER_NAME ).warning( "Maximum physics update interval is 0.2 seconds - capped." );
|
||||
physicsSpace.update( 0.2f * physicsSpeed );
|
||||
}
|
||||
else physicsSpace.update( tpf * physicsSpeed );
|
||||
}
|
||||
|
||||
public void stateRender(float tpf){
|
||||
Renderer r = DisplaySystem.getDisplaySystem().getRenderer();
|
||||
PhysicsDebugger.drawPhysics( physicsSpace, r );
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue