Quellcode durchsuchen

modified the way the player progress is displayed in the game to only increse if level was completed | modified variable names from name to func_name if they received a function to facilitate code readability | currently in the proccess of removing duplicated variables and decreasing the use of global variables

lairaalmas vor 5 Jahren
Ursprung
Commit
38fabdb16a
10 geänderte Dateien mit 806 neuen und 974 gelöschten Zeilen
  1. 0 187
      index.php
  2. 128 66
      js/boot.js
  3. 152 174
      js/circleOne.js
  4. 0 0
      js/jquery.min.js
  5. 117 107
      js/menu.js
  6. 0 0
      js/phaser.js
  7. 0 0
      js/phaser.min.js
  8. 69 64
      js/preMenu.js
  9. 190 210
      js/squareOne.js
  10. 150 166
      js/squareTwo.js

+ 0 - 187
index.php

@@ -1,187 +0,0 @@
-<!DOCTYPE html>  
-<html>
-    <head>  
-        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
-        <title> Fractions </title>
-        <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
-        <script type="text/javascript" src="js/phaser.min.js"></script>
-        <script type="text/javascript" src="js/boot.js"></script>
-        <script type="text/javascript" src="js/menu.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>
-    </head>
-
-    <body>
-
-    <div class="container">
-    	<div class="clearfix"></div>
-        <div class="panel panel-primary">
-          <div class="panel-heading">FRACTIONS GAME</div>
-          <div class="panel-body">
-            <center>
-                <div id="fractions-game" style="padding: 0 auto 0 auto;"></div>
-            </center>
-          </div>
-        </div>
-        <div class="panel panel-info">
-          <div class="panel-heading">COOPERATION TEAM</div>
-          <div class="panel-body">
-            <center>
-                <ul>
-                  <li><strong>BRAZIL:</strong> Le&ocirc;nidas de Oliveira Brand&atilde;o (IME-USP)</li>
-                  <li><strong>PERU:</strong> Manuel Ibarra and Cristhian Serrano (EAPIIS-UNAMBA)</li>
-                  <li><strong>FRANCE:</strong> Jean-Marc (MOCAH-UPMC)</li>
-                </ul>
-            </center>
-          </div>
-        </div>
-        <div class="panel panel-default">
-          <div class="panel-heading">BASED ON</div>
-          <div class="panel-body">
-            <center>
-                <ul>
-                  <li><strong>iLM </strong>(interactive Learning Modules) </li>
-                  <li><strong>Six facets of Serious Game Design</strong>:<br>
-Pedagogical Objectives; Domain Simulation; Interactions with the Simulation; Problems and Progression; Decorum and Conditions of Use.
-</li>
-                </ul>
-            </center>
-          </div>
-        </div>
-        <div class="panel panel-danger">
-          <div class="panel-heading">TECHNOLOGY</div>
-          <div class="panel-body">
-            <center>
-                <ul>
-                  <li> We used <strong>HTML5</strong>, <strong>CSS</strong> and the <strong>Javascript</strong> Library <a href="http://phaser.io/" target="_blank"><strong>Phaser.io</strong></a> </li>
-                </ul>
-            </center>
-          </div>
-        </div>
-    </div>
-        
-    </body>
-
-    
-    <?php /* retrieving parameters */ 
-        
-    $do = $_REQUEST['do'];
-    $lang = $_REQUEST['language'];
-    $shape = $_REQUEST['shape'];
-    $type = $_REQUEST['mode'];
-    $posit = 0;
-    $opera = $_REQUEST['operator'];
-    $diffi = $_REQUEST['difficulty'];
-    $label = $_REQUEST['label'];
-
-    //?do=play&language=es_PE&shape=Circle&mode=A&operator=Plus&difficulty=1&label=true
-    
-    if(!isset($do)){
-    ?>
-    
-    <script type="text/javascript">
-        // Initialize the game
-        var game = new Phaser.Game(900, 600, Phaser.CANVAS, 'fractions-game');
-        
-        hip = "<?=$_SERVER['REMOTE_ADDR']?>"; //Host ip
-        name = ""; //player name
-        lang = ""; //language
-        var timer, totalTime;
-            // Game One 
-         onePosition = 0; //Map position
-         oneMove = false; //Move to next position
-         oneDifficulty = 0; //From one to five 
-         oneOperator= ""; //Plus; Minus; Mixed
-         oneLabel= false; //Show block label
-         oneShape = ""; //Circle; square
-         oneType = ""; // A - Place distance; B - Select blocks
-         oneMenu = true;
-            // Game Two
-         twoPosition = 0; //Map position
-         twoMove = false; //Move to next position
-         twoDifficulty = 0; //From one to five 
-         twoOperator= ""; //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('boot', bootState);  
-        game.state.add('load', loadState); 
-        game.state.add('name', nameState);
-        game.state.add('menu', menuState);  
-        
-        game.state.add('menuCOne', menuCircleOne);
-        game.state.add('mapCOne', mapCircleOne);
-        game.state.add('gameCOne', gameCircleOne);
-        game.state.add('endCOne', endCircleOne);
-                
-        game.state.add('menuSOne', menuSquareOne);
-        game.state.add('mapSOne', mapSquareOne);
-        game.state.add('gameSOne', gameSquareOne);
-        game.state.add('endSOne', endSquareOne);
-        
-        game.state.add('menuSTwo', menuSquareTwo);
-        game.state.add('mapSTwo', mapSquareTwo);
-        game.state.add('gameSTwo', gameSquareTwo);
-        game.state.add('endSTwo', endSquareTwo);
-        
-        //starting to boot game
-        game.state.start('boot');
-    </script>
-    <? } else if($do=="play"){ ?>
-    
-    <script type="text/javascript">
-        // Initialize the game
-        var game = new Phaser.Game(900, 600, Phaser.CANVAS, 'fractions-game');
-        
-        var hip = "<?=$_SERVER['REMOTE_ADDR']?>"; //Host ip
-        var name = "";
-        var lang = "<?=$lang?>";
-        var timer, totalTime;
-        
-        var onePosition = <?=$posit?>;
-        var oneMove = true;
-        var oneDifficulty = <?=$diffi?>;
-        var oneOperator = "<?=$opera?>";
-        var oneLabel = <?=$label?>;
-        var oneShape = "<?=$shape?>";
-        var oneType = "<?=$type?>";
-        var oneMenu = false;
-        
-        var twoPosition = 0; //Map position
-        var twoMove = false; //Move to next position
-        var twoDifficulty = 0; //From one to five 
-        var twoOperator= ""; //Plus; Minus; Mixed
-        var twoLabel= false; //Show block label
-        var twoShape = ""; //Circle; square
-        var twoType = ""; // A - Normal position; B - Random position
-        var twoMenu= true;
-        
-        //adding game states (scenes) 
-        game.state.add('boot', bootState); 
-        game.state.add('load', loadState); 
-        game.state.add('name', nameState);
-        
-        game.state.add('menuCOne', menuCircleOne);
-        game.state.add('mapCOne', mapCircleOne);
-        game.state.add('gameCOne', gameCircleOne);
-        game.state.add('endCOne', endCircleOne);
-                
-        game.state.add('menuSOne', menuSquareOne);
-        game.state.add('mapSOne', mapSquareOne);
-        game.state.add('gameSOne', gameSquareOne);
-        game.state.add('endSOne', endSquareOne);
-        
-        game.state.add('menuSTwo', menuSquareTwo);
-        game.state.add('mapSTwo', mapSquareTwo);
-        game.state.add('gameSTwo', gameSquareTwo);
-        game.state.add('endSTwo', endSquareTwo);
-        
-        //starting to load game
-        game.state.start('load');
-    </script>
-    <? } ?>
-</html>

+ 128 - 66
js/boot.js

@@ -1,14 +1,74 @@
-
-	var username; //user info
+// 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;
+
+				//map
+				var kid, tractor;
+
+				//square 1 + circle 1
+				var startX;
+				var clicked, hideLabels, animate, checkCollide, result, hasFigure;
+				var detail;
+				var endPosition;
+				var fractionClicked, fractionIndex;
+				var blocks, maxBlocks, numBlocks, curBlock, blockDirection, blockDistance, blockLabel, blockSeparator; //blocks control
+
+				//square 1
+				var blockWidth, blockIndex;
+				var floorBlocks, floorIndex, floorCount, floorClicked, curFloor;
+				var move, moveCounter, moveEnd;
+				var arrow;
+				var arrowPlace;
+
+				//circle 1
+				var blockSize, blockAngle, blockTraceColor;
+				var fly, flyCounter, flyend; //flyvariables
+				var trace; //circle trace
+				var numPlus, endIndex;
+				var kid_walk, balloon, basket;
+				var balloonPlace;
+
+				//square 2
+				var sizeA, sizeB, valueA, valueB;
+				var clickA, clickB, animateA, animateB, result, animate, cDelay, eDelay;
+				var blocksA, blocksB, auxblqA, auxblqB;
+				var labelA, fractionA, separatorA, labelB, fractionB, separatorB;
+				var kidDirection, equals, counter, endCounter;
+				var xA, yA, xB, yB, blockW, blockH;
+
+
+
+
+	// INFO
+	var username; //player name
 	var lang; //language
 
+	// IMAGES
 	var beepSound, okSound, errorSound; //sounds
 	var okImg, errorImg;
-
     var timer, totalTime;
 
-    var audioStatus = true;
-    var nameStatus = false;
+    // variaveis globais
+    var audioStatus = true; // turns game audio on/off
+    var firstTime = true; //if player has just oppened the game
+    var debugMode = true; //turns console messages for developers on/off (changeable only by code)
+
 
     // Initialize the game
     var game = new Phaser.Game(
@@ -24,27 +84,28 @@
 
     // Game One : kid and truck
 
-    onePosition = 0; //Map position
-    oneMove = false; //Move to next position
-    oneDifficulty = 0; //From one to five 
-    oneOperator= ""; //Plus; Minus; Mixed
-    oneLabel= false; //Show block label
-    oneShape = ""; //Circle; square
-    oneType = ""; // A - Place distance; B - Select blocks
-    oneMenu = true;
+    levelPosition = 0; //Map position
+    levelMove = false; //Move to next position
+    levelDifficulty = 0; //From one to five 
+    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 
-    twoOperator= ""; //Plus; Minus; Mixed
-    twoLabel= false; //Show block label
-    twoShape = ""; //Circle; square
-    twoType = ""; // A - Normal position; B - Random position
-    twoMenu= true;
+    //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
     game.state.add('load', loadState); // boot.js
     game.state.add('name', nameState); // boot.js
@@ -70,72 +131,73 @@
 
     	preload: function(){
     
+    		//directory auxiliar
 	        var imgsrc = 'assets/img/';
 
 	        //Progress bar image
 	        game.load.image('progressBar', imgsrc+'pgbar.png');
 
 	        //flags
-	        game.load.image('flag_BR', imgsrc+'flag/BRAZ.jpg');
-	        game.load.image('flag_PE', imgsrc+'flag/PERU.jpg');
-	        game.load.image('flag_US', imgsrc+'flag/UNST.jpg');
-	        game.load.image('flag_FR', imgsrc+'flag/FRAN.jpg');
+	        game.load.image('flag_BR', 	imgsrc+'flag/BRAZ.jpg');
+	        game.load.image('flag_PE', 	imgsrc+'flag/PERU.jpg');
+	        game.load.image('flag_US', 	imgsrc+'flag/UNST.jpg');
+	        game.load.image('flag_FR', 	imgsrc+'flag/FRAN.jpg');
 
 	        //scenario
-	        game.load.image('bgimage', imgsrc+'bg.jpg');
-	        game.load.image('bgmap', imgsrc+'bg_map.png');
-	        game.load.image('cloud', imgsrc+'cloud.png');
-	        game.load.image('floor', imgsrc+'floor.png');
-	        game.load.image('road', imgsrc+'road.png');
+	        game.load.image('bgimage', 	imgsrc+'bg.jpg');
+	        game.load.image('bgmap', 	imgsrc+'bg_map.png');
+	        game.load.image('cloud', 	imgsrc+'cloud.png');
+	        game.load.image('floor',	imgsrc+'floor.png');
+	        game.load.image('road', 	imgsrc+'road.png');
 	        
 	        //game phases buttons list
-	        game.load.image('game1s', imgsrc+'game/1-left-subs.png');
-	        game.load.image('game2s', imgsrc+'game/1-right-nosubs.png');
-	        game.load.image('game3s', imgsrc+'game/2-left-subs.png');
-	        game.load.image('game4s', imgsrc+'game/2-right-nosubs.png');
-	        game.load.image('game1c', imgsrc+'game/3-left-subs.png');
-	        game.load.image('game2c', imgsrc+'game/3-right-nosubs.png');
-	        game.load.image('game3c', imgsrc+'game/4-left-subs.png');
-	        game.load.image('game4c', imgsrc+'game/4-right-nosubs.png');
-	        game.load.image('game5s', imgsrc+'game/5.png');
+	        game.load.image('game1s', 	imgsrc+'game/1-left-subs.png');
+	        game.load.image('game2s', 	imgsrc+'game/1-right-nosubs.png');
+	        game.load.image('game3s', 	imgsrc+'game/2-left-subs.png');
+	        game.load.image('game4s', 	imgsrc+'game/2-right-nosubs.png');
+	        game.load.image('game1c', 	imgsrc+'game/3-left-subs.png');
+	        game.load.image('game2c', 	imgsrc+'game/3-right-nosubs.png');
+	        game.load.image('game3c', 	imgsrc+'game/4-left-subs.png');
+	        game.load.image('game4c', 	imgsrc+'game/4-right-nosubs.png');
+	        game.load.image('game5s', 	imgsrc+'game/5.png');
 	        
 	        //header menu buttons
-	        game.load.image('back', imgsrc+'menu/back.png');
-	        game.load.image('home', imgsrc+'menu/home.png');
-	        game.load.image('info', imgsrc+'menu/info.png');
-	        game.load.image('world', imgsrc+'menu/language.png');
-	        game.load.image('list', imgsrc+'menu/menu.png');
-	        game.load.image('help', imgsrc+'menu/help.png');
-	        game.load.image('pgbar', imgsrc+'menu/progressBar.png');
-	        game.load.image('block', imgsrc+'menu/block.png');
-			game.load.spritesheet('audio', imgsrc+'menu/audio_48x48.png',48,48,2);
+	        game.load.image('back', 	imgsrc+'menu/back.png');
+	        game.load.image('home', 	imgsrc+'menu/home.png');
+	        game.load.image('info', 	imgsrc+'menu/info.png');
+	        game.load.image('world', 	imgsrc+'menu/language.png');
+	        game.load.image('list', 	imgsrc+'menu/menu.png');
+	        game.load.image('help', 	imgsrc+'menu/help.png');
+	        game.load.image('pgbar', 	imgsrc+'menu/progressBar.png');
+	        game.load.image('block', 	imgsrc+'menu/block.png');
+			game.load.spritesheet('audio',	imgsrc+'menu/audio_48x48.png',48,48,2);
 
 	        //operators
-	        game.load.image('add', imgsrc+'operator/add.png');
+	        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('equal', imgsrc+'operator/equal.png');
+	        game.load.image('separator',	imgsrc+'operator/separator.png');
+	        game.load.image('equal', 	imgsrc+'operator/equal.png');
 	        
 	        //feedback
-	        game.load.image('h_arrow', imgsrc+'help/arrow.png');
+	        game.load.image('h_arrow', 	imgsrc+'help/arrow.png');
 	        game.load.image('h_double', imgsrc+'help/double.png');
-	        game.load.image('h_error', imgsrc+'help/error.png');
-	        game.load.image('h_ok', imgsrc+'help/ok.png');
-	        game.load.image('down', imgsrc+'help/down.png');        
-	        game.load.image('pointer', imgsrc+'help/pointer.png');
+	        game.load.image('h_error', 	imgsrc+'help/error.png');
+	        game.load.image('h_ok', 	imgsrc+'help/ok.png');
+	        game.load.image('down', 	imgsrc+'help/down.png');        
+	        game.load.image('pointer', 	imgsrc+'help/pointer.png');
 	        
 	        // 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, 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.spritesheet('kid_run',	imgsrc+'kid/run.png', 82, 178, 12);
+	        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('tractor_green', imgsrc+'tractor/frame-0.png');
-	        game.load.image('tractor_red', imgsrc+'tractor/frame-5.png');
+	        game.load.image('tractor_green',	imgsrc+'tractor/frame-0.png');
+	        game.load.image('tractor_red', 		imgsrc+'tractor/frame-5.png');
 	        
-	        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('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');
@@ -168,4 +230,4 @@
 
     //starting to boot game
     game.state.add('loadAssets', loadAssets); // squareTwo.js
-   	game.state.start('loadAssets');
+   	game.state.start('loadAssets');

+ 152 - 174
js/circleOne.js

@@ -3,7 +3,7 @@
     var menuCircleOne = {
         create: function(){},
         ---------------------------- end of phaser functions
-        loadMap: function(){}
+        func_loadMap: function(){}
     };
 
     var mapCircleOne = {
@@ -17,50 +17,46 @@
         create: function(){},
         update: function(){},
         ---------------------------- end of phaser functions
-        updateCounter: function(){},
-        overCircle: function(){},
-        outCircle: function(){},
-        clickCircle: function(){},
-        setPlace: function(){},
-        postScore: function(){},
-        viewHelp: function(){},
-        checkOverlap: function(_,_){}
-            //getRndDivisor: function(){}
+        func_updateCounter: function(){},
+        func_overCircle: function(){},
+        func_outCircle: function(){},
+        func_clickCircle: function(){},
+        func_setPlace: function(){},
+        func_postScore: function(){},
+        func_viewHelp: function(){},
+        func_checkOverlap: function(_,_){}
+            //func_getRndDivisor: function(){}
     };
 
     var endCircleOne = {
         create: function(){},
         update: function(){},
         ---------------------------- end of phaser functions
-        verPrincipal: function(){},
-        verMenu: function(){}
+        func_verPrincipal: function(){},
     };
 */
 
 // Kid and Circle states, games 1 and 2
 
 /****************************** MENU ****************************/
-var stairsPlus, stairsMinus, stairsMixed;
 
 var menuCircleOne = {
     
     create: function() {
-        
-        // Creating sound variable
-        var beepSound = game.add.audio('sound_beep');
                 
-        // Menu options
-        buttonSettings["addButtons"](1,1,
+        // Navigation buttons
+        buttonSettings["func_addButtons"](1,1,
                                     0,1,0,
                                     1,0,
                                     0,0);        
         
-        // Setting title
+        // Title
         var style = { font: '28px Arial', fill: '#00804d'};
         var title = game.add.text(game.world.centerX, 40, lang.game_menu_title, style);
         title.anchor.setTo(0.5, 0.5);
                 
-        //Showing Games and Levels
+        //SETTING DIFFICULTY LEVELS
+
         var maxHeight = 120; //Max height of a stair
         var stairHeight = 29; //height growth of a stair
         var stairWidth = 85; //Width of a stair
@@ -69,22 +65,26 @@ var menuCircleOne = {
         var startCircle = (startSymbol/2)+startStair+stairWidth*5;
         
          //First stairs, plus, 5 levels, blue circle
+
         var blueCircle = game.add.graphics(startCircle, 195);
             blueCircle.anchor.setTo(0.5,0.5);
             blueCircle.lineStyle(2, 0x31314e);
             blueCircle.beginFill(0xefeff5);
             blueCircle.drawCircle(0, 0, 60);
             blueCircle.endFill();
-        var r_arrow = game.add.sprite(startSymbol+40, 195, 'h_arrow'); 
-            r_arrow.scale.setTo(0.35);
-            r_arrow.anchor.setTo(0.5,0.5);
-            r_arrow.alpha = 0.8;
-        var r_arrow2 = game.add.sprite(startSymbol, 195, 'kid_walk'); 
-            r_arrow2.scale.setTo(0.6);
-            r_arrow2.anchor.setTo(0.5,0.5);
-            r_arrow2.alpha = 0.8;
+
+        var plusArrowIcon = game.add.sprite(startSymbol+40, 195, 'h_arrow'); 
+            plusArrowIcon.scale.setTo(0.35);
+            plusArrowIcon.alpha = 0.8;
+            plusArrowIcon.anchor.setTo(0.5,0.5);
+
+        var plusKidIcon = game.add.sprite(startSymbol, 195, 'kid_walk'); 
+            plusKidIcon.scale.setTo(0.6);
+            plusKidIcon.alpha = 0.8;
+            plusKidIcon.anchor.setTo(0.5,0.5);
         
-        stairsPlus = [];
+        var stairsPlus = [];
+
         for(var i=1;i<=5;i++){
             //stair
             var x1 = startStair+(stairWidth*(i-1));
@@ -101,9 +101,10 @@ var menuCircleOne = {
             //event
             stairsPlus[i].inputEnabled = true;
             stairsPlus[i].input.useHandCursor = true;
-            stairsPlus[i].events.onInputDown.add(this.loadMap, {beep: beepSound, difficulty: i, operator: 'Plus' });
+            stairsPlus[i].events.onInputDown.add(this.func_loadMap, {beep: beepSound, difficulty: i, operator: 'Plus' });
             stairsPlus[i].events.onInputOver.add(function (item) { item.alpha=0.5; }, this);
             stairsPlus[i].events.onInputOut.add(function (item) { item.alpha=1; }, this);
+            
             //label
             var xl = x1+stairWidth/2; //x label
             var yl = y1+(stairHeight*i)/2; //y label
@@ -112,6 +113,7 @@ var menuCircleOne = {
         }
         
         //Second stairs, minus, 5 levels, red circle
+
         var redCircle = game.add.graphics(startCircle, 350);
             redCircle.anchor.setTo(0.5,0.5);
             redCircle.lineStyle(2, 0xb30000);
@@ -119,17 +121,18 @@ var menuCircleOne = {
             redCircle.drawCircle(0, 0, 60);
             redCircle.endFill();
 
-        var l_arrow2 = game.add.sprite(startSymbol, 350, 'h_arrow');
-            l_arrow2.scale.setTo(-0.35, 0.35);
-            l_arrow2.anchor.setTo(0.5,0.5);
-            l_arrow2.alpha = 0.8;
-        var l_arrow = game.add.sprite(startSymbol+40, 350, 'kid_walk');
-            l_arrow.scale.setTo(-0.6, 0.6);
-            l_arrow.anchor.setTo(0.5,0.5);
-            l_arrow.alpha = 0.8;
+        var minusArrowIcon = game.add.sprite(startSymbol, 350, 'h_arrow');
+            minusArrowIcon.scale.setTo(-0.35, 0.35);
+            minusArrowIcon.alpha = 0.8;
+            minusArrowIcon.anchor.setTo(0.5,0.5);
 
+        var minusKidIcon = game.add.sprite(startSymbol+40, 350, 'kid_walk');
+            minusKidIcon.scale.setTo(-0.6, 0.6);
+            minusKidIcon.alpha = 0.8;
+            minusKidIcon.anchor.setTo(0.5,0.5);
 
         var stairsMinus = [];
+
         for(var i=1;i<=5;i++){
             //stair
             var x1 = startStair+(stairWidth*(i-1));
@@ -146,7 +149,7 @@ var menuCircleOne = {
             //event
             stairsMinus[i].inputEnabled = true;
             stairsMinus[i].input.useHandCursor = true;
-            stairsMinus[i].events.onInputDown.add(this.loadMap, {beep: beepSound, difficulty: i, operator: 'Minus' });
+            stairsMinus[i].events.onInputDown.add(this.func_loadMap, {beep: beepSound, difficulty: i, operator: 'Minus' });
             stairsMinus[i].events.onInputOver.add(function (item) { item.alpha=0.5; }, this);
             stairsMinus[i].events.onInputOut.add(function (item) { item.alpha=1; }, this);
             //label
@@ -157,26 +160,28 @@ var menuCircleOne = {
         } 
         
         //Thrid stairs, mixed, 5 levels, two circles
-        var bCircle = game.add.graphics(startCircle-30, 500);
-            bCircle.anchor.setTo(0.5,0.5);
-            bCircle.lineStyle(2, 0x31314e);
-            bCircle.beginFill(0xefeff5);
-            bCircle.drawCircle(0, 0, 60);
-            bCircle.endFill();
+
+        var blueCircle2 = game.add.graphics(startCircle-30, 500);
+            blueCircle2.anchor.setTo(0.5,0.5);
+            blueCircle2.lineStyle(2, 0x31314e);
+            blueCircle2.beginFill(0xefeff5);
+            blueCircle2.drawCircle(0, 0, 60);
+            blueCircle2.endFill();
         
-        var rCircle = game.add.graphics(startCircle+40, 500);
-            rCircle.anchor.setTo(0.5,0.5);
-            rCircle.lineStyle(2, 0xb30000);
-            rCircle.beginFill(0xefeff5);
-            rCircle.drawCircle(0, 0, 60);
-            rCircle.endFill();
+        var redCircle2 = game.add.graphics(startCircle+40, 500);
+            redCircle2.anchor.setTo(0.5,0.5);
+            redCircle2.lineStyle(2, 0xb30000);
+            redCircle2.beginFill(0xefeff5);
+            redCircle2.drawCircle(0, 0, 60);
+            redCircle2.endFill();
         
-        var d_arrow = game.add.sprite(startSymbol, 500, 'h_double'); 
-            d_arrow.scale.setTo(0.5);
-            d_arrow.anchor.setTo(0.5,0.5);
-            d_arrow.alpha = 0.8;
+        var doubleArrowIcon = game.add.sprite(startSymbol, 500, 'h_double'); 
+            doubleArrowIcon.scale.setTo(0.5);
+            doubleArrowIcon.anchor.setTo(0.5,0.5);
+            doubleArrowIcon.alpha = 0.8;
         
         var stairsMixed = [];
+
         for(var i=1;i<=5;i++){
             //stair
             var x1 = startStair+(stairWidth*(i-1));
@@ -193,9 +198,10 @@ var menuCircleOne = {
             //event
             stairsMixed[i].inputEnabled = true;
             stairsMixed[i].input.useHandCursor = true;
-            stairsMixed[i].events.onInputDown.add(this.loadMap, {beep: beepSound, difficulty: i, operator: 'Mixed' });
+            stairsMixed[i].events.onInputDown.add(this.func_loadMap, {beep: beepSound, difficulty: i, operator: 'Mixed' });
             stairsMixed[i].events.onInputOver.add(function (item) { item.alpha=0.5; }, this);
             stairsMixed[i].events.onInputOut.add(function (item) { item.alpha=1; }, this);
+            
             //label
             var xl = x1+stairWidth/2; //x label
             var yl = y1+(stairHeight*i)/2; //y label
@@ -206,20 +212,19 @@ var menuCircleOne = {
     },
         
     //MapLoading function
-    loadMap: function(){
+    func_loadMap: function(){
 
         if(audioStatus){
             this.beep.play();
         }
-        onePosition = 0; //Map position
-        oneMove = true; //Move no next point
-        oneDifficulty  = this.difficulty; //Number of difficulty (1 to 5)
-        oneOperator = this.operator; //Operator of game
-        if(onePosition<5){
-            game.state.start('mapCOne');
-        }else{
-            game.state.start('unofinal');
-        }
+
+        levelPosition = 0; //Map position
+        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');
 
     }
     
@@ -230,15 +235,12 @@ var menuCircleOne = {
 var mapCircleOne = {
 
     create: function() {
-        
-        // Creating sound variable
-        beepSound = game.add.audio('sound_beep');
 
         // Background
         game.add.image(0, 40, 'bgmap');
         
-        // Menu options
-        buttonSettings["addButtons"](1,0,
+        // Navigation buttons
+        buttonSettings["func_addButtons"](1,0,
                                     1,1,0,
                                     0,0,
                                     "menuCOne",0);
@@ -248,14 +250,15 @@ var mapCircleOne = {
         var styleMenu = { font: '30px Arial', fill: '#000000', align: 'center'};
         
         // Progress bar
-        var percentText = onePosition*25;
-        var percentBlocks = onePosition;
+        var percentText = passedLevels*25;
+        var percentBlocks = passedLevels;
+
         for(var p=0;p<percentBlocks;p++){
-            var block = game.add.image(660+p*37, 10, 'block');
-            block.scale.setTo(2.5, 1); //Scaling to double width
+            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 + ' ' + oneDifficulty, styleMenu).anchor.setTo(1,0);
+        game.add.text(650, 10, lang.difficulty + ' ' + levelDifficulty, styleMenu).anchor.setTo(1,0);
         game.add.image(660, 10, 'pgbar');
         
          //Road
@@ -308,9 +311,9 @@ var mapCircleOne = {
         // places
         for (var p = 1; p < this.points.x.length -1; p++){
             var place;
-            if(p<onePosition)
+            if(p<levelPosition)
                 	place = game.add.image(this.points.x[p], this.points.y[p], 'place_b');
-            else if (oneMove && p==onePosition)
+            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');
@@ -326,7 +329,7 @@ var mapCircleOne = {
         }
 
         // Kid start position
-        this.kid = game.add.sprite(this.points.x[onePosition], this.points.y[onePosition], 'kid_run');
+        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);
@@ -346,26 +349,27 @@ var mapCircleOne = {
         if(this.count<=this.wait) return;
         
         // If movement is stopped or position is 6 (final), load game
-        if(onePosition==6){
-            oneMove = false;
+        if(levelPosition==6){
+            levelMove = false;
         }
-        if(!oneMove){
+
+        if(!levelMove){
             this.loadGame();
         }
         
         // If momevent is enabled, move to next point from actual
-        if(oneMove){
+        if(levelMove){
             game.physics.arcade.moveToXY(
                 this.kid, 
-                this.points.x[onePosition+1],
-                this.points.y[onePosition+1],
+                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[onePosition+1] || Math.ceil(this.kid.y)==this.points.y[onePosition+1]){
-                oneMove=false;
-                onePosition += 1; //Update position
+            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
             }
         }
     },
@@ -375,29 +379,16 @@ var mapCircleOne = {
         if(audioStatus){
             beepSound.play();
         }
-        if(onePosition<5){
+        if(levelPosition<5){
             game.state.start('gameCOne');
         }else{
             game.state.start('endCOne');
         }
     }
+    
 };
 
 /****************************** GAME ****************************/
-var startX; //start position
-var clicked, hideLabels, animate, checkCollide, result, hasFigure; //control variables
-var detail;
-var endPosition;
-var fractionClicked, fractionIndex;
-//Balloon and blocks control
-var blocks, maxBlocks, numBlocks, curBlock, blockDirection, blockDistance, blockLabel, blockSeparator;
-
-var blockSize, blockAngle, blockTraceColor;
-var fly, flyCounter, flyend; //flyvariables
-var trace; //circle trace
-var numPlus, endIndex;
-var kid_walk, balloon, basket;
-var balloonPlace;
 
 var gameCircleOne = {
 
@@ -406,23 +397,18 @@ var gameCircleOne = {
         //timer
         totalTime = 0;
         timer = game.time.create(false);
-        timer.loop(1000, this.updateCounter, this);
+        timer.loop(1000, this.func_updateCounter, this);
         timer.start();
         detail="";
-        
-        // Creating sound variable
-        beepSound = game.add.audio('sound_beep');
-        okSound = game.add.audio('sound_ok');
-        errorSound = game.add.audio('sound_error');
 
         // Background
         game.add.image(0, 0, 'bgimage');
 
-        // Menu options
-        buttonSettings["addButtons"](1,1,
+        // Navigation buttons
+        buttonSettings["func_addButtons"](1,1,
                                     1,1,1,
                                     1,0,
-                                    "menuCOne", this.viewHelp);
+                                    "menuCOne", this.func_viewHelp);
         
         //Clouds
         game.add.image(300, 100, 'cloud');
@@ -436,7 +422,7 @@ var gameCircleOne = {
         
         //Floor and road
         startX = 66; //Initial kid and place position
-        if(oneOperator=='Minus') startX = 66+5*156;
+        if(levelOperator=='Minus') startX = 66+5*156;
         
         placeDistance = 156; //Distance between places
         blockSize = 60;
@@ -445,9 +431,9 @@ var gameCircleOne = {
         }
         var road = game.add.image(47, 515, 'road');
         road.scale.setTo(1.01,0.94);
-        if(oneType=='A'){
+        if(levelType=='A'){
             road.inputEnabled = true;
-            road.events.onInputDown.add(this.setPlace, {beep: beepSound}); //enabling input for tablets
+            road.events.onInputDown.add(this.func_setPlace, {beep: beepSound}); //enabling input for tablets
         }
         
         for(var p=0;p<=5;p++){// Places
@@ -474,10 +460,10 @@ var gameCircleOne = {
                 
         //generator
         //Circles and fractions
-        var maxBlocks = onePosition+1; //Maximum blocks according to difficulty
-        if(oneType=='B' || oneOperator=='Mixed') maxBlocks = 6;
+        var maxBlocks = levelPosition+1; //Maximum blocks according to difficulty
+        if(levelType=='B' || levelOperator=='Mixed') maxBlocks = 6;
         blocks = game.add.group(); //Fraction arrays
-        numBlocks = game.rnd.integerInRange(onePosition, maxBlocks); //Number of blocks
+        numBlocks = game.rnd.integerInRange(levelPosition, maxBlocks); //Number of blocks
         curBlock = 0; //Actual index block
         blockDirection = []; //Directions right(plus), left (minus)
         blockDistance = []; //Displacement distance of the blocks
@@ -495,16 +481,16 @@ var gameCircleOne = {
         
         for(var p=0;p<numBlocks;p++){
 
-            var portion = game.rnd.integerInRange(1, oneDifficulty); //Portion of the circle, according to difficulty
+            var portion = game.rnd.integerInRange(1, levelDifficulty); //Portion of the circle, according to difficulty
             detail += portion+",";
             
-            if(portion==oneDifficulty){
+            if(portion==levelDifficulty){
                 hasFigure = true;
             }
             
             var direction = '';
             var lineColor = '';
-            if(oneOperator=='Mixed'){
+            if(levelOperator=='Mixed'){
                 if(p<=numPlus){
                     direction = 'Right';
                     lineColor = 0x31314e;
@@ -517,10 +503,10 @@ var gameCircleOne = {
                 direction = directions[rndIndex];
                 if(rndIndex==0) lineColor = 0x31314e;
                 else lineColor = 0xb30000;*/
-            }else if(oneOperator=='Plus'){
+            }else if(levelOperator=='Plus'){
                 direction = 'Right';    
                 lineColor = 0x31314e;
-            }else if(oneOperator=='Minus'){
+            }else if(levelOperator=='Minus'){
                 direction = 'Left';
                 lineColor = 0xb30000;
             }
@@ -542,9 +528,9 @@ var gameCircleOne = {
                 blockDistance.push(placeDistance);
                 blockAngle.push(360);
 
-                if(oneLabel){
+                if(levelLabel){
                     var labelX = startX;
-                    if(oneOperator=='Minus') labelX -= 65;
+                    if(levelOperator=='Minus') labelX -= 65;
                     else labelX += 65;
                     var label = game.add.text(labelX, 490-p*blockSize, portion , styleLabel);
                     label.anchor.setTo(0.5, 0.5);
@@ -557,9 +543,9 @@ var gameCircleOne = {
                 blockDistance.push(Math.floor(placeDistance/portion));
                 blockAngle.push(distance);
 
-                if(oneLabel){
+                if(levelLabel){
                     var labelX = startX;
-                    if(oneOperator=='Minus') labelX -= 65;
+                    if(levelOperator=='Minus') labelX -= 65;
                     else labelX += 65;
                     var separator = game.add.sprite(labelX, 485-p*blockSize, 'separator');
                     separator.anchor.setTo(0.5, 0.5);
@@ -580,13 +566,13 @@ var gameCircleOne = {
             block.angle +=90;
             
             //If game is type B, (select fractions, adding event)
-            if(oneType=='B'){
+            if(levelType=='B'){
                 block.alpha = 0.5;
                 block.inputEnabled = true;
                 block.input.useHandCursor = true;
-                block.events.onInputDown.add(this.clickCircle, {indice: p});
-                block.events.onInputOver.add(this.overCircle, {indice: p});
-                block.events.onInputOut.add(this.outCircle, {indice: p});
+                block.events.onInputDown.add(this.func_clickCircle, {indice: p});
+                block.events.onInputOver.add(this.func_overCircle, {indice: p});
+                block.events.onInputOut.add(this.func_outCircle, {indice: p});
             }
             
             blocks.add(block);
@@ -601,7 +587,7 @@ var gameCircleOne = {
         
         //If game is type B, selectiong a random balloon place
         
-        if(oneType=='B'){
+        if(levelType=='B'){
             balloonPlace = startX;
             endIndex = game.rnd.integerInRange(numPlus, numBlocks);
             for(var i=0;i<endIndex;i++){
@@ -625,7 +611,7 @@ var gameCircleOne = {
         kid_walk.scale.setTo(0.8);
         kid_walk.animations.add('right',[0,1,2,3,4,5,6,7,8,9,10,11]);
         kid_walk.animations.add('left',[23,22,21,20,19,18,17,16,15,14,13,12]);
-        if(oneOperator=='Minus'){
+        if(levelOperator=='Minus'){
             kid_walk.animations.play('left', 6, true);
             kid_walk.animations.stop();
         }
@@ -650,7 +636,7 @@ var gameCircleOne = {
        
         if (game.input.activePointer.isDown && !fly && !clicked){
             //Positionate balloon - Game A
-            if(oneType=='A'){
+            if(levelType=='A'){
                 if(game.input.mousePointer.y>60){ //Dead zone for click
                     balloon.x = game.input.mousePointer.x;
                     balloon.alpha = 1;
@@ -665,7 +651,7 @@ var gameCircleOne = {
                         kid_walk.animations.play('left', 6, true);
                     }
 
-                    if(oneLabel){ //Hiding labels
+                    if(levelLabel){ //Hiding labels
                         blockLabel.visible = false;
                         blockSeparator.visible = false;
                     }
@@ -675,7 +661,7 @@ var gameCircleOne = {
         
         if(!clicked){
             if(!fly){
-                if(oneType=="A"){
+                if(levelType=="A"){
                     //Follow mouse
                     if (game.physics.arcade.distanceToPointer(balloon, game.input.activePointer) > 8){
                         balloon.x = game.input.mousePointer.x;
@@ -755,7 +741,7 @@ var gameCircleOne = {
         if(checkCollide){
             kid_walk.animations.stop();            
             timer.stop();
-            if(this.checkOverlap(basket,kid_walk)){
+            if(this.func_checkOverlap(basket,kid_walk)){
             	if(kid_walk.frame < 12)
             		kid_walk.frame = 24;	            
             	else
@@ -764,7 +750,7 @@ var gameCircleOne = {
             }else{
                 result = false;
             }
-            this.postScore();
+            this.func_postScore();
             fly = true;
             checkCollide = false;
         }
@@ -777,6 +763,8 @@ var gameCircleOne = {
                     if(audioStatus){
                         okSound.play();
                     }
+                    passedLevels++;        
+                    if(debugMode) console.log("passedLevels = "+passedLevels);
                     okImg.alpha = 1;
                 }else{
                     if(audioStatus){
@@ -796,9 +784,9 @@ var gameCircleOne = {
             
             if(flyCounter>=flyEnd){
                 if(result){
-                    oneMove = true;
+                    levelMove = true;
                 }else{
-                    oneMove = false;
+                    levelMove = false;
                 }
                 game.state.start('mapCOne');
             }
@@ -806,11 +794,11 @@ var gameCircleOne = {
 
     },
 
-    updateCounter: function() {
+    func_updateCounter: function() {
         totalTime++;
     },
         
-    overCircle: function(){
+    func_overCircle: function(){
         
         if(!clicked){
             for(var i=0;i<numBlocks;i++){
@@ -824,7 +812,7 @@ var gameCircleOne = {
 
     },
 
-    outCircle: function(){
+    func_outCircle: function(){
         if(!clicked){
             for(var i=0;i<=this.indice;i++){
                 blocks.children[i].alpha = 0.5;
@@ -833,7 +821,7 @@ var gameCircleOne = {
 
     },
     
-    clickCircle: function(){
+    func_clickCircle: function(){
 
         if(!clicked){
             var minusBlocks = 0;
@@ -863,7 +851,7 @@ var gameCircleOne = {
                 kid_walk.animations.play('left', 6, true);
             }
 
-            if(oneLabel){ //Hiding labels
+            if(levelLabel){ //Hiding labels
                 blockLabel.visible = false;
                 blockSeparator.visible = false;
             }
@@ -871,7 +859,7 @@ var gameCircleOne = {
 
     },
 
-    setPlace: function(){
+    func_setPlace: function(){
 
         if(!clicked){
             
@@ -890,7 +878,7 @@ var gameCircleOne = {
                 kid_walk.animations.play('left', 6, true);
             }
 
-            if(oneLabel){ //Hiding labels
+            if(levelLabel){ //Hiding labels
                 blockLabel.visible = false;
                 blockSeparator.visible = false;
             }
@@ -898,39 +886,40 @@ var gameCircleOne = {
 
     },
 
-    postScore: function (){
-        
-        var abst = "numCircles:"+numBlocks+", valCircles: " + detail+" balloonX: " + basket.x + ", selIndex: " + fractionIndex;
+    func_postScore: function (){
+    
+        var abst = "numCircles:" + numBlocks + ", valCircles: " + detail + " balloonX: " + basket.x + ", selIndex: " + fractionIndex;
 
         var lang_str = "pt_BR"; //TODO NAO esta pegando a lingua definida pelo usuario!
 
         var hr = new XMLHttpRequest();
         // Create some variables we need to send to our PHP file
         var url = "assets/cn/save.php";
-        var vars = "s_ip=" + hip + "&s_name=" + username + "&s_lang=" + lang + "&s_game=" + oneShape + "&s_mode=" + oneType;
-        vars += "&s_oper=" + oneOperator + "&s_leve=" + oneDifficulty + "&s_posi=" + onePosition + "&s_resu=" + result + "&s_time=" + totalTime + "&s_deta=" + abst;
+        var vars = "s_ip=" + hip + "&s_name=" + username + "&s_lang=" + lang + "&s_game=" + levelShape + "&s_mode=" + levelType;
+
+        vars += "&s_oper=" + levelOperator + "&s_leve=" + levelDifficulty + "&s_posi=" + levelPosition + "&s_resu=" + result + "&s_time=" + totalTime + "&s_deta=" + abst;
         
         hr.open("POST", url, true);
         hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
         hr.onreadystatechange = function() {
-            if(debugmode) console.log(hr);
+            if(debugMode) console.log(hr);
 
             if(hr.readyState == 4 && hr.status == 200) {
                 var return_data = hr.responseText;
-                if(debugmode) console.log(return_data);
+                if(debugMode) console.log(return_data);
             }
         }
         // Send the data to PHP now... and wait for response to update the status div
         hr.send(vars); // Actually execute the request
-        if(debugmode) console.log("processing...");
+        if(debugMode) console.log("processing...");
 
     },
             
-    viewHelp: function(){
+    func_viewHelp: function(){
 
         if(!clicked){
             var pointer;
-            if(oneType=='A'){
+            if(levelType=='A'){
                 var pointer = game.add.image(endPosition, 490, 'pointer');
             }else{
                 var pointer = game.add.image(blocks.children[endIndex-1].x, blocks.children[endIndex-1].y-blockSize/2, 'pointer');
@@ -941,7 +930,7 @@ var gameCircleOne = {
 
     },
     
-    checkOverlap: function (spriteA, spriteB) {
+    func_checkOverlap: function (spriteA, spriteB) {
 
         var xA = spriteA.x;
         var xB = spriteB.x;
@@ -962,11 +951,6 @@ var endCircleOne = {
     
     create: function() {  
         
-        // Creating sound variable
-        beepSound = game.add.audio('sound_beep');
-        okSound = game.add.audio('sound_ok');
-        errorSound = game.add.audio('sound_error');
-
         // Background
         game.add.image(0, 0, 'bgimage');
                 
@@ -991,7 +975,7 @@ var endCircleOne = {
             block.scale.setTo(2, 1); //Scaling to double width
         }
         game.add.text(820, 10, '100%', styleMenu);
-        game.add.text(650, 10, lang.difficulty + ' ' + oneDifficulty, styleMenu).anchor.setTo(1,0);
+        game.add.text(650, 10, lang.difficulty + ' ' + levelDifficulty, styleMenu).anchor.setTo(1,0);
         game.add.image(660, 10, 'pgbar');
         
         //School and trees
@@ -1020,7 +1004,8 @@ var endCircleOne = {
             if(this.kid.x<=700){
                 this.kid.x += 2;
             }else{
-                if(oneMenu){
+                if(levelMenu){
+	            	passedLevels = 0;
                     game.state.start('menu');
                 }else{
                     this.kid.animations.stop();
@@ -1037,15 +1022,8 @@ var endCircleOne = {
 
     },
     
-    verPrincipal: function(){
+    func_verPrincipal: function(){
         game.state.start('welcome');
     },
-    
-    verMenu: function(){
-
-        if(oneMenu){
-            game.state.start('menu');
-        }
-        
-    }        
+   
 };

+ 0 - 0
js/jquery.min.js


+ 117 - 107
js/menu.js

@@ -1,129 +1,132 @@
-
-var menu1, menu2, menu3, menu4;
-var lbl_game;
-
 /*
+
     var menuState = {
         create: function(){},
         loadGame: function(){},
         ---------------------------- end of phaser functions
-        showTitle: function(){},
-        clearTitle: function(){},
+        func_showTitle: function(){},
+        func_clearTitle: function(){},
     }
+
 */
 
 var menuState = {
 
-    // game menu screen
+    // creating game menu screen assets
     create: function() {
         
-        // Creating sound variable
-        beepSound = game.add.audio('sound_beep');
-        
-        // Reading dictionary
-        lang = game.cache.getJSON('dictionary');
-        
-        // Title
+     	// BACKGROUND
+     	  
+        // Floor
+        for(var i=0;i<9;i++){
+            game.add.image(i*100, 501, 'floor');
+        }
+
+        // LABELS
+
+        // Player name
+        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);
+
+        // Title : Select a game
         var style = { font: "32px Arial", fill: "#00804d", align: "center" };
         var title = game.add.text(this.game.world.centerX, 80, lang.menu_title, style);
         title.anchor.setTo(0.5,0.5);
-        
-        // Subtitle : game mode 
+
+        // Subtitle : Game mode 
         var style_game = { font: "27px Arial", fill: "#003cb3", align: "center" };
-        lbl_game = game.add.text(this.game.world.centerX, 110, "", style_game);
+        var lbl_game = game.add.text(this.game.world.centerX, 110, "BOBHAOSHSOHAIOSH", style_game);
         lbl_game.anchor.setTo(0.5,0.5);
-        
-        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);
 
-        buttonSettings["addButtons"](0,1,
-                                    0,0,0,
-                                    1,1,
-                                    0,0);
-        //game buttons 
+        // BUTTONS
 
-        // loading button sprites
-        menu1 = game.add.sprite(this.game.world.centerX + 10, this.game.world.centerY - 70, 'game1c');
-        menu2 = game.add.sprite(this.game.world.centerX + 160, this.game.world.centerY - 70, 'game2c');
-        menu3 = game.add.sprite(this.game.world.centerX + 10, this.game.world.centerY + 90, 'game3c');
-        menu4 = game.add.sprite(this.game.world.centerX + 160, this.game.world.centerY + 90, 'game4c');
-        
-        menu5 = game.add.sprite(this.game.world.centerX - 350, this.game.world.centerY - 70, 'game1s');
-        menu6 = game.add.sprite(this.game.world.centerX - 200, this.game.world.centerY - 70, 'game2s');
-        menu7 = game.add.sprite(this.game.world.centerX - 350, this.game.world.centerY + 90, 'game3s');
-        menu8 = game.add.sprite(this.game.world.centerX - 200, this.game.world.centerY + 90, 'game4s');
-        
-        menu9 = game.add.sprite(this.game.world.centerX + 350, this.game.world.centerY -70, 'game5s');
+        // Navigation buttons
+		buttonSettings["func_addButtons"](0,1,
+    	                             0,0,0,
+                                     1,1,
+                                     0,0);
+        
+        // Game buttons
+        
+        menu1 = game.add.sprite(this.game.world.centerX - 350, this.game.world.centerY - 70, 'game1s');
+        menu2 = game.add.sprite(this.game.world.centerX - 200, this.game.world.centerY - 70, 'game2s');
+        menu3 = game.add.sprite(this.game.world.centerX - 350, this.game.world.centerY + 90, 'game3s');
+        menu4 = game.add.sprite(this.game.world.centerX - 200, this.game.world.centerY + 90, 'game4s');
+        
+        menu5 = game.add.sprite(this.game.world.centerX + 10,  this.game.world.centerY - 70, 'game1c');
+        menu6 = game.add.sprite(this.game.world.centerX + 160, this.game.world.centerY - 70, 'game2c');
+        menu7 = game.add.sprite(this.game.world.centerX + 10,  this.game.world.centerY + 90, 'game3c');
+        menu8 = game.add.sprite(this.game.world.centerX + 160, this.game.world.centerY + 90, 'game4c');
+
+        menu9 = game.add.sprite(this.game.world.centerX + 350, this.game.world.centerY - 70, 'game5s');
+
+        // ACTIONS
+
+        // Game Button actions
         
-        // button actions
         menu1.anchor.setTo(0.5, 0.5);
         menu1.inputEnabled = true;
         menu1.input.useHandCursor = true;
-        menu1.events.onInputDown.add(this.loadGame,{num:1, beep: beepSound, shape : "Circle", label : true});
-        menu1.events.onInputOver.add(this.showTitle,{num:1, beep: beepSound, shape : "Circle", label : true, menu: menu1});
-        menu1.events.onInputOut.add(this.clearTitle, {menu: menu1});
+        menu1.events.onInputDown.add(this.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,{num:2, beep: beepSound, shape : "Circle", label : false});
-        menu2.events.onInputOver.add(this.showTitle,{num:2, beep: beepSound, shape : "Circle", label : false, menu: menu2});
-        menu2.events.onInputOut.add(this.clearTitle, {menu: menu2});
+        menu2.events.onInputDown.add(this.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,{num:3, beep: beepSound, shape : "Circle", label : true});
-        menu3.events.onInputOver.add(this.showTitle,{num:3, beep: beepSound, shape : "Circle", label : true, menu: menu3});
-        menu3.events.onInputOut.add(this.clearTitle, {menu: menu3});
+        menu3.events.onInputDown.add(this.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,{num:4, beep: beepSound, shape : "Circle", label : false});
-        menu4.events.onInputOver.add(this.showTitle,{num:4, beep: beepSound, shape : "Circle", label : false, menu: menu4});
-        menu4.events.onInputOut.add(this.clearTitle, {menu: menu4});
+        menu4.events.onInputDown.add(this.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,{num:1, beep: beepSound, shape : "Square", label : true});
-        menu5.events.onInputOver.add(this.showTitle,{num:1, beep: beepSound, shape : "Square", label : true, menu: menu5});
-        menu5.events.onInputOut.add(this.clearTitle, {menu: menu5});
+        menu5.events.onInputDown.add(this.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,{num:2, beep: beepSound, shape : "Square", label : false});
-        menu6.events.onInputOver.add(this.showTitle,{num:2, beep: beepSound, shape : "Square", label : false, menu: menu6});
-        menu6.events.onInputOut.add(this.clearTitle, {menu: menu6});
+        menu6.events.onInputDown.add(this.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,{num:3, beep: beepSound, shape : "Square", label : true});
-        menu7.events.onInputOver.add(this.showTitle,{num:3, beep: beepSound, shape : "Square", label : true, menu: menu7});
-        menu7.events.onInputOut.add(this.clearTitle, {menu: menu7});
+        menu7.events.onInputDown.add(this.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,{num:4, beep: beepSound, shape : "Square", label : false});
-        menu8.events.onInputOver.add(this.showTitle,{num:4, beep: beepSound, shape : "Square", label : false, menu: menu8});
-        menu8.events.onInputOut.add(this.clearTitle, {menu: menu8});
-        
+        menu8.events.onInputDown.add(this.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,{num:5, beep: beepSound, shape : "Square", label : false});
-        menu9.events.onInputOver.add(this.showTitle,{num:5, beep: beepSound, shape : "Square", label : false, menu: menu9});
-        menu9.events.onInputOut.add(this.clearTitle, {menu: menu9});
+        menu9.events.onInputDown.add(this.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});
 
-        // Floor
-        for(var i=0;i<9;i++){
-            game.add.image(i*100, 501, 'floor');
-        }
-        
     },
     
     //calls the selected game menu screen
@@ -133,51 +136,58 @@ var menuState = {
             this.beep.play();
         }
 
-        if( (this.num==1 || this.num==2) && this.shape=="Circle"){
-            oneShape = this.shape;
-            oneLabel = this.label;
-            oneType = "A";
-            game.state.start('menuCOne');
-        }
-        if( (this.num==3 || this.num==4) && this.shape=="Circle"){
-            oneShape = this.shape;
-            oneLabel = this.label;
-            oneType = "B";
+        levelShape = this.shape;
+        levelLabel = this.label;
+
+        if(this.shape=="Square"){
+            
+            if(this.levelType==1 || this.levelType==2){
+                
+                if(this.levelType==1){
+                    levelType = "A";
+                }else if(this.levelType==2){
+                    levelType = "B";
+                }
+
+                if(debugMode) console.log("Square One");
+                game.state.start('menuSOne');                
+            
+            }else if(this.levelType==3){
+                
+                levelType = "";
+                
+                if(debugMode) console.log("Square Two");
+                game.state.start('menuSTwo')
+            
+            }
+
+        }else if(this.shape=="Circle"){
+        
+            if (this.levelType==1){
+                levelType = "A";
+            }else if (this.levelType==2){
+                levelType = "B";
+            }
+            
+            if(debugMode) console.log("Circle One");
             game.state.start('menuCOne');
-        }
-        if( (this.num==1 || this.num==2) && this.shape=="Square"){
-            oneShape = this.shape;
-            oneLabel = this.label;
-            oneType = "A";
-            game.state.start('menuSOne');
-        }
-        if( (this.num==3 || this.num==4) && this.shape=="Square"){
-            oneShape = this.shape;
-            oneLabel = this.label;
-            oneType = "B";
-            game.state.start('menuSOne');
-        }
-        if( this.num==5 && this.shape=="Square"){
-            twoShape = this.shape;
-            twoLabel = this.label;
-            twoType = "";
-            game.state.start('menuSTwo');
+        
         }
 
     },
 
-    showTitle: function(){
+    func_showTitle: function(){
         
         var title = "";
         var type = "";
         
-        if( (this.num==1 || this.num==2) ){
+        if(this.levelType==1){
             type = "I";
         }
-        if( (this.num==3 || this.num==4) ){
+        if(this.levelType==2){
             type = "II";
         }
-        if( this.num==5 && this.shape=="Square"){
+        if(this.levelType==3){
             type = "III";
         }
         
@@ -199,17 +209,17 @@ var menuState = {
             title += " - " + lang.without_name + " " + lang.label_name;
         }
         
-        lbl_game.text = title;
+        this.lbl_game.text = title;
 
         this.menu.scale.setTo(1.05);
 
     },
 
-    clearTitle: function(){
+    func_clearTitle: function(){
         
-        lbl_game.text = "";
+        this.lbl_game.text = "";
         
-        this.menu.scale.setTo(1.0);
+        this.menu.scale.setTo(1);
 
     }
     

+ 0 - 0
js/phaser.js


+ 0 - 0
js/phaser.min.js


+ 69 - 64
js/preMenu.js

@@ -1,11 +1,9 @@
-
-var errorEmptyName;
-var debugmode = false;
 /*
+
     var langState = {
         create: function(){},
         --------------------------------------- end of phaser functions
-        setLang: function(){} //calls loadState
+        func_setLang: function(){} //calls loadState
     };
     
     var loadState = {
@@ -17,81 +15,101 @@ var debugmode = false;
     var nameState = {
         create: function(){},
         ------------------------------------------------ end of phaser functions
-        nameIsEmpty: function(){}
-        ready: function(){} //calls menu.js -> menuState
+        func_checkEmptyName: function(){}
+        func_savename: function(){} //calls menu.js -> menuState
     };
 
     var buttonSettings = {
-        addButtons: function(_,_,_,_,_,_,_,_,_){},
+        func_addButtons: function(_,_,_,_,_,_,_,_,_){},
         loadState: function(){}
     };
+
 */
 
 // "choose language" screen
+
 var langState = {
 
     create: function() {
 
+    	// AUX
+
+        var style = { font: '28px Arial', fill: '#00804d', align: 'center' };
+
+		//AUDIO
+
+        beepSound = game.add.audio('sound_beep');	// game sound
+        okSound = game.add.audio('sound_ok'); 		// correct answer sound
+        errorSound = game.add.audio('sound_error'); // wrong answer sound
+
+    	//BACKGROUND
+
         game.stage.backgroundColor = '#cce5ff';
         
-        var style = { font: '28px Arial', fill: '#00804d', align: 'center' };
+        // LANGUAGES
 
         //pt_BR
         var title1 = game.add.text(this.game.world.centerX - 220, this.game.world.centerY - 100, 'FRAÇÕES  ', style);
         title1.anchor.setTo(1, 0.5);
+
         var flag1 = game.add.sprite(this.game.world.centerX - 120, this.game.world.centerY - 100, 'flag_BR');       
         flag1.anchor.setTo(0.5, 0.5);
         flag1.inputEnabled = true;
         flag1.input.useHandCursor = true;
-        flag1.events.onInputDown.add(this.setLang,{lang:'pt_BR'});
+        flag1.events.onInputDown.add(this.func_setLang,{lang:'pt_BR'});
         flag1.events.onInputOver.add(function(){ flag1.scale.setTo(1.05) });
         flag1.events.onInputOut.add(function(){ flag1.scale.setTo(1) });
 
         //es_PE
         var title2 = game.add.text(this.game.world.centerX + 200, this.game.world.centerY - 100, 'FRACCIONES  ', style);
         title2.anchor.setTo(1, 0.5);
+        
         var flag2 = game.add.sprite(this.game.world.centerX + 300, this.game.world.centerY - 100, 'flag_PE');       
         flag2.anchor.setTo(0.5, 0.5);
         flag2.inputEnabled = true;
         flag2.input.useHandCursor = true;
-        flag2.events.onInputDown.add(this.setLang,{lang:'es_PE'});
+        flag2.events.onInputDown.add(this.func_setLang,{lang:'es_PE'});
         flag2.events.onInputOver.add(function(){ flag2.scale.setTo(1.05) });
         flag2.events.onInputOut.add(function(){ flag2.scale.setTo(1) });
 
         //en_US
         var title3 = game.add.text(this.game.world.centerX - 220, this.game.world.centerY + 100, 'FRACTIONS  ', style);
         title3.anchor.setTo(1, 0.5);
+        
         var flag3 = game.add.sprite(this.game.world.centerX - 120, this.game.world.centerY + 100, 'flag_US');       
         flag3.anchor.setTo(0.5, 0.5);
         flag3.inputEnabled = true;
         flag3.input.useHandCursor = true;
-        flag3.events.onInputDown.add(this.setLang,{lang:'en_US'});
+        flag3.events.onInputDown.add(this.func_setLang,{lang:'en_US'});
         flag3.events.onInputOver.add(function(){ flag3.scale.setTo(1.05) });
         flag3.events.onInputOut.add(function(){ flag3.scale.setTo(1) });
 
         //fr_FR
         var title4 = game.add.text(this.game.world.centerX + 200, this.game.world.centerY + 100, 'FRACTIONS  ', style);
         title4.anchor.setTo(1, 0.5);
+        
         var flag4 = game.add.sprite(this.game.world.centerX + 300, this.game.world.centerY + 100, 'flag_FR');       
         flag4.anchor.setTo(0.5, 0.5);
         flag4.inputEnabled = true;
         flag4.input.useHandCursor = true;
-        flag4.events.onInputDown.add(this.setLang,{lang:'fr_FR'});
+        flag4.events.onInputDown.add(this.func_setLang,{lang:'fr_FR'});
         flag4.events.onInputOver.add(function(){ flag4.scale.setTo(1.05) });
         flag4.events.onInputOut.add(function(){ flag4.scale.setTo(1) });
         
     },
     
-    setLang: function(){
+    func_setLang: function(){
+
         //set language
         lang = this.lang;
         //start resource loading
         game.state.start('load');
+    
     }
 
 };
 
-// "loading" screen
+// "loading" screen and load json dictionary
 var loadState = {
     
     preload: function() {
@@ -110,12 +128,12 @@ var loadState = {
 
         // gets selected language from json
         lang = game.cache.getJSON('dictionary');
-        audio_lang_aux = lang.audio_on;
-        if(!nameStatus){
-          nameStatus = true;
-          game.state.start('name');
-        }else{
-          game.state.start('menu');
+        
+        if(firstTime==true){ // select language screen - first time opening ifractions
+          firstTime = false;
+          game.state.start('name'); // go to select name screen, then menu
+        }else{			     // changing language during the game
+          game.state.start('menu'); // go to menu
         }
     
     }
@@ -126,7 +144,9 @@ var loadState = {
 var nameState = {
 
     create: function() {
-                        
+                    
+        // AUX
+
         var style = { font: '30px Arial', fill: '#00804d', align: 'center' };
         var styleName = { font: '44px Arial', fill: '#000000', align: 'center' };
         
@@ -134,6 +154,9 @@ var nameState = {
         var title = game.add.text(this.game.world.centerX, this.game.world.centerY - 100, lang.insert_name, style);
         title.anchor.setTo(0.5);
         
+		var errorEmptyName = game.add.text(this.game.world.centerX, this.game.world.centerY - 70, "", {font: '18px Arial', fill: '#330000', align: 'center'});
+        errorEmptyName.anchor.setTo(0.5);
+
         // "READY" button
         var btn = game.add.graphics(this.game.world.centerX - 84, this.game.world.centerY + 70);
         btn.lineStyle(1, 0x293d3d);
@@ -141,99 +164,77 @@ var nameState = {
         btn.drawRect(0, 0, 168, 60);
         btn.alpha = 0.5;
         btn.endFill();
-        
+
         btn.inputEnabled = true;
         btn.input.useHandCursor = true;
-        btn.events.onInputDown.add(this.nameIsEmpty, null);
+		btn.events.onInputDown.add(this.func_checkEmptyName,{errorEmptyName: errorEmptyName});
         btn.events.onInputOver.add(function(){ btn.alpha=0.4 });
         btn.events.onInputOut.add(function(){ btn.alpha=0.5 });
         
         var ready = game.add.text(this.game.world.centerX + 1, this.game.world.centerY + 102, lang.ready, { font: '34px Arial', fill: '#f0f5f5', align: 'center' });
-        ready.anchor.setTo(0.5);
-
-        errorEmptyName = game.add.text(this.game.world.centerX, this.game.world.centerY - 70, "", {font: '18px Arial', fill: '#330000', align: 'center'});
-        errorEmptyName.anchor.setTo(0.5);
+        ready.anchor.setTo(0.5);      
 
         document.getElementById("text-field-div").style.visibility = "visible";
         document.getElementById("name_id").addEventListener('keypress', function(e){
             var keycode = e.keycode ? e.keycode : e.which; 
             //se apertar enter vai para ready, assim como o botão
             if(keycode == 13){
-                nameState["nameIsEmpty"]();
+                nameState["func_checkEmptyName"]();
             }     
         });
 
     },
          
-    nameIsEmpty: function() {
+    func_checkEmptyName: function() {
 
         if(document.getElementById("name_id").value!=""){
-          nameState["ready"]();
-          errorEmptyName.setText("");
+          	nameState["func_savename"]();
+			this.errorEmptyName.setText("");
         }else{
-          errorEmptyName.setText(lang.empty_name);
-          //D alert('js/preMenu.js: errorEmptyName.setText=' + lang.empty_name);
+			this.errorEmptyName.setText(lang.empty_name);
         }
 
     },
               
-    ready: function() {
+    func_savename: function() {
         
         // saves the typed name on username variable
         username = document.getElementById("name_id").value;
-        if(debugmode) console.log("user is" + username);        
+        if(debugMode) console.log("user is" + username);        
 
         document.getElementById("text-field-div").style.visibility = "hidden";
 
         //clears the text field again
         document.getElementById("name_id").value = "";
 
-        if(oneMenu){ //If menu, normal game
-            // Go to the menu state
-            game.state.start('menu');
-        }else{ //parameters game
-            if(oneShape=="Circle"){
-                game.state.start("mapCOne");
-            }else if(oneShape=="Square"){
-                if(oneOperator=='Mixed'){
-                    twoPosition = 0;
-                    twoMove = true;
-                    twoDifficulty = oneDifficulty; 
-                    twoOperator= "";
-                    twoLabel= false;
-                    twoShape = oneShape;
-                    twoType = oneType;
-                    twoMenu = false;
-                    
-                    game.state.start("mapSTwo");
-                }else{
-                    game.state.start("mapSOne");
-                }
-            }
-            
-        }
+		if(audioStatus){
+	        beepSound.play();
+    	}
+
+        game.state.start('menu');
         
     }
 
 };
 
-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){
-
+    func_addButtons: function(left, right, b0Esq, b1Esq, b2Esq, b0Dir, b1Dir, phase, helpBtn){
+        
+        var m_info_right, m_info_left;
+        var m_world, m_menu, m_back, m_help, m_audio;
         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
@@ -246,6 +247,7 @@ var buttonSettings = {
             
             xEsq+=50;
         }
+
         if(b1Esq == 1){
             // Return to menu button
             m_list = game.add.sprite(xEsq, 10, 'list'); 
@@ -257,6 +259,7 @@ var buttonSettings = {
             
             xEsq+=50;
         }
+
         if(b2Esq == 1){
             // Help button
             m_help = game.add.sprite(xEsq, 10, 'help');
@@ -268,6 +271,7 @@ var buttonSettings = {
             
             xEsq+=50;
         }
+
         //rightButtons
         if(b0Dir == 1){
             m_audio = game.add.sprite(xDir, 10, 'audio');
@@ -280,6 +284,7 @@ var buttonSettings = {
 
             xDir-=50;
         }
+
         if(b1Dir == 1){
             // Return to language button
             m_world = game.add.sprite(xDir, 10, 'world'); 

+ 190 - 210
js/squareOne.js

@@ -1,9 +1,9 @@
-
 /*
+
     var menuSquareOne = {
         create: function(){},
         ---------------------------- end of phaser functions
-        loadMap: function(){}
+        func_loadMap: function(){}
     };
 
     var mapSquareOne = {
@@ -17,50 +17,47 @@
         create: function(){},
         update: function(){},
         ---------------------------- end of phaser functions
-        updateCounter: function(){},
-        overSquare: function(){},
-        outSquare: function(){},
-        clickSquare: function(){},
-            //setPlace: function(){},
-        postScore: function(){},
-        viewHelp: function(){},
-            //checkOverlap: function(){}
-            //getRndDivisor: function(){}
+        func_updateCounter: function(){},
+        func_overSquare: function(){},
+        func_outSquare: function(){},
+        func_clickSquare: function(){},
+            //func_setPlace: function(){},
+        func_postScore: function(){},
+        func_viewHelp: function(){},
+            //func_checkOverlap: function(){}
+            //func_getRndDivisor: function(){}
     };
 
     var endSquareOne = {
         create: function(){},
         update: function(){},
         ---------------------------- end of phaser functions
-        verPrincipal: function(){},
-        verMenu: function(){}
+        func_verPrincipal: function(){},
     };
+
 */
 
 // Tractor and Square states
 
 /****************************** MENU ****************************/
-var stairsRight, stairsLeft;
 
 var menuSquareOne = {
 	
     create: function() {
-        
-        // Creating sound variable
-        var beepSound = game.add.audio('sound_beep');
           
-        // Menu options
-        buttonSettings["addButtons"](1,1,
+        // Navigation buttons
+        buttonSettings["func_addButtons"](1,1,
                                     0,1,0,
                                     1,0,
                                     0,0);
         
-        // Setting title
+        // Title
         var style = { font: '28px Arial', fill: '#00804d'};
         var title = game.add.text(game.world.centerX, 40, lang.game_menu_title, style);
         title.anchor.setTo(0.5, 0.5);
         
-        //Showing Games and Levels
+        //SETTING DIFFICULTY LEVELS
+
         var maxHeight = 120; //Max height of a stair
         var stairHeight = 40; //height growth of a stair
         var stairWidth = 100; //Width of a stair
@@ -68,26 +65,28 @@ var menuSquareOne = {
         var startSymbol = 180; 
         var startSquare = (startSymbol/2)+startStair+stairWidth*3;
         
-         //First stairs, plus, 3 levels, blue square
+        //First stairs, plus, 3 levels, blue square
+
         var blueSquare = game.add.graphics(startSquare, 175);
             blueSquare.anchor.setTo(0.5,0.5);
             blueSquare.lineStyle(2, 0x31314e);
             blueSquare.beginFill(0xefeff5);
             blueSquare.drawRect(0, 0, 80, 40);
             blueSquare.endFill();
-        var bplus = game.add.sprite(startSymbol+30, 215, 'tractor_green');
-            //bplus.frame = 0;
-            bplus.scale.setTo(0.5);
-            bplus.alpha = 0.9;
-            bplus.anchor.setTo(0.5,0.5);
         
-        var bplus2 = game.add.sprite(startSymbol+100, 215, 'h_arrow');
-            bplus2.scale.setTo(0.3);
-            bplus2.alpha = 0.9;
-            bplus2.anchor.setTo(0.5,0.5);
+        var plusTractorIcon = game.add.sprite(startSymbol+30, 215, 'tractor_green');
+            //plus_tractor.frame = 0;
+            plusTractorIcon.scale.setTo(0.5);
+            plusTractorIcon.alpha = 0.9;
+            plusTractorIcon.anchor.setTo(0.5,0.5);
+        
+        var plusArrowIcon = game.add.sprite(startSymbol+100, 215, 'h_arrow');
+            plusArrowIcon.scale.setTo(0.3);
+            plusArrowIcon.alpha = 0.9;
+            plusArrowIcon.anchor.setTo(0.5,0.5);
         
-
         var stairsPlus = [];
+
         for(var i=1;i<=3;i++){
             //stair
             var x1 = startStair+(stairWidth*(i-1));
@@ -104,9 +103,10 @@ var menuSquareOne = {
             //event
             stairsPlus[i].inputEnabled = true;
             stairsPlus[i].input.useHandCursor = true;
-            stairsPlus[i].events.onInputDown.add(this.loadMap, {beep: beepSound, difficulty: i, operator: 'Plus' });
+            stairsPlus[i].events.onInputDown.add(this.func_loadMap, {beep: beepSound, difficulty: i, operator: 'Plus' });
             stairsPlus[i].events.onInputOver.add(function (item) { item.alpha=0.5; }, this);
             stairsPlus[i].events.onInputOut.add(function (item) { item.alpha=1; }, this);
+            
             //label
             var xl = x1+stairWidth/2; //x label
             var yl = y1+(stairHeight*i)/2; //y label
@@ -114,28 +114,29 @@ var menuSquareOne = {
                 label.anchor.setTo(0.5, 0.4);
         }
         
-        //Second stairs, minus, 5 levels, red Square
+        //Second stairs, minus, 3 levels, red Square
+
         var redSquare = game.add.graphics(startSquare, 330);
             redSquare.anchor.setTo(0.5,0.5);
             redSquare.lineStyle(2, 0xb30000);
             redSquare.beginFill(0xefeff5);
             redSquare.drawRect(0, 0, 80, 40);
             redSquare.endFill();
-        var rminus = game.add.sprite(startSymbol+70, 370, 'tractor_red');
-            //rminus.frame = 5;
-            rminus.scale.setTo(0.5);
-            rminus.alpha = 0.9;
-            //rminus.scale.x *= -1;
-            rminus.anchor.setTo(0.5,0.5);
+
+        var minusTractorIcon = game.add.sprite(startSymbol+70, 370, 'tractor_red');
+            //minusTractorIcon.frame = 5;
+            minusTractorIcon.scale.setTo(0.5);
+            minusTractorIcon.alpha = 0.9;
+            minusTractorIcon.anchor.setTo(0.5,0.5);
         
-        var rminus2 = game.add.sprite(startSymbol, 370, 'h_arrow');
-            rminus2.scale.setTo(0.3);
-            rminus2.alpha = 0.9;
-            rminus2.scale.x *= -1;
-            rminus2.anchor.setTo(0.5,0.5);
+        var minusArrowIcon = game.add.sprite(startSymbol, 370, 'h_arrow');
+            minusArrowIcon.scale.setTo(0.3);
+            minusArrowIcon.alpha = 0.9;
+            minusArrowIcon.scale.x *= -1;
+            minusArrowIcon.anchor.setTo(0.5,0.5);
         
-
         var stairsMinus = [];
+
         for(var i=1;i<=3;i++){
             //stair
             var x1 = startStair+(stairWidth*(i-1));
@@ -152,31 +153,33 @@ var menuSquareOne = {
             //event
             stairsMinus[i].inputEnabled = true;
             stairsMinus[i].input.useHandCursor = true;
-            stairsMinus[i].events.onInputDown.add(this.loadMap, {beep: beepSound, difficulty: i, operator: 'Minus' });
+            stairsMinus[i].events.onInputDown.add(this.func_loadMap, {beep: beepSound, difficulty: i, operator: 'Minus' });
             stairsMinus[i].events.onInputOver.add(function (item) { item.alpha=0.5; }, this);
             stairsMinus[i].events.onInputOut.add(function (item) { item.alpha=1; }, this);
+            
             //label
             var xl = x1+stairWidth/2; //x label
             var yl = y1+(stairHeight*i)/2; //y label
             var label = game.add.text(xl, yl, i, { font: '25px Arial', fill: '#ffffff', align: 'center' });
                 label.anchor.setTo(0.5, 0.4);
         } 
+
     },
         
     //MapLoading function
-    loadMap: function(){
+    func_loadMap: function(){
+        
         if(audioStatus){
             this.beep.play();
         }
-        onePosition = 0; //Map position
-        oneMove = true; //Move no next point
-        oneDifficulty  = this.difficulty; //Number of difficulty (1 to 5)
-        oneOperator = this.operator; //Operator of game
-        if(onePosition<5){
-            game.state.start('mapSOne');
-        }else{
-            game.state.start('unofinal');
-        }
+        
+        levelPosition = 0; //Map position
+        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');
+
     }
     
 };
@@ -187,14 +190,11 @@ var mapSquareOne = {
 
     create: function() {
                 
-        // Creating sound variable
-        beepSound = game.add.audio('sound_beep');
-
         // Background
         game.add.image(0, 40, 'bgmap');
         
-        // Menu options
-        buttonSettings["addButtons"](1,0,
+        // Navigation buttons
+        buttonSettings["func_addButtons"](1,0,
                                     1,1,0,
                                     0,0,
                                     "menuSOne",0);
@@ -204,17 +204,18 @@ var mapSquareOne = {
         var styleMenu = { font: '30px Arial', fill: '#000000', align: 'center'};
         
         // Progress bar
-        var percentText = onePosition*20;
-        var percentBlocks = onePosition;
-        for(var p=1;p<=percentBlocks;p++){
-            var block = game.add.image(660+(p-1)*30, 10, 'block');
-            block.scale.setTo(2, 1); //Scaling to double width
+        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 + ' ' + oneDifficulty, styleMenu).anchor.setTo(1,0);
+        game.add.text(650, 10, lang.difficulty + ' ' + levelDifficulty, styleMenu).anchor.setTo(1,0);
         game.add.image(660, 10, 'pgbar');
         
-         //Road
+        //Road
         this.points = {
         'x': [ 90, 204, 318, 432, 546, 660 ],
         'y': [ 486, 422, 358, 294, 230, 166 ]
@@ -259,13 +260,12 @@ var mapSquareOne = {
             sprite.anchor.setTo(0.5, 0.95);
         }
 
-        
         // places
         for (var p = 1; p < this.points.x.length -1; p++){
             var place;
-            if(p<onePosition)
+            if(p<levelPosition)
                 	place = game.add.image(this.points.x[p], this.points.y[p], 'place_b');
-            else if (oneMove && p==onePosition)
+            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');
@@ -281,7 +281,7 @@ var mapSquareOne = {
         }
 
         // tractor start position
-        this.tractor = game.add.sprite(this.points.x[onePosition], this.points.y[onePosition], 'tractor');
+        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);
@@ -296,42 +296,44 @@ var mapSquareOne = {
     },
 
     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(onePosition==6){
-            oneMove = false;
+        if(levelPosition==8){
+            levelMove = false;
         }
-        if(!oneMove){
+
+        if(!levelMove){
             this.loadGame();
         }
         
         // If momevent is enabled, move to next point from actual
-        if(oneMove){
+        if(levelMove){
             game.physics.arcade.moveToXY(
                 this.tractor, 
-                this.points.x[onePosition+1],
-                this.points.y[onePosition+1],
+                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[onePosition+1] || Math.ceil(this.tractor.y)==this.points.y[onePosition+1]){
-                oneMove=false;
-                onePosition += 1; //Update position
+            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(){
+    loadGame: function() {
         if(audioStatus){
             beepSound.play();
         }
-        if(onePosition<5){
+        if(levelPosition<5){
             game.state.start('gameSOne');
         }else{
             game.state.start('endSOne');
@@ -341,19 +343,6 @@ var mapSquareOne = {
 };
 
 /****************************** GAME ****************************/
-var startX;
-var clicked, hideLabels, animate, checkCollide, result, hasFigure;
-var detail;
-var endPosition;
-var fractionClicked, fractionIndex;
-//Balloon and blocks control
-var blocks, maxBlocks, numBlocks, curBlock, blockDirection, blockDistance, blockLabel, blockSeparator;
-
-var blockWidth, blockIndex;
-var floorBlocks, floorIndex, floorCount, floorClicked, curFloor;
-var move, moveCounter, moveEnd;
-var tractor, arrow;
-var arrowPlace;
 
 var gameSquareOne = {
 
@@ -362,23 +351,18 @@ var gameSquareOne = {
         //timer
         totalTime = 0;
         timer = game.time.create(false);
-        timer.loop(1000, this.updateCounter, this);
+        timer.loop(1000, this.func_updateCounter, this);
         timer.start();
         detail="";
-        
-        // Creating sound variable
-        beepSound = game.add.audio('sound_beep');
-        okSound = game.add.audio('sound_ok');
-        errorSound = game.add.audio('sound_error');
 
         // Background
         game.add.image(0, 0, 'bgimage');
         
-        // Menu options
-        buttonSettings["addButtons"](1,1,
+        // Navigation buttons
+        buttonSettings["func_addButtons"](1,1,
                                     1,1,1,
                                     1,0,
-                                    "menuSOne", this.viewHelp);
+                                    "menuSOne", this.func_viewHelp);
 
         //Clouds
         game.add.image(300, 100, 'cloud');
@@ -393,7 +377,7 @@ var gameSquareOne = {
         
         //Floor and road
         var startX = 170; //Initial tractor and place position
-        if(oneOperator=='Minus') startX = 730;
+        if(levelOperator=='Minus') startX = 730;
         startX = startX; //Workaround for initial position inside update
         var blockWidth = 80; //Width of blocks and floor spaces
         var blockHeight = 40; //Height of blocks and floor spaces
@@ -413,27 +397,27 @@ var gameSquareOne = {
                 
         //tractor
         var tractorAlign = -80;
-        if(oneOperator=='Minus'){
+        if(levelOperator=='Minus'){
             tractorAlign *= -1;
         } 
         tractor = game.add.sprite(startX+tractorAlign, 445, 'tractor');
         tractor.anchor.setTo(0.5, 0.5);
         tractor.scale.setTo(0.8);
         tractor.animations.add('right',[0,1,2,3,4]);
-        if(oneOperator=='Minus'){
+        if(levelOperator=='Minus'){
             tractor.scale.x *= -1;
         }
         
         //generator
         //Blocks and fractions
-        if(debugmode) console.log("pos " +onePosition);
+        if(debugMode) console.log("pos " +levelPosition);
         
-        maxBlocks = onePosition+4; //Maximum blocks
-        if(oneType=='B' || oneOperator=='Mixed') maxBlocks = 10;
+        maxBlocks = levelPosition+4; //Maximum blocks
+        if(levelType=='B' || levelOperator=='Mixed') maxBlocks = 10;
         blocks = game.add.group(); //Fraction arrays (apilled)
-        numBlocks = game.rnd.integerInRange(onePosition+2, maxBlocks); //Number of blocks
+        numBlocks = game.rnd.integerInRange(levelPosition+2, maxBlocks); //Number of blocks
         
-        if(debugmode) console.log("num " + numBlocks+", min " + (onePosition+2) + ", max " + maxBlocks);
+        if(debugMode) console.log("num " + numBlocks+", min " + (levelPosition+2) + ", max " + maxBlocks);
         
         curBlock = 0; //Actual index block
         blockDirection = []; //Directions right(plus), left (minus)
@@ -443,7 +427,7 @@ var gameSquareOne = {
         //blockAngle = []; //Angles of blocks
         //blockTraceColor = []; //Trace colors
         endPosition = startX; //Ending position, accumulative
-        if(oneOperator=='Minus') endPosition -= blockWidth;
+        if(levelOperator=='Minus') endPosition -= blockWidth;
         else endPosition += blockWidth;
         
         //Game A exclusive variables 
@@ -455,7 +439,7 @@ var gameSquareOne = {
         
         //Game B exclusive variables
         arrowPlace = startX; //Fixed place for help arrow
-        if(oneOperator=='Minus') arrowPlace  -= blockWidth;
+        if(levelOperator=='Minus') arrowPlace  -= blockWidth;
         else arrowPlace += blockWidth;
         fractionClicked = false; //If clicked a fraction (game B)
         fractionIndex = -1; //Index of clicked fraction (game B)
@@ -464,18 +448,18 @@ var gameSquareOne = {
 
         for(var p=0;p<numBlocks;p++){
 
-            var portion = game.rnd.integerInRange(1, oneDifficulty); //Portion of the square, according to difficulty
+            var portion = game.rnd.integerInRange(1, levelDifficulty); //Portion of the square, according to difficulty
             if(portion==3) detail+= "4,";
             else detail += portion+",";
             
-            if(portion==oneDifficulty) hasFigure = true;
+            if(portion==levelDifficulty) hasFigure = true;
             var direction = '';
             var lineColor = '';
             
-            if(oneOperator=='Plus'){
+            if(levelOperator=='Plus'){
                 direction = 'Right';    
                 lineColor = 0x31314e; //plus block: "black'
-            }else if(oneOperator=='Minus'){
+            }else if(levelOperator=='Minus'){
                 direction = 'Left';
                 lineColor = 0xb30000;//minus block : "red"
             }
@@ -494,9 +478,9 @@ var gameSquareOne = {
                 blockDistance.push(blockWidth);
                 //blockAngle.push(360);
 
-                if(oneLabel){
+                if(levelLabel){
                     var labelX = startX;
-                    if(oneOperator=='Minus') labelX -= (15+blockWidth);
+                    if(levelOperator=='Minus') labelX -= (15+blockWidth);
                     else labelX += blockWidth+15;
                     var label = game.add.text(labelX, 480-p*blockHeight, portion , styleLabel);
                     label.anchor.setTo(0.5, 0.5);
@@ -511,9 +495,9 @@ var gameSquareOne = {
                 
                 blockDistance.push(distance);
 
-                if(oneLabel){
+                if(levelLabel){
                     var labelX = startX;
-                    if(oneOperator=='Minus') labelX -= (15+distance);
+                    if(levelOperator=='Minus') labelX -= (15+distance);
                     else labelX += 15+distance;
                     var separator = game.add.sprite(labelX, 480-p*blockHeight, 'separator');
                     separator.scale.setTo(0.6);
@@ -535,13 +519,13 @@ var gameSquareOne = {
             block.endFill();
             
             //If game is type B, (select fractions, adding event)
-            if(oneType=='B'){
+            if(levelType=='B'){
                 block.alpha = 0.5;
                 block.inputEnabled = true;
                 block.input.useHandCursor = true;
-                block.events.onInputDown.add(this.clickSquare, {indice: p});
-                block.events.onInputOver.add(this.overSquare, {indice: p});
-                block.events.onInputOut.add(this.outSquare, {indice: p});
+                block.events.onInputDown.add(this.func_clickSquare, {indice: p});
+                block.events.onInputOver.add(this.func_overSquare, {indice: p});
+                block.events.onInputOut.add(this.func_outSquare, {indice: p});
             }
             
             blocks.add(block);
@@ -557,14 +541,14 @@ var gameSquareOne = {
         //If end position is out of bounds, restart
         if(!hasFigure) game.state.start('gameSOne');
         
-        if (oneOperator=='Plus' && (endPosition<(startX+blockWidth) || endPosition>(startX+8*blockWidth))){
+        if (levelOperator=='Plus' && (endPosition<(startX+blockWidth) || endPosition>(startX+8*blockWidth))){
             game.state.start('gameSOne');
-        }else if (oneOperator=='Minus' && (endPosition>(startX) || endPosition<(startX-(8*blockWidth)))){
+        }else if (levelOperator=='Minus' && (endPosition>(startX) || endPosition<(startX-(8*blockWidth)))){
             game.state.start('gameSOne');
         }
         
         //If game is type B, selectiong a random block floor place
-        if(oneType=='B'){
+        if(levelType=='B'){
             var end = game.rnd.integerInRange(1, numBlocks);
             for(var i=0;i<end;i++){
                 if(blockDirection[i]=='Right')
@@ -575,11 +559,11 @@ var gameSquareOne = {
         }
         
         //Selectable floor
-        floorCount = 8*oneDifficulty;
+        floorCount = 8*levelDifficulty;
         
-        var widFloor = blockWidth/oneDifficulty;
+        var widFloor = blockWidth/levelDifficulty;
 
-        if(oneDifficulty==3){
+        if(levelDifficulty==3){
             floorCount = 8*4;
             widFloor = blockWidth/4;
         }
@@ -587,11 +571,11 @@ var gameSquareOne = {
         for(var i = 0; i < floorCount; i++){
             var posX = startX;
             
-            if(oneOperator=='Minus') posX -= (blockWidth + i*widFloor);
+            if(levelOperator=='Minus') posX -= (blockWidth + i*widFloor);
             else posX += (blockWidth + i*widFloor);
             
-            if(oneType=='B'){
-                if(oneOperator=='Minus'){
+            if(levelType=='B'){
+                if(levelOperator=='Minus'){
                     if(posX<=arrowPlace){
                         floorCount = i+1;
                         floorIndex = i-1;
@@ -613,15 +597,15 @@ var gameSquareOne = {
                 block.beginFill(0xa8c0e6);
                 block.drawRect(0, 0, widFloor, blockHeight);
                 block.endFill();
-            if(oneOperator=='Minus') block.scale.x *= -1;
+            if(levelOperator=='Minus') block.scale.x *= -1;
             
-            if(oneType=="A"){
+            if(levelType=="A"){
                 block.alpha = 0.5;
                 block.inputEnabled = true;
                 block.input.useHandCursor = true;
-                block.events.onInputDown.add(this.clickSquare, {indice: i});
-                block.events.onInputOver.add(this.overSquare, {indice: i});
-                block.events.onInputOut.add(this.outSquare, {indice: i});
+                block.events.onInputDown.add(this.func_clickSquare, {indice: i});
+                block.events.onInputOver.add(this.func_overSquare, {indice: i});
+                block.events.onInputOut.add(this.func_outSquare, {indice: i});
             }
             
             floorBlocks.add(block);     
@@ -629,7 +613,7 @@ var gameSquareOne = {
         
         for(var i=0;i<=8;i++){
             var posX = startX;
-            if(oneOperator=='Minus')posX -= ((9-i)*blockWidth);
+            if(levelOperator=='Minus')posX -= ((9-i)*blockWidth);
             else posX+=((i+1)*blockWidth);
             
             game.add.text(posX, 560, i , stylePlace).anchor.setTo(0.5, 0.5); 
@@ -646,9 +630,9 @@ var gameSquareOne = {
          //Help arrow
         arrow = game.add.sprite(this.arrowPlace, 480, 'down');
         arrow.anchor.setTo(0.5, 0.5);
-        if(oneType=="B")
+        if(levelType=="B")
             arrow.alpha = 0;
-        else if(oneType=="A")
+        else if(levelType=="A")
             arrow.alpha = 0.5;
 
     },
@@ -657,7 +641,7 @@ var gameSquareOne = {
                 
         if(!clicked){
             if(!move){
-                if(oneType=='A'){
+                if(levelType=='A'){
                     //Follow mouse
                     if (game.physics.arcade.distanceToPointer(arrow, game.input.activePointer) > 8 )
 				    {	
@@ -746,7 +730,7 @@ var gameSquareOne = {
             }else{
                 result = false;
             }
-            this.postScore();
+            this.func_postScore();
             move = true;
             checkCollide = false;
         }
@@ -760,6 +744,8 @@ var gameSquareOne = {
                     if(audioStatus){
                         okSound.play();
                     }
+                    passedLevels++;        
+                    if(debugMode) console.log("passedLevels = "+passedLevels); 
                     okImg.alpha = 1;
                 }else{
                     if(audioStatus){
@@ -772,7 +758,7 @@ var gameSquareOne = {
             moveCounter += 1;
             
             if(result){
-                if(oneOperator=='Minus'){
+                if(levelOperator=='Minus'){
                     tractor.x -=2;
                 }else{
                     tractor.x +=2;
@@ -781,9 +767,9 @@ var gameSquareOne = {
             
             if(moveCounter>=moveEnd){
                 if(result){
-                    oneMove = true;
+                    levelMove = true;
                 }else{
-                    oneMove = false;
+                    levelMove = false;
                 }
                 game.state.start('mapSOne');
             }
@@ -791,15 +777,15 @@ var gameSquareOne = {
         
     },
 
-    updateCounter: function() {
+    func_updateCounter: function() {
         totalTime++;
     },
     
-    overSquare: function(){
+    func_overSquare: function(){
 
         if(!clicked){
             //on level type A
-            if(oneType=="A"){
+            if(levelType=="A"){
                 for(var i=0;i<floorCount;i++){
                     if(i<=this.indice){
                         floorBlocks.children[i].alpha = 1;
@@ -809,7 +795,7 @@ var gameSquareOne = {
                 }
                 floorIndex = this.indice;
             //on level type B
-            }else if(oneType=="B"){
+            }else if(levelType=="B"){
                 for(var i=0;i<numBlocks;i++){
                     if(i<=this.indice){
                         blocks.children[i].alpha = 0.5;
@@ -823,17 +809,17 @@ var gameSquareOne = {
 
     },
 
-    outSquare: function(){
+    func_outSquare: function(){
 
         if(!clicked){
             //on level type A
-            if(oneType=="A"){
+            if(levelType=="A"){
                 for(var i=0;i<floorCount;i++){
                     floorBlocks.children[i].alpha = 0.5;
                 }
                 floorIndex = -1;
             //on level type B
-            }else if(oneType=="B"){
+            }else if(levelType=="B"){
                 for(var i=0;i<numBlocks;i++){
                     blocks.children[i].alpha = 0.5;
                 }
@@ -843,12 +829,12 @@ var gameSquareOne = {
 
     },
     
-    clickSquare: function(){
+    func_clickSquare: function(){
 
         if(!clicked && !move){
             
             //on level type A
-            if(oneType=='A'){
+            if(levelType=='A'){
     
                 arrow.alpha = 1;
                 clicked = true;
@@ -858,13 +844,13 @@ var gameSquareOne = {
                 }            
                 tractor.animations.play('right', 5, true);
                 
-                if(oneLabel){ //Hiding labels
+                if(levelLabel){ //Hiding labels
                     blockLabel.visible = false;
                     blockSeparator.visible = false;
                 }
                 
                 //cleaning path
-                if(oneOperator=='Minus'){
+                if(levelOperator=='Minus'){
                     for(var i=0; i< floorCount; i++){
                         if(i>floorIndex){
                             floorBlocks.children[i].alpha = 0;
@@ -881,7 +867,7 @@ var gameSquareOne = {
                 blockIndex = numBlocks - 1;
 
             //on level type B
-            }else if(oneType=='B'){ //Delete unselected blocks
+            }else if(levelType=='B'){ //Delete unselected blocks
 
                 var minusBlocks = 0;
                 for(var i=0;i<numBlocks;i++){
@@ -902,7 +888,7 @@ var gameSquareOne = {
                 }
                 tractor.animations.play('right', 5, true);
 
-                if(oneLabel){ //Hiding labels
+                if(levelLabel){ //Hiding labels
                     blockLabel.visible = false;
                     blockSeparator.visible = false;
                 }
@@ -911,72 +897,77 @@ var gameSquareOne = {
 
     },
 
-    postScore: function (){
-
-        var lang_str = "pt_BR"; //TODO NAO esta pegando a lingua definida pelo usuario!
-        var aux;
+    func_postScore: function (){
+    
         // Get correct information about username and default language
-	// Variables 'username' and 'lang' is define on: js/menu.js
-	// Variable 'lang' has all the JSON content of 'assets/languages/pt_BR.json', 'lang.lang' defined in 'js/preMenu.js' (setLang())
-	// TODO: nao descobri esquema para pegar 'lang' (como 'pt_BR' ou 'en_US'), 'lang' esta' com o dicinario de lingua (definido em 'assets/languages/pt_BR.json').
-        if (name=='') name = username; //leo the correct is 'username'
+    	// Variables 'username' and 'lang' is define on: js/menu.js
+    	// Variable 'lang' has all the JSON content of 'assets/languages/pt_BR.json', 'lang.lang' defined in 'js/preMenu.js' (func_setLang())
+    	// TODO: nao descobri esquema para pegar 'lang' (como 'pt_BR' ou 'en_US'), 'lang' esta' com o dicinario de lingua (definido em 'assets/languages/pt_BR.json').
+        
+        //if (name=='') name = username; //leo the correct is 'username'
+        
         // assets/languages/pt_BR.json
 
         //DEBUG Testar 'lang'
-	/*
+        /*
+        
         var contact = "";
         if (typeof lang === 'object') {
           //contact = JSON.parse(lang);
           for (var i in lang) // will enumerate values of 'assets/languages/pt_BR.json'
              contact += lang[i];
-          // Finaliza com os valores de 'assets/languages/pt_BR.json': 'CARREGANDOFraçõesSELECIONE UM JOGODificuldadeNívelSELECINAR OPERAÇÃO E DIFICULDADEBom trabalho!Tente novamente!SELECIONAR IDIOMAMENU PRINCIPALVOLTARVER
-          // SOLUÇÃOCírculosQuadriláteroslegendaMODOCOMSEMDIGITE SEU NOMEPRONTOOláVocê deve selecionar uma porção menor que o seu tamanho totalVocê esqueceu de digitar seu nomeÁUDIO'
+          // Finaliza com os valores de 'assets/languages/pt_BR.json': 'CARREGANDOFraçõesSELECIONE UM JOGODificuldadeNívelSELECINAR OPERAÇÃO E DIFICULDADEBom trabalho!Tente novamente!SELECIONAR IDIOMAMENU PRINCIPALVOLTARVER
+          // SOLUÇÃOCírculosQuadriláteroslegendaMODOCOMSEMDIGITE SEU NOMEPRONTOOláVocê deve selecionar uma porção menor que o seu tamanho totalVocê esqueceu de digitar seu nome�UDIO'
           lang_str = contact; aux = 1;
-          }
-	else
-        // if (lang === 'undefined') lang_str = "pt_BR";
+            }
+            else
+            // if (lang === 'undefined') lang_str = "pt_BR";
+    
         */
 
-        var abst = "numBlocks:"+numBlocks+", valBlocks: " + detail+" blockIndex: " + blockIndex + ", floorIndex: " + floorIndex;
+        var abst = "numBlocks:" + numBlocks + ", valBlocks: " + detail + " blockIndex: " + blockIndex + ", floorIndex: " + floorIndex;
 
         var hr = new XMLHttpRequest();
+
         // Create some variables we need to send to our PHP file
         var url = "assets/cn/save.php";
-        var vars = "s_ip="+hip+"&s_name=" + name+"&s_lang=" + lang_str + "&s_game=" + oneShape + "&s_mode=" + oneType;
-        vars += "&s_oper=" + oneOperator + "&s_leve=" + oneDifficulty + "&s_posi=" + onePosition + "&s_resu=" + result + "&s_time=" + totalTime + "&s_deta=" + abst;
+        var vars = "s_ip=" + hip + "&s_name=" + username + "&s_lang=" + lang + "&s_game=" + levelShape + "&s_mode=" + levelType;
+
+        vars += "&s_oper=" + levelOperator + "&s_leve=" + levelDifficulty + "&s_posi=" + levelPosition + "&s_resu=" + result + "&s_time=" + totalTime + "&s_deta=" + abst;
 
         //D alert('/js/squareOne.js: url=' + url + '; aux=' + aux + ', lang_str=' + lang_str + ', lang=' + lang); //  + ', this.lang=" + this.lang
-        //D /js/squareOne.js: url=assets/cn/save.php; aux=1, lang_str=CARREGANDOFraçõesSELECIONE UM JOGODificuldadeNívelSELECINAR OPERAÇÃO E DIFICULDADEBom trabalho!Tente novamente!SELECIONAR IDIOMAMENU PRINCIPALVOLTARVER
-        //D SOLUÇÃOCírculosQuadriláteroslegendaMODOCOMSEMDIGITE SEU NOMEPRONTOOláVocê deve selecionar uma porção menor que o seu tamanho totalVocê esqueceu de digitar seu nomeÁUDIO, lang=[object Object]
+        //D /js/squareOne.js: url=assets/cn/save.php; aux=1, lang_str=CARREGANDOFraçõesSELECIONE UM JOGODificuldadeNívelSELECINAR OPERAÇÃO E DIFICULDADEBom trabalho!Tente novamente!SELECIONAR IDIOMAMENU PRINCIPALVOLTARVER
+        //D SOLUÇÃOCírculosQuadriláteroslegendaMODOCOMSEMDIGITE SEU NOMEPRONTOOláVocê deve selecionar uma porção menor que o seu tamanho totalVocê esqueceu de digitar seu nome�UDIO, lang=[object Object]
 
         // Sobre nome do usuario:
-	// * js/squareOne.js: name
-	// * js/pt_BR.json:   welcome="Ola'", insert_name="DIGITE SEU NOME"
-	// * assets/cn/save.php : $play = $_REQUEST["s_name"];
-	// * js/preMenu.js : insert_name, game.add.text(...), username = document.getElementById("name_id").value;
+    	// * js/squareOne.js: name
+    	// * js/pt_BR.json:   welcome="Ola'", insert_name="DIGITE SEU NOME"
+    	// * assets/cn/save.php : $play = $_REQUEST["s_name"];
+    	// * js/preMenu.js : insert_name, game.add.text(...), username = document.getElementById("name_id").value;
 
-	// Pegar valor de PHP para JS: echo("<script language='javascript'>location.href='download.php?arquivo=$nome_arquivo&dir=$dir&id_exer=$id_exer'</script>");
+    	// Pegar valor de PHP para JS: echo("<script language='javascript'>location.href='download.php?arquivo=$nome_arquivo&dir=$dir&id_exer=$id_exer'</script>");
 
         hr.open("POST", url, true);
         hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
         hr.onreadystatechange = function() {
-            if(debugmode) console.log(hr);
+            if(debugMode) console.log(hr);
+            
             if(hr.readyState == 4 && hr.status == 200) {
                 var return_data = hr.responseText;
-                if(debugmode) console.log(return_data);
+                if(debugMode) console.log(return_data);
             }
         }
         // Send the data to PHP now... and wait for response to update the status div
         hr.send(vars); // Actually execute the request
-        if(debugmode) console.log("processing...");
+        if(debugMode) console.log("processing...");
 
     },       
         
-    viewHelp: function(){
+    func_viewHelp: function(){
 
         if(!clicked){
             var pointer;
-            if(oneType=='A'){
+            if(levelType=='A'){
                 var pointer = game.add.image(endPosition, 490, 'pointer');
             }else{
                 var pointer = game.add.image(blocks.children[endIndex-1].x, blocks.children[endIndex-1].y-blockSize/2, 'pointer');
@@ -994,11 +985,6 @@ var gameSquareOne = {
 var endSquareOne = {
 
     create: function() {  
-        
-        // Creating sound variable
-        this.beepSound = game.add.audio('sound_beep');
-        this.okSound = game.add.audio('sound_ok');
-        this.errorSound = game.add.audio('sound_error');
 
         // Background
         game.add.image(0, 0, 'bgimage');
@@ -1019,12 +1005,12 @@ var endSquareOne = {
         }
         
         // Progress bar
-        for(var p=1;p<=5;p++){
-            var block = game.add.image(660+(p-1)*30, 10, 'block');
+        for(var p=0;p<5;p++){
+            var block = game.add.image(660+p*30, 10, 'block');
             block.scale.setTo(2, 1); //Scaling to double width
         }
         game.add.text(820, 10, '100%', styleMenu);
-        game.add.text(650, 10, lang.difficulty + ' ' + oneDifficulty, styleMenu).anchor.setTo(1,0);
+        game.add.text(650, 10, lang.difficulty + ' ' + levelDifficulty, styleMenu).anchor.setTo(1,0);
         game.add.image(660, 10, 'pgbar');
         
         //Farm and trees
@@ -1047,7 +1033,8 @@ var endSquareOne = {
         if(this.tractor.x<=700){
             this.tractor.x += 2;
         }else{
-            if(oneMenu){
+            if(levelMenu){
+            	passedLevels = 0;
                 game.state.start('menu');
             }else{
                 this.tractor.animations.stop();
@@ -1056,15 +1043,8 @@ var endSquareOne = {
 
     },
     
-    verPrincipal: function(){
+    func_verPrincipal: function(){
         game.state.start('welcome');
     },
-    
-    verMenu: function(){
-        if(oneMenu){
-            game.state.start('menu');
-        }
-
-    }     
 
 };

+ 150 - 166
js/squareTwo.js

@@ -1,8 +1,9 @@
 /*
+
     var menuSquareTwo = {
         create: function(){},
         ---------------------------- end of phaser functions
-        loadMap: function(){}
+        func_loadMap: function(){}
     };
 
     var mapSquareTwo = {
@@ -16,15 +17,15 @@
         create: function(){},
         update: function(){},
         ---------------------------- end of phaser functions
-        updateCounter: function(){},
-        overSquare: function(){},
-        outSquare: function(){},
-        clickSquare: function(){},
-            //setPlace: function(){},
-        postScore: function(){},
-            //viewHelp: function(){},
-            //checkOverlap: function(){}
-        getRndDivisor: function(){}
+        func_updateCounter: function(){},
+        func_overSquare: function(){},
+        func_outSquare: function(){},
+        func_clickSquare: function(){},
+            //func_setPlace: function(){},
+        func_postScore: function(){},
+            //func_viewHelp: function(){},
+            //func_checkOverlap: function(){}
+        func_getRndDivisor: function(){}
             
     };
 
@@ -32,10 +33,9 @@
         create: function(){},
         update: function(){},
         ---------------------------- end of phaser functions
-        verPrincipal: function(){},
-        verMenu: function(){}
+        func_verPrincipal: function(){},
     };
-        }
+        
 */
 
 // Fractions Comparison Square states
@@ -45,12 +45,9 @@
 var menuSquareTwo = {
 
     create: function() {
-        
-        // Creating sound variable
-        var beepSound = game.add.audio('sound_beep');
           
-        // Menu options
-        buttonSettings["addButtons"](1,1,
+        // Navigation buttons
+        buttonSettings["func_addButtons"](1,1,
                                     0,1,0,
                                     1,0,
                                     0,0);
@@ -60,7 +57,8 @@ var menuSquareTwo = {
         var title = game.add.text(game.world.centerX, 40, lang.game_menu_title, style);
         title.anchor.setTo(0.5, 0.5);
         
-        //Showing Games and Levels
+        //SETTING DIFFICULTY LEVELS
+
         var maxHeight = 120;  //Max height of a stair
         var stairHeight = 29; //height growth of a stair
         var stairWidth = 80;  //Width of a stair
@@ -68,13 +66,15 @@ var menuSquareTwo = {
         var startSymbol = 150;
         var startSquare = (startSymbol/2)+startStair+stairWidth*5;
         
-        var bplus = game.add.sprite(startSymbol, 300, 'equal');
-            bplus.frame = 0;
-            bplus.scale.setTo(0.7);
-            bplus.anchor.setTo(0.5,0.5);
+        var equalsIcon = game.add.sprite(startSymbol, 300, 'equal');
+            equalsIcon.frame = 0;
+            equalsIcon.scale.setTo(0.7);
+            equalsIcon.anchor.setTo(0.5,0.5);
             
-        //First stairs, 6 levels
-        var stairsA = [];
+        //First stairs, More divisions to less divisions 1, 5 levels
+
+        var stairsMoreToLess1 = [];
+
         for(var i=1;i<=5;i++){
             //stair
             var x1 = startStair+(stairWidth*(i-1));
@@ -82,18 +82,19 @@ var menuSquareTwo = {
             var x2 = stairWidth;//x1 + 40;
             var y2 = stairHeight*i;//y1 + 24;
             
-            stairsA[i] = game.add.graphics(0, 0);
-            stairsA[i].lineStyle(1, 0xFFFFFF, 1);
-            stairsA[i].beginFill(0x99b3ff);
-            stairsA[i].drawRect(x1, y1, x2, y2);
-            stairsA[i].endFill();
+            stairsMoreToLess1[i] = game.add.graphics(0, 0);
+            stairsMoreToLess1[i].lineStyle(1, 0xFFFFFF, 1);
+            stairsMoreToLess1[i].beginFill(0x99b3ff);
+            stairsMoreToLess1[i].drawRect(x1, y1, x2, y2);
+            stairsMoreToLess1[i].endFill();
             
             //event
-            stairsA[i].inputEnabled = true;
-            stairsA[i].input.useHandCursor = true;
-            stairsA[i].events.onInputDown.add(this.loadMap, {beep: beepSound, difficulty: i, type: 'A' });
-            stairsA[i].events.onInputOver.add(function (item) { item.alpha=0.5; }, this);
-            stairsA[i].events.onInputOut.add(function (item) { item.alpha=1; }, this);
+            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.onInputOver.add(function (item) { item.alpha=0.5; }, this);
+            stairsMoreToLess1[i].events.onInputOut.add(function (item) { item.alpha=1; }, this);
+            
             //label
             var xl = x1+stairWidth/2; //x label
             var yl = y1+(stairHeight*i)/2; //y label
@@ -101,8 +102,10 @@ var menuSquareTwo = {
                 label.anchor.setTo(0.5, 0.4);
         }
 
-        //second stairs        
-        var stairsB = [];
+        //Second stairs, More divisions to less divisions 2, 5 levels
+
+        var stairsMoreToLess2 = [];
+
         for(var i=1;i<=5;i++){
             //stair
             var x1 = startStair+(stairWidth*(i-1));
@@ -110,18 +113,19 @@ var menuSquareTwo = {
             var x2 = stairWidth;//x1 + 40;
             var y2 = stairHeight*i;//y1 + 24;
             
-            stairsB[i] = game.add.graphics(0, 0);
-            stairsB[i].lineStyle(1, 0xFFFFFF, 1);
-            stairsB[i].beginFill(0xff6666);
-            stairsB[i].drawRect(x1, y1, x2, y2);
-            stairsB[i].endFill();
+            stairsMoreToLess2[i] = game.add.graphics(0, 0);
+            stairsMoreToLess2[i].lineStyle(1, 0xFFFFFF, 1);
+            stairsMoreToLess2[i].beginFill(0xff6666);
+            stairsMoreToLess2[i].drawRect(x1, y1, x2, y2);
+            stairsMoreToLess2[i].endFill();
             
             //event
-            stairsB[i].inputEnabled = true;
-            stairsB[i].input.useHandCursor = true;
-            stairsB[i].events.onInputDown.add(this.loadMap, {beep: beepSound, difficulty: i, type: 'B' });
-            stairsB[i].events.onInputOver.add(function (item) { item.alpha=0.5; }, this);
-            stairsB[i].events.onInputOut.add(function (item) { item.alpha=1; }, this);
+            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.onInputOver.add(function (item) { item.alpha=0.5; }, this);
+            stairsMoreToLess2[i].events.onInputOut.add(function (item) { item.alpha=1; }, this);
+            
             //label
             var xl = x1+stairWidth/2; //x label
             var yl = y1+(stairHeight*i)/2; //y label
@@ -129,8 +133,10 @@ var menuSquareTwo = {
                 label.anchor.setTo(0.5, 0.4);
         } 
         
-        //third stair        
-        var stairsC = [];
+        //Third stairs, Less divisions to more divisions, 5 levels
+
+        var stairsLessToMore = [];
+
         for(var i=1;i<=5;i++){
             //stair
             var x1 = startStair+(stairWidth*(i-1));
@@ -138,18 +144,19 @@ var menuSquareTwo = {
             var x2 = stairWidth;//x1 + 40;
             var y2 = stairHeight*i;//y1 + 24;
             
-            stairsC[i] = game.add.graphics(0, 0);
-            stairsC[i].lineStyle(1, 0xFFFFFF, 1);
-            stairsC[i].beginFill(0xb366ff);
-            stairsC[i].drawRect(x1, y1, x2, y2);
-            stairsC[i].endFill();
+            stairsLessToMore[i] = game.add.graphics(0, 0);
+            stairsLessToMore[i].lineStyle(1, 0xFFFFFF, 1);
+            stairsLessToMore[i].beginFill(0xb366ff);
+            stairsLessToMore[i].drawRect(x1, y1, x2, y2);
+            stairsLessToMore[i].endFill();
             
             //event
-            stairsC[i].inputEnabled = true;
-            stairsC[i].input.useHandCursor = true;
-            stairsC[i].events.onInputDown.add(this.loadMap, {beep: beepSound, difficulty: i, type: 'C' });
-            stairsC[i].events.onInputOver.add(function (item) { item.alpha=0.5; }, this);
-            stairsC[i].events.onInputOut.add(function (item) { item.alpha=1; }, this);
+            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.onInputOver.add(function (item) { item.alpha=0.5; }, this);
+            stairsLessToMore[i].events.onInputOut.add(function (item) { item.alpha=1; }, this);
+            
             //label
             var xl = x1+stairWidth/2; //x label
             var yl = y1+(stairHeight*i)/2; //y label
@@ -160,20 +167,19 @@ var menuSquareTwo = {
     },
         
     //MapLoading function
-    loadMap: function(){
+    func_loadMap: function(){
 
         if(audioStatus){
             this.beep.play();
         }
-        twoPosition = 0; //Map position
-        twoMove = true; //Move no next point
-        twoDifficulty  = this.difficulty; //Number of difficulty (1 to 5)
-        twoType = this.type; //Operator of game
-        if(twoPosition<5){
-            game.state.start('mapSTwo');
-        }else{
-            game.state.start('unofinal');
-        }
+
+        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;
+
+        game.state.start('mapSTwo');
 
     },
     
@@ -184,15 +190,12 @@ var menuSquareTwo = {
 var mapSquareTwo={
 
     create: function() {
-                
-        // Creating sound variable
-        beepSound = game.add.audio('sound_beep');
 
         // Background
         game.add.image(0, 40, 'bgmap');
         
-        // Menu options
-        buttonSettings["addButtons"](1,0,
+        // Navigation buttons
+        buttonSettings["func_addButtons"](1,0,
                                     1,1,0,
                                     0,0,
                                     "menuSTwo",0);
@@ -202,14 +205,15 @@ var mapSquareTwo={
         var styleMenu = { font: '30px Arial', fill: '#000000', align: 'center'};
         
         // Progress bar
-        var percentText = onePosition*20;
-        var percentBlocks = onePosition;
-        for(var p=1;p<=percentBlocks;p++){
-            var block = game.add.image(660+(p-1)*30, 10, 'block');
-            block.scale.setTo(2, 1); //Scaling to double width
+        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 + ' ' + oneDifficulty, styleMenu).anchor.setTo(1,0);
+        game.add.text(650, 10, lang.difficulty + ' ' + levelDifficulty, styleMenu).anchor.setTo(1,0);
         game.add.image(660, 10, 'pgbar');
         
          //Road
@@ -260,9 +264,9 @@ var mapSquareTwo={
         // places
         for (var p = 1; p < this.points.x.length -1; p++){
             var place;
-            if(p<twoPosition)
+            if(p<levelPosition)
                 place = game.add.image(this.points.x[p], this.points.y[p], 'place_b');
-            else if (twoMove && p==twoPosition)
+            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');
@@ -278,7 +282,7 @@ var mapSquareTwo={
         }
 
         // Kid start position
-        this.kid = game.add.sprite(this.points.x[twoPosition], this.points.y[twoPosition], 'kid_run');
+        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);
@@ -298,27 +302,27 @@ var mapSquareTwo={
         if(this.count<=this.wait) return;
         
         // If movement is stopped or position is 5 (final), load game
-        if(twoPosition==5){
-            twoMove = false;
+        if(levelPosition==5){
+            levelMove = false;
         }
         
-        if(!twoMove){
+        if(!levelMove){
             this.loadGame();
         }
         
         // If momevent is enabled, move to next point from actual
-        if(twoMove){
+        if(levelMove){
             game.physics.arcade.moveToXY(
                 this.kid, 
-                this.points.x[twoPosition+1],
-                this.points.y[twoPosition+1],
+                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[twoPosition+1] || Math.ceil(this.kid.y)==this.points.y[twoPosition+1]){
-                twoMove=false;
-                twoPosition += 1; //Update position
+            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
             }
         }
 
@@ -330,22 +334,17 @@ var mapSquareTwo={
         if(audioStatus){
            beepSound.play();
         }
-        if(twoPosition<5){
+        if(levelPosition<5){
             game.state.start('gameSTwo');
         }else{
             game.state.start('endSTwo');
         }
 
     }
+
 };
 
 /****************************** GAME ****************************/
-var sizeA, sizeB, valueA, valueB;
-var clickA, clickB, animateA, animateB, result, animate, cDelay, eDelay;
-var blocksA, blocksB, auxblqA, auxblqB;
-var labelA, fractionA, separatorA, labelB, fractionB, separatorB;
-var kid, kidDirection, equals, counter, endCounter;
-var xA, yA, xB, yB, blockW, blockH;
 
 var gameSquareTwo = {
 
@@ -354,21 +353,16 @@ var gameSquareTwo = {
         //timer
         totalTime = 0;
         timer = game.time.create(false);
-        timer.loop(1000, this.updateCounter, this);
+        timer.loop(1000, this.func_updateCounter, this);
         timer.start();        
         
         points = [2,4,6,8,9,10,12,14,15,16,18,20];
-        
-        // Creating sound variable
-        beepSound = game.add.audio('sound_beep');
-        okSound = game.add.audio('sound_ok');
-        errorSound = game.add.audio('sound_error');
 
         // Background
         game.add.image(0, 0, 'bgimage');
         
-        // Menu options
-        buttonSettings["addButtons"](1,1,
+        // Navigation buttons
+        buttonSettings["func_addButtons"](1,1,
                                     1,1,0,
                                     1,0,
                                     "menuSTwo", 0);
@@ -415,19 +409,19 @@ var gameSquareTwo = {
         animate = null; //Final animation sequence
         
         //generator
-        if(debugmode) console.log("----------");
-        if(debugmode) console.log("Diff " + twoDifficulty + ", ini " + ((twoDifficulty-1)*2+1) + ", end " + ((twoDifficulty-1)*2+3));
+        if(debugMode) console.log("----------");
+        if(debugMode) console.log("Diff " + levelDifficulty + ", ini " + ((levelDifficulty-1)*2+1) + ", end " + ((levelDifficulty-1)*2+3));
         
-        var rPoint = game.rnd.integerInRange((twoDifficulty-1)*2+1,(twoDifficulty-1)*2+3);
+        var rPoint = game.rnd.integerInRange((levelDifficulty-1)*2+1,(levelDifficulty-1)*2+3);
         sizeA = points[rPoint];
         
-        if(debugmode) console.log("Rpoint " + rPoint + ", val " + sizeA);
+        if(debugMode) console.log("Rpoint " + rPoint + ", val " + sizeA);
         
-        sizeB =  this.getRndDivisor(sizeA);
+        sizeB =  this.func_getRndDivisor(sizeA);
         blockB = game.rnd.integerInRange(1, sizeB);
         blockA = (sizeA/sizeB) * blockB;
         
-        if(debugmode) console.log("SA " + sizeA + ", SB " + sizeB + ", BA " + blockA + ", BB " + blockB );
+        if(debugMode) console.log("SA " + sizeA + ", SB " + sizeB + ", BA " + blockA + ", BB " + blockB );
         
         //Blocks and fractions group
         blocksA = game.add.group(); //Main blocks A
@@ -438,7 +432,7 @@ var gameSquareTwo = {
          //Creating blocks
         blockW = 400;
         blockH = 50;
-        if(twoType!="C"){
+        if(levelType!="C"){
             xA=230, yA=90;
             xB=xA, yB=yA+3*blockH+30;
         }else{
@@ -453,7 +447,7 @@ var gameSquareTwo = {
         var fillColorS = 0xe0ebeb;
         
         for(var i=0; i<sizeA; i++){
-            //if(debugmode) console.log("Block A"+i+": x:"+(xA+i*widthA)+", y:"+yA);
+            //if(debugMode) console.log("Block A"+i+": x:"+(xA+i*widthA)+", y:"+yA);
                         
             var block = game.add.graphics(xA+i*widthA, yA);
                 block.anchor.setTo(0.5, 0.5);
@@ -465,22 +459,22 @@ var gameSquareTwo = {
 
                 block.inputEnabled = true;
                 block.input.useHandCursor = true;
-                block.events.onInputDown.add(this.clickSquare, {who: 'A',indice: i});
-                block.events.onInputOver.add(this.overSquare, {who: 'A',indice: i});
-                block.events.onInputOut.add(this.outSquare, {who: 'A',indice: i});
+                block.events.onInputDown.add(this.func_clickSquare, {who: 'A',indice: i});
+                block.events.onInputOver.add(this.func_overSquare, {who: 'A',indice: i});
+                block.events.onInputOut.add(this.func_outSquare, {who: 'A',indice: i});
             
             blocksA.add(block);
             
             //aux blocks
             var xAux = xA+i*widthA, yAux = yA+blockH+10;
-            if(twoType == 'C') yAux = yA;
+            if(levelType == '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(twoType!='A') block.alpha = 0;
+                if(levelType!='A') block.alpha = 0;
                 else block.alpha = 0.2;
                     
             auxblqA.add(block);
@@ -521,21 +515,21 @@ var gameSquareTwo = {
             
                 block.inputEnabled = true;
                 block.input.useHandCursor = true;
-                block.events.onInputDown.add(this.clickSquare, {who: 'B',indice: i});
-                block.events.onInputOver.add(this.overSquare, {who: 'B',indice: i});
-                block.events.onInputOut.add(this.outSquare, {who: 'B',indice: i});
+                block.events.onInputDown.add(this.func_clickSquare, {who: 'B',indice: i});
+                block.events.onInputOver.add(this.func_overSquare, {who: 'B',indice: i});
+                block.events.onInputOut.add(this.func_outSquare, {who: 'B',indice: i});
 
             blocksB.add(block);
             //aux blocks
             var xAux = xB+i*widthB, yAux = yB+blockH+10;
-            if(twoType == 'C') yAux = yB;
+            if(levelType == '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(twoType!='A') block.alpha = 0;
+                if(levelType!='A') block.alpha = 0;
                 else block.alpha = 0.2;
             auxblqB.add(block);
             
@@ -579,10 +573,8 @@ var gameSquareTwo = {
 
     },
     
-    update: function() 
-    {
-    	if (game.physics.arcade.distanceToPointer(kid, game.input.activePointer) > 20 )
-	    {	
+    update: function() {
+    	if (game.physics.arcade.distanceToPointer(kid, game.input.activePointer) > 20 ){	
     		    		
         	var xPos = game.input.mousePointer.x;
         	
@@ -640,23 +632,26 @@ var gameSquareTwo = {
                 //fractions are equivalent : correct
                 if((valueA/sizeA) == (valueB/sizeB)){
                     result = true;
-                    twoMove = true;
+                    levelMove = true;
                     if(audioStatus){
                         okSound.play();
                     }
                     kid.animations.stop();
+
+                    passedLevels++;        
+                    if(debugMode) console.log("passedLevels = " + passedLevels); 
                     okImg.alpha = 1;
                 //fractions are not equivalent
                 }else{
                     result = false;
-                    twoMove = false;
+                    levelMove = false;
                     if(audioStatus){
                         errorSound.play();
                     }
                     kid.animations.stop();
                     errorImg.alpha = 1;
                 }
-                this.postScore();
+                this.func_postScore();
                 clickA = false;
                 clickB = false;
                 animate = true;
@@ -666,9 +661,9 @@ var gameSquareTwo = {
         if(animate){
             counter++;
             if(result){
-//              kid.x += 2;
-//            	kidDirection='right';
-//				kid.animations.play('right', 8, true);
+				// kid.x += 2;
+				// kidDirection='right';
+				// kid.animations.play('right', 8, true);
             }
             if(counter>endCounter){
                 game.state.start('mapSTwo');
@@ -677,11 +672,11 @@ var gameSquareTwo = {
 
     },
 
-    updateCounter: function() {
+    func_updateCounter: function() {
         totalTime++;
     },
     
-    overSquare: function(){
+    func_overSquare: function(){
 
         if(!clickA && this.who=="A"){
             if(this.indice == sizeA-1){
@@ -735,7 +730,7 @@ var gameSquareTwo = {
 
     },
 
-    outSquare: function(){
+    func_outSquare: function(){
 
         if(!clickA && this.who=="A"){
             for(var i=0;i<=this.indice;i++){
@@ -752,7 +747,7 @@ var gameSquareTwo = {
 
     },
     
-    clickSquare: function(){
+    func_clickSquare: function(){
 
         if(!clickA && this.who=="A" && this.indice!=sizeA-1){
             for(var i=0;i<sizeA;i++){
@@ -798,35 +793,35 @@ var gameSquareTwo = {
 
     },
     
-    postScore: function (){
+    func_postScore: function (){
+    
+        var abst = "numBlocksA:" + sizeA + ", valueA: " + valueA +", numBlocksB: " + sizeB + ", valueB: " + valueB;
         
-        var abst = "numBlocksA:"+sizeA+", valueA: " + valueA +", numBlocksB: " + sizeB + ", valueB: " + valueB;
-
-        var lang_str = "pt_BR"; //TODO NAO esta pegando a lingua definida pelo usuario!
         var hr = new XMLHttpRequest();
         // Create some variables we need to send to our PHP file
         var url = "assets/cn/save.php";
-        var vars = "s_ip="+hip+"&s_name=" + username + "&s_lang=" + lang_str + "&s_game=" + twoShape + "&s_mode=" + twoType;
-        vars += "&s_oper=Equal&s_leve=" + twoDifficulty + "&s_posi=" + twoPosition + "&s_resu=" + result + "&s_time=" + totalTime + "&s_deta=" + abst;
+        var vars = "s_ip="+hip+"&s_name=" + username + "&s_lang=" + lang + "&s_game=" + levelShape + "&s_mode=" + levelType;
+
+        vars += "&s_oper=Equal&s_leve=" + levelDifficulty + "&s_posi=" + levelPosition + "&s_resu=" + result + "&s_time=" + totalTime + "&s_deta=" + abst;
         
         hr.open("POST", url, true);
         hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
         hr.onreadystatechange = function() {
-            if(debugmode) console.log(hr);
+            if(debugMode) console.log(hr);
 
             if(hr.readyState == 4 && hr.status == 200) {
                 var return_data = hr.responseText;
-                if(debugmode) console.log(return_data);
+                if(debugMode) console.log(return_data);
             }
         }
         // Send the data to PHP now... and wait for response to update the status div
         hr.send(vars); // Actually execute the request
-        if(debugmode) console.log("processing...");
-
+        if(debugMode) console.log("processing...");
+    
     },
 
     //Calculation help functions
-    getRndDivisor: function(number){ //Get random divisor for a number
+    func_getRndDivisor: function(number){ //Get random divisor for a number
 
         var div = []; //Divisors found
         var p = 0; //current dividor index
@@ -848,11 +843,6 @@ var gameSquareTwo = {
 var endSquareTwo = {
 
     create: function() {  
-        
-        // Creating sound variable
-        beepSound = game.add.audio('sound_beep');
-        okSound = game.add.audio('sound_ok');
-        errorSound = game.add.audio('sound_error');
 
         // Background
         game.add.image(0, 0, 'bgimage');
@@ -878,7 +868,7 @@ var endSquareTwo = {
             block.scale.setTo(2, 1); //Scaling to double width
         }
         game.add.text(820, 10, '100%', styleMenu);
-        game.add.text(650, 10, lang.difficulty + ' ' + oneDifficulty, styleMenu).anchor.setTo(1,0);
+        game.add.text(650, 10, lang.difficulty + ' ' + levelDifficulty, styleMenu).anchor.setTo(1,0);
         game.add.image(660, 10, 'pgbar');
         
         //School and trees
@@ -900,7 +890,8 @@ var endSquareTwo = {
         if(this.kid.x<=700){
             this.kid.x += 2;
         }else{
-            if(twoMenu){
+            if(levelMenu){            	
+            	passedLevels = 0;
                 game.state.start('menu');
             }else{
                 this.kid.animations.stop();
@@ -909,15 +900,8 @@ var endSquareTwo = {
 
     },
     
-    verPrincipal: function(){
+    func_verPrincipal: function(){
         game.state.start('welcome');
     },
-    
-    verMenu: function(){
-
-        if(twoMenu){
-            game.state.start('menu');
-        }
-
-    }               
+          
 };