Browse Source

Fixed game progress percentage blocks that were not behaving according to value | fixed a bug in which after clicking the back icon, the game wouldnt restart the players progress when restarting a level | now map.js manages the map in all the levels due to their similarities

lairaalmas 5 years ago
parent
commit
2fae6fda60
9 changed files with 276 additions and 597 deletions
  1. BIN
      assets/img/garage (copy).png
  2. BIN
      assets/img/school (copy).png
  3. 1 0
      index.html
  4. 29 58
      js/boot.js
  5. 6 171
      js/circleOne.js
  6. 202 0
      js/map.js
  7. 17 17
      js/menu.js
  8. 8 172
      js/squareOne.js
  9. 13 179
      js/squareTwo.js

BIN
assets/img/garage (copy).png


BIN
assets/img/school (copy).png


+ 1 - 0
index.html

@@ -13,6 +13,7 @@
         
         <script type="text/javascript" src="js/preMenu.js"></script>
         <script type="text/javascript" src="js/menu.js"></script>
+        <script type="text/javascript" src="js/map.js"></script>
         <script type="text/javascript" src="js/circleOne.js"></script>
         <script type="text/javascript" src="js/squareOne.js"></script>
         <script type="text/javascript" src="js/squareTwo.js"></script>

+ 29 - 58
js/boot.js

@@ -1,22 +1,6 @@
 // OUTRAS VARIAVEIS GLOBAIS
 
-				/*
-				--- DO PHASER
-				this.game.world.centerX...
-				
-				--- vem do phaser.js
-				this.points
-				this.count 
-
-				--- falta olhar ainda  
-				this.rocks
-				this.trees
-				this.r_types
-				this t_types
-				this.wait;
-				*/
-
-				var passedLevels = 0;
+				var passedLevels;
 
 				//map
 				var kid, tractor;
@@ -52,9 +36,6 @@
 				var kidDirection, equals, counter, endCounter;
 				var xA, yA, xB, yB, blockW, blockH;
 
-
-
-
 	// INFO
 	var username; //player name
 	var lang; //language
@@ -87,23 +68,14 @@
     levelPosition = 0; //Map position
     levelMove = false; //Move to next position
     levelDifficulty = 0; //From one to five 
-    levelOperator= ""; //Plus; Minus; Mixed
+
+    levelOperator= ""; //Plus; Minus; Mixed 
+
     levelLabel= false; //Show block label
     levelShape = ""; //Circle; square
     levelType = ""; // A - Place distance; B - Select blocks
     levelMenu = true;
 
-    // Game Two : fractions association
-
-    //twoPosition = 0; //Map position
-    //twoMove = false; //Move to next position
-    //twoDifficulty = 0; //From one to five 
-    //levelOperator= ""; //Plus; Minus; Mixed
-    //twoLabel= false; //Show block label
-    //twoShape = ""; //Circle; square
-    //twoType = ""; // A - Normal position; B - Random position
-    //twoMenu= true;
-
     //adding game states (scenes)
     
     game.state.add('language', langState); // boot.js
@@ -112,20 +84,19 @@
 
     game.state.add('menu', menuState); // menu.js
 
-    game.state.add('menuCOne', menuCircleOne); // circleOne.js
-    game.state.add('mapCOne', mapCircleOne); // circleOne.js
-    game.state.add('gameCOne', gameCircleOne); // circleOne.js
-    game.state.add('endCOne', endCircleOne); // circleOne.js
+    game.state.add('map', mapState); // map.js
+
+    game.state.add('menuCircleOne', menuCircleOne); // circleOne.js
+    game.state.add('gameCircleOne', gameCircleOne); // circleOne.js
+    game.state.add('endCircleOne', endCircleOne); // circleOne.js
 
-    game.state.add('menuSOne', menuSquareOne); // squareOne.js
-    game.state.add('mapSOne', mapSquareOne); // squareOne.js
-    game.state.add('gameSOne', gameSquareOne); // squareOne.js
-    game.state.add('endSOne', endSquareOne); // squareOne.js
+    game.state.add('menuSquareOne', menuSquareOne); // squareOne.js
+    game.state.add('gameSquareOne', gameSquareOne); // squareOne.js
+    game.state.add('endSquareOne', endSquareOne); // squareOne.js
 
-    game.state.add('menuSTwo', menuSquareTwo); // squareTwo.js
-    game.state.add('mapSTwo', mapSquareTwo); // squareTwo.js
-    game.state.add('gameSTwo', gameSquareTwo); // squareTwo.js
-    game.state.add('endSTwo', endSquareTwo); // squareTwo.js
+    game.state.add('menuSquareTwo', menuSquareTwo); // squareTwo.js
+    game.state.add('gameSquareTwo', gameSquareTwo); // squareTwo.js
+    game.state.add('endSquareTwo', endSquareTwo); // squareTwo.js
 
     var loadAssets = {
 
@@ -175,7 +146,7 @@
 	        //operators
 	        game.load.image('add',		imgsrc+'operator/add.png');
 	        game.load.image('subtract', imgsrc+'operator/subtract.png');
-	        game.load.image('separator',	imgsrc+'operator/separator.png');
+	        game.load.image('separator',imgsrc+'operator/separator.png');
 	        game.load.image('equal', 	imgsrc+'operator/equal.png');
 	        
 	        //feedback
@@ -198,19 +169,19 @@
 	        game.load.image('balloon', 			imgsrc+'airballoon_upper.png');
 	        game.load.image('balloon_basket', 	imgsrc+'airballoon_base.png');
 	        game.load.image('birch', 			imgsrc+'birch.png');
-	        game.load.image('flag', imgsrc+'flag.png');
-	        game.load.image('house', imgsrc+'house.png');
-	        game.load.image('place_a', imgsrc+'place_a.png');
-	        game.load.image('place_b', imgsrc+'place_b.png');
-	        game.load.image('garage', imgsrc+'garage.png');
-	        game.load.image('farm', imgsrc+'farm.png');
-	        game.load.image('rock', imgsrc+'rock.png');
-	        game.load.image('school', imgsrc+'school.png');
-	        game.load.image('sign', imgsrc+'sign.png');
-	        game.load.image('tree1', imgsrc+'tree.png');
-	        game.load.image('tree2', imgsrc+'tree2.png');
-	        game.load.image('tree3', imgsrc+'tree3.png');
-	        game.load.image('tree4', imgsrc+'tree4.png');
+	        game.load.image('flag', 	imgsrc+'flag.png');
+	        game.load.image('house', 	imgsrc+'house.png');
+	        game.load.image('place_a', 	imgsrc+'place_a.png');
+	        game.load.image('place_b', 	imgsrc+'place_b.png');
+	        game.load.image('garage', 	imgsrc+'garage.png');
+	        game.load.image('farm', 	imgsrc+'farm.png');
+	        game.load.image('rock', 	imgsrc+'rock.png');
+	        game.load.image('school', 	imgsrc+'school.png');
+	        game.load.image('sign',		imgsrc+'sign.png');
+	        game.load.image('tree1', 	imgsrc+'tree.png');
+	        game.load.image('tree2', 	imgsrc+'tree2.png');
+	        game.load.image('tree3', 	imgsrc+'tree3.png');
+	        game.load.image('tree4', 	imgsrc+'tree4.png');
 	        
 	        // Loadind Sound Effects
 	        game.load.audio('sound_ok', ['assets/fx/ok.ogg', 'assets/fx/ok.mp3']);

+ 6 - 171
js/circleOne.js

@@ -6,13 +6,6 @@
         func_loadMap: function(){}
     };
 
-    var mapCircleOne = {
-        create: function(){},
-        update: function(){},
-        ---------------------------- end of phaser functions
-        loadGame: function()
-    };
-
     var gameCircleOne = {
         create: function(){},
         update: function(){},
@@ -222,168 +215,10 @@ var menuCircleOne = {
         levelMove = true; //Move no next point
         levelDifficulty  = this.difficulty; //Number of difficulty (1 to 5)
         levelOperator = this.operator; //Operator of game
-        passedLevels = 0;
-
-        game.state.start('mapCOne');
-
-    }
-    
-};
-
-/****************************** MAP *****************************/
-
-var mapCircleOne = {
+        passedLevels = 0; //reset the game progress when entering a new level
 
-    create: function() {
-
-        // Background
-        game.add.image(0, 40, 'bgmap');
-        
-        // Navigation buttons
-        buttonSettings["func_addButtons"](1,0,
-                                    1,1,0,
-                                    0,0,
-                                    "menuCOne",0);
-        
-        // Styles for labels
-        var stylePlace = { font: '26px Arial', fill: '#ffffff', align: 'center'};
-        var styleMenu = { font: '30px Arial', fill: '#000000', align: 'center'};
-        
-        // Progress bar
-        var percentText = passedLevels*25;
-        var percentBlocks = passedLevels;
+        game.state.start('map');
 
-        for(var p=0;p<percentBlocks;p++){
-            var block = game.add.image(660+p*30, 10, 'block');
-            block.scale.setTo(3.75, 1); //Scaling to double width
-        }
-        game.add.text(820, 10, percentText+'%', styleMenu);
-        game.add.text(650, 10, lang.difficulty + ' ' + levelDifficulty, styleMenu).anchor.setTo(1,0);
-        game.add.image(660, 10, 'pgbar');
-        
-         //Road
-        this.points = {
-        'x': [ 90, 204, 318, 432, 546, 660 ],
-        'y': [ 486, 422, 358, 294, 230, 166 ]
-        };
-        
-          //House
-        var house = game.add.image(this.points.x[0], this.points.y[0], 'house');
-        house.scale.setTo(0.7);
-        house.anchor.setTo(0.7, 0.8);
-         //School
-        var school = game.add.image(this.points.x[5], this.points.y[5], 'school');
-        school.scale.setTo(0.35);
-        school.anchor.setTo(0.2, 0.7);
-        
-         //Trees and Rocks
-        
-        this.rocks = {
-             'x': [156, 275, 276, 441, 452, 590, 712],
-             'y': [309, 543, 259, 156, 419, 136, 316]
-        }
-        this.r_types = [1, 1, 2, 1, 2, 2, 2];
-        
-        for(var i=0; i<this.r_types.length; i++){
-            if(this.r_types[i]==1){
-                var sprite = game.add.image(this.rocks.x[i], this.rocks.y[i], 'rock');
-                sprite.scale.setTo(0.32);
-                sprite.anchor.setTo(0.5, 0.95);
-            }else if(this.r_types[i]==2){
-                var sprite = game.add.image(this.rocks.x[i], this.rocks.y[i], 'birch');
-                sprite.scale.setTo(0.4);
-                sprite.anchor.setTo(0.5, 0.95);
-            }
-        }
-        this.trees = {
-             'x': [105, 214, 354, 364, 570, 600, 740, 779],
-             'y': [341, 219, 180, 520, 550, 392, 488, 286]
-        }
-        this.t_types = [2, 4, 3, 4, 1, 2, 4, 4];
-        
-        for(var i=0; i<this.t_types.length; i++){
-            var sprite = game.add.image(this.trees.x[i], this.trees.y[i], 'tree'+this.t_types[i]);
-            sprite.scale.setTo(0.6);
-            sprite.anchor.setTo(0.5, 0.95);
-        }
-
-        
-        // places
-        for (var p = 1; p < this.points.x.length -1; p++){
-            var place;
-            if(p<levelPosition)
-                	place = game.add.image(this.points.x[p], this.points.y[p], 'place_b');
-            else if (levelMove && p==levelPosition)
-                	place = game.add.image(this.points.x[p], this.points.y[p], 'place_b');
-            else
-                    place = game.add.image(this.points.x[p], this.points.y[p], 'place_a');
-            place.anchor.setTo(0.5, 0.5);
-            place.scale.setTo(0.3);
-            var sign = game.add.image(this.points.x[p]-20, this.points.y[p]-60, 'sign');
-            sign.anchor.setTo(0.5, 1);
-            sign.scale.setTo(0.4);
-            if(p>0 && p<this.points.x.length-1){
-                var text = game.add.text(this.points.x[p]-23, this.points.y[p]-84, p, stylePlace);
-                text.anchor.setTo(0.35, 0.5);
-            }
-        }
-
-        // Kid start position
-        this.kid = game.add.sprite(this.points.x[levelPosition], this.points.y[levelPosition], 'kid_run');
-        this.kid.anchor.setTo(0.5,1);
-        this.kid.scale.setTo(0.5);
-        game.physics.arcade.enable(this.kid);
-        this.kid.animations.add('run');
-        this.kid.animations.play('run', 6, true);
-        
-        // Delay to next level
-        this.count = 0;
-        this.wait = 60;
-        
-    },
-
-    update: function() {
-        
-        // Wait 2 seconds before moving or staring a game
-        this.count ++;
-        if(this.count<=this.wait) return;
-        
-        // If movement is stopped or position is 6 (final), load game
-        if(levelPosition==6){
-            levelMove = false;
-        }
-
-        if(!levelMove){
-            this.loadGame();
-        }
-        
-        // If momevent is enabled, move to next point from actual
-        if(levelMove){
-            game.physics.arcade.moveToXY(
-                this.kid, 
-                this.points.x[levelPosition+1],
-                this.points.y[levelPosition+1],
-                100
-            );
-            
-            // I kid reached the end, stop movement
-            if(Math.ceil(this.kid.x)==this.points.x[levelPosition+1] || Math.ceil(this.kid.y)==this.points.y[levelPosition+1]){
-                levelMove=false;
-                levelPosition += 1; //Update position
-            }
-        }
-    },
-        
-    //MapLoading function
-    loadGame: function(){
-        if(audioStatus){
-            beepSound.play();
-        }
-        if(levelPosition<5){
-            game.state.start('gameCOne');
-        }else{
-            game.state.start('endCOne');
-        }
     }
     
 };
@@ -408,7 +243,7 @@ var gameCircleOne = {
         buttonSettings["func_addButtons"](1,1,
                                     1,1,1,
                                     1,0,
-                                    "menuCOne", this.func_viewHelp);
+                                    "menuCircleOne", this.func_viewHelp);
         
         //Clouds
         game.add.image(300, 100, 'cloud');
@@ -597,13 +432,13 @@ var gameCircleOne = {
                     balloonPlace -= blockDistance[i];
             }
             if(balloonPlace<66 || balloonPlace>66+5*placeDistance || !hasFigure){
-                game.state.start('gameCOne');
+                game.state.start('gameCircleOne');
             }
         }
         
         //If end position is out of bounds, restart
         if (endPosition<66 || endPosition>66+3*260 || !hasFigure){
-            game.state.start('gameCOne');
+            game.state.start('gameCircleOne');
         }
         //kid
         kid_walk = game.add.sprite(startX, 495-numBlocks*blockSize, 'kid_walk');
@@ -788,7 +623,7 @@ var gameCircleOne = {
                 }else{
                     levelMove = false;
                 }
-                game.state.start('mapCOne');
+                game.state.start('map');
             }
         }
 

+ 202 - 0
js/map.js

@@ -0,0 +1,202 @@
+var mapState = {
+
+    create: function() {
+
+        if(levelType=="C"){
+            this.gameStateString = "game"+levelShape+"Two";
+            this.endStateString = "end"+levelShape+"Two";
+            this.menuStateString = "menu"+levelShape+"Two";
+        }else{
+            this.gameStateString = "game"+levelShape+"One";
+            this.endStateString = "end"+levelShape+"One";
+            this.menuStateString = "menu"+levelShape+"One";
+        }
+        
+        // Background
+        game.add.image(0, 40, 'bgmap');
+        
+        // Navigation buttons
+        buttonSettings["func_addButtons"](1,0,
+                                    1,1,0,
+                                    0,0,
+                                    this.menuStateString,0);
+        
+        // Styles for labels
+        var stylePlace = { font: '26px Arial', fill: '#ffffff', align: 'center'};
+        var styleMenu = { font: '30px Arial', fill: '#000000', align: 'center'};
+        
+        // Progress bar
+        var percentText = passedLevels*25;
+        var percentBlocks = passedLevels;
+
+        for(var p=0;p<percentBlocks;p++){
+            var block = game.add.image(660+p*37.5, 10, 'block');
+                block.scale.setTo(2.6, 1);
+        }
+
+        game.add.text(820, 10, percentText+'%', styleMenu);
+        game.add.text(650, 10, lang.difficulty + ' ' + levelDifficulty, styleMenu).anchor.setTo(1,0);
+        game.add.image(660, 10, 'pgbar');
+        
+         //Road
+        this.points = {
+            'x': [ 90, 204, 318, 432, 546, 660 ],
+            'y': [ 486, 422, 358, 294, 230, 166 ]
+        };
+        
+        if(this.gameStateString=="gameSquareOne"){
+        	//Garage
+	        var garage = game.add.image(this.points.x[0], this.points.y[0], 'garage');
+	        garage.scale.setTo(0.4);
+	        garage.anchor.setTo(0.5, 1);
+	         //Farm
+	        var farm = game.add.image(this.points.x[5], this.points.y[5], 'farm');
+	        farm.scale.setTo(0.6);
+	        farm.anchor.setTo(0.1, 0.7);
+        }else{
+	      	//House
+	        var house = game.add.image(this.points.x[0], this.points.y[0], 'house');
+	        house.scale.setTo(0.7);
+	        house.anchor.setTo(0.7, 0.8);
+	         //School
+	        var school = game.add.image(this.points.x[5], this.points.y[5], 'school');
+	        school.scale.setTo(0.35);
+	        school.anchor.setTo(0.2, 0.7);
+	    }
+
+         //Trees and Rocks
+        
+        this.rocks = {
+             'x': [156, 275, 276, 441, 452, 590, 712],
+             'y': [309, 543, 259, 156, 419, 136, 316]
+        }
+
+        this.r_types = [1, 1, 2, 1, 2, 2, 2];
+        
+        for(var i=0; i<this.r_types.length; i++){
+            if(this.r_types[i]==1){
+                var sprite = game.add.image(this.rocks.x[i], this.rocks.y[i], 'rock');
+                sprite.scale.setTo(0.32);
+                sprite.anchor.setTo(0.5, 0.95);
+            }else if(this.r_types[i]==2){
+                var sprite = game.add.image(this.rocks.x[i], this.rocks.y[i], 'birch');
+                sprite.scale.setTo(0.4);
+                sprite.anchor.setTo(0.5, 0.95);
+            }
+        }
+
+        this.trees = {
+             'x': [105, 214, 354, 364, 570, 600, 740, 779],
+             'y': [341, 219, 180, 520, 550, 392, 488, 286]
+        }
+
+        this.t_types = [2, 4, 3, 4, 1, 2, 4, 4];
+        
+        for(var i=0; i<this.t_types.length; i++){
+            var sprite = game.add.image(this.trees.x[i], this.trees.y[i], 'tree'+this.t_types[i]);
+            sprite.scale.setTo(0.6);
+            sprite.anchor.setTo(0.5, 0.95);
+        }
+        
+        // places
+        for (var p = 1; p < this.points.x.length -1; p++){
+            var place;
+            if(p<levelPosition){
+                place = game.add.image(this.points.x[p], this.points.y[p], 'place_b');
+            }else if (levelMove && p==levelPosition){
+                place = game.add.image(this.points.x[p], this.points.y[p], 'place_b');
+            }else{
+                place = game.add.image(this.points.x[p], this.points.y[p], 'place_a');
+            }
+            place.anchor.setTo(0.5, 0.5);
+            place.scale.setTo(0.3);
+            var sign = game.add.image(this.points.x[p]-20, this.points.y[p]-60, 'sign');
+            sign.anchor.setTo(0.5, 1);
+            sign.scale.setTo(0.4);
+            if(p>0 && p<this.points.x.length-1){
+                var text = game.add.text(this.points.x[p]-23, this.points.y[p]-84, p, stylePlace);
+                text.anchor.setTo(0.35, 0.5);
+            }
+        }
+
+        if(this.gameStateString=="gameSquareOne"){
+	    	this.character = game.add.sprite(this.points.x[levelPosition], this.points.y[levelPosition], 'tractor');
+
+	        var walk = this.character.animations.add('walk',[0,1,2,3,4]);
+	        this.character.animations.play('walk', 5, true);
+	        this.character.angle -= 25;
+        }else{
+	        this.character = game.add.sprite(this.points.x[levelPosition], this.points.y[levelPosition], 'kid_run');
+
+	        this.character.animations.add('run');
+	        this.character.animations.play('run', 6, true);
+        }
+        this.character.anchor.setTo(0.5, 1);
+        this.character.scale.setTo(0.5);
+        game.physics.arcade.enable(this.character);
+
+        // Delay to next level
+        this.count = 0;
+        this.wait = 60;
+        
+    },
+
+    update: function() {
+        
+        // Wait 2 seconds before moving or staring a game
+        this.count ++;
+        if(this.count<=this.wait) return;
+        
+        // If movement is stopped or position is 6 (final), load game
+    	if(this.gameStateString=="gameSquareOne"){
+		    if(levelPosition==8){
+	            levelMove = false;
+	        }
+		}else if(this.gameStateString=="gameCircleOne"){
+			if(levelPosition==6){
+	            levelMove = false;
+	        }
+		}else if(this.gameStateString=="gameSquareTwo"){
+			if(levelPosition==5){
+	            levelMove = false;
+	        }
+		}
+
+
+        if(!levelMove){
+            this.func_loadGame();
+        }
+        
+        // If momevent is enabled, move to next point from actual
+        if(levelMove){
+            game.physics.arcade.moveToXY(
+                this.character, 
+                this.points.x[levelPosition+1],
+                this.points.y[levelPosition+1],
+                100
+            );    	
+            
+            // I kid/tractor reached the end, stop movement
+            if(Math.ceil(this.character.x)==this.points.x[levelPosition+1] || Math.ceil(this.character.y)==this.points.y[levelPosition+1]){
+                levelMove=false;
+                levelPosition += 1; //Update position
+            }
+        }
+    },
+        
+    //MapLoading function
+    func_loadGame: function(){
+    	
+        if(audioStatus){
+            beepSound.play();
+        }
+
+        if(levelPosition<5){
+        	game.state.start(this.gameStateString);
+        }else{
+        	game.state.start(this.endStateString);
+    	}
+
+    }
+    
+};

+ 17 - 17
js/menu.js

@@ -2,7 +2,7 @@
 
     var menuState = {
         create: function(){},
-        loadGame: function(){},
+        func_loadGame: function(){},
         ---------------------------- end of phaser functions
         func_showTitle: function(){},
         func_clearTitle: function(){},
@@ -35,7 +35,7 @@ var menuState = {
 
         // Subtitle : Game mode 
         var style_game = { font: "27px Arial", fill: "#003cb3", align: "center" };
-        var lbl_game = game.add.text(this.game.world.centerX, 110, "BOBHAOSHSOHAIOSH", style_game);
+        var lbl_game = game.add.text(this.game.world.centerX, 110, "", style_game);
         lbl_game.anchor.setTo(0.5,0.5);
 
         // BUTTONS
@@ -67,70 +67,70 @@ var menuState = {
         menu1.anchor.setTo(0.5, 0.5);
         menu1.inputEnabled = true;
         menu1.input.useHandCursor = true;
-        menu1.events.onInputDown.add(this.loadGame,{levelType:1, beep: beepSound, shape : "Square", label : true});
+        menu1.events.onInputDown.add(this.func_loadGame,{levelType:1, beep: beepSound, shape : "Square", label : true});
         menu1.events.onInputOver.add(this.func_showTitle,{levelType:1, beep: beepSound, shape : "Square", label : true, menu: menu1, lbl_game: lbl_game});
         menu1.events.onInputOut.add(this.func_clearTitle, {menu: menu1, lbl_game: lbl_game});
         
         menu2.anchor.setTo(0.5, 0.5);
         menu2.inputEnabled = true;
         menu2.input.useHandCursor = true;
-        menu2.events.onInputDown.add(this.loadGame,{levelType:1, beep: beepSound, shape : "Square", label : false});
+        menu2.events.onInputDown.add(this.func_loadGame,{levelType:1, beep: beepSound, shape : "Square", label : false});
         menu2.events.onInputOver.add(this.func_showTitle,{levelType:1, beep: beepSound, shape : "Square", label : false, menu: menu2, lbl_game: lbl_game});
         menu2.events.onInputOut.add(this.func_clearTitle, {menu: menu2, lbl_game: lbl_game});
         
         menu3.anchor.setTo(0.5, 0.5);
         menu3.inputEnabled = true;
         menu3.input.useHandCursor = true;
-        menu3.events.onInputDown.add(this.loadGame,{levelType:2, beep: beepSound, shape : "Square", label : true});
+        menu3.events.onInputDown.add(this.func_loadGame,{levelType:2, beep: beepSound, shape : "Square", label : true});
         menu3.events.onInputOver.add(this.func_showTitle,{levelType:2, beep: beepSound, shape : "Square", label : true, menu: menu3, lbl_game: lbl_game});
         menu3.events.onInputOut.add(this.func_clearTitle, {menu: menu3, lbl_game: lbl_game});
         
         menu4.anchor.setTo(0.5, 0.5);
         menu4.inputEnabled = true;
         menu4.input.useHandCursor = true;
-        menu4.events.onInputDown.add(this.loadGame,{levelType:2, beep: beepSound, shape : "Square", label : false});
+        menu4.events.onInputDown.add(this.func_loadGame,{levelType:2, beep: beepSound, shape : "Square", label : false});
         menu4.events.onInputOver.add(this.func_showTitle,{levelType:2, beep: beepSound, shape : "Square", label : false, menu: menu4, lbl_game: lbl_game});
         menu4.events.onInputOut.add(this.func_clearTitle, {menu: menu4, lbl_game: lbl_game});
         
         menu5.anchor.setTo(0.5, 0.5);
         menu5.inputEnabled = true;
         menu5.input.useHandCursor = true;
-        menu5.events.onInputDown.add(this.loadGame,{levelType:1, beep: beepSound, shape : "Circle", label : true});
+        menu5.events.onInputDown.add(this.func_loadGame,{levelType:1, beep: beepSound, shape : "Circle", label : true});
         menu5.events.onInputOver.add(this.func_showTitle,{levelType:1, beep: beepSound, shape : "Circle", label : true, menu: menu5, lbl_game: lbl_game});
         menu5.events.onInputOut.add(this.func_clearTitle, {menu: menu5, lbl_game: lbl_game});
         
         menu6.anchor.setTo(0.5, 0.5);
         menu6.inputEnabled = true;
         menu6.input.useHandCursor = true;
-        menu6.events.onInputDown.add(this.loadGame,{levelType:1, beep: beepSound, shape : "Circle", label : false});
+        menu6.events.onInputDown.add(this.func_loadGame,{levelType:1, beep: beepSound, shape : "Circle", label : false});
         menu6.events.onInputOver.add(this.func_showTitle,{levelType:1, beep: beepSound, shape : "Circle", label : false, menu: menu6, lbl_game: lbl_game});
         menu6.events.onInputOut.add(this.func_clearTitle, {menu: menu6, lbl_game: lbl_game});
         
         menu7.anchor.setTo(0.5, 0.5);
         menu7.inputEnabled = true;
         menu7.input.useHandCursor = true;
-        menu7.events.onInputDown.add(this.loadGame,{levelType:2, beep: beepSound, shape : "Circle", label : true});
+        menu7.events.onInputDown.add(this.func_loadGame,{levelType:2, beep: beepSound, shape : "Circle", label : true});
         menu7.events.onInputOver.add(this.func_showTitle,{levelType:2, beep: beepSound, shape : "Circle", label : true, menu: menu7, lbl_game: lbl_game});
         menu7.events.onInputOut.add(this.func_clearTitle, {menu: menu7, lbl_game: lbl_game});
         
         menu8.anchor.setTo(0.5, 0.5);
         menu8.inputEnabled = true;
         menu8.input.useHandCursor = true;
-        menu8.events.onInputDown.add(this.loadGame,{levelType:2, beep: beepSound, shape : "Circle", label : false});
+        menu8.events.onInputDown.add(this.func_loadGame,{levelType:2, beep: beepSound, shape : "Circle", label : false});
         menu8.events.onInputOver.add(this.func_showTitle,{levelType:2, beep: beepSound, shape : "Circle", label : false, menu: menu8, lbl_game: lbl_game});
         menu8.events.onInputOut.add(this.func_clearTitle, {menu: menu8, lbl_game: lbl_game});
 
         menu9.anchor.setTo(0.5, 0.5);
         menu9.inputEnabled = true;
         menu9.input.useHandCursor = true;
-        menu9.events.onInputDown.add(this.loadGame,{levelType:3, beep: beepSound, shape : "Square", label : true});
+        menu9.events.onInputDown.add(this.func_loadGame,{levelType:3, beep: beepSound, shape : "Square", label : true});
         menu9.events.onInputOver.add(this.func_showTitle,{levelType:3, beep: beepSound, shape : "Square", label : true, menu: menu9, lbl_game: lbl_game});
         menu9.events.onInputOut.add(this.func_clearTitle, {menu: menu9, lbl_game: lbl_game});
 
     },
     
     //calls the selected game menu screen
-    loadGame: function(){
+    func_loadGame: function(){
 
         if(audioStatus){
             this.beep.play();
@@ -150,14 +150,14 @@ var menuState = {
                 }
 
                 if(debugMode) console.log("Square One");
-                game.state.start('menuSOne');                
+                game.state.start('menuSquareOne');                
             
             }else if(this.levelType==3){
                 
-                levelType = "";
+                levelType = "C";
                 
-                if(debugMode) console.log("Square Two");
-                game.state.start('menuSTwo')
+                if(debugMode) console.log("Square Two, "+levelType);
+                game.state.start('menuSquareTwo')
             
             }
 
@@ -170,7 +170,7 @@ var menuState = {
             }
             
             if(debugMode) console.log("Circle One");
-            game.state.start('menuCOne');
+            game.state.start('menuCircleOne');
         
         }
 

+ 8 - 172
js/squareOne.js

@@ -6,13 +6,6 @@
         func_loadMap: function(){}
     };
 
-    var mapSquareOne = {
-        create: function(){},
-        update: function(){},
-        ---------------------------- end of phaser functions
-        loadGame: function()
-    };
-
     var gameSquareOne = {
         create: function(){},
         update: function(){},
@@ -177,169 +170,12 @@ var menuSquareOne = {
         levelMove = true; //Move no next point
         levelDifficulty  = this.difficulty; //Number of difficulty (1 to 3)
         levelOperator = this.operator; //Operator of game
-
-        game.state.start('mapSOne');
-
-    }
-    
-};
-
-/****************************** MAP ****************************/
-
-var mapSquareOne = {
-
-    create: function() {
-                
-        // Background
-        game.add.image(0, 40, 'bgmap');
+        passedLevels = 0; //reset the game progress when entering a new level
         
-        // Navigation buttons
-        buttonSettings["func_addButtons"](1,0,
-                                    1,1,0,
-                                    0,0,
-                                    "menuSOne",0);
-        
-        // Styles for labels
-        var stylePlace = { font: '26px Arial', fill: '#ffffff', align: 'center'};
-        var styleMenu = { font: '30px Arial', fill: '#000000', align: 'center'};
-        
-        // Progress bar
-        var percentText = passedLevels*25;
-        var percentBlocks = passedLevels;
-
-        for(var p=0;p<percentBlocks;p++){
-            var block = game.add.image(660+p*30, 10, 'block');
-            block.scale.setTo(3.75, 1); //Scaling to double width
-        }
-        game.add.text(820, 10, percentText+'%', styleMenu);
-        game.add.text(650, 10, lang.difficulty + ' ' + levelDifficulty, styleMenu).anchor.setTo(1,0);
-        game.add.image(660, 10, 'pgbar');
-        
-        //Road
-        this.points = {
-        'x': [ 90, 204, 318, 432, 546, 660 ],
-        'y': [ 486, 422, 358, 294, 230, 166 ]
-        };
+        game.state.start('map');
 
-        //Garage
-        var garage = game.add.image(this.points.x[0], this.points.y[0], 'garage');
-        garage.scale.setTo(0.4);
-        garage.anchor.setTo(0.5, 1);
-         //Farm
-        var farm = game.add.image(this.points.x[5], this.points.y[5], 'farm');
-        farm.scale.setTo(0.6);
-        farm.anchor.setTo(0.1, 0.7);
-        
-         //Trees and Rocks
-        this.rocks = {
-             'x': [156, 275, 276, 441, 452, 590, 712],
-             'y': [309, 543, 259, 156, 419, 136, 316]
-        }
-        this.r_types = [1, 1, 2, 1, 2, 2, 2];
-        
-        for(var i=0; i<this.r_types.length; i++){
-            if(this.r_types[i]==1){
-                var sprite = game.add.image(this.rocks.x[i], this.rocks.y[i], 'rock');
-                sprite.scale.setTo(0.32);
-                sprite.anchor.setTo(0.5, 0.95);
-            }else if(this.r_types[i]==2){
-                var sprite = game.add.image(this.rocks.x[i], this.rocks.y[i], 'birch');
-                sprite.scale.setTo(0.4);
-                sprite.anchor.setTo(0.5, 0.95);
-            }
-        }
-        this.trees = {
-             'x': [105, 214, 354, 364, 570, 600, 740, 779],
-             'y': [341, 219, 180, 520, 550, 392, 488, 286]
-        }
-        this.t_types = [2, 4, 3, 4, 1, 2, 4, 4];
-        
-        for(var i=0; i<this.t_types.length; i++){
-            var sprite = game.add.image(this.trees.x[i], this.trees.y[i], 'tree'+this.t_types[i]);
-            sprite.scale.setTo(0.6);
-            sprite.anchor.setTo(0.5, 0.95);
-        }
-
-        // places
-        for (var p = 1; p < this.points.x.length -1; p++){
-            var place;
-            if(p<levelPosition)
-                	place = game.add.image(this.points.x[p], this.points.y[p], 'place_b');
-            else if (levelMove && p==levelPosition)
-                	place = game.add.image(this.points.x[p], this.points.y[p], 'place_b');
-            else
-                    place = game.add.image(this.points.x[p], this.points.y[p], 'place_a');
-            place.anchor.setTo(0.5, 0.5);
-            place.scale.setTo(0.3);
-            var sign = game.add.image(this.points.x[p]-20, this.points.y[p]-60, 'sign');
-            sign.anchor.setTo(0.5, 1);
-            sign.scale.setTo(0.4);
-            if(p>0 && p<this.points.x.length-1){
-                var text = game.add.text(this.points.x[p]-23, this.points.y[p]-84, p, stylePlace);
-                text.anchor.setTo(0.35, 0.5);
-            }
-        }
-
-        // tractor start position
-        this.tractor = game.add.sprite(this.points.x[levelPosition], this.points.y[levelPosition], 'tractor');
-        this.tractor.anchor.setTo(0.5, 1);
-        this.tractor.scale.setTo(0.5);
-        game.physics.arcade.enable(this.tractor);
-        var walk = this.tractor.animations.add('walk',[0,1,2,3,4]);
-        this.tractor.animations.play('walk', 5, true);
-        this.tractor.angle -= 25;
-        
-        // Delay to next level
-        this.count = 0;
-        this.wait = 60;
-        
-    },
-
-    update: function() {
-
-        // Wait 2 seconds before moving or staring a game
-        this.count ++;
-        if(this.count<=this.wait) return;
-        
-        // If movement is stopped or position is 6 (final), load game
-        if(levelPosition==8){
-            levelMove = false;
-        }
-
-        if(!levelMove){
-            this.loadGame();
-        }
-        
-        // If momevent is enabled, move to next point from actual
-        if(levelMove){
-            game.physics.arcade.moveToXY(
-                this.tractor, 
-                this.points.x[levelPosition+1],
-                this.points.y[levelPosition+1],
-                100
-            );
-            
-            // I tractor reached the end, stop movement
-            if(Math.ceil(this.tractor.x)==this.points.x[levelPosition+1] || Math.ceil(this.tractor.y)==this.points.y[levelPosition+1]){
-                levelMove=false;
-                levelPosition += 1; //Update position
-            }
-        }
-
-    },
-        
-    //MapLoading function
-    loadGame: function() {
-        if(audioStatus){
-            beepSound.play();
-        }
-        if(levelPosition<5){
-            game.state.start('gameSOne');
-        }else{
-            game.state.start('endSOne');
-        }
     }
-
+    
 };
 
 /****************************** GAME ****************************/
@@ -362,7 +198,7 @@ var gameSquareOne = {
         buttonSettings["func_addButtons"](1,1,
                                     1,1,1,
                                     1,0,
-                                    "menuSOne", this.func_viewHelp);
+                                    "menuSquareOne", this.func_viewHelp);
 
         //Clouds
         game.add.image(300, 100, 'cloud');
@@ -539,12 +375,12 @@ var gameSquareOne = {
         }
         
         //If end position is out of bounds, restart
-        if(!hasFigure) game.state.start('gameSOne');
+        if(!hasFigure) game.state.start('gameSquareOne');
         
         if (levelOperator=='Plus' && (endPosition<(startX+blockWidth) || endPosition>(startX+8*blockWidth))){
-            game.state.start('gameSOne');
+            game.state.start('gameSquareOne');
         }else if (levelOperator=='Minus' && (endPosition>(startX) || endPosition<(startX-(8*blockWidth)))){
-            game.state.start('gameSOne');
+            game.state.start('gameSquareOne');
         }
         
         //If game is type B, selectiong a random block floor place
@@ -771,7 +607,7 @@ var gameSquareOne = {
                 }else{
                     levelMove = false;
                 }
-                game.state.start('mapSOne');
+                game.state.start('map');
             }
         }
         

+ 13 - 179
js/squareTwo.js

@@ -6,13 +6,6 @@
         func_loadMap: function(){}
     };
 
-    var mapSquareTwo = {
-        create: function(){},
-        update: function(){},
-        ---------------------------- end of phaser functions
-        loadGame: function()
-    };
-
     var gameSquareTwo = {
         create: function(){},
         update: function(){},
@@ -91,7 +84,7 @@ var menuSquareTwo = {
             //event
             stairsMoreToLess1[i].inputEnabled = true;
             stairsMoreToLess1[i].input.useHandCursor = true;
-            stairsMoreToLess1[i].events.onInputDown.add(this.func_loadMap, {beep: beepSound, difficulty: i, type: 'A' });
+            stairsMoreToLess1[i].events.onInputDown.add(this.func_loadMap, {beep: beepSound, difficulty: i, operator: 'A' });
             stairsMoreToLess1[i].events.onInputOver.add(function (item) { item.alpha=0.5; }, this);
             stairsMoreToLess1[i].events.onInputOut.add(function (item) { item.alpha=1; }, this);
             
@@ -122,7 +115,7 @@ var menuSquareTwo = {
             //event
             stairsMoreToLess2[i].inputEnabled = true;
             stairsMoreToLess2[i].input.useHandCursor = true;
-            stairsMoreToLess2[i].events.onInputDown.add(this.func_loadMap, {beep: beepSound, difficulty: i, type: 'B' });
+            stairsMoreToLess2[i].events.onInputDown.add(this.func_loadMap, {beep: beepSound, difficulty: i, operator: 'B' });
             stairsMoreToLess2[i].events.onInputOver.add(function (item) { item.alpha=0.5; }, this);
             stairsMoreToLess2[i].events.onInputOut.add(function (item) { item.alpha=1; }, this);
             
@@ -153,7 +146,7 @@ var menuSquareTwo = {
             //event
             stairsLessToMore[i].inputEnabled = true;
             stairsLessToMore[i].input.useHandCursor = true;
-            stairsLessToMore[i].events.onInputDown.add(this.func_loadMap, {beep: beepSound, difficulty: i, type: 'C' });
+            stairsLessToMore[i].events.onInputDown.add(this.func_loadMap, {beep: beepSound, difficulty: i, operator: 'C' });
             stairsLessToMore[i].events.onInputOver.add(function (item) { item.alpha=0.5; }, this);
             stairsLessToMore[i].events.onInputOut.add(function (item) { item.alpha=1; }, this);
             
@@ -176,174 +169,15 @@ var menuSquareTwo = {
         levelPosition = 0; //Map position
         levelMove = true; //Move no next point
         levelDifficulty  = this.difficulty; //Number of difficulty (1 to 5)
-        levelType = this.type; //Type of game
-        passedLevels = 0;
+        leveloperator = this.operator; //Type of game
+        passedLevels = 0; //reset the game progress when entering a new level
 
-        game.state.start('mapSTwo');
+        game.state.start('map');
 
     },
     
 };
 
-/****************************** MAP ****************************/
-
-var mapSquareTwo={
-
-    create: function() {
-
-        // Background
-        game.add.image(0, 40, 'bgmap');
-        
-        // Navigation buttons
-        buttonSettings["func_addButtons"](1,0,
-                                    1,1,0,
-                                    0,0,
-                                    "menuSTwo",0);
-        
-        // Styles for labels
-        var stylePlace = { font: '26px Arial', fill: '#ffffff', align: 'center'};
-        var styleMenu = { font: '30px Arial', fill: '#000000', align: 'center'};
-        
-        // Progress bar
-        var percentText = passedLevels*25;
-        var percentBlocks = passedLevels;
-
-        for(var p=0;p<percentBlocks;p++){
-            var block = game.add.image(660+p*30, 10, 'block');
-            block.scale.setTo(3.75, 1); //Scaling to double width
-        }
-        game.add.text(820, 10, percentText+'%', styleMenu);
-        game.add.text(650, 10, lang.difficulty + ' ' + levelDifficulty, styleMenu).anchor.setTo(1,0);
-        game.add.image(660, 10, 'pgbar');
-        
-         //Road
-        this.points = {
-        'x': [ 90, 204, 318, 432, 546, 660 ],
-        'y': [ 486, 422, 358, 294, 230, 166 ]
-        };
-
-        //House
-        var house = game.add.image(this.points.x[0], this.points.y[0], 'house');
-        house.scale.setTo(0.7);
-        house.anchor.setTo(0.7, 0.8);
-        //School
-        var school = game.add.image(this.points.x[5], this.points.y[5], 'school');
-        school.scale.setTo(0.35);
-        school.anchor.setTo(0.2, 0.7);
-        
-        //Trees and Rocks
-        this.rocks = {
-             'x': [156, 275, 276, 441, 452, 590, 712],
-             'y': [309, 543, 259, 156, 419, 136, 316]
-        }
-        this.r_types = [1, 1, 2, 1, 2, 2, 2];
-        
-        for(var i=0; i<this.r_types.length; i++){
-            if(this.r_types[i]==1){
-                var sprite = game.add.image(this.rocks.x[i], this.rocks.y[i], 'rock');
-                sprite.scale.setTo(0.32);
-                sprite.anchor.setTo(0.5, 0.95);
-            }else if(this.r_types[i]==2){
-                var sprite = game.add.image(this.rocks.x[i], this.rocks.y[i], 'birch');
-                sprite.scale.setTo(0.4);
-                sprite.anchor.setTo(0.5, 0.95);
-            }
-        }
-        this.trees = {
-             'x': [105, 214, 354, 364, 570, 600, 740, 779],
-             'y': [341, 219, 180, 520, 550, 392, 488, 286]
-        }
-        this.t_types = [2, 4, 3, 4, 1, 2, 4, 4];
-        
-        for(var i=0; i<this.t_types.length; i++){
-            var sprite = game.add.image(this.trees.x[i], this.trees.y[i], 'tree'+this.t_types[i]);
-            sprite.scale.setTo(0.6);
-            sprite.anchor.setTo(0.5, 0.95);
-        }
-        
-        // places
-        for (var p = 1; p < this.points.x.length -1; p++){
-            var place;
-            if(p<levelPosition)
-                place = game.add.image(this.points.x[p], this.points.y[p], 'place_b');
-            else if (levelMove && p==levelPosition)
-                place = game.add.image(this.points.x[p], this.points.y[p], 'place_b');
-            else
-                place = game.add.image(this.points.x[p], this.points.y[p], 'place_a');
-            place.anchor.setTo(0.5, 0.5);
-            place.scale.setTo(0.3);
-            var sign = game.add.image(this.points.x[p]-20, this.points.y[p]-60, 'sign');
-            sign.anchor.setTo(0.5, 1);
-            sign.scale.setTo(0.4);
-            if(p>0 && p<this.points.x.length-1){
-                var text = game.add.text(this.points.x[p]-23, this.points.y[p]-84, p, stylePlace);
-                text.anchor.setTo(0.35, 0.5);
-            }
-        }
-
-        // Kid start position
-        this.kid = game.add.sprite(this.points.x[levelPosition], this.points.y[levelPosition], 'kid_run');
-        this.kid.anchor.setTo(0.5,1);
-        this.kid.scale.setTo(0.5);
-        game.physics.arcade.enable(this.kid);
-        this.kid.animations.add('run');
-        this.kid.animations.play('run', 6, true);
-        
-        // Delay to next level
-        this.count = 0;
-        this.wait = 60;
-
-    },
-
-    update: function() {
-        
-        // Wait before moving or staring a game
-        this.count ++;
-        if(this.count<=this.wait) return;
-        
-        // If movement is stopped or position is 5 (final), load game
-        if(levelPosition==5){
-            levelMove = false;
-        }
-        
-        if(!levelMove){
-            this.loadGame();
-        }
-        
-        // If momevent is enabled, move to next point from actual
-        if(levelMove){
-            game.physics.arcade.moveToXY(
-                this.kid, 
-                this.points.x[levelPosition+1],
-                this.points.y[levelPosition+1],
-                100
-            );
-            
-            // I tractor reached the end, stop movement
-            if(Math.ceil(this.kid.x)==this.points.x[levelPosition+1] || Math.ceil(this.kid.y)==this.points.y[levelPosition+1]){
-                levelMove=false;
-                levelPosition += 1; //Update position
-            }
-        }
-
-    }, 
-        
-    //MapLoading function
-    loadGame: function(){
-
-        if(audioStatus){
-           beepSound.play();
-        }
-        if(levelPosition<5){
-            game.state.start('gameSTwo');
-        }else{
-            game.state.start('endSTwo');
-        }
-
-    }
-
-};
-
 /****************************** GAME ****************************/
 
 var gameSquareTwo = {
@@ -365,7 +199,7 @@ var gameSquareTwo = {
         buttonSettings["func_addButtons"](1,1,
                                     1,1,0,
                                     1,0,
-                                    "menuSTwo", 0);
+                                    "menuSquareTwo", 0);
 
         //Clouds
         game.add.image(300, 100, 'cloud');
@@ -432,7 +266,7 @@ var gameSquareTwo = {
          //Creating blocks
         blockW = 400;
         blockH = 50;
-        if(levelType!="C"){
+        if(levelOperator!="C"){
             xA=230, yA=90;
             xB=xA, yB=yA+3*blockH+30;
         }else{
@@ -467,14 +301,14 @@ var gameSquareTwo = {
             
             //aux blocks
             var xAux = xA+i*widthA, yAux = yA+blockH+10;
-            if(levelType == 'C') yAux = yA;
+            if(levelOperator == 'C') yAux = yA;
             var block = game.add.graphics(xAux, yAux );
                 block.anchor.setTo(0.5, 0.5);
                 block.lineStyle(1, lineColor);
                 block.beginFill(fillColorS);
                 block.drawRect(0, 0, widthA, blockH);
                 
-                if(levelType!='A') block.alpha = 0;
+                if(levelOperator!='A') block.alpha = 0;
                 else block.alpha = 0.2;
                     
             auxblqA.add(block);
@@ -522,14 +356,14 @@ var gameSquareTwo = {
             blocksB.add(block);
             //aux blocks
             var xAux = xB+i*widthB, yAux = yB+blockH+10;
-            if(levelType == 'C') yAux = yB;
+            if(levelOperator == 'C') yAux = yB;
             var block = game.add.graphics(xAux, yAux);
                 block.anchor.setTo(0.5, 0.5);
                 block.lineStyle(1, lineColor);
                 block.beginFill(fillColorS);
                 block.drawRect(0, 0, widthB, blockH);
                 
-                if(levelType!='A') block.alpha = 0;
+                if(levelOperator!='A') block.alpha = 0;
                 else block.alpha = 0.2;
             auxblqB.add(block);
             
@@ -666,7 +500,7 @@ var gameSquareTwo = {
 				// kid.animations.play('right', 8, true);
             }
             if(counter>endCounter){
-                game.state.start('mapSTwo');
+                game.state.start('map');
             }
         }