// Tractor and Square states /****************************** MENU ****************************/ var stairsRight, stairsLeft; var menuSquareOne={ 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 // Remove language icon ::Igor m_world = game.add.sprite(10, 10, 'about'); m_world.inputEnabled = true; m_world.input.useHandCursor = true; m_world.events.onInputDown.add(showInfo); 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 = 40; //height growth of a stair var stairWidth = 100; //Width of a stair var startStair = 320; var startSymbol = 150; var startSquare = (startSymbol/2)+startStair+stairWidth*3; //First stairs, plus, 3 levels, blue square var blueSquare = game.add.graphics(startSquare, 175); blueSquare.anchor.setTo(0.5,0.5); blueSquare.lineStyle(2, 0x31314e); blueSquare.beginFill(0xefeff5); blueSquare.drawRect(0, 0, 80, 40); blueSquare.endFill(); var bplus = game.add.sprite(startSymbol, 195, 'h_arrow'); bplus.frame = 0; bplus.scale.setTo(0.7); bplus.anchor.setTo(0.5,0.5); var stairsPlus = []; for(var i=1;i<=3;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 Square var redSquare = game.add.graphics(startSquare, 330); redSquare.anchor.setTo(0.5,0.5); redSquare.lineStyle(2, 0xb30000); redSquare.beginFill(0xefeff5); redSquare.drawRect(0, 0, 80, 40); redSquare.endFill(); var rminus = game.add.sprite(startSymbol, 350, 'h_arrow'); rminus.frame = 5; rminus.scale.setTo(0.7); rminus.scale.x *= -1; rminus.anchor.setTo(0.5,0.5); var stairsMinus = []; for(var i=1;i<=3;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); } // ::Igor //this.beep.play(); onePosition = 0; //Map position oneMove = true; //Move no next point oneDifficulty = jogo.difficulty; //Number of difficulty (1 to 5) oneOperator = jogo.operator; oneLabel = (jogo.label == 'true'); game.state.start('mapSOne'); /// ::Igor }, //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(); 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('mapSOne'); }else{ game.state.start('unofinal'); } } }; /****************************** MAP ****************************/ var mapSquareOne={ 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 // Remove language icon ::Igor m_world = game.add.sprite(10, 10, 'about'); m_world.inputEnabled = true; m_world.input.useHandCursor = true; m_world.events.onInputDown.add(showInfo); 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: "menuSOne", 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 ] }; //Garage var garage = game.add.image(this.points.x[0], this.points.y[0], 'garage'); garage.scale.setTo(0.4); garage.anchor.setTo(0.5, 1); //Farm var farm = game.add.image(this.points.x[5], this.points.y[5], 'farm'); farm.scale.setTo(0.6); farm.anchor.setTo(0.1, 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(startX+8*blockWidth))){ game.state.start('gameSOne'); }else if (oneOperator=='Minus' && (endPosition>(startX) || endPosition<(startX-(8*blockWidth)))){ game.state.start('gameSOne'); } //If game is type B, selectiong a random block floor place if(oneType=='B'){ var end = game.rnd.integerInRange(1, numBlocks); for(var i=0;i=arrowPlace){ floorCount = i+1; floorIndex = i-1; break; } } } var block = game.add.graphics(posX, 500); block.anchor.setTo(0.5, 0); block.lineStyle(0.2, 0xffffff); block.beginFill(0x000000); block.drawRect(0, 0, widFloor, blockHeight); block.endFill(); if(oneOperator=='Minus') block.scale.x *= -1; if(oneType=="A"){ block.alpha = 0.5; block.inputEnabled = true; block.input.useHandCursor = true; block.events.onInputDown.add(this.clickSquare, {indice: i}); block.events.onInputOver.add(this.overSquare, {indice: i}); block.events.onInputOut.add(this.outSquare, {indice: i}); } floorBlocks.add(block); } for(var i=0;i<=8;i++){ var posX = startX; if(oneOperator=='Minus')posX -= ((9-i)*blockWidth); else posX+=((i+1)*blockWidth); game.add.text(posX, 560, i , stylePlace).anchor.setTo(0.5, 0.5); } if(oneMenu){ // Menu options //information label m_info = game.add.text(14, 53, "", { font: "20px Arial", fill: "#330000", align: "center" }); // Return to language button // Remove language icon ::Igor m_world = game.add.sprite(10, 10, 'about'); m_world.inputEnabled = true; m_world.input.useHandCursor = true; m_world.events.onInputDown.add(showInfo); 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: "menuSOne", beep: beepSound}); m_back.events.onInputOver.add(this.showOption, {message: words.menu_back}); m_back.events.onInputOut.add(this.showOption, {message: ""}); } // Help button /* m_help = game.add.sprite(160, 10, 'help'); m_help.inputEnabled = true; m_help.input.useHandCursor = true; m_help.events.onInputDown.add(this.viewHelp, {beep: this.beepSound}); m_help.events.onInputOver.add(this.showOption, {message: words.menu_help}); m_help.events.onInputOut.add(this.showOption, {message: ""}); */ //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; //Help arrow arrow = game.add.sprite(this.arrowPlace, 480, 'down'); arrow.anchor.setTo(0.5, 0.5); if(oneType=="B") arrow.alpha = 0; else if(oneType=="A") arrow.alpha = 0.5; }, updateCounter: function() { totalTime++; }, overSquare: function(){ if(!clicked){ if(oneType=="A"){ for(var i=0;ifloorIndex){ floorBlocks.children[i].alpha = 0; } } }else{ for(var i=0; i< floorCount; i++){ if(i>floorIndex){ floorBlocks.children[i].alpha = 0; } } } blockIndex = numBlocks - 1; }else if(oneType=='B'){ //Delete unselected blocks var minusBlocks = 0; for(var i=0;i 8){ var xPos = game.input.mousePointer.x; arrow.x = xPos; } } } } //Start animation if(animate){ if(blockDirection[curBlock]=='Right'){ tractor.x+=2; }else if(blockDirection[curBlock]=='Left'){ tractor.x-=2; } for(var i=0;i=nextEnd+extra){ blocks.children[curBlock].alpha = 0; blocks.y += 40; curBlock +=1; nextEnd += blockDistance[curBlock]; for(var i=0; i<=floorIndex; i++ ){ if(floorBlocks.children[i].x<(blocks.children[curBlock-1].x+blockDistance[curBlock-1])){ floorBlocks.children[i].alpha = 0.2; curFloor = i; } } } }else if(blockDirection[curBlock]=='Left'){ if(blocks.children[curBlock].x<=(nextEnd-extra)){ blocks.children[curBlock].alpha = 0; blocks.y += 40; curBlock+=1; nextEnd -= blockDistance[curBlock]; for(var i=0; i<=floorIndex; i++ ){ if(floorBlocks.children[i].x>(blocks.children[curBlock-1].x-blockDistance[curBlock-1])){ floorBlocks.children[i].alpha = 0.2; curFloor = i; } } } } if( curBlock>blockIndex || curFloor>=floorIndex){ //Final position animate= false; checkCollide = true; } } //Check if tractor has blocks left or floor holes if(checkCollide){ tractor.animations.stop(); timer.stop(); //Check left blocks var resultBlock = true; for(var i=0; i<=blockIndex; i++){ if(blocks.children[i].alpha==1) resultBlock = false; } //check floor Holes var resultFloor = true; for(var i=0; i<=floorIndex; i++){ if(floorBlocks.children[i].alpha==1) resultFloor = false; } if(resultBlock && resultFloor){ result = true; }else{ result = false; } this.postScore(); move = true; checkCollide = false; } //Continue moving animation if(move){ if(moveCounter==0){ if(result){ tractor.animations.play('right', 6, true); okSound.play(); okImg.alpha = 1; }else{ errorSound.play(); errorImg.alpha = 1; } } moveCounter += 1; if(result){ if(oneOperator=='Minus'){ tractor.x -=2; }else{ tractor.x +=2; } } if(moveCounter>=moveEnd){ if(result){ oneMove = true; }else{ oneMove = false; } game.state.start('mapSOne'); } } }, //Navigation functions, showOption: function(){ m_info.text = this.message; }, loadState: function(){ this.beep.play(); game.state.start(this.state); }, viewHelp: function(){ if(!clicked){ var pointer; if(oneType=='A'){ var pointer = game.add.image(endPosition, 490, 'pointer'); }else{ var pointer = game.add.image(blocks.children[endIndex-1].x, blocks.children[endIndex-1].y-blockSize/2, 'pointer'); } pointer.anchor.setTo(0.5, 0); pointer.alpha = 0.7; } } }; /****************************** END ****************************/ var endSquareOne={ create: function() { // Creating sound variable this.beepSound = game.add.audio('sound_beep'); this.okSound = game.add.audio('sound_ok'); this.errorSound = game.add.audio('sound_error'); // Reading dictionary var words = game.cache.getJSON('dictionary'); // 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(680+(p-1)*30, 10, 'block'); block.scale.setTo(2, 1); //Scaling to double width } game.add.text(830, 10, '100%', styleMenu); game.add.text(670, 10, words.difficulty + ' ' + oneDifficulty, styleMenu).anchor.setTo(1,0); game.add.image(680, 10, 'pgbar'); //Farm and trees game.add.sprite(650, 260 , 'farm').scale.setTo(1.1); game.add.sprite(30, 280 , 'tree4'); game.add.sprite(360, 250 , 'tree2'); //tractor this.tractor = game.add.sprite(0, 490 , 'tractor'); this.tractor.anchor.setTo(0.5,0.5); this.tractor.scale.setTo(0.8); this.tractor.animations.add('right',[0,1,2,3,4]); this.tractor.animations.play('right', 5, true); }, update: function() { if(this.tractor.x<=700){ this.tractor.x += 2; }else{ if(oneMenu){ // REDIRECIONAR AQUI!! ::Igor if (redir == true) { this.tractor.animations.stop(); finish_redirect(); redir = false; } }else{ this.tractor.animations.stop(); } } }, verPrincipal: function(){ game.state.start('welcome'); }, verMenu: function(){ if(oneMenu){ game.state.start('menu'); } } };