/* var menuCircleOne = { create: function(){}, ---------------------------- end of phaser functions loadMap: function(){} }; var mapCircleOne = { create: function(){}, update: function(){}, ---------------------------- end of phaser functions loadGame: function() }; var gameCircleOne = { 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(){} }; var endCircleOne = { create: function(){}, update: function(){}, ---------------------------- end of phaser functions verPrincipal: function(){}, verMenu: 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, 0,1,0, 1,0, 0,0); // 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 = 85; //Width of a stair var startStair = 240; var startSymbol = 150; 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, 195, 'h_arrow'); r_arrow.scale.setTo(0.7); r_arrow.anchor.setTo(0.5,0.5); stairsPlus = []; for(var i=1;i<=5;i++){ //stair var x1 = startStair+(stairWidth*(i-1)); var y1 = 135+maxHeight-i*stairHeight; var x2 = stairWidth;//x1 + 40; var y2 = stairHeight*i;//y1 + 24; stairsPlus[i] = game.add.graphics(0, 0); stairsPlus[i].lineStyle(1, 0xFFFFFF, 1); stairsPlus[i].beginFill(0x99b3ff); stairsPlus[i].drawRect(x1, y1, x2, y2); stairsPlus[i].endFill(); //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.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 var label = game.add.text(xl, yl, i, { font: '25px Arial', fill: '#ffffff', align: 'center' }); label.anchor.setTo(0.5, 0.4); } //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); redCircle.beginFill(0xefeff5); redCircle.drawCircle(0, 0, 60); redCircle.endFill(); var l_arrow = game.add.sprite(startSymbol, 350, 'h_arrow'); l_arrow.scale.setTo(-0.7, 0.7); l_arrow.anchor.setTo(0.5,0.5); var stairsMinus = []; for(var i=1;i<=5;i++){ //stair var x1 = startStair+(stairWidth*(i-1)); var y1 = 285+maxHeight-i*stairHeight; var x2 = stairWidth;//x1 + 40; var y2 = stairHeight*i;//y1 + 24; stairsMinus[i] = game.add.graphics(0, 0); stairsMinus[i].lineStyle(1, 0xFFFFFF, 1); stairsMinus[i].beginFill(0xff6666); stairsMinus[i].drawRect(x1, y1, x2, y2); stairsMinus[i].endFill(); //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.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); } //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 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 d_arrow = game.add.sprite(startSymbol, 500, 'h_double'); d_arrow.scale.setTo(0.7); d_arrow.anchor.setTo(0.5,0.5); var stairsMixed = []; for(var i=1;i<=5;i++){ //stair var x1 = startStair+(stairWidth*(i-1)); var y1 = 435+maxHeight-i*stairHeight; var x2 = stairWidth;//x1 + 40; var y2 = stairHeight*i;//y1 + 24; stairsMixed[i] = game.add.graphics(0, 0); stairsMixed[i].lineStyle(1, 0xFFFFFF, 1); stairsMixed[i].beginFill(0xb366ff); stairsMixed[i].drawRect(x1, y1, x2, y2); stairsMixed[i].endFill(); //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.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 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(){ 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'); } } }; /****************************** MAP *****************************/ 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, 1,1,0, 0,0, "menuCOne",0); // 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*25; var percentBlocks = onePosition; for(var p=0;p0 && p66+5*placeDistance || !hasFigure){ game.state.start('gameCOne'); } } //If end position is out of bounds, restart if (endPosition<66 || endPosition>66+3*260 || !hasFigure){ game.state.start('gameCOne'); } //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(oneOperator=='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(oneType=='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(oneLabel){ //Hiding labels blockLabel.visible = false; blockSeparator.visible = false; } } } } if(!clicked){ if(!fly){ if(oneType=="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){ var 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(var 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.checkOverlap(basket,kid_walk)){ if(kid_walk.frame < 12) kid_walk.frame = 24; else kid_walk.frame = 25; result = true; }else{ result = false; } this.postScore(); fly = true; checkCollide = false; } //Fly animation if(fly){ if(flyCounter==0){ if(result){ if(audioStatus){ okSound.play(); } 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){ oneMove = true; }else{ oneMove = false; } game.state.start('mapCOne'); } } }, updateCounter: function() { totalTime++; }, overCircle: function(){ if(!clicked){ for(var i=0;i14){ return false; }else{ return true; } } }; /****************************** END ****************************/ 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'); //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 var stylePlace = { font: '26px Arial', fill: '#400080', align: 'center'}; var styleLabel = { font: '26px Arial', fill: '#000080', align: 'center'}; var styleMenu = { font: '30px Arial', fill: '#000000', align: 'center'}; //Floor for(var i=0;i<9;i++){ game.add.image(i*100, 501, 'floor'); } // Progress bar for(var p=1;p<=5;p++){ var block = game.add.image(660+(p-1)*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.image(660, 10, 'pgbar'); //School and trees game.add.sprite(600, 222 , 'school').scale.setTo(0.7); game.add.sprite(30, 280 , 'tree4'); game.add.sprite(360, 250 , 'tree2'); //kid this.kid = game.add.sprite(0, -152 , 'kid_run'); this.kid.anchor.setTo(0.5,0.5); this.kid.scale.setTo(0.7); var walk = this.kid.animations.add('walk', [0,1,2,3,4,5,6,7,8,9,10,11]); //globo this.balloon = game.add.sprite(0, -260, 'balloon'); this.balloon.anchor.setTo(0.5,0.5); this.basket = game.add.sprite(0, -150, 'balloon_basket'); this.basket.anchor.setTo(0.5,0.5); }, update: function() { if(this.kid.y>=460){ this.kid.animations.play('walk', 6, true); if(this.kid.x<=700){ this.kid.x += 2; }else{ if(oneMenu){ game.state.start('menu'); }else{ this.kid.animations.stop(); } } }else{ this.balloon.y += 2; this.basket.y += 2; this.kid.y +=2; this.balloon.x += 1; this.basket.x += 1; this.kid.x +=1; } }, verPrincipal: function(){ game.state.start('welcome'); }, verMenu: function(){ if(oneMenu){ game.state.start('menu'); } } };