/* let gameSquareTwo = { create: function(){}, update: function(){}, ---------------------------- end of phaser functions 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(){} }; */ // Fractions Comparison Square states let gameSquareTwo = { create: function() { //timer totalTime = 0; timer = game.time.create(false); timer.loop(1000, this.func_updateCounter, this); timer.start(); points = [2,4,6,8,9,10,12,14,15,16,18,20]; // Background game.add.image(0, 0, 'bgimage'); // Calls function that loads navigation icons iconSettings["func_addButtons"](true,true, true,true,false, true,false, 'difficulty', false); //Clouds game.add.image(300, 100, 'cloud'); game.add.image(660, 80, 'cloud'); game.add.image(110, 85, 'cloud').scale.setTo(0.8); // Styles for labels let stylePlace = { font: '26px Arial', fill: '#400080', align: 'center'}; let styleLabel = { font: '26px Arial', fill: '#000080', align: 'center'}; let styleFraction = { font: '20px Arial', fill: '#000080', align: 'center'}; let styleMenu = { font: '30px Arial', fill: '#000000', align: 'center'}; //Floor for(let i=0;i<9;i++){ game.add.image(i*100, 501, 'floor'); } //kid kid = game.add.sprite(100, 470, 'kid_lost'); kid.anchor.setTo(0.5, 0.7); kid.scale.setTo(0.8); //kid.animations.add('right',[0,1,2,3,4,5,6,7,8,9,10,11]); //kid.animations.add('left',[23,22,21,20,19,18,17,16,15,14,13,12]); kid.animations.add('front', [3,4,5]) kidDirection = 'front'; kidLeftLimit = 100; kidRightLimit = 800; kid.animations.play('front', 6, true); //Control variables sizeA = 0; //Size of first block sizeB = 0; //Size of second block valueA = 0; //Number of clicked blocks for a valueB = 0; //Number of clicked blocks for b clickA = false; //If block A is clicked clickB = false; //If block B is clicked animateA = false; //Animate A selected blocks to position animateB = false; //Animate B selected blocks to position result = false; //Game is correct animate = null; //Final animation sequence //generator if(debugMode) console.log("----------"); if(debugMode) console.log("Diff " + levelDifficulty + ", ini " + ((levelDifficulty-1)*2+1) + ", end " + ((levelDifficulty-1)*2+3)); let rPoint = game.rnd.integerInRange((levelDifficulty-1)*2+1,(levelDifficulty-1)*2+3); sizeA = points[rPoint]; if(debugMode) console.log("Rpoint " + rPoint + ", val " + 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 ); //Blocks and fractions group blocksA = game.add.group(); //Main blocks A blocksB = game.add.group(); //Main blocks B auxblqA = game.add.group(); //Auxiliar blocks A auxblqB = game.add.group(); //Auxiliar blocks B //Creating blocks blockW = 400; blockH = 50; if(levelOperator!="C"){ xA=230, yA=90; xB=xA, yB=yA+3*blockH+30; }else{ xB=230, yB=90; xA=xB, yA=yB+3*blockH+30; } //Blocks A let widthA = blockW/sizeA; let lineColor = 0x1e2f2f; let fillColor = 0x83afaf; let fillColorS = 0xe0ebeb; for(let i=0; i 20 ){ let xPos = game.input.mousePointer.x; /*if (xPos < kid.x + 10){ kidDirection='right'; kid.animations.play('right', 8, true); }else if (xPos > kid.x){ kidDirection='right'; kid.animations.play('right', 8, true); }*/ //set limit to the arrow if (xPos < kidLeftLimit){ xPos = kidLeftLimit; } if (xPos > kidRightLimit){ xPos = kidRightLimit; } kid.x = xPos; } //If clicked A only, animate if(animateA){ for(let 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(let 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; 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; levelMove = false; if(audioStatus){ errorSound.play(); } kid.animations.stop(); errorImg.alpha = 1; } this.func_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('map'); } } }, func_updateCounter: function() { totalTime++; }, func_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(let i=0;i