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.

71 lines
1.8 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. package wow.doge.mygame.state
  2. import wow.doge.mygame.implicits._
  3. import wow.doge.mygame.components.TestComponent
  4. import com.jme3.scene.shape.Box
  5. import com.jme3.scene.Geometry
  6. import com.jme3.material.Material
  7. import com.jme3.math.ColorRGBA
  8. import com.jme3.asset.AssetManager
  9. import com.jme3.math.Vector3f
  10. class TestAppState(
  11. // private var _entity: Option[EntityData] = Some(new DefaultEntityData())
  12. ) extends MyBaseState {
  13. var geom: Option[Geometry] = None
  14. // def entity = _entity
  15. // override def initialize(app: Application): Unit = {
  16. // super.initialize(app)
  17. // }
  18. override def init() = {
  19. entityData
  20. .createEntity()
  21. .withComponents(TestComponent())
  22. // entityData.setComponents(x, TestComponent())
  23. val es = entityData.getEntities(classOf[TestComponent])
  24. println(es)
  25. val b = new Box(1, 1, 1)
  26. geom = Some(new Geometry("Box", b))
  27. val mat = MyMaterial(
  28. assetManager = assetManager,
  29. path = os.rel / "Common" / "MatDefs" / "Misc" / "Unshaded.j3md"
  30. )
  31. geom.foreach(e => {
  32. e.setMaterial(mat)
  33. rootNode.attachChild(e)
  34. })
  35. }
  36. override def update(tpf: Float) = {
  37. geom.foreach(_.rotate(0, 0.5f * tpf, 0))
  38. geom.foreach(_.move(new Vector3f(0, 1 * tpf, 0)))
  39. }
  40. // override def cleanup(app: Application): Unit = {
  41. // // _entity.map(_.close())
  42. // // _entity = None
  43. // }
  44. override def onEnable(): Unit = {}
  45. override def onDisable(): Unit = {}
  46. override def stop(): Unit = {}
  47. }
  48. object MyMaterial {
  49. def apply(
  50. color: String = "Color",
  51. colorType: com.jme3.math.ColorRGBA = ColorRGBA.Blue,
  52. assetManager: AssetManager,
  53. path: os.RelPath
  54. ): Material = {
  55. val mat =
  56. new Material(assetManager, path.toString())
  57. mat.setColor(color, colorType)
  58. mat
  59. }
  60. }