Josh Engebretson 11 years ago
parent
commit
a9d9be4431

+ 18 - 0
PhysicsPlatformer/Resources/Components/Level.js

@@ -30,6 +30,7 @@ self.batWaypoints = [];
 // parsed coins
 var coins = [];
 var bats = [];
+var vines = [];
 
 var beginContactCallbacks = {};
 
@@ -76,6 +77,13 @@ function createBat(obj) {
     self.batNodes.push(batNode);
 }
 
+function createVine(obj) {
+
+    var vineNode = scene.createChild("Vine");
+    vineNode.position2D = obj.position;
+    vineNode.createJSComponent("Vine");
+}
+
 
 function parseEntities() {
 
@@ -116,8 +124,13 @@ function parseEntities() {
 
                 self.batWaypoints.push(o.position);
 
+            } else if (o.type == "Vine") {
+
+                vines.push(o);
+
             }
 
+
         }
     }
 
@@ -138,6 +151,11 @@ function parseEntities() {
         createBat(bats[i]);
 
     }
+    for (var i in vines) {
+
+        createVine(vines[i]);
+
+    }
 
 }
 

+ 52 - 0
PhysicsPlatformer/Resources/Components/Vine.js

@@ -0,0 +1,52 @@
+// Rope Vine
+
+var NUM_OBJECTS = 10;
+
+var node = self.node;
+
+var x = node.position2D[0];
+var y = node.position2D[1];
+node.position = [0, 0, 0];
+
+print("VINE!");
+
+function start() {
+
+    // create the node body
+    var groundBody = node.createComponent("RigidBody2D");
+
+    var prevBody = groundBody;
+
+    for (var i = 0; i < NUM_OBJECTS; i++) {
+
+        // can we create off our node instead of scene?
+        var vnode = scene.createChild("RigidBody");
+        var vbody = vnode.createComponent("RigidBody2D");
+        vbody.bodyType = Atomic.BT_DYNAMIC;
+
+        // Create box
+        var vbox = vnode.createComponent("CollisionBox2D");
+        // Set friction
+        vbox.friction = .2;
+        // Set mask bits.
+        vbox.maskBits = 0xFFFF & ~0x0002;
+
+        vnode.position = [x + 0.5 + 1.0 * i, y, 0.0];
+        vbox.size = [1.0, 0.1];
+        vbox.density = 10.0;
+        vbox.categoryBits = 0x0001;
+
+        var joint = vnode.createComponent("ConstraintRevolute2D");
+        joint.otherBody = prevBody;
+        joint.anchor = [x + i, y];
+        joint.collideConnected = false;
+        prevBody = vbody;
+
+    }
+
+    var constraintRope = node.createComponent("ConstraintRope2D");
+    constraintRope.otherBody = prevBody;
+    constraintRope.ownerBodyAnchor = [x, y];
+    constraintRope.maxLength = (NUM_OBJECTS - 1.0 + 0.01);
+
+}

+ 3 - 0
PhysicsPlatformer/Resources/Levels/Level1.tmx

@@ -2212,5 +2212,8 @@
   <object name="BatWaypoint" type="BatWaypoint" x="768.779" y="1417.67" width="85.5131" height="65.3924"/>
   <object name="BatWaypoint" type="BatWaypoint" x="2021.29" y="587.693" width="85.5131" height="65.3924"/>
   <object name="BatWaypoint" type="BatWaypoint" x="2297.95" y="1050.47" width="85.5131" height="65.3924"/>
+  <object name="Vine" type="Vine" x="867.834" y="274.682" width="51.7516" height="51.7516"/>
+  <object name="Vine" type="Vine" x="1761.54" y="256.768" width="51.7516" height="51.7516"/>
+  <object name="Vine" type="Vine" x="2454.22" y="324.443" width="91.5605" height="95.5414"/>
  </objectgroup>
 </map>

+ 2 - 2
PhysicsPlatformer/Resources/PhysicsPlatformer.js

@@ -24,7 +24,7 @@ function Start() {
 
 function Update() {
     
-  // physicsWorld.drawDebugGeometry();
+    physicsWorld.drawDebugGeometry();
 
 }
 
@@ -58,7 +58,7 @@ function CreateScene() {
     avatarNode = scene.createChild("Avatar");
     avatarNode.createJSComponent("Avatar");
     backgroundNode = scene.createChild("Background");
-    backgroundNode .createJSComponent("Background");
+    backgroundNode .createJSComponent("Background");