Browse Source

Change identation to spaces

rsredsq 10 years ago
parent
commit
7121df0967

+ 8 - 9
PhysicsPlatformer/Resources/Components/Background.js

@@ -2,23 +2,22 @@
 
 //A Background
 var component = function(self) {
-	//getting a main camera of current scene
+    //getting a main camera of current scene
     var camera = self.node.scene.getMainCamera();
     var cameraNode = camera.node;
 
-	//This function will be called each frame after the update function
+    //This function will be called each frame after the update function
     self.postUpdate = function() {
-		//get position of our camera
-		//position2D returns an array, which has 3 elements, the first is x, second is y, third is z
+        //get position of our camera
+        //position2D returns an array, which has 3 elements, the first is x, second is y, third is z
         var pos = cameraNode.position2D;
-		pos[1] -= 4;
-		//set position to the current node
+        pos[1] -= 4;
+        //set position to the current node
         self.node.position2D = pos;
-		//get camera's zoom, and changing it to make a nice paralax effect
+        //get camera's zoom, and changing it to make a nice paralax effect
         var zoom = 4.0 - camera.zoom;
-		//scale2D is an array with two elements, the first is x, the second is y
+        //scale2D is an array with two elements, the first is x, the second is y
         self.node.scale2D = [zoom , zoom];
-
     }
 
 }

+ 3 - 3
PhysicsPlatformer/Resources/Components/Bat.js

@@ -8,7 +8,7 @@ var vec2 = glmatrix.vec2;
 var component = function (self) {
 
   var node = self.node;
-  
+
   //get a component from our current node
   var sprite = node.getComponent("AnimatedSprite2D")
   sprite.setAnimation("Fly");
@@ -22,7 +22,7 @@ var component = function (self) {
       time += timestep * 4;
 
       var waypoints = node.waypoints;
-	  //get node position, returns an array with two elements, the first is x, the second is y
+      //get node position, returns an array with two elements, the first is x, the second is y
       var pos = node.position2D;
 
       if (cwaypoint == -1 || vec2.distance(pos, waypoints[cwaypoint]) < .5) {
@@ -43,7 +43,7 @@ var component = function (self) {
           sprite.flipX = false;
 
       vec2.add(pos, pos, dir);
-	  //set position of our node
+      //set position of our node
       node.position2D = pos;
 
   }

+ 16 - 16
PhysicsPlatformer/Resources/Components/Coin.js

@@ -39,34 +39,34 @@ var component = function(self) {
     if (vec2.distance(cameraNode.position2D, node.position2D) < 3.0) {
 
       activated = true;
-	  //setting rigid body
+      //setting rigid body
       body = node.createComponent("RigidBody2D");
       //our body is Dynamic
-	  body.setBodyType(Atomic.BT_DYNAMIC);
-	  //fix rotation
+      body.setBodyType(Atomic.BT_DYNAMIC);
+      //fix rotation
       body.fixedRotation = true;
-	  //don't make our body to cast shadows
+      //don't make our body to cast shadows
       body.castShadows = false;
-	  
-	  //subscribing to PhysicsBeginContact2D event, and specifying a callback 
+      
+      //subscribing to PhysicsBeginContact2D event, and specifying a callback
       self.subscribeToEvent("PhysicsBeginContact2D", function(ev) {
-		//checking if nodeB is our current node
+        //checking if nodeB is our current node
         if (ev.nodeB == node) {
-		  //checking if nodeA(another node) is a Player
+          //checking if nodeA(another node) is a Player
           if (ev.nodeA && ev.nodeA.name == "Player") {
-			//picking up a coin
-			//setting scale to 0, 0
+            //picking up a coin
+            //setting scale to 0, 0
             node.scale2D = [0, 0];
-			//disable sprite
+            //disable sprite
             sprite.enabled = false;
-			//disable body
+            //disable body
             body.enabled = false;
             if (self.pickupSound) {
               soundSource.gain = 1.0;
-			  //playing pickupSound
+              //playing pickupSound
               soundSource.play(self.pickupSound);
             }
-		  //if it's not a player, and we have bounceSound, then play it
+          //if it's not a player, and we have bounceSound, then play it
           } else if (self.bounceSound) {
 
             var vel = body.linearVelocity;
@@ -77,8 +77,8 @@ var component = function(self) {
           }
         }
       });
-	  
-	  //adding circle colision shape
+
+      //adding circle colision shape
       var circle = node.createComponent("CollisionCircle2D");
 
       // Set radius

+ 17 - 17
PhysicsPlatformer/Resources/Components/Level.js

@@ -7,23 +7,23 @@ var LevelParser = require("LevelParser");
 var component = function (self) {
   //start function will be excecuted, after connecting our component to the node, after the constructor
   self.start = function() {
-	//get TileMap2D component from our current node
+    //get TileMap2D component from our current node
     var tileMap = self.node.getComponent("TileMap2D");
     var tmxFile = tileMap.tmxFile;
-	
-	//create LevelParser object
+
+    //create LevelParser object
     var levelParser = new LevelParser(tileMap);
     levelParser.createPhysics(tileMap, tmxFile);
 
     var position = levelParser.getSpawnpoint();
     position[1] += 1.5;
-	
-	//create a child prefab
+
+    //create a child prefab
     var node = self.scene.createChildPrefab("Player", "Prefabs/Hero.prefab");
-	//set it position to the current node position
+    //set it position to the current node position
     node.position2D = position;
-	
-	//get all entities from our map which names MovingPlatform
+
+    //get all entities from our map which names MovingPlatform
     var platforms = levelParser.getEntities("MovingPlatform");
     for (var i = 0; i < platforms.length; i++) {
 
@@ -34,22 +34,22 @@ var component = function (self) {
         node.startPos = p.start;
         node.stopPos = p.stop;
     }
-	
-	//get all entities from our map which names Coin
+
+    //get all entities from our map which names Coin
     var coins = levelParser.getEntities("Coin");
     for (var i = 0; i < coins.length; i++) {
         var node = self.scene.createChildPrefab("Coin", "Prefabs/Coin.prefab");
         node.position2D = coins[i].position;
     }
-	
-	//get all entities from our map which names BatWaypoint
+
+    //get all entities from our map which names BatWaypoint
     var waypoints = [];
     var batWaypoints = levelParser.getEntities("BatWaypoint");
     for (var i = 0; i < batWaypoints.length; i++) {
         waypoints.push(batWaypoints[i].position);
     }
-	
-	//get all entities from our map which names Bat
+
+    //get all entities from our map which names Bat
     var bats = levelParser.getEntities("Bat");
     for (var i = 0; i < bats.length; i++) {
         var node = self.scene.createChildPrefab("Bat", "Prefabs/Bat.prefab");
@@ -57,14 +57,14 @@ var component = function (self) {
         node.scale2D = [.5, .5];
         node.waypoints = waypoints;
     }
-	
-	//get all entities from our map which names Vine
+
+    //get all entities from our map which names Vine
     var vines = levelParser.getEntities("Vine");
     for (var i = 0; i < vines.length; i++) {
         var vnode  = self.scene.createChild("Vine");
         vnode.createJSComponent("Components/Vine.js", {startPosition : vines[i].position});
     }
-	
+
   }
 
 }

+ 2 - 2
PhysicsPlatformer/Resources/Components/MovingPlatform.js

@@ -17,7 +17,7 @@ var movingToStop = true;
 var body = self.getComponent("RigidBody2D");
 //update function called each frame
 self.update = function(timeStep) {
-	//get node position
+    //get node position
     var pos = node.position2D;
     var dir = vec2.create();
     var dist = 0.0;
@@ -53,7 +53,7 @@ self.update = function(timeStep) {
         vec2.normalize(dir, dir);
         vec2.scale(dir, dir, MAX_VELOCITY);
     }
-	//set velocity of our body(node) to the dir value
+    //set velocity of our body(node) to the dir value
     body.setLinearVelocity(dir);
 
 }

+ 37 - 37
PhysicsPlatformer/Resources/Components/Player.js

@@ -10,13 +10,13 @@ var inspectorFields = {
 exports.component = function(self) {
 
     var node = self.node;
-	//get main camera of the current scene
+    //get main camera of the current scene
     var camera = self.node.scene.getMainCamera();
     var cameraNode = camera.node;
-	//link to Atomic.Input
+    //link to Atomic.Input
     var input = Atomic.input;
     //get SoundSource component
-	var soundSource = node.getComponent("SoundSource");
+    var soundSource = node.getComponent("SoundSource");
 
     var MAX_VELOCITY = 3;
     var anim = "";
@@ -36,39 +36,39 @@ exports.component = function(self) {
     // physics
     var body;
     var circle;
-	
-	//function called after the component attached to the node
+
+    //function called after the component attached to the node
     self.start = function() {
-		
-		//get components
+
+        //get components
         sprite = node.getComponent("AnimatedSprite2D");
         body = node.getComponent("RigidBody2D");
         circle = node.getComponent("CollisionCircle2D");
 
         setAnimation("Idle");
-        
-		//subscribe to PhysicsPostStep2D
+
+        //subscribe to PhysicsPostStep2D
         self.subscribeToEvent("PhysicsPostStep2D", function(event) {
             //set camera position to the current node position
-			cameraNode.position = node.position;
+            cameraNode.position = node.position;
         });
-		//subscribe to PhysicsBeginContact2D
+        //subscribe to PhysicsBeginContact2D
         self.subscribeToEvent("PhysicsBeginContact2D", function(event) {
-			//if bodyB is our body, so increment contactCount
+            //if bodyB is our body, so increment contactCount
             if (event.bodyB == body)
                 contactCount++;
         });
-		//subscribe to 
+        //subscribe to
         self.subscribeToEvent("PhysicsEndContact2D", function(event) {
             //if bodyB is our body, so decrement contactCount
-			if (event.bodyB == body)
+            if (event.bodyB == body)
                 contactCount--;
         });
 
     }
 
     self.update = function(timeStep) {
-		//handle our input and animation stuff
+        //handle our input and animation stuff
         handleInput(timeStep);
         handleAnimation(timeStep);
 
@@ -77,7 +77,7 @@ exports.component = function(self) {
             // setposition catching dirty
             node.scale2D = [0, 0];
             node.position2D = spawnPosition;
-           	node.scale2D = [1, 1];
+               node.scale2D = [1, 1];
         }
 
     }
@@ -88,7 +88,7 @@ exports.component = function(self) {
             return;
 
         lastAnimDelta = .25;
-		//sprite is an AnimatedSprite2D object, set its animation to the given animName
+        //sprite is an AnimatedSprite2D object, set its animation to the given animName
         sprite.setAnimation(animName);
         anim = animName;
 
@@ -99,33 +99,33 @@ exports.component = function(self) {
         lastAnimDelta -= timeStep;
 
         var vel = body.linearVelocity;
-		//if we have a contact with something
+        //if we have a contact with something
         if (contactCount) {
-			//if velocity by X less than zero
+            //if velocity by X less than zero
             if (vel[0] < -0 && control) {
                 if (!flipped) {
                     sprite.flipX = true;
                     flipped = true;
                 }
-				//set current animation to Run animation
+                //set current animation to Run animation
                 setAnimation("Run");
-			//if velocity by X is greater than zero
+            //if velocity by X is greater than zero
             } else if (vel[0] > 0 && control) {
                 if (flipped) {
                     sprite.flipX = false;
                     flipped = false;
                 }
-				//set current animation to Run animation
+                //set current animation to Run animation
                 setAnimation("Run");
             } else {
-				//if our velocity equals to zero, so set current animation to Idle animation
+                //if our velocity equals to zero, so set current animation to Idle animation
                 setAnimation("Idle");
             }
         } else {
-			//if velocity by Y greater than 1, so we are jumping
+            //if velocity by Y greater than 1, so we are jumping
             if (vel[1] > 1.0) {
                 setAnimation("Jump");
-			//if velocity by Y is less than 1, so we are falling
+            //if velocity by Y is less than 1, so we are falling
             } else if (vel[1] < -1.0) {
                 setAnimation("Land");
             }
@@ -143,27 +143,27 @@ exports.component = function(self) {
 
         if (Math.abs(vel[0]) > MAX_VELOCITY) {
             vel[0] = (vel[0] ? vel[0] < 0 ? -1 : 1 : 0) * MAX_VELOCITY;
-			//set body linear velocity to the current velocity
+            //set body linear velocity to the current velocity
             body.setLinearVelocity(vel);
         }
-		//input stuff
+        //input stuff
         var left = input.getKeyDown(Atomic.KEY_LEFT) || input.getKeyDown(Atomic.KEY_A);
         var right = input.getKeyDown(Atomic.KEY_RIGHT) || input.getKeyDown(Atomic.KEY_D);
 
         var jump = input.getKeyDown(Atomic.KEY_UP) || input.getKeyDown(Atomic.KEY_SPACE) || input.getKeyDown(Atomic.KEY_W);
 
         control = false;
-		//if left or right is pressed
+        //if left or right is pressed
         if (left || right)
             control = true;
-			
-		//applying linear impulses to the left and right
+
+        //applying linear impulses to the left and right
         if (left && vel[0] > -MAX_VELOCITY) {
             body.applyLinearImpulse([-2, 0], pos, true);
         } else if (right && vel[0] < MAX_VELOCITY) {
             body.applyLinearImpulse([2, 0], pos, true);
         }
-		//if we are not pressing any buttons, so enable friction
+        //if we are not pressing any buttons, so enable friction
         if (!left && !right) {
             vel[0] *= 0.9;
             body.linearVelocity = vel;
@@ -174,24 +174,24 @@ exports.component = function(self) {
 
         if (!contactCount)
             circle.friction = 0.0;
-		
-		//if we are jumping and colliding with something
+
+        //if we are jumping and colliding with something
         if (jump && jumpDelta <= 0 && contactCount) {
 
             jumpDelta = .25;
-			//is sound exists
+            //is sound exists
             if (self.jumpSound) {
                 soundSource.gain = 0.45;
-				//playing sound
+                //playing sound
                 soundSource.play(self.jumpSound);
             }
 
             vel[1] = 0;
             body.linearVelocity = vel;
-			//applying linear impuls to the Y
+            //applying linear impuls to the Y
             body.applyLinearImpulse([0, 6], pos, true);
         }
 
     }
 
-}
+}

+ 18 - 18
PhysicsPlatformer/Resources/Components/Vine.js

@@ -17,25 +17,25 @@ self.start = function() {
 
         // create the node body
         var groundBody = node.createComponent("RigidBody2D");
-		//do not cast shadows
+        //do not cast shadows
         groundBody.castShadows = false;
 
         var prevBody = groundBody;
 
         for (var i = 0; i < NUM_OBJECTS; i++) {
-			//create a new vine node
+            //create a new vine node
             var vnode = node.scene.createChild("RigidBody");
-			//add StaticSprite2D to the created node
+            //add StaticSprite2D to the created node
             var sprite2D = vnode.createComponent("StaticSprite2D");
             //set its sprite
-			sprite2D.sprite = Atomic.cache.getResource("Sprite2D", "Sprites/vine.png");
-			
-			//create rigid body component
+            sprite2D.sprite = Atomic.cache.getResource("Sprite2D", "Sprites/vine.png");
+
+            //create rigid body component
             var vbody = vnode.createComponent("RigidBody2D");
             //do not cast shadows
-			vbody.castShadows = false;
+            vbody.castShadows = false;
             //set body type to Dynamic
-			vbody.bodyType = Atomic.BT_DYNAMIC;
+            vbody.bodyType = Atomic.BT_DYNAMIC;
 
             // Create box
             var vbox = vnode.createComponent("CollisionBox2D");
@@ -43,32 +43,32 @@ self.start = function() {
             vbox.friction = .2;
             // Set mask bits.
             vbox.maskBits = 0xFFFF & ~0x0002;
-			//set vine node position
+            //set vine node position
             vnode.position = [x + 0.5 + 1.0 * i, y, 0.0];
             //set box collision size
-			vbox.size = [1.0, 0.1];
-			//set density
+            vbox.size = [1.0, 0.1];
+            //set density
             vbox.density = 5.0;
-			//set category bits
+            //set category bits
             vbox.categoryBits = 0x0001;
 
             if (i == NUM_OBJECTS - 1)
                 vbody.angularDamping = 0.4;
-				
-			//create joint component
+
+            //create joint component
             var joint = vnode.createComponent("ConstraintRevolute2D");
             //join it to the previous body
-			joint.otherBody = prevBody;
-			//set ancor
+            joint.otherBody = prevBody;
+            //set ancor
             joint.anchor = [x + i, y];
             joint.collideConnected = false;
             prevBody = vbody;
 
         }
-		//create ConstraintRope2D component
+        //create ConstraintRope2D component
         var constraintRope = node.createComponent("ConstraintRope2D");
         //set other body to the previous body
-		constraintRope.otherBody = prevBody;
+        constraintRope.otherBody = prevBody;
         constraintRope.ownerBodyAnchor = [x, y];
         constraintRope.maxLength = (NUM_OBJECTS + 0.01);
 

+ 27 - 27
PhysicsPlatformer/Resources/Modules/LevelParser.js

@@ -12,26 +12,26 @@ LevelParser = function(tileMap) {
 }
 //Define a prototype
 LevelParser.prototype = {
-	
-	//parsing our entities from tileMap object
+
+    //parsing our entities from tileMap object
     parseEntities: function() {
 
         entityLayer = this.tileMap.getLayerByName("Entities");
 
         var platforms = {};
-		//if layer Entities exists
+        //if layer Entities exists
         if (entityLayer) {
-			//iterating through each object
+            //iterating through each object
             for (var i = 0; i < entityLayer.numObjects; i++) {
-				//get object itself
+                //get object itself
                 var o = entityLayer.getObject(i);
                 //get node of object
-				var onode = entityLayer.getObjectNode(i);
+                var onode = entityLayer.getObjectNode(i);
 
                 var entity = {
                     type: null
                 };
-				//checks for type of object
+                //checks for type of object
                 if (o.type == "PlayerSpawn") {
 
                     entity.type = "PlayerSpawn";
@@ -76,7 +76,7 @@ LevelParser.prototype = {
 
                     platforms[pnum][1] = o;
                 }
-				//if type was found, then push an object to the entities array
+                //if type was found, then push an object to the entities array
                 if (entity.type)
                     this.entities.push(entity);
 
@@ -96,8 +96,8 @@ LevelParser.prototype = {
         }
 
     },
-	
-	//returns the first found entity of the given type
+
+    //returns the first found entity of the given type
     getEntity: function(type) {
 
         for (var i = 0; i < this.entities.length; i++)
@@ -107,8 +107,8 @@ LevelParser.prototype = {
         return null;
 
     },
-	
-	//returns an array of entities of the given type
+
+    //returns an array of entities of the given type
     getEntities: function(type) {
 
         var entities = [];
@@ -120,8 +120,8 @@ LevelParser.prototype = {
         return entities;
 
     },
-	
-	//returns spawnpoint
+
+    //returns spawnpoint
     getSpawnpoint: function(type) {
 
         var pos = [0, 0];
@@ -130,25 +130,25 @@ LevelParser.prototype = {
         return entity ? entity.position : pos;
 
     },
-	
-	createPhysics: function(tileMap, tmxFile) {
-		//get Physics layer
+
+    createPhysics: function(tileMap, tmxFile) {
+        //get Physics layer
         physicsLayer = tileMap.getLayerByName("Physics");
 
-		//if layer exists
+        //if layer exists
         if (physicsLayer) {
-			//iterate through each object
+            //iterate through each object
             for (var i = 0; i < physicsLayer.numObjects; i++) {
-				//get object
+                //get object
                 var o = physicsLayer.getObject(i);
-				//get node
+                //get node
                 var onode = physicsLayer.getObjectNode(i);
                 //returns object group
-				var group = tmxFile.getTileObjectGroup(o.tileGid);
+                var group = tmxFile.getTileObjectGroup(o.tileGid);
                 var obody = null;
-				//if group exists
+                //if group exists
                 if (group) {
-					//iterate through each group object
+                    //iterate through each group object
                     for (var j = 0; j < group.numObjects; j++) {
 
                         var go = group.getObject(j);
@@ -156,12 +156,12 @@ LevelParser.prototype = {
                         if (go.validCollisionShape()) {
 
                             if (!obody) {
-								//create rigid body
+                                //create rigid body
                                 obody = onode.createComponent("RigidBody2D");
-								obody.bodyType = Atomic.BT_DYNAMIC;
+                                obody.bodyType = Atomic.BT_DYNAMIC;
                                 obody.awake = false;
                             }
-							//create a collision shape for our object
+                            //create a collision shape for our object
                             var shape = go.createCollisionShape(onode);
                             shape.density = 1.0;
                             shape.friction = 1.0;