Permalink
Browse files

Work on physics engine mostly.

  • Loading branch information...
1 parent 9e98cd0 commit 5fd22d8c6567baf6a3e7f7cfee5edae6583b06bd @zzorn committed Apr 30, 2011
@@ -4,13 +4,27 @@ import com.jme3.asset.AssetManager
import com.jme3.bullet.BulletAppState
import com.jme3.scene.Spatial
import java.util.ArrayList
+import com.jme3.bounding.BoundingBox
+import scala.collection.JavaConversions._
/**
* Singleton for accessing services.
*/
object Context {
+ val settings = new Settings
+
+ // TODO: Make into a physics ApplicationState
val platforms: ArrayList[Spatial] = new ArrayList()
+ var platformBounds: BoundingBox = new BoundingBox()
+
+ def updatePlatformBounds() {
+ platformBounds = new BoundingBox()
+
+ platforms foreach {platform =>
+ platformBounds.mergeLocal(platform.getWorldBound)
+ }
+ }
def assetManager: AssetManager = Ludum20.getAssetManager
@@ -1,6 +1,7 @@
package net.zzorn
import com.jme3.scene.{Node, Spatial}
+import controls.WalkerControl
import level.PlatformType
import simplex3d.math.float.functions._
import simplex3d.math.float._
@@ -87,6 +88,10 @@ class Level extends Bean {
val blob = ShapeUtils.createSphere(pos, size, color)
+ val walkerControl = new WalkerControl(Context.settings.gemCreature())
+
+ blob.addControl(walkerControl)
+
level.attachChild(blob)
// Create physics collision shape
@@ -24,7 +24,7 @@ class LevelEditor() {
}
def setLevel(_level: Level) {
- if (level != null) level.removeListener(changeListener)
+ if (level != null) level.removeDeepListener(changeListener)
level = _level
@@ -36,7 +36,7 @@ class LevelEditor() {
mainPanel.repaint()
frame.pack()
- if (level != null) level.addListener(changeListener)
+ if (level != null) level.addDeepListener(changeListener)
}
def start() {
@@ -8,18 +8,20 @@ import com.jme3.bullet.BulletAppState
import com.jme3.scene.{Spatial, Geometry}
import com.jme3.bullet.collision.shapes.CapsuleCollisionShape
import com.jme3.bullet.control.CharacterControl
-import com.jme3.input.KeyInput
import com.jme3.input.controls.{ActionListener, KeyTrigger}
import com.jme3.light.{AmbientLight, DirectionalLight}
+import controls.{PhysicsSettings, SpeedSettings, WalkerControl, Steerable}
import net.zzorn.utils.VectorConversion._
import utils.ShapeUtils
import simplex3d.math.float.functions._
import simplex3d.math.float._
import com.jme3.asset.plugins.FileLocator
+import com.jme3.input.{ChaseCamera, KeyInput}
/**
*
*/
+// TODO: Extract input handling & player control
object Ludum20 extends SimpleApplication {
//val bulletAppState = new BulletAppState()
@@ -28,6 +30,7 @@ object Ludum20 extends SimpleApplication {
private var right = false
private var up = false
private var down = false
+ private var jump = false
def main(args: Array[ String ])
@@ -41,11 +44,10 @@ object Ludum20 extends SimpleApplication {
private var level: Level = new Level()
private var player: Spatial = null
- //private var playerControl: CharacterControl = null
+ private var playerSteering: Steerable = null
private var levelToLoad: Level = null
private var levelNode: Spatial = null
- private val walkDirection = new Vector3f()
def simpleInitApp() {
@@ -73,10 +75,14 @@ object Ludum20 extends SimpleApplication {
//Context.physicsState.getPhysicsSpace.add(playerControl);
val actionListener = createActionListener()
- //setupInput(actionListener)
+ setupInput(actionListener)
flyCam.setDragToRotate(true)
+
+ flyCam.setEnabled(false);
+ val chaseCam = new ChaseCamera(cam, player, inputManager);
+
setPauseOnLostFocus(false)
}
@@ -89,16 +95,25 @@ object Ludum20 extends SimpleApplication {
startLevel(level)
}
+ // Update platform bounding area
+ Context.updatePlatformBounds()
+
// Handle player movement
- val camDir = cam.getDirection.clone().multLocal(0.6f)
- val camLeft = cam.getLeft.clone().multLocal(0.4f)
- walkDirection.set(0, 0, 0)
- if (left) walkDirection.addLocal(camLeft)
- if (right) walkDirection.addLocal(camLeft.negate())
- if (up) walkDirection.addLocal(camDir)
- if (down) walkDirection.addLocal(camDir.negate())
- //playerControl.setWalkDirection(walkDirection)
- //cam.setLocation(playerControl.getPhysicsLocation)
+ if (playerSteering != null) {
+ val camDir: Vec3 = cam.getDirection.clone().multLocal(0.6f)
+ val camLeft: Vec3 = cam.getLeft.clone().multLocal(0.4f)
+ playerSteering.steeringMovement := Vec3.Zero
+ if (left) playerSteering.steeringMovement += camLeft
+ if (right) playerSteering.steeringMovement -= camLeft
+ if (up) playerSteering.steeringMovement += camDir
+ if (down) playerSteering.steeringMovement -= camDir
+ playerSteering.jump = jump
+ }
+
+ val playerWalker = player.getControl(classOf[WalkerControl])
+ if (playerWalker != null) {
+ playerWalker.heading := cam.getDirection
+ }
}
@@ -123,6 +138,8 @@ object Ludum20 extends SimpleApplication {
// Spawn player
//playerControl.setPhysicsLocation(level.spawnLocation)
player.setLocalTranslation(level.spawnLocation)
+ player.getControl(classOf[WalkerControl]).reset()
+
}
@@ -167,16 +184,13 @@ object Ludum20 extends SimpleApplication {
}
def setupPlayer(): Spatial = {
- /*
- val capsuleShape = new CapsuleCollisionShape(1f, 3f, 1)
- playerControl = new CharacterControl(capsuleShape, 0.1f)
- playerControl.setJumpSpeed(50)
- playerControl.setFallSpeed(30)
- playerControl.setGravity(30)
- */
-
- val player = ShapeUtils.createSphere(size = Vec3(2, 3, 2))
- //player.addControl(playerControl)
+ val player = ShapeUtils.createBox(size = Vec3(Context.settings.player().radius(),
+ Context.settings.player().height(),
+ Context.settings.player().radius()))
+ val playerWalker = new WalkerControl(Context.settings.player())
+ //playerWalker.loggingOn = true
+ playerSteering = playerWalker
+ player.addControl(playerWalker)
player
}
@@ -187,7 +201,7 @@ object Ludum20 extends SimpleApplication {
case "Rights" => right = value
case "Downs" => down = value
case "Ups" => up = value
- case "Jumps" => //player.jump()
+ case "Jumps" => jump = value
case _ => // Do nothing
}
}
@@ -0,0 +1,19 @@
+package net.zzorn
+
+import controls.{SpeedSettings, PhysicsSettings}
+import creatures.CreatureSettings
+import org.scalaprops.Bean
+import org.scalaprops.ui.editors.BeanEditorFactory
+
+/**
+ * Contains various settings
+ */
+class Settings extends Bean {
+
+ val player = p('player, new CreatureSettings)
+ val gemCreature = p('gems, new CreatureSettings)
+
+ val cameraBehindDistance = p('cameraBehindDistance, 10f)
+ val cameraAboveDistance = p('cameraAboveDistance, 5f)
+
+}
@@ -0,0 +1,14 @@
+package net.zzorn.controls
+
+import org.scalaprops.Bean
+
+/**
+ *
+ */
+
+class PhysicsSettings extends Bean {
+ val gravityEffect = p('gravityEffect, 0.2f)
+ val dragFactor = p('dragFactor, 0.05f)
+ val jumpSpeed = p('jumpSpeed, 0.1f)
+
+}
@@ -0,0 +1,16 @@
+package net.zzorn.controls
+
+import org.scalaprops.Bean
+
+/**
+ *
+ */
+
+class SpeedSettings extends Bean {
+ val strafeSpeed = p('strafeSpeed, 10f)
+ val forwardSpeed = p('forwardSpeed, 30f)
+ val backSpeed = p('backSpeed, 5f)
+ val upSpeed = p('upSpeed, 0f)
+ val downSpeed = p('downSpeed, 0f)
+
+}
@@ -14,6 +14,13 @@ trait Steerable {
val velocity: Vec3 = Vec3(0, 0, 0)
- val jump: Boolean = false
+ var jump: Boolean = false
+
+ def reset() {
+ heading := Vec3(1, 0, 0)
+ velocity := Vec3.Zero
+ steeringMovement := Vec3.Zero
+ jump = false
+ }
}
Oops, something went wrong.

0 comments on commit 5fd22d8

Please sign in to comment.