Testing out JmonkeyEngine to make a game in Scala with Akka Actors within a pure FP layer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
2.3 KiB

  1. package wow.doge.mygame.game.subsystems.level
  2. import com.jme3.bullet.BulletAppState
  3. import com.jme3.bullet.collision.shapes.CapsuleCollisionShape
  4. import com.jme3.bullet.control.CharacterControl
  5. import com.jme3.bullet.control.RigidBodyControl
  6. import com.jme3.bullet.util.CollisionShapeFactory
  7. import com.jme3.scene.Spatial
  8. import wow.doge.mygame.implicits._
  9. import wow.doge.mygame.game.GameApp
  10. import com.jme3.syntax._
  11. import com.jme3.math.ColorRGBA
  12. import com.jme3.light.DirectionalLight
  13. import com.jme3.math.Vector3f
  14. import com.jme3.light.AmbientLight
  15. object DefaultGameLevel {
  16. // lazy valbulletAppState: BulletAppState
  17. // bulletAppState.setThreadingType(ThreadingType.SEQUENTIAL)
  18. // We set up collision detection for the scene by creating a
  19. // compound collision shape and a static RigidBodyControl with mass zero.
  20. // We set up collision detection for the player by creating
  21. // a capsule collision shape and a CharacterControl.
  22. // The CharacterControl offers extra settings for
  23. // size, stepheight, jumping, falling, and gravity.
  24. // We also put the player in its starting position.
  25. lazy val capsuleShape = new CapsuleCollisionShape(1.5f, 6f, 1)
  26. lazy val player: CharacterControl =
  27. new CharacterControl(capsuleShape, 0.05f)
  28. def apply(app: GameApp, bulletAppState: BulletAppState) = {
  29. lazy val sceneModel: Spatial = app.assetManager.loadModel("main.scene")
  30. lazy val sceneShape = CollisionShapeFactory.createMeshShape(
  31. sceneModel.toNode match {
  32. case util.Right(node) => node
  33. case util.Left(ex) =>
  34. throw new NotImplementedError("No fallback sceneshape")
  35. }
  36. )
  37. lazy val landscape: RigidBodyControl =
  38. new RigidBodyControl(sceneShape, 0)
  39. // // discard { app.stateManager.attach(bulletAppState) }
  40. app.viewPort.setBackgroundColor(new ColorRGBA(0.7f, 0.8f, 1f, 1f))
  41. sceneModel.setLocalScale(2f)
  42. sceneModel.addControl(landscape)
  43. discard { app.rootNode.attachChild(sceneModel) }
  44. bulletAppState.getPhysicsSpace.add(landscape)
  45. bulletAppState.getPhysicsSpace.add(player)
  46. val al = new AmbientLight();
  47. al.setColor(ColorRGBA.White.mult(1.3f));
  48. app.rootNode.addLight(al);
  49. val dl = new DirectionalLight();
  50. dl.setColor(ColorRGBA.White);
  51. dl.setDirection(new Vector3f(2.8f, -2.8f, -2.8f).normalizeLocal());
  52. app.rootNode.addLight(dl);
  53. }
  54. }