Josh Engebretson 11 years ago
parent
commit
66d49fd067

+ 31 - 2
PhysicsPlatformer/Resources/Components/Avatar.js

@@ -30,6 +30,35 @@ circle.setRestitution(0.1);
 var anim = "Idle";
 var anim = "Idle";
 var flipped = false;
 var flipped = false;
 
 
+var contactCount = 0;
+
+self.onPhysicsBeginContact2D = function(world, bodyA, bodyB, nodeA, nodeB) {
+
+    if (nodeB == node)
+    {
+        print("contact: ", contactCount);
+        contactCount++;
+    }
+    
+
+}
+
+self.onPhysicsEndContact2D = function(world, bodyA, bodyB, nodeA, nodeB) {
+
+    if (nodeB == node)
+    {
+        print("end contact: ", contactCount);
+        contactCount--;
+    }
+}
+
+
+function start() {
+
+    self.listenToEvent(null, "PhysicsBeginContact2D", self.onPhysicsBeginContact2D);
+    self.listenToEvent(null, "PhysicsEndContact2D", self.onPhysicsEndContact2D);
+}
+
 function handleAnimation() {
 function handleAnimation() {
 
 
     var vel = body.linearVelocity;
     var vel = body.linearVelocity;
@@ -91,10 +120,10 @@ function handleInput(timeStep) {
         body.linearVelocity = vel;
         body.linearVelocity = vel;
     }
     }
 
 
-    if (jump) {
+    if (jump && contactCount) {
         vel[1] = 0;
         vel[1] = 0;
         body.linearVelocity = vel;
         body.linearVelocity = vel;
-        body.applyLinearImpulse([0, 4], pos, true);
+        body.applyLinearImpulse([0, 3], pos, true);
     }
     }
 
 
 }
 }

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

@@ -2,28 +2,10 @@ var node = self.node;
 
 
 var tmxFile = cache.getResource("TmxFile2D", "Levels/Level1.tmx");
 var tmxFile = cache.getResource("TmxFile2D", "Levels/Level1.tmx");
 
 
-
-
 var tileMapNode = scene.createChild("TileMap");
 var tileMapNode = scene.createChild("TileMap");
 tileMapNode.setPosition([0.0, 0.0, 0.0]);
 tileMapNode.setPosition([0.0, 0.0, 0.0]);
 var tileMap = tileMapNode.createComponent("TileMap2D");
 var tileMap = tileMapNode.createComponent("TileMap2D");
 tileMap.setTmxFile(tmxFile);
 tileMap.setTmxFile(tmxFile);
 
 
-print(tileMap.numLayers);
-
 cameraNode.setPosition([8, 12, 0]);
 cameraNode.setPosition([8, 12, 0]);
 camera.setZoom(1.0);
 camera.setZoom(1.0);
-
-/*
-
-    TileMap2D* tileMap = tileMapNode->CreateComponent<TileMap2D>();
-    // Set animation
-    tileMap->SetTmxFile(tmxFile);
-
-    // Set camera's position
-    const TileMapInfo2D& info = tileMap->GetInfo();
-    float x = info.GetMapWidth() * 0.5f;
-    float y = info.GetMapHeight() * 0.5f;
-    cameraNode_->SetPosition(Vector3(x, y, -10.0f));
-    
-*/

+ 1 - 1
PhysicsPlatformer/Resources/PhysicsPlatformer.js

@@ -24,7 +24,7 @@ function Start() {
 
 
 function Update() {
 function Update() {
     
     
-    physicsWorld.drawDebugGeometry();
+    //physicsWorld.drawDebugGeometry();
 
 
 }
 }