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.7 KiB

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