forked from nova/jmonkey-test
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.
106 lines
3.2 KiB
106 lines
3.2 KiB
package wow.doge.mygame.game.subsystems.level
|
|
import com.jme3.asset.AssetManager
|
|
import com.jme3.bullet.control.RigidBodyControl
|
|
import com.jme3.bullet.util.CollisionShapeFactory
|
|
import com.jme3.light.AmbientLight
|
|
import com.jme3.light.DirectionalLight
|
|
import com.jme3.math.ColorRGBA
|
|
import com.jme3.math.Vector3f
|
|
import com.jme3.renderer.ViewPort
|
|
import com.jme3.scene.Spatial
|
|
import monix.bio.IO
|
|
import monix.bio.UIO
|
|
import wow.doge.mygame.AppError
|
|
object DefaultGameLevel {
|
|
|
|
def apply(
|
|
assetManager: AssetManager,
|
|
viewPort: ViewPort
|
|
) = {
|
|
val sceneModel: Spatial = assetManager.loadModel("main.scene")
|
|
val sceneShape = CollisionShapeFactory.createMeshShape(
|
|
sceneModel.toNode match {
|
|
case Right(node) => node
|
|
case Left(ex) =>
|
|
throw new NotImplementedError("No fallback sceneshape")
|
|
}
|
|
)
|
|
val landscape: RigidBodyControl = new RigidBodyControl(sceneShape, 0)
|
|
|
|
viewPort.setBackgroundColor(new ColorRGBA(0.7f, 0.8f, 1f, 1f))
|
|
sceneModel.setLocalScale(2f)
|
|
sceneModel.addControl(landscape)
|
|
// discard { rootNode.attachChild(sceneModel) }
|
|
// bulletAppState.getPhysicsSpace.add(landscape)
|
|
// bulletAppState.getPhysicsSpace.add(player)
|
|
|
|
val al = new AmbientLight();
|
|
al.setColor(ColorRGBA.White.mult(1.3f));
|
|
// app.rootNode.addLight(al);
|
|
|
|
val dl = new DirectionalLight();
|
|
dl.setColor(ColorRGBA.White);
|
|
dl.setDirection(new Vector3f(2.8f, -2.8f, -2.8f).normalizeLocal());
|
|
// app.rootNode.addLight(dl);
|
|
new GameLevel(
|
|
model = sceneModel,
|
|
physicsControl = landscape,
|
|
ambientLight = al,
|
|
directionalLight = dl
|
|
)
|
|
}
|
|
|
|
def apply(
|
|
assetManager: wow.doge.mygame.utils.wrappers.jme.AssetManager,
|
|
viewPort: ViewPort
|
|
): IO[AppError, GameLevel] =
|
|
// for {
|
|
// sceneModel <- assetManager.loadModelAs[Node](os.rel / "main.scene")
|
|
// sceneShape <- UIO(CollisionShapeFactory.createMeshShape(sceneModel))
|
|
// landscape <- UIO(new RigidBodyControl(sceneShape, 0))
|
|
|
|
// _ <- UIO {
|
|
// viewPort.setBackgroundColor(new ColorRGBA(0.7f, 0.8f, 1f, 1f))
|
|
// sceneModel.setLocalScale(2f)
|
|
// sceneModel.addControl(landscape)
|
|
// }
|
|
|
|
// al = {
|
|
// val al = new AmbientLight()
|
|
// al.setColor(ColorRGBA.White.mult(1.3f))
|
|
// al
|
|
// }
|
|
|
|
// dl = {
|
|
// val dl = new DirectionalLight()
|
|
// dl.setColor(ColorRGBA.White)
|
|
// dl.setDirection(new Vector3f(2.8f, -2.8f, -2.8f).normalizeLocal())
|
|
// dl
|
|
// }
|
|
|
|
// } yield new GameLevel(
|
|
// model = sceneModel,
|
|
// physicsControl = landscape,
|
|
// ambientLight = al,
|
|
// directionalLight = dl
|
|
// )
|
|
GameLevel(
|
|
os.rel / "main.scene", {
|
|
val al = new AmbientLight()
|
|
al.setColor(ColorRGBA.White.mult(1.3f))
|
|
al
|
|
}, {
|
|
val dl = new DirectionalLight()
|
|
dl.setColor(ColorRGBA.White)
|
|
dl.setDirection(new Vector3f(2.8f, -2.8f, -2.8f).normalizeLocal())
|
|
dl
|
|
}
|
|
)(assetManager).flatMap(gameLevel =>
|
|
UIO {
|
|
viewPort.setBackgroundColor(new ColorRGBA(0.7f, 0.8f, 1f, 1f))
|
|
gameLevel.model.setLocalScale(2f)
|
|
gameLevel.model.addControl(gameLevel.physicsControl)
|
|
gameLevel
|
|
}
|
|
)
|
|
}
|