/* var menuSquareTwo = { create: function(){}, ---------------------------- end of phaser functions loadState: function(){}, loadMap: function(){} }; var mapSquareTwo = { create: function(){}, update: function(){}, ---------------------------- end of phaser functions loadState: function(){}, loadGame: function() }; var gameSquareTwo = { create: function(){}, loadGame: function(){}, ---------------------------- end of phaser functions updateCounter: function(){}, overSquare: function(){}, outSquare: function(){}, clickSquare: function(){}, //setPlace: function(){}, postScore: function(){}, update: function(){}, loadState: function(){}, //viewHelp: function(){}, //checkOverlap: function(){} getRndDivisor: function(){} }; var endSquareTwo = { create: function(){}, update: function(){}, ---------------------------- end of phaser functions verPrincipal: function(){}, verMenu: function(){} }; } */ // Fractions Comparison Square states /****************************** MENU ****************************/ var menuSquareTwo = { create: function() { // Creating sound variable var beepSound = game.add.audio('sound_beep'); // Menu options //information label m_info_left = game.add.text(14, 53, "", { font: "20px Arial", fill: "#330000", align: "center" }); m_info_right = game.add.text(game.world.width - 10, 53, "", { font: "20px Arial", fill: "#330000", align: "right" }); m_info_right.anchor.setTo(1,0.02); // Return to menu button m_list = game.add.sprite(10, 10, 'list'); m_list.inputEnabled = true; m_list.input.useHandCursor = true; m_list.events.onInputDown.add(this.loadState, {state: "menu", beep: beepSound}); m_list.events.onInputOver.add(function(){ this.m_info_left.text = lang.menu_list}); m_list.events.onInputOut.add(function(){ this.m_info_left.text = ""}); // Return to diffculty m_back = game.add.sprite(60, 10, 'back'); m_back.inputEnabled = true; m_back.input.useHandCursor = true; m_back.events.onInputDown.add(this.loadState, {state: "menuSTwo", beep: beepSound}); m_back.events.onInputOver.add(function(){ this.m_info_left.text = lang.menu_back}); m_back.events.onInputOut.add(function(){ this.m_info_left.text = ""}); // Return to language button m_world = game.add.sprite(game.world.width - 120, 10, 'world'); m_world.inputEnabled = true; m_world.input.useHandCursor = true; m_world.events.onInputDown.add(this.loadState, {state: "language", beep: beepSound}); m_world.events.onInputOver.add(function(){ this.m_info_right.text = lang.menu_world }); m_world.events.onInputOut.add(function(){ this.m_info_right.text = "" }); // change audio status button m_audio = game.add.sprite(game.world.width - 60, 10, 'audio'); audioStatus ? m_audio.frame = 0 : m_audio.frame = 1; m_audio.inputEnabled = true; m_audio.input.useHandCursor = true; m_audio.events.onInputDown.add(function(){ if(audioStatus){ audioStatus=false; m_audio.frame = 1; }else{ audioStatus=true; m_audio.frame = 0; }}); m_audio.events.onInputOver.add(function(){ this.m_info_right.text = lang.audio }); m_audio.events.onInputOut.add(function(){ this.m_info_right.text = "" }); // Setting 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 var maxHeight = 120; //Max height of a stair var stairHeight = 29; //height growth of a stair var stairWidth = 80; //Width of a stair var startStair = 240; 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); //First stairs, 6 levels var stairsA = []; for(var i=1;i<=5;i++){ //stair var x1 = startStair+(stairWidth*(i-1)); var y1 = 100+maxHeight-i*stairHeight; 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(); //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); //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); } //second stairs var stairsB = []; for(var i=1;i<=5;i++){ //stair var x1 = startStair+(stairWidth*(i-1)); var y1 = 270+maxHeight-i*stairHeight; 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(); //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); //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); } //third stair var stairsC = []; for(var i=1;i<=5;i++){ //stair var x1 = startStair+(stairWidth*(i-1)); var y1 = 440+maxHeight-i*stairHeight; 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(); //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); //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); } }, //Navigation functions, loadState: function(){ if(audioStatus){ this.beep.play(); } game.state.start(this.state); }, //MapLoading function 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'); } }, }; /****************************** MAP ****************************/ var mapSquareTwo={ create: function() { // Creating sound variable beepSound = game.add.audio('sound_beep'); // Background game.add.image(0, 40, 'bgmap'); // Menu options //information label m_info_left = game.add.text(14, 53, "", { font: "20px Arial", fill: "#330000", align: "center" }); if(twoMenu){ // Return to menu button m_list = game.add.sprite(10, 10, 'list'); m_list.inputEnabled = true; m_list.input.useHandCursor = true; m_list.events.onInputDown.add(this.loadState, {state: "menu", beep: beepSound}); m_list.events.onInputOver.add(function(){ this.m_info_left.text = lang.menu_list}); m_list.events.onInputOut.add(function(){ this.m_info_left.text = ""}); // Return to diffculty m_back = game.add.sprite(60, 10, 'back'); m_back.inputEnabled = true; m_back.input.useHandCursor = true; m_back.events.onInputDown.add(this.loadState, {state: "menuSTwo", beep: beepSound}); m_back.events.onInputOver.add(function(){ this.m_info_left.text = lang.menu_back}); m_back.events.onInputOut.add(function(){ this.m_info_left.text = ""}); } // Styles for labels var stylePlace = { font: '26px Arial', fill: '#ffffff', align: 'center'}; var styleMenu = { font: '30px Arial', fill: '#000000', align: 'center'}; // Progress bar var percentText = onePosition*20; var percentBlocks = onePosition; for(var p=1;p<=percentBlocks;p++){ var block = game.add.image(680+(p-1)*30, 10, 'block'); block.scale.setTo(2, 1); //Scaling to double width } game.add.text(840, 10, percentText+'%', styleMenu); game.add.text(670, 10, lang.difficulty + ' ' + oneDifficulty, styleMenu).anchor.setTo(1,0); game.add.image(680, 10, 'pgbar'); //Road this.points = { 'x': [ 90, 204, 318, 432, 546, 660 ], 'y': [ 486, 422, 358, 294, 230, 166 ] }; //House var house = game.add.image(this.points.x[0], this.points.y[0], 'house'); house.scale.setTo(0.7); house.anchor.setTo(0.7, 0.8); //School var school = game.add.image(this.points.x[5], this.points.y[5], 'school'); school.scale.setTo(0.35); school.anchor.setTo(0.2, 0.7); //Trees and Rocks this.rocks = { 'x': [156, 275, 276, 441, 452, 590, 712], 'y': [309, 543, 259, 156, 419, 136, 316] } this.r_types = [1, 1, 2, 1, 2, 2, 2]; for(var i=0; i0 && p=800){ kidDirection='left'; kid.animations.play('left', 8, true); } }else{ kid.x -= 1; if(kid.x<=100){ kidDirection='right'; kid.animations.play('right', 8, true); } } } //If clicked A only, animate if(animateA){ for(var i=0;i=auxblqA.children[0].y){ animateA = false; fractionA.alpha = 1; fractionA.setText(valueA+"\n"+sizeA); separatorA.alpha = 1; } } //If clicked B only, animate if(animateB){ for(var i=0;i=auxblqB.children[0].y){ animateB = false; fractionB.alpha = 1; fractionB.setText(valueB+"\n"+sizeB); separatorB.alpha = 1; } } //if clicked A and B if(clickA && clickB && !this.animate){ //Check result timer.stop(); cDelay++; if(cDelay>=eDelay){ //fractions are equivalent : correct if((valueA/sizeA) == (valueB/sizeB)){ result = true; twoMove = true; if(audioStatus){ okSound.play(); } okImg.alpha = 1; //fractions are not equivalent }else{ result = false; twoMove = false; if(audioStatus){ errorSound.play(); } kid.animations.stop(); errorImg.alpha = 1; } this.postScore(); clickA = false; clickB = false; animate = true; } } if(animate){ counter++; if(result){ kid.x += 2; kidDirection='right'; kid.animations.play('right', 8, true); } if(counter>endCounter){ game.state.start('mapSTwo'); } } }, updateCounter: function() { totalTime++; }, overSquare: function(){ if(!clickA && this.who=="A"){ if(this.indice == sizeA-1){ if(yA==90){ errorTextA.setText(lang.error_msg); errorTextB.setText(""); }else{ errorTextA.setText(""); errorTextB.setText(lang.error_msg); } }else{ errorTextA.setText(""); errorTextB.setText(""); for(var i=0;i