squareOne.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885
  1. /*
  2. var menuSquareOne = {
  3. create: function(){},
  4. ---------------------------- end of phaser functions
  5. func_loadMap: function(){}
  6. };
  7. var gameSquareOne = {
  8. create: function(){},
  9. update: function(){},
  10. ---------------------------- end of phaser functions
  11. func_updateCounter: function(){},
  12. func_overSquare: function(){},
  13. func_outSquare: function(){},
  14. func_clickSquare: function(){},
  15. //func_setPlace: function(){},
  16. func_postScore: function(){},
  17. func_viewHelp: function(){},
  18. //func_checkOverlap: function(){}
  19. //func_getRndDivisor: function(){}
  20. };
  21. var endSquareOne = {
  22. create: function(){},
  23. update: function(){},
  24. ---------------------------- end of phaser functions
  25. func_verPrincipal: function(){},
  26. };
  27. */
  28. // Tractor and Square states
  29. /****************************** MENU ****************************/
  30. var menuSquareOne = {
  31. create: function() {
  32. // Navigation buttons
  33. buttonSettings["func_addButtons"](true,true,
  34. false,true,false,
  35. true,false,
  36. false,false);
  37. // Title
  38. var style = { font: '28px Arial', fill: '#00804d'};
  39. var title = game.add.text(game.world.centerX, 40, lang.game_menu_title, style);
  40. title.anchor.setTo(0.5, 0.5);
  41. //SETTING DIFFICULTY LEVELS
  42. var maxHeight = 120; //Max height of a stair
  43. var stairHeight = 40; //height growth of a stair
  44. var stairWidth = 100; //Width of a stair
  45. var startStair = 320;
  46. var startSymbol = 180;
  47. var startSquare = (startSymbol/2)+startStair+stairWidth*3;
  48. //First stairs, plus, 3 levels, blue square
  49. var blueSquare = game.add.graphics(startSquare, 175);
  50. blueSquare.anchor.setTo(0.5,0.5);
  51. blueSquare.lineStyle(2, 0x31314e);
  52. blueSquare.beginFill(0xefeff5);
  53. blueSquare.drawRect(0, 0, 80, 40);
  54. blueSquare.endFill();
  55. var plusTractorIcon = game.add.sprite(startSymbol+30, 215, 'tractor_green');
  56. //plus_tractor.frame = 0;
  57. plusTractorIcon.scale.setTo(0.5);
  58. plusTractorIcon.alpha = 0.9;
  59. plusTractorIcon.anchor.setTo(0.5,0.5);
  60. var plusArrowIcon = game.add.sprite(startSymbol+100, 215, 'h_arrow');
  61. plusArrowIcon.scale.setTo(0.3);
  62. plusArrowIcon.alpha = 0.9;
  63. plusArrowIcon.anchor.setTo(0.5,0.5);
  64. var stairsPlus = [];
  65. for(var i=1;i<=3;i++){
  66. //stair
  67. var x1 = startStair+(stairWidth*(i-1));
  68. var y1 = 135+maxHeight-i*stairHeight;
  69. var x2 = stairWidth;//x1 + 40;
  70. var y2 = stairHeight*i;//y1 + 24;
  71. stairsPlus[i] = game.add.graphics(0, 0);
  72. stairsPlus[i].lineStyle(1, 0xFFFFFF, 1);
  73. stairsPlus[i].beginFill(0x99b3ff);
  74. stairsPlus[i].drawRect(x1, y1, x2, y2);
  75. stairsPlus[i].endFill();
  76. //event
  77. stairsPlus[i].inputEnabled = true;
  78. stairsPlus[i].input.useHandCursor = true;
  79. stairsPlus[i].events.onInputDown.add(this.func_loadMap, {beep: beepSound, difficulty: i, operator: 'Plus' });
  80. stairsPlus[i].events.onInputOver.add(function (item) { item.alpha=0.5; }, this);
  81. stairsPlus[i].events.onInputOut.add(function (item) { item.alpha=1; }, this);
  82. //label
  83. var xl = x1+stairWidth/2; //x label
  84. var yl = y1+(stairHeight*i)/2; //y label
  85. var label = game.add.text(xl, yl, i, { font: '25px Arial', fill: '#ffffff', align: 'center' });
  86. label.anchor.setTo(0.5, 0.4);
  87. }
  88. //Second stairs, minus, 3 levels, red Square
  89. var redSquare = game.add.graphics(startSquare, 330);
  90. redSquare.anchor.setTo(0.5,0.5);
  91. redSquare.lineStyle(2, 0xb30000);
  92. redSquare.beginFill(0xefeff5);
  93. redSquare.drawRect(0, 0, 80, 40);
  94. redSquare.endFill();
  95. var minusTractorIcon = game.add.sprite(startSymbol+70, 370, 'tractor_red');
  96. //minusTractorIcon.frame = 5;
  97. minusTractorIcon.scale.setTo(0.5);
  98. minusTractorIcon.alpha = 0.9;
  99. minusTractorIcon.anchor.setTo(0.5,0.5);
  100. var minusArrowIcon = game.add.sprite(startSymbol, 370, 'h_arrow');
  101. minusArrowIcon.scale.setTo(0.3);
  102. minusArrowIcon.alpha = 0.9;
  103. minusArrowIcon.scale.x *= -1;
  104. minusArrowIcon.anchor.setTo(0.5,0.5);
  105. var stairsMinus = [];
  106. for(var i=1;i<=3;i++){
  107. //stair
  108. var x1 = startStair+(stairWidth*(i-1));
  109. var y1 = 285+maxHeight-i*stairHeight;
  110. var x2 = stairWidth;//x1 + 40;
  111. var y2 = stairHeight*i;//y1 + 24;
  112. stairsMinus[i] = game.add.graphics(0, 0);
  113. stairsMinus[i].lineStyle(1, 0xFFFFFF, 1);
  114. stairsMinus[i].beginFill(0xff6666);
  115. stairsMinus[i].drawRect(x1, y1, x2, y2);
  116. stairsMinus[i].endFill();
  117. //event
  118. stairsMinus[i].inputEnabled = true;
  119. stairsMinus[i].input.useHandCursor = true;
  120. stairsMinus[i].events.onInputDown.add(this.func_loadMap, {beep: beepSound, difficulty: i, operator: 'Minus' });
  121. stairsMinus[i].events.onInputOver.add(function (item) { item.alpha=0.5; }, this);
  122. stairsMinus[i].events.onInputOut.add(function (item) { item.alpha=1; }, this);
  123. //label
  124. var xl = x1+stairWidth/2; //x label
  125. var yl = y1+(stairHeight*i)/2; //y label
  126. var label = game.add.text(xl, yl, i, { font: '25px Arial', fill: '#ffffff', align: 'center' });
  127. label.anchor.setTo(0.5, 0.4);
  128. }
  129. },
  130. //MapLoading function
  131. func_loadMap: function(){
  132. if(audioStatus){
  133. this.beep.play();
  134. }
  135. levelPosition = 0; //Map position
  136. levelMove = true; //Move no next point
  137. levelDifficulty = this.difficulty; //Number of difficulty (1 to 3)
  138. levelOperator = this.operator; //Operator of game
  139. passedLevels = 0; //reset the game progress when entering a new level
  140. game.state.start('map');
  141. }
  142. };
  143. /****************************** GAME ****************************/
  144. var gameSquareOne = {
  145. create: function() {
  146. //timer
  147. totalTime = 0;
  148. timer = game.time.create(false);
  149. timer.loop(1000, this.func_updateCounter, this);
  150. timer.start();
  151. detail="";
  152. // Background
  153. game.add.image(0, 0, 'bgimage');
  154. // Navigation buttons
  155. buttonSettings["func_addButtons"](true,true,
  156. true,true,true,
  157. true,false,
  158. "menuSquareOne", this.func_viewHelp);
  159. //Clouds
  160. game.add.image(300, 100, 'cloud');
  161. game.add.image(660, 80, 'cloud');
  162. game.add.image(110, 85, 'cloud').scale.setTo(0.8);
  163. // Styles for labels
  164. var stylePlace = { font: '26px Arial', fill: '#400080', align: 'center'};
  165. var styleLabel = { font: '26px Arial', fill: '#000080', align: 'center'};
  166. var styleFraction = { font: '15px Arial', fill: '#000080', align: 'center'};
  167. var styleMenu = { font: '30px Arial', fill: '#000000', align: 'center'};
  168. //Floor and road
  169. var startX = 170; //Initial tractor and place position
  170. if(levelOperator=='Minus') startX = 730;
  171. startX = startX; //Workaround for initial position inside update
  172. var blockWidth = 80; //Width of blocks and floor spaces
  173. var blockHeight = 40; //Height of blocks and floor spaces
  174. for(var i=0;i<9;i++){
  175. game.add.image(i*100, 501, 'floor');
  176. }
  177. //Control variables
  178. clicked = false; //Floor blocks or apilled blocks clicked
  179. hideLabels = false; //Labels of blocks
  180. animate = false; //Start move animation
  181. checkCollide = false; //Check if tractor fon't any block left or floor hole
  182. result = false; //Game is correct
  183. move = false; //Continue tractor animation
  184. moveCounter = 0; //Move counter
  185. moveEnd = 140; //Move end counter
  186. //tractor
  187. var tractorAlign = -80;
  188. if(levelOperator=='Minus'){
  189. tractorAlign *= -1;
  190. }
  191. tractor = game.add.sprite(startX+tractorAlign, 445, 'tractor');
  192. tractor.anchor.setTo(0.5, 0.5);
  193. tractor.scale.setTo(0.8);
  194. tractor.animations.add('right',[0,1,2,3,4]);
  195. if(levelOperator=='Minus'){
  196. tractor.scale.x *= -1;
  197. }
  198. //generator
  199. //Blocks and fractions
  200. if(debugMode) console.log("pos " +levelPosition);
  201. maxBlocks = levelPosition+4; //Maximum blocks
  202. if(levelType=='B' || levelOperator=='Mixed') maxBlocks = 10;
  203. blocks = game.add.group(); //Fraction arrays (apilled)
  204. numBlocks = game.rnd.integerInRange(levelPosition+2, maxBlocks); //Number of blocks
  205. if(debugMode) console.log("num " + numBlocks+", min " + (levelPosition+2) + ", max " + maxBlocks);
  206. curBlock = 0; //Actual index block
  207. blockDirection = []; //Directions right(plus), left (minus)
  208. blockDistance = []; //Displacement distance of the blocks
  209. blockLabel = game.add.group(); //Labels of the blocks
  210. blockSeparator = game.add.group(); //Separator of the labels
  211. //blockAngle = []; //Angles of blocks
  212. //blockTraceColor = []; //Trace colors
  213. endPosition = startX; //Ending position, accumulative
  214. if(levelOperator=='Minus') endPosition -= blockWidth;
  215. else endPosition += blockWidth;
  216. //Game A exclusive variables
  217. floorBlocks = game.add.group(); //Selectable floor blocks
  218. floorIndex = -1; //Selected floor block
  219. floorCount = 8; //Number of floor blocks
  220. floorClicked = false; //If clicked portion of floor
  221. curFloor = -1;
  222. //Game B exclusive variables
  223. arrowPlace = startX; //Fixed place for help arrow
  224. if(levelOperator=='Minus') arrowPlace -= blockWidth;
  225. else arrowPlace += blockWidth;
  226. fractionClicked = false; //If clicked a fraction (game B)
  227. fractionIndex = -1; //Index of clicked fraction (game B)
  228. hasFigure = false;
  229. for(var p=0;p<numBlocks;p++){
  230. var portion = game.rnd.integerInRange(1, levelDifficulty); //Portion of the square, according to difficulty
  231. if(portion==3) detail+= "4,";
  232. else detail += portion+",";
  233. if(portion==levelDifficulty) hasFigure = true;
  234. var direction = '';
  235. var lineColor = '';
  236. if(levelOperator=='Plus'){
  237. direction = 'Right';
  238. lineColor = 0x31314e; //plus block: "black'
  239. }else if(levelOperator=='Minus'){
  240. direction = 'Left';
  241. lineColor = 0xb30000;//minus block : "red"
  242. }
  243. //blocks close to tractor
  244. var block = game.add.graphics(startX, 460-p*blockHeight);
  245. block.anchor.setTo(0.5, 0.5);
  246. block.lineStyle(2, lineColor);
  247. block.beginFill(0xefeff5);
  248. blockDirection[p] = direction;
  249. if(portion==1){
  250. block.drawRect(0, 0, blockWidth, blockHeight);
  251. blockDistance.push(blockWidth);
  252. //blockAngle.push(360);
  253. if(levelLabel){
  254. var labelX = startX;
  255. if(levelOperator=='Minus') labelX -= (15+blockWidth);
  256. else labelX += blockWidth+15;
  257. var label = game.add.text(labelX, 480-p*blockHeight, portion , styleLabel);
  258. label.anchor.setTo(0.5, 0.5);
  259. blockLabel.add(label);
  260. }
  261. }else{
  262. if(portion==3) portion = 4;
  263. var distance = blockWidth/portion;
  264. block.drawRect(0, 0, distance, blockHeight);
  265. blockDistance.push(distance);
  266. if(levelLabel){
  267. var labelX = startX;
  268. if(levelOperator=='Minus') labelX -= (15+distance);
  269. else labelX += 15+distance;
  270. var separator = game.add.sprite(labelX, 480-p*blockHeight, 'separator');
  271. separator.scale.setTo(0.6);
  272. separator.anchor.setTo(0.5, 0.5);
  273. blockSeparator.add(separator);
  274. var label = game.add.text(labelX, 483-p*blockHeight, '1\n'+portion , styleFraction);
  275. label.anchor.setTo(0.5, 0.5);
  276. blockLabel.add(label);
  277. }
  278. }
  279. if(direction=='Right'){
  280. endPosition += Math.floor(blockWidth/portion);
  281. }else if(direction=='Left'){
  282. endPosition -= Math.floor(blockWidth/portion);
  283. block.scale.x *= -1;
  284. }
  285. block.endFill();
  286. //If game is type B, (select fractions, adding event)
  287. if(levelType=='B'){
  288. block.alpha = 0.5;
  289. block.inputEnabled = true;
  290. block.input.useHandCursor = true;
  291. block.events.onInputDown.add(this.func_clickSquare, {indice: p});
  292. block.events.onInputOver.add(this.func_overSquare, {indice: p});
  293. block.events.onInputOut.add(this.func_outSquare, {indice: p});
  294. }
  295. blocks.add(block);
  296. }
  297. //Calculate next block
  298. if(blockDirection[curBlock]=='Right'){
  299. nextEnd = startX+blockDistance[curBlock];
  300. }else{
  301. nextEnd = startX-blockDistance[curBlock];
  302. }
  303. //If end position is out of bounds, restart
  304. if(!hasFigure) game.state.start('gameSquareOne');
  305. if (levelOperator=='Plus' && (endPosition<(startX+blockWidth) || endPosition>(startX+8*blockWidth))){
  306. game.state.start('gameSquareOne');
  307. }else if (levelOperator=='Minus' && (endPosition>(startX) || endPosition<(startX-(8*blockWidth)))){
  308. game.state.start('gameSquareOne');
  309. }
  310. //If game is type B, selectiong a random block floor place
  311. if(levelType=='B'){
  312. var end = game.rnd.integerInRange(1, numBlocks);
  313. for(var i=0;i<end;i++){
  314. if(blockDirection[i]=='Right')
  315. arrowPlace += blockDistance[i];
  316. else if(blockDirection[i]=='Left')
  317. arrowPlace -= blockDistance[i];
  318. }
  319. }
  320. //Selectable floor
  321. floorCount = 8*levelDifficulty;
  322. var widFloor = blockWidth/levelDifficulty;
  323. if(levelDifficulty==3){
  324. floorCount = 8*4;
  325. widFloor = blockWidth/4;
  326. }
  327. for(var i = 0; i < floorCount; i++){
  328. var posX = startX;
  329. if(levelOperator=='Minus') posX -= (blockWidth + i*widFloor);
  330. else posX += (blockWidth + i*widFloor);
  331. if(levelType=='B'){
  332. if(levelOperator=='Minus'){
  333. if(posX<=arrowPlace){
  334. floorCount = i+1;
  335. floorIndex = i-1;
  336. break;
  337. }
  338. }else{
  339. if(posX>=arrowPlace){
  340. floorCount = i+1;
  341. floorIndex = i-1;
  342. break;
  343. }
  344. }
  345. }
  346. // blocks on the floor
  347. var block = game.add.graphics(posX, 500);
  348. block.anchor.setTo(0.5, 0);
  349. block.lineStyle(0.9, 0xffffff);
  350. block.beginFill(0xa8c0e6);
  351. block.drawRect(0, 0, widFloor, blockHeight);
  352. block.endFill();
  353. if(levelOperator=='Minus') block.scale.x *= -1;
  354. if(levelType=="A"){
  355. block.alpha = 0.5;
  356. block.inputEnabled = true;
  357. block.input.useHandCursor = true;
  358. block.events.onInputDown.add(this.func_clickSquare, {indice: i});
  359. block.events.onInputOver.add(this.func_overSquare, {indice: i});
  360. block.events.onInputOut.add(this.func_outSquare, {indice: i});
  361. }
  362. floorBlocks.add(block);
  363. }
  364. for(var i=0;i<=8;i++){
  365. var posX = startX;
  366. if(levelOperator=='Minus')posX -= ((9-i)*blockWidth);
  367. else posX+=((i+1)*blockWidth);
  368. game.add.text(posX, 560, i , stylePlace).anchor.setTo(0.5, 0.5);
  369. }
  370. //ok and error images
  371. okImg = game.add.image(game.world.centerX, game.world.centerY, 'h_ok');
  372. okImg.anchor.setTo(0.5);
  373. okImg.alpha = 0;
  374. errorImg = game.add.image(game.world.centerX, game.world.centerY, 'h_error');
  375. errorImg.anchor.setTo(0.5);
  376. errorImg.alpha = 0;
  377. //Help arrow
  378. arrow = game.add.sprite(this.arrowPlace, 480, 'down');
  379. arrow.anchor.setTo(0.5, 0.5);
  380. if(levelType=="B")
  381. arrow.alpha = 0;
  382. else if(levelType=="A")
  383. arrow.alpha = 0.5;
  384. },
  385. update: function() {
  386. if(!clicked){
  387. if(!move){
  388. if(levelType=='A'){
  389. //Follow mouse
  390. if (game.physics.arcade.distanceToPointer(arrow, game.input.activePointer) > 8 )
  391. {
  392. var xPos = game.input.mousePointer.x;
  393. //set left limit to the arrow
  394. if (xPos < 250){
  395. xPos = 250;
  396. }
  397. arrow.x = xPos;
  398. }
  399. }
  400. }
  401. }
  402. //Start animation
  403. if(animate){
  404. if(blockDirection[curBlock]=='Right'){
  405. tractor.x+=2;
  406. }else if(blockDirection[curBlock]=='Left'){
  407. tractor.x-=2;
  408. }
  409. for(var i=0;i<numBlocks;i++){ //Moving every block
  410. if(blockDirection[curBlock]=='Right'){
  411. blocks.children[i].x +=2;
  412. }else{
  413. blocks.children[i].x -=2;
  414. }
  415. }
  416. var extra = 80-blockDistance[curBlock];
  417. if(blockDirection[curBlock]=='Right'){
  418. if(blocks.children[curBlock].x>=nextEnd+extra){
  419. blocks.children[curBlock].alpha = 0;
  420. blocks.y += 40;
  421. curBlock +=1;
  422. nextEnd += blockDistance[curBlock];
  423. for(var i=0; i<=floorIndex; i++ ){
  424. if(floorBlocks.children[i].x<(blocks.children[curBlock-1].x+blockDistance[curBlock-1])){
  425. floorBlocks.children[i].alpha = 0.2;
  426. curFloor = i;
  427. }
  428. }
  429. }
  430. }else if(blockDirection[curBlock]=='Left'){
  431. if(blocks.children[curBlock].x<=(nextEnd-extra)){
  432. blocks.children[curBlock].alpha = 0;
  433. blocks.y += 40;
  434. curBlock+=1;
  435. nextEnd -= blockDistance[curBlock];
  436. for(var i=0; i<=floorIndex; i++ ){
  437. if(floorBlocks.children[i].x>(blocks.children[curBlock-1].x-blockDistance[curBlock-1])){
  438. floorBlocks.children[i].alpha = 0.2;
  439. curFloor = i;
  440. }
  441. }
  442. }
  443. }
  444. if( curBlock>blockIndex || curFloor>=floorIndex){ //Final position
  445. animate= false;
  446. checkCollide = true;
  447. }
  448. }
  449. //Check if tractor has blocks left or floor holes
  450. if(checkCollide){
  451. tractor.animations.stop();
  452. timer.stop();
  453. //Check left blocks
  454. var resultBlock = true;
  455. for(var i=0; i<=blockIndex; i++){
  456. if(blocks.children[i].alpha==1) resultBlock = false;
  457. }
  458. //check floor Holes
  459. var resultFloor = true;
  460. for(var i=0; i<=floorIndex; i++){
  461. if(floorBlocks.children[i].alpha==1) resultFloor = false;
  462. }
  463. if(resultBlock && resultFloor){
  464. result = true;
  465. }else{
  466. result = false;
  467. }
  468. this.func_postScore();
  469. move = true;
  470. checkCollide = false;
  471. }
  472. //Continue moving animation
  473. if(move){
  474. if(moveCounter==0){
  475. if(result){
  476. tractor.animations.play('right', 6, true);
  477. if(audioStatus){
  478. okSound.play();
  479. }
  480. passedLevels++;
  481. if(debugMode) console.log("passedLevels = "+passedLevels);
  482. okImg.alpha = 1;
  483. }else{
  484. if(audioStatus){
  485. errorSound.play();
  486. }
  487. errorImg.alpha = 1;
  488. }
  489. }
  490. moveCounter += 1;
  491. if(result){
  492. if(levelOperator=='Minus'){
  493. tractor.x -=2;
  494. }else{
  495. tractor.x +=2;
  496. }
  497. }
  498. if(moveCounter>=moveEnd){
  499. if(result){
  500. levelMove = true;
  501. }else{
  502. levelMove = false;
  503. }
  504. game.state.start('map');
  505. }
  506. }
  507. },
  508. func_updateCounter: function() {
  509. totalTime++;
  510. },
  511. func_overSquare: function(){
  512. if(!clicked){
  513. //on level type A
  514. if(levelType=="A"){
  515. for(var i=0;i<floorCount;i++){
  516. if(i<=this.indice){
  517. floorBlocks.children[i].alpha = 1;
  518. }else{
  519. floorBlocks.children[i].alpha = 0.5;
  520. }
  521. }
  522. floorIndex = this.indice;
  523. //on level type B
  524. }else if(levelType=="B"){
  525. for(var i=0;i<numBlocks;i++){
  526. if(i<=this.indice){
  527. blocks.children[i].alpha = 0.5;
  528. }else{
  529. blocks.children[i].alpha = 0.2;
  530. }
  531. }
  532. blockIndex = this.indice;
  533. }
  534. }
  535. },
  536. func_outSquare: function(){
  537. if(!clicked){
  538. //on level type A
  539. if(levelType=="A"){
  540. for(var i=0;i<floorCount;i++){
  541. floorBlocks.children[i].alpha = 0.5;
  542. }
  543. floorIndex = -1;
  544. //on level type B
  545. }else if(levelType=="B"){
  546. for(var i=0;i<numBlocks;i++){
  547. blocks.children[i].alpha = 0.5;
  548. }
  549. blockIndex = -1;
  550. }
  551. }
  552. },
  553. func_clickSquare: function(){
  554. if(!clicked && !move){
  555. //on level type A
  556. if(levelType=='A'){
  557. arrow.alpha = 1;
  558. clicked = true;
  559. animate = true;
  560. if(audioStatus){
  561. beepSound.play();
  562. }
  563. tractor.animations.play('right', 5, true);
  564. if(levelLabel){ //Hiding labels
  565. blockLabel.visible = false;
  566. blockSeparator.visible = false;
  567. }
  568. //cleaning path
  569. if(levelOperator=='Minus'){
  570. for(var i=0; i< floorCount; i++){
  571. if(i>floorIndex){
  572. floorBlocks.children[i].alpha = 0;
  573. }
  574. }
  575. }else{
  576. for(var i=0; i< floorCount; i++){
  577. if(i>floorIndex){
  578. floorBlocks.children[i].alpha = 0;
  579. }
  580. }
  581. }
  582. blockIndex = numBlocks - 1;
  583. //on level type B
  584. }else if(levelType=='B'){ //Delete unselected blocks
  585. var minusBlocks = 0;
  586. for(var i=0;i<numBlocks;i++){
  587. if(i<=blockIndex){
  588. blocks.children[i].alpha = 1;
  589. }else{
  590. blocks.children[i].visible = false; //Delete unselected block
  591. minusBlocks +=1; //number of blocks to reduce
  592. }
  593. }
  594. numBlocks -= minusBlocks; //Final reduced blocks
  595. arrow.alpha = 0;
  596. clicked = true;
  597. animate = true;
  598. if(audioStatus){
  599. beepSound.play();
  600. }
  601. tractor.animations.play('right', 5, true);
  602. if(levelLabel){ //Hiding labels
  603. blockLabel.visible = false;
  604. blockSeparator.visible = false;
  605. }
  606. }
  607. }
  608. },
  609. func_postScore: function (){
  610. // Get correct information about username and default language
  611. // Variables 'username' and 'lang' is define on: js/menu.js
  612. // Variable 'lang' has all the JSON content of 'assets/languages/pt_BR.json', 'lang.lang' defined in 'js/preMenu.js' (func_setLang())
  613. // 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').
  614. //if (name=='') name = username; //leo the correct is 'username'
  615. // assets/languages/pt_BR.json
  616. //DEBUG Testar 'lang'
  617. /*
  618. var contact = "";
  619. if (typeof lang === 'object') {
  620. //contact = JSON.parse(lang);
  621. for (var i in lang) // will enumerate values of 'assets/languages/pt_BR.json'
  622. contact += lang[i];
  623. // 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
  624. // SOLUÇÃOCírculosQuadriláteroslegendaMODOCOMSEMDIGITE SEU NOMEPRONTOOláVocê deve selecionar uma porção menor que o seu tamanho totalVocê esqueceu de digitar seu nomeÁUDIO'
  625. lang_str = contact; aux = 1;
  626. }
  627. else
  628. // if (lang === 'undefined') lang_str = "pt_BR";
  629. */
  630. var abst = "numBlocks:" + numBlocks + ", valBlocks: " + detail + " blockIndex: " + blockIndex + ", floorIndex: " + floorIndex;
  631. var hr = new XMLHttpRequest();
  632. // Create some variables we need to send to our PHP file
  633. var url = "php/save.php";
  634. var vars = "s_ip=" + hip + "&s_name=" + username + "&s_lang=" + lang + "&s_game=" + levelShape + "&s_mode=" + levelType;
  635. vars += "&s_oper=" + levelOperator + "&s_leve=" + levelDifficulty + "&s_posi=" + levelPosition + "&s_resu=" + result + "&s_time=" + totalTime + "&s_deta=" + abst;
  636. //D alert('/js/squareOne.js: url=' + url + '; aux=' + aux + ', lang_str=' + lang_str + ', lang=' + lang); // + ', this.lang=" + this.lang
  637. //D /js/squareOne.js: url=php/save.php; aux=1, lang_str=CARREGANDOFraçõesSELECIONE UM JOGODificuldadeNívelSELECINAR OPERAÇÃO E DIFICULDADEBom trabalho!Tente novamente!SELECIONAR IDIOMAMENU PRINCIPALVOLTARVER
  638. //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]
  639. // Sobre nome do usuario:
  640. // * js/squareOne.js: name
  641. // * js/pt_BR.json: welcome="Ola'", insert_name="DIGITE SEU NOME"
  642. // * php/save.php : $play = $_REQUEST["s_name"];
  643. // * js/preMenu.js : insert_name, game.add.text(...), username = document.getElementById("name_id").value;
  644. // Pegar valor de PHP para JS: echo("<script language='javascript'>location.href='download.php?arquivo=$nome_arquivo&dir=$dir&id_exer=$id_exer'</script>");
  645. hr.open("POST", url, true);
  646. hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  647. hr.onreadystatechange = function() {
  648. if(debugMode) console.log(hr);
  649. if(hr.readyState == 4 && hr.status == 200) {
  650. var return_data = hr.responseText;
  651. if(debugMode) console.log(return_data);
  652. }
  653. }
  654. // Send the data to PHP now... and wait for response to update the status div
  655. hr.send(vars); // Actually execute the request
  656. if(debugMode) console.log("processing...");
  657. },
  658. func_viewHelp: function(){
  659. if(!clicked){
  660. var pointer;
  661. if(levelType=='A'){
  662. var pointer = game.add.image(endPosition, 490, 'pointer');
  663. }else{
  664. var pointer = game.add.image(blocks.children[endIndex-1].x, blocks.children[endIndex-1].y-blockSize/2, 'pointer');
  665. }
  666. pointer.anchor.setTo(0.5, 0);
  667. pointer.alpha = 0.7;
  668. }
  669. }
  670. };
  671. /****************************** END ****************************/
  672. var endSquareOne = {
  673. create: function() {
  674. // Background
  675. game.add.image(0, 0, 'bgimage');
  676. //Clouds
  677. game.add.image(300, 100, 'cloud');
  678. game.add.image(660, 80, 'cloud');
  679. game.add.image(110, 85, 'cloud').scale.setTo(0.8);
  680. // Styles for labels
  681. var stylePlace = { font: '26px Arial', fill: '#400080', align: 'center'};
  682. var styleLabel = { font: '26px Arial', fill: '#000080', align: 'center'};
  683. var styleMenu = { font: '30px Arial', fill: '#000000', align: 'center'};
  684. //Floor
  685. for(var i=0;i<9;i++){
  686. game.add.image(i*100, 501, 'floor');
  687. }
  688. // Progress bar
  689. for(var p=0;p<5;p++){
  690. var block = game.add.image(660+p*30, 10, 'block');
  691. block.scale.setTo(2, 1); //Scaling to double width
  692. }
  693. game.add.text(820, 10, '100%', styleMenu);
  694. game.add.text(650, 10, lang.difficulty + ' ' + levelDifficulty, styleMenu).anchor.setTo(1,0);
  695. game.add.image(660, 10, 'pgbar');
  696. //Farm and trees
  697. game.add.sprite(650, 260 , 'farm').scale.setTo(1.1);
  698. game.add.sprite(30, 280 , 'tree4');
  699. game.add.sprite(360, 250 , 'tree2');
  700. //tractor
  701. this.tractor = game.add.sprite(0, 490 , 'tractor');
  702. this.tractor.anchor.setTo(0.5,0.5);
  703. this.tractor.scale.setTo(0.8);
  704. this.tractor.animations.add('right',[0,1,2,3,4]);
  705. this.tractor.animations.play('right', 5, true);
  706. },
  707. update: function() {
  708. if(this.tractor.x<=700){
  709. this.tractor.x += 2;
  710. }else{
  711. if(levelMenu){
  712. passedLevels = 0;
  713. game.state.start('menu');
  714. }else{
  715. this.tractor.animations.stop();
  716. }
  717. }
  718. },
  719. func_verPrincipal: function(){
  720. game.state.start('welcome');
  721. },
  722. };