12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070 |
- /*
- var menuSquareOne = {
- create: function(){},
- ---------------------------- end of phaser functions
- loadMap: function(){}
- };
- var mapSquareOne = {
- create: function(){},
- update: function(){},
- ---------------------------- end of phaser functions
- loadGame: function()
- };
- var gameSquareOne = {
- create: function(){},
- update: function(){},
- ---------------------------- end of phaser functions
- updateCounter: function(){},
- overSquare: function(){},
- outSquare: function(){},
- clickSquare: function(){},
- //setPlace: function(){},
- postScore: function(){},
- viewHelp: function(){},
- //checkOverlap: function(){}
- //getRndDivisor: function(){}
- };
- var endSquareOne = {
- create: function(){},
- update: function(){},
- ---------------------------- end of phaser functions
- verPrincipal: function(){},
- verMenu: function(){}
- };
- */
- // Tractor and Square states
- /****************************** MENU ****************************/
- var stairsRight, stairsLeft;
- var menuSquareOne = {
-
- 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 = 40; //height growth of a stair
- var stairWidth = 100; //Width of a stair
- var startStair = 320;
- var startSymbol = 180;
- 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+30, 215, 'tractor_green');
- //bplus.frame = 0;
- bplus.scale.setTo(0.5);
- bplus.alpha = 0.9;
- bplus.anchor.setTo(0.5,0.5);
-
- var bplus2 = game.add.sprite(startSymbol+100, 215, 'h_arrow');
- bplus2.scale.setTo(0.3);
- bplus2.alpha = 0.9;
- bplus2.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+70, 370, 'tractor_red');
- //rminus.frame = 5;
- rminus.scale.setTo(0.5);
- rminus.alpha = 0.9;
- //rminus.scale.x *= -1;
- rminus.anchor.setTo(0.5,0.5);
-
- var rminus2 = game.add.sprite(startSymbol, 370, 'h_arrow');
- rminus2.scale.setTo(0.3);
- rminus2.alpha = 0.9;
- rminus2.scale.x *= -1;
- rminus2.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);
- }
- },
-
- //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('mapSOne');
- }else{
- game.state.start('unofinal');
- }
- }
-
- };
- /****************************** MAP ****************************/
- var mapSquareOne = {
- 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,
- "menuSOne",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*20;
- var percentBlocks = onePosition;
- for(var p=1;p<=percentBlocks;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, percentText+'%', styleMenu);
- game.add.text(650, 10, lang.difficulty + ' ' + oneDifficulty, styleMenu).anchor.setTo(1,0);
- game.add.image(660, 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; i<this.r_types.length; i++){
- if(this.r_types[i]==1){
- var sprite = game.add.image(this.rocks.x[i], this.rocks.y[i], 'rock');
- sprite.scale.setTo(0.32);
- sprite.anchor.setTo(0.5, 0.95);
- }else if(this.r_types[i]==2){
- var sprite = game.add.image(this.rocks.x[i], this.rocks.y[i], 'birch');
- sprite.scale.setTo(0.4);
- sprite.anchor.setTo(0.5, 0.95);
- }
- }
- this.trees = {
- 'x': [105, 214, 354, 364, 570, 600, 740, 779],
- 'y': [341, 219, 180, 520, 550, 392, 488, 286]
- }
- this.t_types = [2, 4, 3, 4, 1, 2, 4, 4];
-
- for(var i=0; i<this.t_types.length; i++){
- var sprite = game.add.image(this.trees.x[i], this.trees.y[i], 'tree'+this.t_types[i]);
- sprite.scale.setTo(0.6);
- sprite.anchor.setTo(0.5, 0.95);
- }
-
- // places
- for (var p = 1; p < this.points.x.length -1; p++){
- var place;
- if(p<onePosition)
- place = game.add.image(this.points.x[p], this.points.y[p], 'place_b');
- else if (oneMove && p==onePosition)
- place = game.add.image(this.points.x[p], this.points.y[p], 'place_b');
- else
- place = game.add.image(this.points.x[p], this.points.y[p], 'place_a');
- place.anchor.setTo(0.5, 0.5);
- place.scale.setTo(0.3);
- var sign = game.add.image(this.points.x[p]-20, this.points.y[p]-60, 'sign');
- sign.anchor.setTo(0.5, 1);
- sign.scale.setTo(0.4);
- if(p>0 && p<this.points.x.length-1){
- var text = game.add.text(this.points.x[p]-23, this.points.y[p]-84, p, stylePlace);
- text.anchor.setTo(0.35, 0.5);
- }
- }
- // tractor start position
- this.tractor = game.add.sprite(this.points.x[onePosition], this.points.y[onePosition], 'tractor');
- this.tractor.anchor.setTo(0.5, 1);
- this.tractor.scale.setTo(0.5);
- game.physics.arcade.enable(this.tractor);
- var walk = this.tractor.animations.add('walk',[0,1,2,3,4]);
- this.tractor.animations.play('walk', 5, true);
- this.tractor.angle -= 25;
-
- // Delay to next level
- this.count = 0;
- this.wait = 60;
-
- },
- update: function() {
-
- // Wait 2 seconds before moving or staring a game
- this.count ++;
- if(this.count<=this.wait) return;
-
- // If movement is stopped or position is 6 (final), load game
- if(onePosition==6){
- oneMove = false;
- }
- if(!oneMove){
- this.loadGame();
- }
-
- // If momevent is enabled, move to next point from actual
- if(oneMove){
- game.physics.arcade.moveToXY(
- this.tractor,
- this.points.x[onePosition+1],
- this.points.y[onePosition+1],
- 100
- );
-
- // I tractor reached the end, stop movement
- if(Math.ceil(this.tractor.x)==this.points.x[onePosition+1] || Math.ceil(this.tractor.y)==this.points.y[onePosition+1]){
- oneMove=false;
- onePosition += 1; //Update position
- }
- }
- },
-
- //MapLoading function
- loadGame: function(){
- if(audioStatus){
- beepSound.play();
- }
- if(onePosition<5){
- game.state.start('gameSOne');
- }else{
- game.state.start('endSOne');
- }
- }
- };
- /****************************** GAME ****************************/
- var startX;
- var clicked, hideLabels, animate, checkCollide, result, hasFigure;
- var detail;
- var endPosition;
- var fractionClicked, fractionIndex;
- //Balloon and blocks control
- var blocks, maxBlocks, numBlocks, curBlock, blockDirection, blockDistance, blockLabel, blockSeparator;
- var blockWidth, blockIndex;
- var floorBlocks, floorIndex, floorCount, floorClicked, curFloor;
- var move, moveCounter, moveEnd;
- var tractor, arrow;
- var arrowPlace;
- var gameSquareOne = {
- create: function() {
-
- //timer
- totalTime = 0;
- timer = game.time.create(false);
- timer.loop(1000, this.updateCounter, this);
- timer.start();
- detail="";
-
- // 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');
-
- // Menu options
- buttonSettings["addButtons"](1,1,
- 1,1,1,
- 1,0,
- "menuSOne", this.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
- var stylePlace = { font: '26px Arial', fill: '#400080', align: 'center'};
- var styleLabel = { font: '26px Arial', fill: '#000080', align: 'center'};
- var styleFraction = { font: '15px Arial', fill: '#000080', align: 'center'};
- var styleMenu = { font: '30px Arial', fill: '#000000', align: 'center'};
-
- //Floor and road
- var startX = 170; //Initial tractor and place position
- if(oneOperator=='Minus') startX = 730;
- startX = startX; //Workaround for initial position inside update
- var blockWidth = 80; //Width of blocks and floor spaces
- var blockHeight = 40; //Height of blocks and floor spaces
- for(var i=0;i<9;i++){
- game.add.image(i*100, 501, 'floor');
- }
-
- //Control variables
- clicked = false; //Floor blocks or apilled blocks clicked
- hideLabels = false; //Labels of blocks
- animate = false; //Start move animation
- checkCollide = false; //Check if tractor fon't any block left or floor hole
- result = false; //Game is correct
- move = false; //Continue tractor animation
- moveCounter = 0; //Move counter
- moveEnd = 140; //Move end counter
-
- //tractor
- var tractorAlign = -80;
- if(oneOperator=='Minus'){
- tractorAlign *= -1;
- }
- tractor = game.add.sprite(startX+tractorAlign, 445, 'tractor');
- tractor.anchor.setTo(0.5, 0.5);
- tractor.scale.setTo(0.8);
- tractor.animations.add('right',[0,1,2,3,4]);
- if(oneOperator=='Minus'){
- tractor.scale.x *= -1;
- }
-
- //generator
- //Blocks and fractions
- if(debugmode) console.log("pos " +onePosition);
-
- maxBlocks = onePosition+4; //Maximum blocks
- if(oneType=='B' || oneOperator=='Mixed') maxBlocks = 10;
- blocks = game.add.group(); //Fraction arrays (apilled)
- numBlocks = game.rnd.integerInRange(onePosition+2, maxBlocks); //Number of blocks
-
- if(debugmode) console.log("num " + numBlocks+", min " + (onePosition+2) + ", max " + maxBlocks);
-
- 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
- if(oneOperator=='Minus') endPosition -= blockWidth;
- else endPosition += blockWidth;
-
- //Game A exclusive variables
- floorBlocks = game.add.group(); //Selectable floor blocks
- floorIndex = -1; //Selected floor block
- floorCount = 8; //Number of floor blocks
- floorClicked = false; //If clicked portion of floor
- curFloor = -1;
-
- //Game B exclusive variables
- arrowPlace = startX; //Fixed place for help arrow
- if(oneOperator=='Minus') arrowPlace -= blockWidth;
- else arrowPlace += blockWidth;
- fractionClicked = false; //If clicked a fraction (game B)
- fractionIndex = -1; //Index of clicked fraction (game B)
-
- hasFigure = false;
- for(var p=0;p<numBlocks;p++){
- var portion = game.rnd.integerInRange(1, oneDifficulty); //Portion of the square, according to difficulty
- if(portion==3) detail+= "4,";
- else detail += portion+",";
-
- if(portion==oneDifficulty) hasFigure = true;
- var direction = '';
- var lineColor = '';
-
- if(oneOperator=='Plus'){
- direction = 'Right';
- lineColor = 0x31314e; //plus block: "black'
- }else if(oneOperator=='Minus'){
- direction = 'Left';
- lineColor = 0xb30000;//minus block : "red"
- }
-
- //blocks close to tractor
- var block = game.add.graphics(startX, 460-p*blockHeight);
- block.anchor.setTo(0.5, 0.5);
- block.lineStyle(2, lineColor);
- block.beginFill(0xefeff5);
- blockDirection[p] = direction;
-
- if(portion==1){
- block.drawRect(0, 0, blockWidth, blockHeight);
-
- blockDistance.push(blockWidth);
- //blockAngle.push(360);
- if(oneLabel){
- var labelX = startX;
- if(oneOperator=='Minus') labelX -= (15+blockWidth);
- else labelX += blockWidth+15;
- var label = game.add.text(labelX, 480-p*blockHeight, portion , styleLabel);
- label.anchor.setTo(0.5, 0.5);
- blockLabel.add(label);
- }
- }else{
- if(portion==3) portion = 4;
-
- var distance = blockWidth/portion;
-
- block.drawRect(0, 0, distance, blockHeight);
-
- blockDistance.push(distance);
- if(oneLabel){
- var labelX = startX;
- if(oneOperator=='Minus') labelX -= (15+distance);
- else labelX += 15+distance;
- var separator = game.add.sprite(labelX, 480-p*blockHeight, 'separator');
- separator.scale.setTo(0.6);
- separator.anchor.setTo(0.5, 0.5);
- blockSeparator.add(separator);
- var label = game.add.text(labelX, 483-p*blockHeight, '1\n'+portion , styleFraction);
- label.anchor.setTo(0.5, 0.5);
- blockLabel.add(label);
- }
- }
- if(direction=='Right'){
- endPosition += Math.floor(blockWidth/portion);
- }else if(direction=='Left'){
- endPosition -= Math.floor(blockWidth/portion);
- block.scale.x *= -1;
- }
- block.endFill();
-
- //If game is type B, (select fractions, adding event)
- if(oneType=='B'){
- block.alpha = 0.5;
- block.inputEnabled = true;
- block.input.useHandCursor = true;
- block.events.onInputDown.add(this.clickSquare, {indice: p});
- block.events.onInputOver.add(this.overSquare, {indice: p});
- block.events.onInputOut.add(this.outSquare, {indice: p});
- }
-
- blocks.add(block);
- }
-
- //Calculate next block
- if(blockDirection[curBlock]=='Right'){
- nextEnd = startX+blockDistance[curBlock];
- }else{
- nextEnd = startX-blockDistance[curBlock];
- }
-
- //If end position is out of bounds, restart
- if(!hasFigure) game.state.start('gameSOne');
-
- if (oneOperator=='Plus' && (endPosition<(startX+blockWidth) || endPosition>(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<end;i++){
- if(blockDirection[i]=='Right')
- arrowPlace += blockDistance[i];
- else if(blockDirection[i]=='Left')
- arrowPlace -= blockDistance[i];
- }
- }
-
- //Selectable floor
- floorCount = 8*oneDifficulty;
-
- var widFloor = blockWidth/oneDifficulty;
- if(oneDifficulty==3){
- floorCount = 8*4;
- widFloor = blockWidth/4;
- }
-
- for(var i = 0; i < floorCount; i++){
- var posX = startX;
-
- if(oneOperator=='Minus') posX -= (blockWidth + i*widFloor);
- else posX += (blockWidth + i*widFloor);
-
- if(oneType=='B'){
- if(oneOperator=='Minus'){
- if(posX<=arrowPlace){
- floorCount = i+1;
- floorIndex = i-1;
- break;
- }
- }else{
- if(posX>=arrowPlace){
- floorCount = i+1;
- floorIndex = i-1;
- break;
- }
- }
- }
- // blocks on the floor
- var block = game.add.graphics(posX, 500);
- block.anchor.setTo(0.5, 0);
- block.lineStyle(0.9, 0xffffff);
- block.beginFill(0xa8c0e6);
- 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);
- }
-
- //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;
- },
-
- update: function() {
-
- if(!clicked){
- if(!move){
- if(oneType=='A'){
- //Follow mouse
- if (game.physics.arcade.distanceToPointer(arrow, game.input.activePointer) > 8 )
- {
- var xPos = game.input.mousePointer.x;
- //set left limit to the arrow
- if (xPos < 250){
- xPos = 250;
- }
- 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<numBlocks;i++){ //Moving every block
- if(blockDirection[curBlock]=='Right'){
- blocks.children[i].x +=2;
- }else{
- blocks.children[i].x -=2;
- }
- }
-
- var extra = 80-blockDistance[curBlock];
-
- if(blockDirection[curBlock]=='Right'){
- 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;
- }
- }
- }
- }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);
- if(audioStatus){
- okSound.play();
- }
- okImg.alpha = 1;
- }else{
- if(audioStatus){
- 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');
- }
- }
-
- },
- updateCounter: function() {
- totalTime++;
- },
-
- overSquare: function(){
- if(!clicked){
- //on level type A
- if(oneType=="A"){
- for(var i=0;i<floorCount;i++){
- if(i<=this.indice){
- floorBlocks.children[i].alpha = 1;
- }else{
- floorBlocks.children[i].alpha = 0.5;
- }
- }
- floorIndex = this.indice;
- //on level type B
- }else if(oneType=="B"){
- for(var i=0;i<numBlocks;i++){
- if(i<=this.indice){
- blocks.children[i].alpha = 0.5;
- }else{
- blocks.children[i].alpha = 0.2;
- }
- }
- blockIndex = this.indice;
- }
- }
- },
- outSquare: function(){
- if(!clicked){
- //on level type A
- if(oneType=="A"){
- for(var i=0;i<floorCount;i++){
- floorBlocks.children[i].alpha = 0.5;
- }
- floorIndex = -1;
- //on level type B
- }else if(oneType=="B"){
- for(var i=0;i<numBlocks;i++){
- blocks.children[i].alpha = 0.5;
- }
- blockIndex = -1;
- }
- }
- },
-
- clickSquare: function(){
- if(!clicked && !move){
-
- //on level type A
- if(oneType=='A'){
-
- arrow.alpha = 1;
- clicked = true;
- animate = true;
- if(audioStatus){
- beepSound.play();
- }
- tractor.animations.play('right', 5, true);
-
- if(oneLabel){ //Hiding labels
- blockLabel.visible = false;
- blockSeparator.visible = false;
- }
-
- //cleaning path
- if(oneOperator=='Minus'){
- for(var i=0; i< floorCount; i++){
- if(i>floorIndex){
- floorBlocks.children[i].alpha = 0;
- }
- }
- }else{
- for(var i=0; i< floorCount; i++){
- if(i>floorIndex){
- floorBlocks.children[i].alpha = 0;
- }
- }
- }
-
- blockIndex = numBlocks - 1;
- //on level type B
- }else if(oneType=='B'){ //Delete unselected blocks
- var minusBlocks = 0;
- for(var i=0;i<numBlocks;i++){
- if(i<=blockIndex){
- blocks.children[i].alpha = 1;
- }else{
- blocks.children[i].visible = false; //Delete unselected block
- minusBlocks +=1; //number of blocks to reduce
- }
- }
- numBlocks -= minusBlocks; //Final reduced blocks
-
- arrow.alpha = 0;
- clicked = true;
- animate = true;
- if(audioStatus){
- beepSound.play();
- }
- tractor.animations.play('right', 5, true);
- if(oneLabel){ //Hiding labels
- blockLabel.visible = false;
- blockSeparator.visible = false;
- }
- }
- }
- },
- postScore: function (){
- var lang_str = "pt_BR"; //TODO NAO esta pegando a lingua definida pelo usuario!
- var aux;
- // Get correct information about username and default language
- // Variables 'username' and 'lang' is define on: js/menu.js
- // Variable 'lang' has all the JSON content of 'assets/languages/pt_BR.json', 'lang.lang' defined in 'js/preMenu.js' (setLang())
- // TODO: nao descobri esquema para pegar 'lang' (como 'pt_BR' ou 'en_US'), 'lang' esta' com o dicinario de lingua (definido em 'assets/languages/pt_BR.json').
- if (name=='') name = username; //leo the correct is 'username'
- // assets/languages/pt_BR.json
- //DEBUG Testar 'lang'
- /*
- var contact = "";
- if (typeof lang === 'object') {
- //contact = JSON.parse(lang);
- for (var i in lang) // will enumerate values of 'assets/languages/pt_BR.json'
- contact += lang[i];
- // Finaliza com os valores de 'assets/languages/pt_BR.json': 'CARREGANDOFraçõesSELECIONE UM JOGODificuldadeNívelSELECINAR OPERAÇÃO E DIFICULDADEBom trabalho!Tente novamente!SELECIONAR IDIOMAMENU PRINCIPALVOLTARVER
- // SOLUÇÃOCírculosQuadriláteroslegendaMODOCOMSEMDIGITE SEU NOMEPRONTOOláVocê deve selecionar uma porção menor que o seu tamanho totalVocê esqueceu de digitar seu nomeÁUDIO'
- lang_str = contact; aux = 1;
- }
- else
- // if (lang === 'undefined') lang_str = "pt_BR";
- */
- var abst = "numBlocks:"+numBlocks+", valBlocks: " + detail+" blockIndex: " + blockIndex + ", floorIndex: " + floorIndex;
- var hr = new XMLHttpRequest();
- // Create some variables we need to send to our PHP file
- var url = "assets/cn/save.php";
- var vars = "s_ip="+hip+"&s_name=" + name+"&s_lang=" + lang_str + "&s_game=" + oneShape + "&s_mode=" + oneType;
- vars += "&s_oper=" + oneOperator + "&s_leve=" + oneDifficulty + "&s_posi=" + onePosition + "&s_resu=" + result + "&s_time=" + totalTime + "&s_deta=" + abst;
- //D alert('/js/squareOne.js: url=' + url + '; aux=' + aux + ', lang_str=' + lang_str + ', lang=' + lang); // + ', this.lang=" + this.lang
- //D /js/squareOne.js: url=assets/cn/save.php; aux=1, lang_str=CARREGANDOFraçõesSELECIONE UM JOGODificuldadeNívelSELECINAR OPERAÇÃO E DIFICULDADEBom trabalho!Tente novamente!SELECIONAR IDIOMAMENU PRINCIPALVOLTARVER
- //D SOLUÇÃOCírculosQuadriláteroslegendaMODOCOMSEMDIGITE SEU NOMEPRONTOOláVocê deve selecionar uma porção menor que o seu tamanho totalVocê esqueceu de digitar seu nomeÁUDIO, lang=[object Object]
- // Sobre nome do usuario:
- // * js/squareOne.js: name
- // * js/pt_BR.json: welcome="Ola'", insert_name="DIGITE SEU NOME"
- // * assets/cn/save.php : $play = $_REQUEST["s_name"];
- // * js/preMenu.js : insert_name, game.add.text(...), username = document.getElementById("name_id").value;
- // Pegar valor de PHP para JS: echo("<script language='javascript'>location.href='download.php?arquivo=$nome_arquivo&dir=$dir&id_exer=$id_exer'</script>");
- hr.open("POST", url, true);
- hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
- hr.onreadystatechange = function() {
- if(debugmode) console.log(hr);
- if(hr.readyState == 4 && hr.status == 200) {
- var return_data = hr.responseText;
- if(debugmode) console.log(return_data);
- }
- }
- // Send the data to PHP now... and wait for response to update the status div
- hr.send(vars); // Actually execute the request
- if(debugmode) console.log("processing...");
- },
-
- 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');
- // 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');
-
- //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){
- game.state.start('menu');
- }else{
- this.tractor.animations.stop();
- }
- }
- },
-
- verPrincipal: function(){
- game.state.start('welcome');
- },
-
- verMenu: function(){
- if(oneMenu){
- game.state.start('menu');
- }
- }
- };
|