Browse Source

Adjustable zoom

Josh Engebretson 11 years ago
parent
commit
a07df2ee94

+ 41 - 12
PhysicsPlatformer/Resources/Components/Avatar.js

@@ -12,12 +12,15 @@ sprite.setAnimation(animationSet, "Idle");
 sprite.setLayer(100);
 sprite.setLayer(100);
 
 
 
 
+camera.zoom = .9;
+
 node.setPosition(PlayerSpawnPoint);
 node.setPosition(PlayerSpawnPoint);
 //node.scale2D = [.25, .25];
 //node.scale2D = [.25, .25];
 
 
 var body = node.createComponent("RigidBody2D");
 var body = node.createComponent("RigidBody2D");
 body.setBodyType(Atomic.BT_DYNAMIC);
 body.setBodyType(Atomic.BT_DYNAMIC);
 body.fixedRotation = true;
 body.fixedRotation = true;
+body.bullet = true;
 
 
 var circle = node.createComponent("CollisionCircle2D");
 var circle = node.createComponent("CollisionCircle2D");
 // Set radius
 // Set radius
@@ -36,18 +39,16 @@ var contactCount = 0;
 
 
 self.onPhysicsBeginContact2D = function(world, bodyA, bodyB, nodeA, nodeB) {
 self.onPhysicsBeginContact2D = function(world, bodyA, bodyB, nodeA, nodeB) {
 
 
-    if (nodeB == node)
-    {
+    if (nodeB == node) {
         contactCount++;
         contactCount++;
     }
     }
-    
+
 
 
 }
 }
 
 
 self.onPhysicsEndContact2D = function(world, bodyA, bodyB, nodeA, nodeB) {
 self.onPhysicsEndContact2D = function(world, bodyA, bodyB, nodeA, nodeB) {
 
 
-    if (nodeB == node)
-    {
+    if (nodeB == node) {
         contactCount--;
         contactCount--;
     }
     }
 }
 }
@@ -107,6 +108,8 @@ function handleInput(timeStep) {
     var left = input.getKeyDown(Atomic.KEY_A);
     var left = input.getKeyDown(Atomic.KEY_A);
     var right = input.getKeyDown(Atomic.KEY_D);
     var right = input.getKeyDown(Atomic.KEY_D);
     var jump = input.getKeyDown(Atomic.KEY_SPACE);
     var jump = input.getKeyDown(Atomic.KEY_SPACE);
+    var zoomIn = input.getKeyDown(Atomic.KEY_W);
+    var zoomOut = input.getKeyDown(Atomic.KEY_S);
 
 
     if (input.getNumJoysticks()) {
     if (input.getNumJoysticks()) {
         var state = GetGamepadState(0);
         var state = GetGamepadState(0);
@@ -117,8 +120,28 @@ function handleInput(timeStep) {
 
 
         if (state.button0)
         if (state.button0)
             jump = true;
             jump = true;
+
+        if (state.button1)
+            zoomIn = true;
+        if (state.button2)
+            zoomOut = true;
+
     }
     }
 
 
+    if (zoomIn)
+        camera.zoom += timeStep;
+    
+    if (zoomOut)
+        camera.zoom -= timeStep;
+
+
+    if (camera.zoom > 1.5)
+        camera.zoom = 1.5;
+    if (camera.zoom < .75)
+        camera.zoom = .75;
+
+    print(camera.zoom);
+
     if (left && vel[0] > -MAX_VELOCITY) {
     if (left && vel[0] > -MAX_VELOCITY) {
         body.applyLinearImpulse([-2, 0], pos, true);
         body.applyLinearImpulse([-2, 0], pos, true);
     } else if (right && vel[0] < MAX_VELOCITY) {
     } else if (right && vel[0] < MAX_VELOCITY) {
@@ -129,15 +152,13 @@ function handleInput(timeStep) {
         vel[0] *= 0.9;
         vel[0] *= 0.9;
         body.linearVelocity = vel;
         body.linearVelocity = vel;
         circle.friction = 1000.0;
         circle.friction = 1000.0;
+    } else {
+        circle.friction = .2;
     }
     }
-    else
-    {
-       circle.friction = .2;    
-    }
-   
+
     if (!contactCount)
     if (!contactCount)
         circle.friction = 0.0;
         circle.friction = 0.0;
-    
+
     if (jump && contactCount) {
     if (jump && contactCount) {
         vel[1] = 0;
         vel[1] = 0;
         body.linearVelocity = vel;
         body.linearVelocity = vel;
@@ -154,8 +175,16 @@ function postUpdate() {
 
 
 function update(timeStep) {
 function update(timeStep) {
 
 
-    handleInput();
+    handleInput(timeStep);
     handleAnimation();
     handleAnimation();
 
 
+    if (node.position[1] < 14) {
+        //TODO: FIX, I have to set scale to 0 and the back to 1 to force 
+        // setposition catching dirty
+        node.scale2D = [0, 0];
+        node.setPosition(PlayerSpawnPoint);
+        node.scale2D = [1, 1];
+
+    }
 
 
 }
 }

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

@@ -25,9 +25,6 @@ self.batWaypoints = [];
 var coins = [];
 var coins = [];
 var bats = [];
 var bats = [];
 
 
-camera.setZoom(.9);
-
-
 self.onPhysicsBeginContact2D = function(world, bodyA, bodyB, nodeA, nodeB) {
 self.onPhysicsBeginContact2D = function(world, bodyA, bodyB, nodeA, nodeB) {
 
 
     if (nodeA == ThePlayer.node && self.coinNodes.indexOf(nodeB) != -1) {
     if (nodeA == ThePlayer.node && self.coinNodes.indexOf(nodeB) != -1) {

BIN
PhysicsPlatformer/Resources/Levels/ForestObjects.png


BIN
PhysicsPlatformer/Resources/Sprites/GoldIcon/1.png


BIN
PhysicsPlatformer/Resources/Sprites/GoldIcon/2.png


BIN
PhysicsPlatformer/Resources/Sprites/GoldIcon/3.png


BIN
PhysicsPlatformer/Resources/Sprites/GoldIcon/4.png


BIN
PhysicsPlatformer/Resources/Sprites/GoldIcon/5.png