// Fractions Comparison Square states /****************************** MENU ****************************/ var menuSquareTwo={ create: function() { // Creating sound variable var beepSound = game.add.audio('sound_beep'); // Reading dictionary var words = game.cache.getJSON('dictionary'); // Menu options //information label m_info = game.add.text(14, 53, "", { font: "20px Arial", fill: "#330000", align: "center" }); // Return to language button m_world = game.add.sprite(10, 10, 'world'); m_world.inputEnabled = true; m_world.input.useHandCursor = true; m_world.events.onInputDown.add(this.loadState, {state: "boot", beep: beepSound}); m_world.events.onInputOver.add(this.showOption, {message: words.menu_world}); m_world.events.onInputOut.add(this.showOption, {message: ""}); // Return to menu button m_list = game.add.sprite(60, 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(this.showOption, {message: words.menu_list}); m_list.events.onInputOut.add(this.showOption, {message: ""}); // Setting title var style = { font: '28px Arial', fill: '#00804d'}; var title = game.add.text(860, 40, words.game_menu_title, style); title.anchor.setTo(1, 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); } 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); } 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, showOption: function(){ m_info.text = this.message; }, loadState: function(){ this.beep.play(); game.state.start(this.state); }, //MapLoading function loadMap: function(){ 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'); // Reading dictionary var words = game.cache.getJSON('dictionary'); // Background game.add.image(0, 40, 'bgmap'); if(oneMenu){ // Menu options //information label m_info = game.add.text(14, 53, "", { font: "20px Arial", fill: "#330000", align: "center" }); // Return to language button m_world = game.add.sprite(10, 10, 'world'); m_world.inputEnabled = true; m_world.input.useHandCursor = true; m_world.events.onInputDown.add(this.loadState, {state: "boot", beep: beepSound}); m_world.events.onInputOver.add(this.showOption, {message: words.menu_world}); m_world.events.onInputOut.add(this.showOption, {message: ""}); // Return to menu button m_list = game.add.sprite(60, 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(this.showOption, {message: words.menu_list}); m_list.events.onInputOut.add(this.showOption, {message: ""}); // Return to diffculty m_back = game.add.sprite(110, 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(this.showOption, {message: words.menu_back}); m_back.events.onInputOut.add(this.showOption, {message: ""}); } // 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, words.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 ] }; //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(animateA){ //If clicked A only, animate for(var i=0;i=auxblqA.children[0].y){ animateA = false; fractionA.alpha = 1; fractionA.setText(valueA+"\n"+sizeA); separatorA.alpha = 1; } } if(animateB){ //If clicked B only, animate for(var i=0;i=auxblqB.children[0].y){ animateB = false; fractionB.alpha = 1; fractionB.setText(valueB+"\n"+sizeB); separatorB.alpha = 1; } } if(clickA && clickB && !this.animate){ //Check result timer.stop(); cDelay++; if(cDelay>=eDelay){ if((valueA/sizeA) == (valueB/sizeB)){ result = true; twoMove = true; okSound.play(); okImg.alpha = 1; }else{ result = false; twoMove = false; 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'); } } }, //Navigation functions, showOption: function(){ m_info.text = this.message; }, loadState: function(){ this.beep.play(); game.state.start(this.state); }, //MapLoading function loadGame: function(){ beepSound.play(); if(onePosition<5){ game.state.start('gameSOne'); }else{ game.state.start('endSOne'); } }, //Calculation help functions getRndDivisor: function(number){ //Get random divisor for a number var div = []; //Divisors found var p = 0; //current dividor index for(var i=2; i