ComputerCraft32

GameState.java

Jul 7th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.53 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package mygame.controls_states;
  7.  
  8. import com.jme3.app.Application;
  9. import com.jme3.app.SimpleApplication;
  10. import com.jme3.app.state.AbstractAppState;
  11. import com.jme3.app.state.AppStateManager;
  12. import com.jme3.asset.AssetManager;
  13. import com.jme3.bullet.BulletAppState;
  14. import com.jme3.bullet.control.RigidBodyControl;
  15. import com.jme3.material.Material;
  16. import com.jme3.math.ColorRGBA;
  17. import com.jme3.math.Vector3f;
  18. import com.jme3.renderer.Camera;
  19. import com.jme3.scene.Geometry;
  20. import com.jme3.scene.Node;
  21. import com.jme3.scene.Spatial;
  22. import com.jme3.scene.shape.Box;
  23.  
  24. /**
  25.  *
  26.  
  27.  */
  28. public class GameState extends AbstractAppState{
  29.    
  30.     static  Geometry vehicle;
  31.     static RigidBodyControl vehicleControler;
  32.     BulletAppState appState = new BulletAppState();
  33.     Node rootNode;
  34.     SimpleApplication app;
  35.     AssetManager assetManager;
  36.     Camera camera;
  37.    
  38.       @Override  
  39.       public void initialize(AppStateManager stateManager, Application app) {
  40.         super.initialize(stateManager, app);
  41.        
  42.         this.assetManager = app.getAssetManager();
  43.         this.app = (SimpleApplication) app;
  44.         this.rootNode = this.app.getRootNode();
  45.         this.camera = app.getCamera();
  46.        
  47.         this.app.getFlyByCamera().setMoveSpeed(100);
  48.        
  49.        createTerrain();
  50.        createVehicle();
  51.        
  52.     }
  53.    
  54.     private void createTerrain() {
  55.        
  56.         Spatial terrain = assetManager.loadModel("Textures/GameScene.j3o");
  57.         terrain.setLocalTranslation(0, -100, 0);
  58.         rootNode.attachChild(terrain);
  59.        
  60.        
  61.          appState = new BulletAppState();
  62.         app.getStateManager().attach(appState);
  63.        
  64.         RigidBodyControl terrainPhysics = new RigidBodyControl(0);
  65.         terrain.addControl(terrainPhysics);
  66.        
  67.       //  appState.getPhysicsSpace().setGravity(new Vector3f(0, -0.25f, 0));
  68.        
  69.         appState.getPhysicsSpace().add(terrainPhysics);
  70.        
  71.     }
  72.    
  73.     private void createVehicle() {
  74.         Box box = new Box(2, 2, 2);
  75.        
  76.         Material material = new Material(assetManager,
  77.           "Common/MatDefs/Misc/Unshaded.j3md");
  78.          vehicle = new Geometry("Vechicle", box);
  79.         material.setColor("Color", ColorRGBA.Blue);
  80.        // material.getAdditionalRenderState().setWireframe(true);
  81.        
  82.         vehicleControler = new RigidBodyControl(2);
  83.         vehicle.addControl(vehicleControler);
  84.         appState.getPhysicsSpace().add(vehicleControler);
  85.         appState.getPhysicsSpace().setGravity(new Vector3f(0, -9.8f, 0));
  86.         vehicleControler.setFriction(0);
  87.        // vehicleControler.setKinematic(true);
  88.         vehicle.setMaterial(material);
  89.         vehicle.setLocalTranslation(0, -90, 0);
  90.         vehicle.setCullHint(Spatial.CullHint.Never);
  91.       //  this.app.getFlyByCamera().
  92.         rootNode.attachChild(vehicle);
  93.        
  94.        
  95.         VehicleControl vehicleControl = new VehicleControl(this.app.getInputManager());
  96.         vehicle.addControl(vehicleControl);
  97.        
  98.          
  99.        
  100.        
  101.         }
  102.    
  103.     public static RigidBodyControl getVehicleController() {
  104.         return vehicleControler;
  105.     }
  106.  
  107.    
  108.      @Override
  109.     public void update(float tpf) {
  110.         //  getVehicleController().applyCentralForce(new Vector3f(0, 20, 0));
  111.          
  112.          
  113.     }
  114.  
  115. }
Add Comment
Please, Sign In to add comment