diff --git a/README.md b/README.md index 60b6977..91d3c76 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ A game about a journey involving vehicles and obstacles. ## Status ### DONE * Physics-based vehicles +* One car model * Driving controls (WASDX) * Enter / Exit a car (Enter) * Camera following the player diff --git a/assets-src/Models/rivercrossing.blend b/assets-src/Models/rivercrossing.blend new file mode 100644 index 0000000..9f3a202 Binary files /dev/null and b/assets-src/Models/rivercrossing.blend differ diff --git a/assets/Models/rivercrossing.j3o b/assets/Models/rivercrossing.j3o new file mode 100644 index 0000000..35baaec Binary files /dev/null and b/assets/Models/rivercrossing.j3o differ diff --git a/assets/Models/rivercrossing.j3odata b/assets/Models/rivercrossing.j3odata new file mode 100644 index 0000000..6534776 --- /dev/null +++ b/assets/Models/rivercrossing.j3odata @@ -0,0 +1,3 @@ +# +#Fri Jan 06 07:21:19 CET 2017 +ORIGINAL_PATH=Models/rivercrossing.scene diff --git a/screenshot.png b/screenshot.png index 2740451..e8a407d 100644 Binary files a/screenshot.png and b/screenshot.png differ diff --git a/src/roadtrip/RoadTrip.java b/src/roadtrip/RoadTrip.java index bb49d1b..7f63493 100644 --- a/src/roadtrip/RoadTrip.java +++ b/src/roadtrip/RoadTrip.java @@ -11,6 +11,7 @@ import com.jme3.bullet.collision.shapes.HeightfieldCollisionShape; import com.jme3.bullet.control.BetterCharacterControl; import com.jme3.bullet.control.RigidBodyControl; import com.jme3.bullet.control.VehicleControl; +import com.jme3.input.ChaseCamera; import com.jme3.input.KeyInput; import com.jme3.input.controls.ActionListener; import com.jme3.input.controls.KeyTrigger; @@ -20,9 +21,11 @@ import com.jme3.math.ColorRGBA; import com.jme3.math.FastMath; import com.jme3.math.Quaternion; import com.jme3.math.Vector3f; +import com.jme3.scene.CameraNode; import com.jme3.scene.Geometry; import com.jme3.scene.Node; import com.jme3.scene.Spatial; +import com.jme3.scene.control.CameraControl.ControlDirection; import com.jme3.scene.shape.Box; import com.jme3.scene.shape.Cylinder; import com.jme3.terrain.geomipmap.TerrainGrid; @@ -59,6 +62,8 @@ public class RoadTrip extends SimpleApplication implements ActionListener { public static boolean DEBUG = false;//true; private BulletAppState bulletAppState; + + private ChaseCamera chaseCam; // START Terrain private Material mat_terrain; @@ -122,6 +127,9 @@ public class RoadTrip extends SimpleApplication implements ActionListener { addPerson(); addPlayer(); + + chaseCam = new ChaseCamera(cam, playerNode, inputManager); + chaseCam.setSmoothMotion(true); } private void setupKeys() { @@ -163,15 +171,25 @@ public class RoadTrip extends SimpleApplication implements ActionListener { float xOff = 1.6f; float zOff = 2f; - Geometry carBody = new Geometry("car body", new Box(new Vector3f(0.0f, 1f, 0.0f), 1.4f, 0.5f, 3.6f)); Material matBody = new Material(getAssetManager(), "Common/MatDefs/Light/Lighting.j3md"); matBody.setFloat("Shininess", 32f); matBody.setBoolean("UseMaterialColors", true); matBody.setColor("Ambient", ColorRGBA.Black); matBody.setColor("Diffuse", ColorRGBA.Red); matBody.setColor("Specular", ColorRGBA.White); - carBody.setMaterial(matBody); - vehicleModel.attachChild(carBody); + + + if (vehicleInstance.carType == VehicleInstance.WEAK) { + Spatial carBody = getAssetManager().loadModel("Models/rivercrossing.j3o"); + carBody.setLocalScale(1.1f, 0.8f, 0.8f); + carBody.setLocalTranslation(0f, -1f, 0f); + carBody.rotate(0f, 3.1415f, 0f); + vehicleModel.attachChild(carBody); + } else { + Geometry carBody = new Geometry("car body", new Box(new Vector3f(0.0f, 1f, 0.0f), 1.4f, 0.5f, 3.6f)); + carBody.setMaterial(matBody); + vehicleModel.attachChild(carBody); + } //create a compound shape and attach the BoxCollisionShape for the car body at 0,1,0 //this shifts the effective center of mass of the BoxCollisionShape to 0,-1,0 @@ -462,8 +480,8 @@ public class RoadTrip extends SimpleApplication implements ActionListener { public void simpleUpdate(float tpf) { Vector3f playerLocation = playerNode.getWorldTranslation(); Vector3f newLocation = new Vector3f(playerLocation).add(new Vector3f(-1f, 1.5f, 2.4f).mult(20f)); - cam.setLocation(new Vector3f(cam.getLocation()).interpolate(newLocation, Math.min(tpf, 1f))); - cam.lookAt(playerLocation, Vector3f.UNIT_Y); + /*cam.setLocation(new Vector3f(cam.getLocation()).interpolate(newLocation, Math.min(tpf, 1f))); + cam.lookAt(playerLocation, Vector3f.UNIT_Y);*/ for (VehicleNode vehicle : vehicles) { vehicle.vehicleInstance.accelerationSmooth = (vehicle.vehicleInstance.accelerationSmooth + vehicle.vehicleInstance.accelerationValue * (tpf * 10f)) / (1 + tpf * 10f); @@ -546,7 +564,7 @@ public class RoadTrip extends SimpleApplication implements ActionListener { if (dist < 5f) { playerVehicleNode = vehicle; playerNode.removeFromParent(); - playerNode.setLocalTranslation(0f, 0f, 0f); + playerNode.setLocalTranslation(0f, 0f, -1f); playerNode.setLocalRotation(Quaternion.DIRECTION_Z); playerNode.removeControl(playerPersonControl); playerVehicleNode.attachChild(playerNode);