/* let gameCircleOne = { create: function(){}, update: function(){}, ---------------------------- end of phaser functions 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(){} }; */ // Kid and Circle states, games 1 and 2 let gameCircleOne = { create: function() { //timer totalTime = 0; timer = game.time.create(false); timer.loop(1000, this.func_updateCounter, this); timer.start(); detail=""; // Sets background image game.add.image(0, 0, 'bgimage'); // Calls function that loads navigation icons iconSettings["func_addButtons"](true,true, true,true,true, true,false, 'difficulty', this.func_viewHelp); //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 styleMenu = { font: '30px Arial', fill: '#000000', align: 'center'}; //Floor and road startX = 66; //Initial kid and place position if(levelOperator=='Minus') startX = 66+5*156; placeDistance = 156; //Distance between places blockSize = 60; for(let i=0;i<9;i++){ game.add.image(i*100, 501, 'floor'); } let road = game.add.image(47, 515, 'road'); road.scale.setTo(1.01,0.94); if(levelType=='A'){ road.inputEnabled = true; road.events.onInputDown.add(this.func_setPlace, {beep: beepSound}); //enabling input for tablets } for(let p=0;p<=5;p++){// Places let place = game.add.image(66+p*placeDistance, 526, 'place_a'); place.anchor.setTo(0.5); place.scale.setTo(0.3); game.add.text(66+p*placeDistance, 560, p , stylePlace).anchor.setTo(0.5); } //Control variables clicked = false; //Air ballon positioned hideLabels = false; //Labels animations animate = false; //Start move animation checkCollide = false; //Check kid inside ballon's basket result = false; //Game is correct fly = false; //Start ballon fly animation flyCounter = 0; //Fly counter flyEnd = 140; //Fly end counter hasFigure = false; //If has level figure //trace trace = this.add.bitmapData(this.game.width, this.game.height); trace.addToWorld(); trace.clear(); //generator //Circles and fractions let 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(levelPosition, maxBlocks); //Number of blocks curBlock = 0; //Actual index block blockDirection = []; //Directions right(plus), left (minus) blockDistance = []; //Displacement distance of the blocks blockLabel = game.add.group(); //Labels of the blocks blockSeparator = game.add.group(); //Separator of the labels blockAngle = []; //Angles of blocks blockTraceColor = []; //Trace colors endPosition = startX; //Ending position, accumulative //Game B exclusive variables balloonPlace = this.game.world.centerX; //Fixed place for ballon (game B) fractionClicked = false; //If clicked a fraction (game B) fractionIndex = -1; //Index of clicked fraction (game B) numPlus = game.rnd.integerInRange(1, numBlocks-1); for(let p=0;p66+5*placeDistance || !hasFigure){ game.state.start('gameCircleOne'); } } //If end position is out of bounds, restart if (endPosition<66 || endPosition>66+3*260 || !hasFigure){ game.state.start('gameCircleOne'); } //kid kid_walk = game.add.sprite(startX, 495-numBlocks*blockSize, 'kid_walk'); kid_walk.anchor.setTo(0.5, 0.8); 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(levelOperator=='Minus'){ kid_walk.animations.play('left', 6, true); kid_walk.animations.stop(); } //globo balloon = game.add.sprite(balloonPlace, 350, 'balloon'); balloon.anchor.setTo(0.5, 0.5); balloon.alpha = 0.5; basket = game.add.sprite(balloonPlace, 472, 'balloon_basket'); basket.anchor.setTo(0.5, 0.5); //ok and error images okImg = game.add.image(game.world.centerX, game.world.centerY, 'h_ok'); okImg.anchor.setTo(0.5); okImg.alpha = 0; errorImg = game.add.image(game.world.centerX, game.world.centerY, 'h_error'); errorImg.anchor.setTo(0.5); errorImg.alpha = 0; }, update: function() { if (game.input.activePointer.isDown && !fly && !clicked){ //Positionate balloon - Game A if(levelType=='A'){ if(game.input.mousePointer.y>60){ //Dead zone for click balloon.x = game.input.mousePointer.x; balloon.alpha = 1; clicked = true; animate = true; if(audioStatus){ beepSound.play(); } if(blockDirection[curBlock]=='Right'){ kid_walk.animations.play('right', 6, true); }else{ kid_walk.animations.play('left', 6, true); } if(levelLabel){ //Hiding labels blockLabel.visible = false; blockSeparator.visible = false; } } } } if(!clicked){ if(!fly){ if(levelType=="A"){ //Follow mouse if (game.physics.arcade.distanceToPointer(balloon, game.input.activePointer) > 8){ balloon.x = game.input.mousePointer.x; basket.x = game.input.mousePointer.x; } } } } //Start animation if(animate){ let color = ''; if(blockDirection[curBlock]=='Right'){ kid_walk.x+=2; color = 'rgba(0, 51, 153, 1)'; }else if(blockDirection[curBlock]=='Left'){ kid_walk.x-=2; color = 'rgba(179, 0, 0, 1)'; } trace.rect(kid_walk.x, 526, 2, 2, color); for(let i=0;i=nextEnd){ blocks.children[curBlock].visible = false; blocks.y += blockSize; kid_walk.y += blockSize; curBlock+=1; if(blockDirection[curBlock]=='Right'){ nextEnd += blockDistance[curBlock]; kid_walk.animations.play('right', 6, true); }else if(blockDirection[curBlock]=='Left'){ nextEnd -= blockDistance[curBlock]; kid_walk.animations.play('left', 6, true); } } }else{ if(blocks.children[curBlock].x<=nextEnd){ blocks.children[curBlock].visible = false; blocks.y += blockSize; kid_walk.y += blockSize; curBlock+=1; if(blockDirection[curBlock]=='Right'){ nextEnd += blockDistance[curBlock]; kid_walk.animations.play('right', 6, true); }else if(blockDirection[curBlock]=='Left'){ nextEnd -= blockDistance[curBlock]; kid_walk.animations.play('left', 6, true); } } } if(curBlock==numBlocks ){ //Final position animate= false; checkCollide = true; } } //Check if kid is inside the basket if(checkCollide){ kid_walk.animations.stop(); timer.stop(); if(this.func_checkOverlap(basket,kid_walk)){ if(kid_walk.frame < 12) kid_walk.frame = 24; else kid_walk.frame = 25; result = true; }else{ result = false; } this.func_postScore(); fly = true; checkCollide = false; } //Fly animation if(fly){ if(flyCounter==0){ if(result){ if(audioStatus){ okSound.play(); } passedLevels++; if(debugMode) console.log("passedLevels = "+passedLevels); okImg.alpha = 1; }else{ if(audioStatus){ errorSound.play(); } errorImg.alpha = 1; } } flyCounter += 1; balloon.y -= 2; basket.y -= 2; if(result){ kid_walk.y -=2; } if(flyCounter>=flyEnd){ if(result){ levelMove = true; }else{ levelMove = false; } game.state.start('map'); } } }, func_updateCounter: function() { totalTime++; }, func_overCircle: function(){ if(!clicked){ for(let i=0;i14){ return false; }else{ return true; } } };