Quellcode durchsuchen

button rearragement and name change | code simplification | user no longer needs to type name avery time he changes language | kid no longer sticks foot out of the balloon at levels

lairaalmas vor 5 Jahren
Ursprung
Commit
46f507e91a
12 geänderte Dateien mit 238 neuen und 452 gelöschten Zeilen
  1. BIN
      assets/img/kid/walk.png
  2. 1 1
      assets/languages/en_US.json
  3. 1 1
      assets/languages/es_PE.json
  4. 1 1
      assets/languages/fr_FR.json
  5. 1 1
      assets/languages/pt_BR.json
  6. 2 2
      index.html
  7. 6 1
      js/boot.js
  8. 45 137
      js/circleOne.js
  9. 8 31
      js/menu.js
  10. 107 5
      js/preMenu.js
  11. 29 135
      js/squareOne.js
  12. 37 137
      js/squareTwo.js

BIN
assets/img/kid/walk.png


+ 1 - 1
assets/languages/en_US.json

@@ -8,7 +8,7 @@
     "good_job": "Good Job",
     "retry": "Try again",
     "menu_world" : "LANGUAGE SELECTION",
-    "menu_list" : "RETURN TO MENU",
+    "menu_list" : "MAIN MENU",
     "menu_back" : "GO BACK",
     "menu_help" : "SEE SOLUTION",
     "circle_name": "Circles",

+ 1 - 1
assets/languages/es_PE.json

@@ -8,7 +8,7 @@
     "good_job": "Bien hecho",
     "retry": "Inténtalo de nuevo",
     "menu_world" : "SELECCION DE IDIOMA",
-    "menu_list" : "REGRESAR AL MENU",
+    "menu_list" : "MENU PRINCIPAL",
     "menu_back" : "REGRESAR",
     "menu_help" : "VER SOLUCION",
     "circle_name": "Circulos",

+ 1 - 1
assets/languages/fr_FR.json

@@ -8,7 +8,7 @@
     "good_job": "Bon travail",
     "retry": "Réessayer",
     "menu_world" : "SÉLECTION DE LA LANGUE",
-    "menu_list" : "RETOUR AU MENU",
+    "menu_list" : "MENU PRINCIPAL",
     "menu_back" : "RETOUR",
     "menu_help" : "VIEW SOLUTION",
     "circle_name": "Circles",

+ 1 - 1
assets/languages/pt_BR.json

@@ -8,7 +8,7 @@
     "good_job": "Bom trabalho!",
     "retry": "Tente novamente!",
     "menu_world" : "SELECIONAR IDIOMA",
-    "menu_list" : "VOLTAR AO MENU",
+    "menu_list" : "MENU PRINCIPAL",
     "menu_back" : "VOLTAR",
     "menu_help" : "VER SOLUÇÃO",
     "circle_name": "Círculos",

+ 2 - 2
index.html

@@ -4,6 +4,7 @@
 <html>
     
     <head>  
+
         <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
         <title> iFractions </title>
         <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
@@ -35,6 +36,7 @@
 			  color: rgb(0, 0, 0);
 			  text-align: center;
 			}
+			
         </style>
 
     </head>
@@ -102,6 +104,4 @@
 
     </body>
 
-
-
 </html>

+ 6 - 1
js/boot.js

@@ -8,6 +8,7 @@
     var timer, totalTime;
 
     var audioStatus = true;
+    var nameStatus = false;
 
     // Initialize the game
     var game = new Phaser.Game(
@@ -125,7 +126,7 @@
 	        
 	        // Loading assets based on language        
 	        game.load.spritesheet('kid_run', imgsrc+'kid/run.png', 82, 178, 12);
-	        game.load.spritesheet('kid_walk', imgsrc+'kid/walk.png', 78, 175, 24);
+	        game.load.spritesheet('kid_walk', imgsrc+'kid/walk.png', 78, 175, 26);
 	        game.load.spritesheet('kid_lost', imgsrc+'kid/lost.png', 72, 170, 6);
 	        game.load.spritesheet('tractor', imgsrc+'tractor/frame.png', 201, 144, 10);
 	        game.load.image('balloon', imgsrc+'airballoon_upper.png');
@@ -149,12 +150,16 @@
 	        game.load.audio('sound_ok', ['assets/fx/ok.ogg', 'assets/fx/ok.mp3']);
 	        game.load.audio('sound_error', ['assets/fx/error.ogg', 'assets/fx/error.mp3']);
 	        game.load.audio('sound_beep', ['assets/fx/beep.ogg', 'assets/fx/beep.mp3']);
+
     	},
 
     	create: function(){
+
     		game.physics.startSystem(Phaser.Physics.ARCADE);
 		    game.state.start('language');
+    	
     	}
+    	
     };
 
     //starting to boot game

+ 45 - 137
js/circleOne.js

@@ -3,7 +3,6 @@
     var menuCircleOne = {
         create: function(){},
         ---------------------------- end of phaser functions
-        loadState: function(){},
         loadMap: function(){}
     };
 
@@ -11,7 +10,6 @@
         create: function(){},
         update: function(){},
         ---------------------------- end of phaser functions
-        loadState: function(){},
         loadGame: function()
     };
 
@@ -25,9 +23,8 @@
         clickCircle: function(){},
         setPlace: function(){},
         postScore: function(){},
-        loadState: function(){},
         viewHelp: function(){},
-        checkOverlap: function(){}
+        checkOverlap: function(_,_){}
             //getRndDivisor: function(){}
     };
 
@@ -53,42 +50,10 @@ var menuCircleOne = {
         var beepSound = game.add.audio('sound_beep');
                 
         // Menu options
-        //information label
-        m_info_left = game.add.text(14, 53, "", { font: "20px Arial", fill: "#330000", align: "center" });
-        
-        m_info_right = game.add.text(game.world.width - 10, 53, "", { font: "20px Arial", fill: "#330000", align: "right" });
-        m_info_right.anchor.setTo(1,0.02);
-
-        // Return to menu button
-        m_list = game.add.sprite(10, 10, 'list'); 
-        m_list.inputEnabled = true;
-        m_list.input.useHandCursor = true;
-        m_list.events.onInputDown.add(this.loadState, {state: "menu", beep: beepSound});
-        m_list.events.onInputOver.add(function(){ this.m_info_left.text = lang.menu_list});
-        m_list.events.onInputOut.add(function(){ this.m_info_left.text = ""});
-        // Return to diffculty
-        m_back = game.add.sprite(60, 10, 'back'); 
-        m_back.inputEnabled = true;
-        m_back.input.useHandCursor = true;
-        m_back.events.onInputDown.add(this.loadState, {state: "menuCOne", beep: beepSound});
-        m_back.events.onInputOver.add(function(){ this.m_info_left.text = lang.menu_back});
-        m_back.events.onInputOut.add(function(){ this.m_info_left.text = ""});
-
-        // Return to language button
-        m_world = game.add.sprite(game.world.width - 120, 10, 'world'); 
-        m_world.inputEnabled = true;
-        m_world.input.useHandCursor = true;
-        m_world.events.onInputDown.add(this.loadState, {state: "language", beep: beepSound});
-        m_world.events.onInputOver.add(function(){ this.m_info_right.text = lang.menu_world });
-        m_world.events.onInputOut.add(function(){ this.m_info_right.text = "" });
-        // change audio status button
-        m_audio = game.add.sprite(game.world.width - 60, 10, 'audio');
-        audioStatus ? m_audio.frame = 0 : m_audio.frame = 1;
-        m_audio.inputEnabled = true;
-        m_audio.input.useHandCursor = true;
-        m_audio.events.onInputDown.add(function(){ if(audioStatus){ audioStatus=false; m_audio.frame = 1; }else{ audioStatus=true; m_audio.frame = 0; }});
-        m_audio.events.onInputOver.add(function(){ this.m_info_right.text = lang.audio });
-        m_audio.events.onInputOut.add(function(){ this.m_info_right.text = "" });
+        buttonSettings["addButtons"](1,1,
+                                    0,1,0,
+                                    1,0,
+                                    0,0);        
         
         // Setting title
         var style = { font: '28px Arial', fill: '#00804d'};
@@ -224,17 +189,12 @@ var menuCircleOne = {
             var label = game.add.text(xl, yl, i, { font: '25px Arial', fill: '#ffffff', align: 'center' });
                 label.anchor.setTo(0.5, 0.4);
         } 
-    },
-    
-    loadState: function(){
-        if(audioStatus){
-            this.beep.play();
-        }
-        game.state.start(this.state);
+
     },
         
     //MapLoading function
     loadMap: function(){
+
         if(audioStatus){
             this.beep.play();
         }
@@ -247,6 +207,7 @@ var menuCircleOne = {
         }else{
             game.state.start('unofinal');
         }
+
     }
     
 };
@@ -254,6 +215,7 @@ var menuCircleOne = {
 /****************************** MAP *****************************/
 
 var mapCircleOne = {
+
     create: function() {
         
         // Creating sound variable
@@ -263,26 +225,10 @@ var mapCircleOne = {
         game.add.image(0, 40, 'bgmap');
         
         // Menu options
-        //information label
-        m_info_left = game.add.text(14, 53, "", { font: "20px Arial", fill: "#330000", align: "center" });
-
-        if(oneMenu){
-            // Return to menu button
-            m_list = game.add.sprite(10, 10, 'list'); 
-            m_list.inputEnabled = true;
-            m_list.input.useHandCursor = true;
-            m_list.events.onInputDown.add(this.loadState, {state: "menu", beep: beepSound});
-            m_list.events.onInputOver.add(function(){ this.m_info_left.text = lang.menu_list});
-            m_list.events.onInputOut.add(function(){ this.m_info_left.text = ""});
-            // Return to diffculty
-            m_back = game.add.sprite(60, 10, 'back'); 
-            m_back.inputEnabled = true;
-            m_back.input.useHandCursor = true;
-            m_back.events.onInputDown.add(this.loadState, {state: "menuCOne", beep: beepSound});
-            m_back.events.onInputOver.add(function(){ this.m_info_left.text = lang.menu_back});
-            m_back.events.onInputOut.add(function(){ this.m_info_left.text = ""});
-
-        }
+        buttonSettings["addButtons"](1,0,
+                                    1,1,0,
+                                    0,0,
+                                    "menuCOne",0);
         
         // Styles for labels
         var stylePlace = { font: '26px Arial', fill: '#ffffff', align: 'center'};
@@ -410,15 +356,6 @@ var mapCircleOne = {
             }
         }
     },
-    
-    //Navigation functions,
-    
-    loadState: function(){
-        if(audioStatus){
-            this.beep.play();
-        }
-        game.state.start(this.state);
-    },
         
     //MapLoading function
     loadGame: function(){
@@ -467,6 +404,12 @@ var gameCircleOne = {
 
         // Background
         game.add.image(0, 0, 'bgimage');
+
+        // Menu options
+        buttonSettings["addButtons"](1,1,
+                                    1,1,1,
+                                    1,0,
+                                    "menuCOne", this.viewHelp);
         
         //Clouds
         game.add.image(300, 100, 'cloud');
@@ -516,7 +459,7 @@ var gameCircleOne = {
         trace.addToWorld();
         trace.clear();
                 
-         //generator
+        //generator
         //Circles and fractions
         var maxBlocks = onePosition+1; //Maximum blocks according to difficulty
         if(oneType=='B' || oneOperator=='Mixed') maxBlocks = 6;
@@ -680,53 +623,6 @@ var gameCircleOne = {
         basket = game.add.sprite(balloonPlace, 472, 'balloon_basket');
         basket.anchor.setTo(0.5, 0.5);
         
-        // Menu options
-        //information label
-        m_info_left = game.add.text(14, 53, "", { font: "20px Arial", fill: "#330000", align: "center" });
-        
-        m_info_right = game.add.text(game.world.width - 10, 53, "", { font: "20px Arial", fill: "#330000", align: "right" });
-        m_info_right.anchor.setTo(1,0.02);
-
-        if(oneMenu){
-            // Return to menu button
-            m_list = game.add.sprite(10, 10, 'list'); 
-            m_list.inputEnabled = true;
-            m_list.input.useHandCursor = true;
-            m_list.events.onInputDown.add(this.loadState, {state: "menu", beep: beepSound});
-            m_list.events.onInputOver.add(function(){ this.m_info_left.text = lang.menu_list});
-            m_list.events.onInputOut.add(function(){ this.m_info_left.text = ""});
-            // Return to diffculty
-            m_back = game.add.sprite(60, 10, 'back'); 
-            m_back.inputEnabled = true;
-            m_back.input.useHandCursor = true;
-            m_back.events.onInputDown.add(this.loadState, {state: "menuCOne", beep: beepSound});
-            m_back.events.onInputOver.add(function(){ this.m_info_left.text = lang.menu_back});
-            m_back.events.onInputOut.add(function(){ this.m_info_left.text = ""});
-
-            // Return to language button
-            m_world = game.add.sprite(game.world.width - 120, 10, 'world'); 
-            m_world.inputEnabled = true;
-            m_world.input.useHandCursor = true;
-            m_world.events.onInputDown.add(this.loadState, {state: "language", beep: beepSound});
-            m_world.events.onInputOver.add(function(){ this.m_info_right.text = lang.menu_world });
-            m_world.events.onInputOut.add(function(){ this.m_info_right.text = "" });
-            // change audio status button
-            m_audio = game.add.sprite(game.world.width - 60, 10, 'audio');
-            audioStatus ? m_audio.frame = 0 : m_audio.frame = 1;
-            m_audio.inputEnabled = true;
-            m_audio.input.useHandCursor = true;
-            m_audio.events.onInputDown.add(function(){ if(audioStatus){ audioStatus=false; m_audio.frame = 1; }else{ audioStatus=true; m_audio.frame = 0; }});
-            m_audio.events.onInputOver.add(function(){ this.m_info_right.text = lang.audio });
-            m_audio.events.onInputOut.add(function(){ this.m_info_right.text = "" });
-        }
-         // Help button
-        m_help = game.add.sprite(110, 10, 'help');
-        m_help.inputEnabled = true;
-        m_help.input.useHandCursor = true;
-        m_help.events.onInputDown.add(this.viewHelp, {beep: this.beepSound});
-        m_help.events.onInputOver.add(function(){ this.m_info_left.text = lang.menu_help});
-        m_help.events.onInputOut.add(function(){ this.m_info_left.text = ""});
-        
         //ok and error images
         okImg = game.add.image(game.world.centerX, game.world.centerY, 'h_ok');
         okImg.anchor.setTo(0.5);
@@ -734,6 +630,7 @@ var gameCircleOne = {
         errorImg = game.add.image(game.world.centerX, game.world.centerY, 'h_error');
         errorImg.anchor.setTo(0.5);
         errorImg.alpha = 0;
+
     },
     
     update: function() {
@@ -843,9 +740,13 @@ var gameCircleOne = {
         
         //Check if kid is inside the basket
         if(checkCollide){
-            kid_walk.animations.stop();
+            kid_walk.animations.stop();            
             timer.stop();
             if(this.checkOverlap(basket,kid_walk)){
+            	if(kid_walk.frame < 12)
+            		kid_walk.frame = 24;	            
+            	else
+            		kid_walk.frame = 25;	            
                 result = true;
             }else{
                 result = false;
@@ -889,6 +790,7 @@ var gameCircleOne = {
                 game.state.start('mapCOne');
             }
         }
+
     },
 
     updateCounter: function() {
@@ -915,9 +817,11 @@ var gameCircleOne = {
                 blocks.children[i].alpha = 0.5;
             }
         }
+
     },
     
     clickCircle: function(){
+
         if(!clicked){
             var minusBlocks = 0;
             
@@ -951,9 +855,11 @@ var gameCircleOne = {
                 blockSeparator.visible = false;
             }
         }
+
     },
 
     setPlace: function(){
+
         if(!clicked){
             
             balloon.x = game.input.x;
@@ -976,6 +882,7 @@ var gameCircleOne = {
                 blockSeparator.visible = false;
             }
         }
+
     },
 
     postScore: function (){
@@ -1001,18 +908,11 @@ var gameCircleOne = {
         // Send the data to PHP now... and wait for response to update the status div
         hr.send(vars); // Actually execute the request
         console.log("processing...");
+
     },
-    
-    //Navigation functions, 
-    
-    loadState: function(){
-        if(audioStatus){
-            this.beep.play();
-        }
-        game.state.start(this.state);
-    },
-        
+            
     viewHelp: function(){
+
         if(!clicked){
             var pointer;
             if(oneType=='A'){
@@ -1023,17 +923,20 @@ var gameCircleOne = {
             pointer.anchor.setTo(0.5, 0);
             pointer.alpha = 0.7;
         }
+
     },
     
     checkOverlap: function (spriteA, spriteB) {
+
         var xA = spriteA.x;
         var xB = spriteB.x;
                 
-        if(Math.abs(xA-xB)>25){
+        if(Math.abs(xA-xB)>14){
             return false;
         }else{
             return true;
         }
+
     }
     
 };
@@ -1092,9 +995,11 @@ var endCircleOne = {
         this.balloon.anchor.setTo(0.5,0.5);
         this.basket = game.add.sprite(0, -150, 'balloon_basket');
         this.basket.anchor.setTo(0.5,0.5);
+    
     },
 
-    update: function() {                
+    update: function() {   
+
         if(this.kid.y>=460){
             this.kid.animations.play('walk', 6, true);
             if(this.kid.x<=700){
@@ -1114,6 +1019,7 @@ var endCircleOne = {
             this.basket.x += 1;
             this.kid.x +=1;
         }
+
     },
     
     verPrincipal: function(){
@@ -1121,8 +1027,10 @@ var endCircleOne = {
     },
     
     verMenu: function(){
+
         if(oneMenu){
             game.state.start('menu');
         }
+        
     }        
 };

+ 8 - 31
js/menu.js

@@ -1,6 +1,5 @@
 
 var menu1, menu2, menu3, menu4;
-var m_info, m_world, m_menu, m_back, m_help, m_audio;
 var lbl_game;
 
 /*
@@ -10,7 +9,6 @@ var lbl_game;
         ---------------------------- end of phaser functions
         showTitle: function(){},
         clearTitle: function(){},
-        loadState: function(){}
     }
 */
 
@@ -38,27 +36,10 @@ var menuState = {
         var player_info = game.add.text(this.game.world.centerX, 40, lang.welcome + ", " + username + "!", { font: "20px Arial", fill: "#330000", align: "center" });        
         player_info.anchor.setTo(0.5,0.5);
 
-        // Menu options
-
-        //information label
-        m_info_right = game.add.text(game.world.width - 10, 53, "", { font: "20px Arial", fill: "#330000", align: "right" });
-        m_info_right.anchor.setTo(1,0.02);
-        // Return to language button
-        m_world = game.add.sprite(game.world.width - 120, 10, 'world'); 
-        m_world.inputEnabled = true;
-        m_world.input.useHandCursor = true;
-        m_world.events.onInputDown.add(this.loadState, {state: "language", beep: beepSound});
-        m_world.events.onInputOver.add(function(){ this.m_info_right.text = lang.menu_world });
-        m_world.events.onInputOut.add(function(){ this.m_info_right.text = "" });
-              
-        m_audio = game.add.sprite(game.world.width - 60, 10, 'audio');
-        audioStatus ? m_audio.frame = 0 : m_audio.frame = 1;
-        m_audio.inputEnabled = true;
-        m_audio.input.useHandCursor = true;
-        m_audio.events.onInputDown.add(function(){ if(audioStatus){ audioStatus=false; m_audio.frame = 1; }else{ audioStatus=true; m_audio.frame = 0; }});
-        m_audio.events.onInputOver.add(function(){ this.m_info_right.text = lang.audio });
-        m_audio.events.onInputOut.add(function(){ this.m_info_right.text = "" });
-
+        buttonSettings["addButtons"](0,1,
+                                    0,0,0,
+                                    1,1,
+                                    0,0);
         //game buttons 
 
         // loading button sprites
@@ -147,6 +128,7 @@ var menuState = {
     
     //calls the selected game menu screen
     loadGame: function(){
+
         if(audioStatus){
             this.beep.play();
         }
@@ -181,6 +163,7 @@ var menuState = {
             twoType = "";
             game.state.start('menuSTwo');
         }
+
     },
 
     showTitle: function(){
@@ -217,17 +200,11 @@ var menuState = {
         }
         
         lbl_game.text = title;
+
     },
 
     clearTitle: function(){
         lbl_game.text = "";
-    },
+    }
     
-    loadState: function(){
-        if(audioStatus){
-            this.beep.play();
-        }
-        game.state.start(this.state);
-    },
-
 };

+ 107 - 5
js/preMenu.js

@@ -15,11 +15,16 @@ var errorEmptyName;
     };
         
     var nameState = {
-        preload: function(){},
         create: function(){},
         ------------------------------------------------ end of phaser functions
+        nameIsEmpty: function(){}
         ready: function(){} //calls menu.js -> menuState
     };
+
+    var buttonSettings = {
+        addButtons: function(_,_,_,_,_,_,_,_,_){},
+        loadState: function(){}
+    };
 */
 
 // "choose language" screen
@@ -70,10 +75,12 @@ var langState = {
     },
     
     setLang: function(){
+
         //set language
         lang = this.lang;
         //start resource loading
         game.state.start('load');
+
     }
 
 };
@@ -94,10 +101,17 @@ var loadState = {
     },
 
     create: function() {  
+
         // gets selected language from json
         lang = game.cache.getJSON('dictionary');
         audio_lang_aux = lang.audio_on;
-        game.state.start('name');
+        if(!nameStatus){
+        	nameStatus = true;
+        	game.state.start('name');
+        }else{
+        	game.state.start('menu');
+        }
+    
     }
 
 };
@@ -140,9 +154,11 @@ var nameState = {
                 nameState["nameIsEmpty"]();
             }     
         });
+
     },
          
     nameIsEmpty: function() {
+
         if(document.getElementById("name_id").value!=""){
             nameState["ready"]();
             errorEmptyName.setText("");
@@ -151,9 +167,7 @@ var nameState = {
         }
 
     },
-
-    //var ready = function readyFunction() {...},
-    //var ready = function() {...},                
+              
     ready: function() {
         
         // saves the typed name on username variable
@@ -192,4 +206,92 @@ var nameState = {
         
     }
 
+};
+
+var m_info_right, m_info_left;
+var m_world, m_menu, m_back, m_help, m_audio;
+
+var buttonSettings = {
+
+    addButtons: function(left, right, b0Esq, b1Esq, b2Esq, b0Dir, b1Dir, phase, helpBtn){
+
+        var xEsq = 10;
+        var xDir = (game.world.width - 50 - 10);
+        
+        if(left == 1){
+            m_info_left = game.add.text(xEsq, 53, "", { font: "20px Arial", fill: "#330000", align: "center" });
+        }
+        if(right == 1){
+            m_info_right = game.add.text(xDir+50, 53, "", { font: "20px Arial", fill: "#330000", align: "right" });
+            m_info_right.anchor.setTo(1,0.02);
+        }
+        //left buttons
+        if(b0Esq == 1){
+            // Return to diffculty
+            m_back = game.add.sprite(xEsq, 10, 'back'); 
+            m_back.inputEnabled = true;
+            m_back.input.useHandCursor = true;
+            m_back.events.onInputDown.add(this.loadState, {state: phase, beep: beepSound});
+            m_back.events.onInputOver.add(function(){ m_info_left.text = lang.menu_back});
+            m_back.events.onInputOut.add(function(){ m_info_left.text = ""});
+            
+            xEsq+=50;
+        }
+        if(b1Esq == 1){
+            // Return to menu button
+            m_list = game.add.sprite(xEsq, 10, 'list'); 
+            m_list.inputEnabled = true;
+            m_list.input.useHandCursor = true;
+            m_list.events.onInputDown.add(this.loadState, {state: "menu", beep: beepSound});
+            m_list.events.onInputOver.add(function(){ m_info_left.text = lang.menu_list});
+            m_list.events.onInputOut.add(function(){ m_info_left.text = ""});
+            
+            xEsq+=50;
+        }
+        if(b2Esq == 1){
+            // Help button
+            m_help = game.add.sprite(xEsq, 10, 'help');
+            m_help.inputEnabled = true;
+            m_help.input.useHandCursor = true;
+            m_help.events.onInputDown.add(helpBtn, {beep: beepSound});
+            m_help.events.onInputOver.add(function(){ m_info_left.text = lang.menu_help});
+            m_help.events.onInputOut.add(function(){ m_info_left.text = ""});
+            
+            xEsq+=50;
+        }
+        //rightButtons
+        if(b0Dir == 1){
+            m_audio = game.add.sprite(xDir, 10, 'audio');
+            audioStatus ? m_audio.frame = 0 : m_audio.frame = 1;
+            m_audio.inputEnabled = true;
+            m_audio.input.useHandCursor = true;
+            m_audio.events.onInputDown.add(function(){ if(audioStatus){ audioStatus=false; m_audio.frame = 1; }else{ audioStatus=true; m_audio.frame = 0; }});
+            m_audio.events.onInputOver.add(function(){ m_info_right.text = lang.audio });
+            m_audio.events.onInputOut.add(function(){ m_info_right.text = "" });
+
+            xDir-=50;
+        }
+        if(b1Dir == 1){
+            // Return to language button
+            m_world = game.add.sprite(xDir, 10, 'world'); 
+            m_world.inputEnabled = true;
+            m_world.input.useHandCursor = true;
+            m_world.events.onInputDown.add(this.loadState, {state: "language", beep: beepSound});
+            m_world.events.onInputOver.add(function(){ m_info_right.text = lang.menu_world });
+            m_world.events.onInputOut.add(function(){ m_info_right.text = "" });
+                  
+            xDir-=50;
+        }
+
+    },
+
+    loadState: function(){
+
+        if(audioStatus){
+            this.beep.play();
+        }
+        game.state.start(this.state);
+    
+    }
+
 };

+ 29 - 135
js/squareOne.js

@@ -3,7 +3,6 @@
     var menuSquareOne = {
         create: function(){},
         ---------------------------- end of phaser functions
-        loadState: function(){},
         loadMap: function(){}
     };
 
@@ -11,13 +10,12 @@
         create: function(){},
         update: function(){},
         ---------------------------- end of phaser functions
-        loadState: function(){},
         loadGame: function()
     };
 
     var gameSquareOne = {
         create: function(){},
-        loadState: function(){},
+        update: function(){},
         ---------------------------- end of phaser functions
         updateCounter: function(){},
         overSquare: function(){},
@@ -25,7 +23,6 @@
         clickSquare: function(){},
             //setPlace: function(){},
         postScore: function(){},
-        update: function(){},
         viewHelp: function(){},
             //checkOverlap: function(){}
             //getRndDivisor: function(){}
@@ -53,42 +50,10 @@ var menuSquareOne = {
         var beepSound = game.add.audio('sound_beep');
           
         // Menu options
-        //information label
-        m_info_left = game.add.text(14, 53, "", { font: "20px Arial", fill: "#330000", align: "center" });
-        
-        m_info_right = game.add.text(game.world.width - 10, 53, "", { font: "20px Arial", fill: "#330000", align: "right" });
-        m_info_right.anchor.setTo(1,0.02);
-
-        // Return to menu button
-        m_list = game.add.sprite(10, 10, 'list'); 
-        m_list.inputEnabled = true;
-        m_list.input.useHandCursor = true;
-        m_list.events.onInputDown.add(this.loadState, {state: "menu", beep: beepSound});
-        m_list.events.onInputOver.add(function(){ this.m_info_left.text = lang.menu_list});
-        m_list.events.onInputOut.add(function(){ this.m_info_left.text = ""});
-        // Return to diffculty
-        m_back = game.add.sprite(60, 10, 'back'); 
-        m_back.inputEnabled = true;
-        m_back.input.useHandCursor = true;
-        m_back.events.onInputDown.add(this.loadState, {state: "menuSOne", beep: beepSound});
-        m_back.events.onInputOver.add(function(){ this.m_info_left.text = lang.menu_back});
-        m_back.events.onInputOut.add(function(){ this.m_info_left.text = ""});
-
-        // Return to language button
-        m_world = game.add.sprite(game.world.width - 120, 10, 'world'); 
-        m_world.inputEnabled = true;
-        m_world.input.useHandCursor = true;
-        m_world.events.onInputDown.add(this.loadState, {state: "language", beep: beepSound});
-        m_world.events.onInputOver.add(function(){ this.m_info_right.text = lang.menu_world });
-        m_world.events.onInputOut.add(function(){ this.m_info_right.text = "" });
-        // change audio status button
-        m_audio = game.add.sprite(game.world.width - 60, 10, 'audio');
-        audioStatus ? m_audio.frame = 0 : m_audio.frame = 1;
-        m_audio.inputEnabled = true;
-        m_audio.input.useHandCursor = true;
-        m_audio.events.onInputDown.add(function(){ if(audioStatus){ audioStatus=false; m_audio.frame = 1; }else{ audioStatus=true; m_audio.frame = 0; }});
-        m_audio.events.onInputOver.add(function(){ this.m_info_right.text = lang.audio });
-        m_audio.events.onInputOut.add(function(){ this.m_info_right.text = "" });
+        buttonSettings["addButtons"](1,1,
+                                    0,1,0,
+                                    1,0,
+                                    0,0);
         
         // Setting title
         var style = { font: '28px Arial', fill: '#00804d'};
@@ -182,15 +147,6 @@ var menuSquareOne = {
                 label.anchor.setTo(0.5, 0.4);
         } 
     },
-    
-    //Navigation functions,
-    
-    loadState: function(){
-        if(audioStatus){
-            this.beep.play();
-        }
-        game.state.start(this.state);
-    },
         
     //MapLoading function
     loadMap: function(){
@@ -223,26 +179,10 @@ var mapSquareOne = {
         game.add.image(0, 40, 'bgmap');
         
         // Menu options
-        //information label
-        m_info_left = game.add.text(14, 53, "", { font: "20px Arial", fill: "#330000", align: "center" });
-
-        if(oneMenu){
-            // Return to menu button
-            m_list = game.add.sprite(10, 10, 'list'); 
-            m_list.inputEnabled = true;
-            m_list.input.useHandCursor = true;
-            m_list.events.onInputDown.add(this.loadState, {state: "menu", beep: beepSound});
-            m_list.events.onInputOver.add(function(){ this.m_info_left.text = lang.menu_list});
-            m_list.events.onInputOut.add(function(){ this.m_info_left.text = ""});
-            // Return to diffculty
-            m_back = game.add.sprite(60, 10, 'back'); 
-            m_back.inputEnabled = true;
-            m_back.input.useHandCursor = true;
-            m_back.events.onInputDown.add(this.loadState, {state: "menuSOne", beep: beepSound});
-            m_back.events.onInputOver.add(function(){ this.m_info_left.text = lang.menu_back});
-            m_back.events.onInputOut.add(function(){ this.m_info_left.text = ""});
-
-        }
+        buttonSettings["addButtons"](1,0,
+                                    1,1,0,
+                                    0,0,
+                                    "menuSOne",0);
         
         // Styles for labels
         var stylePlace = { font: '26px Arial', fill: '#ffffff', align: 'center'};
@@ -370,15 +310,6 @@ var mapSquareOne = {
             }
         }
     },
-    
-    //Navigation functions,  
-    
-    loadState: function(){
-        if(audioStatus){
-            this.beep.play();
-        }
-        game.state.start(this.state);
-    },
         
     //MapLoading function
     loadGame: function(){
@@ -428,6 +359,12 @@ var gameSquareOne = {
         // Background
         game.add.image(0, 0, 'bgimage');
         
+        // Menu options
+        buttonSettings["addButtons"](1,1,
+                                    1,1,1,
+                                    1,0,
+                                    "menuSOne", this.viewHelp);
+
         //Clouds
         game.add.image(300, 100, 'cloud');
         game.add.image(660, 80, 'cloud');
@@ -671,54 +608,6 @@ var gameSquareOne = {
             game.add.text(posX, 560, i , stylePlace).anchor.setTo(0.5, 0.5); 
         }
         
-        // Menu options
-        //information label
-        m_info_left = game.add.text(14, 53, "", { font: "20px Arial", fill: "#330000", align: "center" });
-        
-        m_info_right = game.add.text(game.world.width - 10, 53, "", { font: "20px Arial", fill: "#330000", align: "right" });
-        m_info_right.anchor.setTo(1,0.02);
-
-        if(oneMenu){
-            // Return to menu button
-            m_list = game.add.sprite(10, 10, 'list'); 
-            m_list.inputEnabled = true;
-            m_list.input.useHandCursor = true;
-            m_list.events.onInputDown.add(this.loadState, {state: "menu", beep: beepSound});
-            m_list.events.onInputOver.add(function(){ this.m_info_left.text = lang.menu_list});
-            m_list.events.onInputOut.add(function(){ this.m_info_left.text = ""});
-            // Return to diffculty
-            m_back = game.add.sprite(60, 10, 'back'); 
-            m_back.inputEnabled = true;
-            m_back.input.useHandCursor = true;
-            m_back.events.onInputDown.add(this.loadState, {state: "menuSOne", beep: beepSound});
-            m_back.events.onInputOver.add(function(){ this.m_info_left.text = lang.menu_back});
-            m_back.events.onInputOut.add(function(){ this.m_info_left.text = ""});
-
-            // Return to language button
-            m_world = game.add.sprite(game.world.width - 120, 10, 'world'); 
-            m_world.inputEnabled = true;
-            m_world.input.useHandCursor = true;
-            m_world.events.onInputDown.add(this.loadState, {state: "language", beep: beepSound});
-            m_world.events.onInputOver.add(function(){ this.m_info_right.text = lang.menu_world });
-            m_world.events.onInputOut.add(function(){ this.m_info_right.text = "" });
-            // change audio status button
-            m_audio = game.add.sprite(game.world.width - 60, 10, 'audio');
-            audioStatus ? m_audio.frame = 0 : m_audio.frame = 1;
-            m_audio.inputEnabled = true;
-            m_audio.input.useHandCursor = true;
-            m_audio.events.onInputDown.add(function(){ if(audioStatus){ audioStatus=false; m_audio.frame = 1; }else{ audioStatus=true; m_audio.frame = 0; }});
-            m_audio.events.onInputOver.add(function(){ this.m_info_right.text = lang.audio });
-            m_audio.events.onInputOut.add(function(){ this.m_info_right.text = "" });
-        }
-         // Help button
-        
-        m_help = game.add.sprite(110, 10, 'help');
-        m_help.inputEnabled = true;
-        m_help.input.useHandCursor = true;
-        m_help.events.onInputDown.add(this.viewHelp, {beep: this.beepSound});
-        m_help.events.onInputOver.add(function(){ this.m_info_left.text = lang.menu_help});
-        m_help.events.onInputOut.add(function(){ this.m_info_left.text = ""});
-        
         //ok and error images
         okImg = game.add.image(game.world.centerX, game.world.centerY, 'h_ok');
         okImg.anchor.setTo(0.5);
@@ -734,6 +623,7 @@ var gameSquareOne = {
             arrow.alpha = 0;
         else if(oneType=="A")
             arrow.alpha = 0.5;
+
     },
     
     update: function() {
@@ -874,6 +764,7 @@ var gameSquareOne = {
     },
     
     overSquare: function(){
+
         if(!clicked){
             if(oneType=="A"){
                 for(var i=0;i<floorCount;i++){
@@ -896,9 +787,11 @@ var gameSquareOne = {
                 blockIndex = this.indice;
             }
         }
+
     },
 
     outSquare: function(){
+
         if(!clicked){
             if(oneType=="A"){
                 for(var i=0;i<floorCount;i++){
@@ -912,9 +805,11 @@ var gameSquareOne = {
                 blockIndex = -1;
             }
         }
+
     },
     
     clickSquare: function(){
+
         if(!clicked && !move){
             
             if(oneType=='A'){
@@ -975,6 +870,7 @@ var gameSquareOne = {
                 }
             }
         }
+
     },
 
     postScore: function (){
@@ -1000,18 +896,11 @@ var gameSquareOne = {
         // Send the data to PHP now... and wait for response to update the status div
         hr.send(vars); // Actually execute the request
         console.log("processing...");
-    },       
-    
-    //Navigation functions,
 
-    loadState: function(){
-        if(audioStatus){
-            this.beep.play();
-        }
-        game.state.start(this.state);
-    },
+    },       
         
     viewHelp: function(){
+
         if(!clicked){
             var pointer;
             if(oneType=='A'){
@@ -1022,6 +911,7 @@ var gameSquareOne = {
             pointer.anchor.setTo(0.5, 0);
             pointer.alpha = 0.7;
         }
+
     }
     
 };
@@ -1080,6 +970,7 @@ var endSquareOne = {
     },
 
     update: function() {
+
         if(this.tractor.x<=700){
             this.tractor.x += 2;
         }else{
@@ -1089,6 +980,7 @@ var endSquareOne = {
                 this.tractor.animations.stop();
             }
         }
+
     },
     
     verPrincipal: function(){
@@ -1096,9 +988,11 @@ var endSquareOne = {
     },
     
     verMenu: function(){
+
         if(oneMenu){
             game.state.start('menu');
         }
+
     }     
 
 };

+ 37 - 137
js/squareTwo.js

@@ -2,7 +2,6 @@
     var menuSquareTwo = {
         create: function(){},
         ---------------------------- end of phaser functions
-        loadState: function(){},
         loadMap: function(){}
     };
 
@@ -10,13 +9,12 @@
         create: function(){},
         update: function(){},
         ---------------------------- end of phaser functions
-        loadState: function(){},
         loadGame: function()
     };
 
     var gameSquareTwo = {
         create: function(){},
-        loadGame: function(){},
+        update: function(){},
         ---------------------------- end of phaser functions
         updateCounter: function(){},
         overSquare: function(){},
@@ -24,8 +22,6 @@
         clickSquare: function(){},
             //setPlace: function(){},
         postScore: function(){},
-        update: function(){},
-        loadState: function(){},
             //viewHelp: function(){},
             //checkOverlap: function(){}
         getRndDivisor: function(){}
@@ -54,42 +50,10 @@ var menuSquareTwo = {
         var beepSound = game.add.audio('sound_beep');
           
         // Menu options
-        //information label
-        m_info_left = game.add.text(14, 53, "", { font: "20px Arial", fill: "#330000", align: "center" });
-        
-        m_info_right = game.add.text(game.world.width - 10, 53, "", { font: "20px Arial", fill: "#330000", align: "right" });
-        m_info_right.anchor.setTo(1,0.02);
-
-        // Return to menu button
-        m_list = game.add.sprite(10, 10, 'list'); 
-        m_list.inputEnabled = true;
-        m_list.input.useHandCursor = true;
-        m_list.events.onInputDown.add(this.loadState, {state: "menu", beep: beepSound});
-        m_list.events.onInputOver.add(function(){ this.m_info_left.text = lang.menu_list});
-        m_list.events.onInputOut.add(function(){ this.m_info_left.text = ""});
-        // Return to diffculty
-        m_back = game.add.sprite(60, 10, 'back'); 
-        m_back.inputEnabled = true;
-        m_back.input.useHandCursor = true;
-        m_back.events.onInputDown.add(this.loadState, {state: "menuSTwo", beep: beepSound});
-        m_back.events.onInputOver.add(function(){ this.m_info_left.text = lang.menu_back});
-        m_back.events.onInputOut.add(function(){ this.m_info_left.text = ""});
-
-        // Return to language button
-        m_world = game.add.sprite(game.world.width - 120, 10, 'world'); 
-        m_world.inputEnabled = true;
-        m_world.input.useHandCursor = true;
-        m_world.events.onInputDown.add(this.loadState, {state: "language", beep: beepSound});
-        m_world.events.onInputOver.add(function(){ this.m_info_right.text = lang.menu_world });
-        m_world.events.onInputOut.add(function(){ this.m_info_right.text = "" });
-        // change audio status button
-        m_audio = game.add.sprite(game.world.width - 60, 10, 'audio');
-        audioStatus ? m_audio.frame = 0 : m_audio.frame = 1;
-        m_audio.inputEnabled = true;
-        m_audio.input.useHandCursor = true;
-        m_audio.events.onInputDown.add(function(){ if(audioStatus){ audioStatus=false; m_audio.frame = 1; }else{ audioStatus=true; m_audio.frame = 0; }});
-        m_audio.events.onInputOver.add(function(){ this.m_info_right.text = lang.audio });
-        m_audio.events.onInputOut.add(function(){ this.m_info_right.text = "" });
+        buttonSettings["addButtons"](1,1,
+                                    0,1,0,
+                                    1,0,
+                                    0,0);
         
         // Setting title
         var style = { font: '28px Arial', fill: '#00804d'};
@@ -194,18 +158,10 @@ var menuSquareTwo = {
         } 
 
     },
-    
-    //Navigation functions,
-    
-    loadState: function(){
-        if(audioStatus){
-            this.beep.play();
-        }
-        game.state.start(this.state);
-    },  
         
     //MapLoading function
     loadMap: function(){
+
         if(audioStatus){
             this.beep.play();
         }
@@ -218,6 +174,7 @@ var menuSquareTwo = {
         }else{
             game.state.start('unofinal');
         }
+
     },
     
 };
@@ -235,26 +192,10 @@ var mapSquareTwo={
         game.add.image(0, 40, 'bgmap');
         
         // Menu options
-        //information label
-        m_info_left = game.add.text(14, 53, "", { font: "20px Arial", fill: "#330000", align: "center" });
-
-        if(twoMenu){
-            // Return to menu button
-            m_list = game.add.sprite(10, 10, 'list'); 
-            m_list.inputEnabled = true;
-            m_list.input.useHandCursor = true;
-            m_list.events.onInputDown.add(this.loadState, {state: "menu", beep: beepSound});
-            m_list.events.onInputOver.add(function(){ this.m_info_left.text = lang.menu_list});
-            m_list.events.onInputOut.add(function(){ this.m_info_left.text = ""});
-            // Return to diffculty
-            m_back = game.add.sprite(60, 10, 'back'); 
-            m_back.inputEnabled = true;
-            m_back.input.useHandCursor = true;
-            m_back.events.onInputDown.add(this.loadState, {state: "menuSTwo", beep: beepSound});
-            m_back.events.onInputOver.add(function(){ this.m_info_left.text = lang.menu_back});
-            m_back.events.onInputOut.add(function(){ this.m_info_left.text = ""});
-
-        }
+        buttonSettings["addButtons"](1,0,
+                                    1,1,0,
+                                    0,0,
+                                    "menuSTwo",0);
         
         // Styles for labels
         var stylePlace = { font: '26px Arial', fill: '#ffffff', align: 'center'};
@@ -348,6 +289,7 @@ var mapSquareTwo={
         // Delay to next level
         this.count = 0;
         this.wait = 60;
+
     },
 
     update: function() {
@@ -380,17 +322,12 @@ var mapSquareTwo={
                 twoPosition += 1; //Update position
             }
         }
+
     }, 
-    
-    loadState: function(){
-        if(audioStatus){
-            this.beep.play();
-        }
-        game.state.start(this.state);
-    },
         
     //MapLoading function
     loadGame: function(){
+
         if(audioStatus){
            beepSound.play();
         }
@@ -399,6 +336,7 @@ var mapSquareTwo={
         }else{
             game.state.start('endSTwo');
         }
+
     }
 };
 
@@ -430,6 +368,12 @@ var gameSquareTwo = {
         // Background
         game.add.image(0, 0, 'bgimage');
         
+        // Menu options
+        buttonSettings["addButtons"](1,1,
+                                    1,1,0,
+                                    1,0,
+                                    "menuSOne", 0);
+
         //Clouds
         game.add.image(300, 100, 'cloud');
         game.add.image(660, 80, 'cloud');
@@ -612,46 +556,6 @@ var gameSquareTwo = {
         fractionB.alpha = 0;
         separatorB.alpha = 0;
         
-        // Menu options
-        //information label
-        m_info_left = game.add.text(14, 53, "", { font: "20px Arial", fill: "#330000", align: "center" });
-        
-        m_info_right = game.add.text(game.world.width - 10, 53, "", { font: "20px Arial", fill: "#330000", align: "right" });
-        m_info_right.anchor.setTo(1,0.02);
-
-        if(twoMenu){
-            // Return to menu button
-            m_list = game.add.sprite(10, 10, 'list'); 
-            m_list.inputEnabled = true;
-            m_list.input.useHandCursor = true;
-            m_list.events.onInputDown.add(this.loadState, {state: "menu", beep: beepSound});
-            m_list.events.onInputOver.add(function(){ this.m_info_left.text = lang.menu_list});
-            m_list.events.onInputOut.add(function(){ this.m_info_left.text = ""});
-            // Return to diffculty
-            m_back = game.add.sprite(60, 10, 'back'); 
-            m_back.inputEnabled = true;
-            m_back.input.useHandCursor = true;
-            m_back.events.onInputDown.add(this.loadState, {state: "menuSTwo", beep: beepSound});
-            m_back.events.onInputOver.add(function(){ this.m_info_left.text = lang.menu_back});
-            m_back.events.onInputOut.add(function(){ this.m_info_left.text = ""});
-
-            // Return to language button
-            m_world = game.add.sprite(game.world.width - 120, 10, 'world'); 
-            m_world.inputEnabled = true;
-            m_world.input.useHandCursor = true;
-            m_world.events.onInputDown.add(this.loadState, {state: "language", beep: beepSound});
-            m_world.events.onInputOver.add(function(){ this.m_info_right.text = lang.menu_world });
-            m_world.events.onInputOut.add(function(){ this.m_info_right.text = "" });
-            // change audio status button
-            m_audio = game.add.sprite(game.world.width - 60, 10, 'audio');
-            audioStatus ? m_audio.frame = 0 : m_audio.frame = 1;
-            m_audio.inputEnabled = true;
-            m_audio.input.useHandCursor = true;
-            m_audio.events.onInputDown.add(function(){ if(audioStatus){ audioStatus=false; m_audio.frame = 1; }else{ audioStatus=true; m_audio.frame = 0; }});
-            m_audio.events.onInputOver.add(function(){ this.m_info_right.text = lang.audio });
-            m_audio.events.onInputOut.add(function(){ this.m_info_right.text = "" });
-        }
-        
         //ok and error images
         okImg = game.add.image(game.world.centerX, game.world.centerY, 'h_ok');
         okImg.anchor.setTo(0.5);
@@ -670,6 +574,7 @@ var gameSquareTwo = {
         endCounter = 100;
         cDelay = 0;
         eDelay = 60;
+
     },
     
     update: function() {
@@ -759,6 +664,7 @@ var gameSquareTwo = {
                 game.state.start('mapSTwo');
             }
         }
+
     },
 
     updateCounter: function() {
@@ -766,6 +672,7 @@ var gameSquareTwo = {
     },
     
     overSquare: function(){
+
         if(!clickA && this.who=="A"){
             if(this.indice == sizeA-1){
                 if(yA==90){
@@ -815,9 +722,11 @@ var gameSquareTwo = {
                 fractionB.setText(this.indice +1);
             }
         }
+
     },
 
     outSquare: function(){
+
         if(!clickA && this.who=="A"){
             for(var i=0;i<=this.indice;i++){
                 blocksA.children[i].alpha = 0.5;
@@ -830,9 +739,11 @@ var gameSquareTwo = {
             }
             fractionB.alpha = 0;
         }
+
     },
     
     clickSquare: function(){
+
         if(!clickA && this.who=="A" && this.indice!=sizeA-1){
             for(var i=0;i<sizeA;i++){
                 blocksA.children[i].inputEnabled = false;
@@ -874,6 +785,7 @@ var gameSquareTwo = {
             separatorB.x = fractionB.x
             animateB = true;
         }
+
     },
     
     postScore: function (){
@@ -899,30 +811,12 @@ var gameSquareTwo = {
         // Send the data to PHP now... and wait for response to update the status div
         hr.send(vars); // Actually execute the request
         console.log("processing...");
-    },
 
-    //Navigation functions,
-    
-    loadState: function(){
-        if(audioStatus){
-            this.beep.play();
-        }
-        game.state.start(this.state);
-    },
-    
-    //MapLoading function
-    loadGame: function(){
-        if(audioStatus){
-            beepSound.play();
-        }
-        if(onePosition<5){
-            game.state.start('gameSOne');
-        }else{
-            game.state.start('endSOne');
-        }
     },
+
     //Calculation help functions
     getRndDivisor: function(number){ //Get random divisor for a number
+
         var div = []; //Divisors found
         var p = 0; //current dividor index
         for(var i=2; i<number;i++){
@@ -933,6 +827,7 @@ var gameSquareTwo = {
         }
         var x = game.rnd.integerInRange(0,p-1);
         return div[x];
+
     },
     
 };
@@ -986,9 +881,11 @@ var endSquareTwo = {
         this.kid.scale.setTo(0.7);
         this.kid.animations.add('walk', [0,1,2,3,4,5,6,7,8,9,10,11]);
         this.kid.animations.play('walk', 6, true);
+
     },
 
     update: function() {
+
         if(this.kid.x<=700){
             this.kid.x += 2;
         }else{
@@ -998,6 +895,7 @@ var endSquareTwo = {
                 this.kid.animations.stop();
             }
         }
+
     },
     
     verPrincipal: function(){
@@ -1005,8 +903,10 @@ var endSquareTwo = {
     },
     
     verMenu: function(){
+
         if(twoMenu){
             game.state.start('menu');
         }
+
     }               
 };