squareOne.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. /**
  2. * LInE - Free Education, Private Data
  3. * iFractions GAME STATE
  4. *
  5. * LEVELS - SQUARE I & II: tractor level
  6. *
  7. * Name of game state : squareOne
  8. * Shape : square
  9. * Character : tractor
  10. * Theme : farm
  11. * Concept : Player associates 'blocks carried by the tractor' and 'floor spaces to be filled by them'
  12. * Represent fractions as : blocks
  13. *
  14. * # of different difficulties for each level : 3
  15. *
  16. * Levels can be : 'A' or 'B' (in variable 'levelType')
  17. *
  18. * A : Player can select # of 'floor blocks' (hole in the ground)
  19. * Selects size of hole to be made in the ground (to fill with the blocks in front of the truck)
  20. * B : Player can select # of 'stacked blocks' (in front of the truck)
  21. * Selects number of blocks in front of the truck (to fill the hole on the ground)
  22. *
  23. * Sublevels can be : 'Plus' or 'Minus' (in variable 'sublevelType')
  24. *
  25. * Plus : addition of fractions
  26. * Represented by : tractor going to the right (floor positions 0..8
  27. * Minus : subtraction of fractions
  28. * Represented by: tractor going to the left (floor positions 8..0)
  29. *
  30. * @namespace
  31. */
  32. const squareOne = {
  33. /**
  34. * Main code
  35. */
  36. create: function () {
  37. // CONTROL VARIABLES
  38. this.checkAnswer = false; // When true allows game to run 'check answer' code in update
  39. this.animate = false; // When true allows game to run 'tractor animation' code in update (turns animation of the moving tractor ON/OFF)
  40. this.animateEnding = false; // When true allows game to run 'tractor ending animation' code in update (turns 'ending' animation of the moving tractor ON/OFF)
  41. this.hasClicked = false; // Checks if player 'clicked' on a block
  42. this.result = false; // Checks player 'answer'
  43. this.count = 0; // An 'x' position counter used in the tractor animation
  44. this.divisorsList = ''; // Hold the divisors for each fraction on stacked blocks (created for postScore())
  45. this.DIREC_LEVEL = (sublevelType == 'Minus') ? -1 : 1; // Will be multiplied to values to easily change tractor direction when needed
  46. this.animationSpeed = 2 * this.DIREC_LEVEL; // X distance in which the tractor moves in each iteration of the animation
  47. // GAME VARIABLES
  48. this.defaultBlockWidth = 80; // Base block width
  49. this.defaultBlockHeight = 40; // Base block height
  50. this.startX = (sublevelType == 'Minus') ? 730 : 170; // Initial 'x' coordinate for the tractor and stacked blocks
  51. // BACKGROUND
  52. // Add background image
  53. game.add.image(0, 0, 'bgimage');
  54. // Add clouds
  55. game.add.image(300, 100, 'cloud');
  56. game.add.image(660, 80, 'cloud');
  57. game.add.image(110, 85, 'cloud', 0.8);
  58. // Add floor of grass
  59. for (let i = 0; i < 9; i++) { game.add.image(i * 100, 501, 'floor'); }
  60. // Calls function that loads navigation icons
  61. navigationIcons.func_addIcons(
  62. true, true, true, // Left icons
  63. true, false, // Right icons
  64. 'customMenu', this.func_viewHelp
  65. );
  66. // TRACTOR
  67. this.tractor = game.add.sprite(this.startX, 445, 'tractor', 0, 0.8);
  68. if (sublevelType == 'Plus') {
  69. this.tractor.anchor(1, 0.5);
  70. this.tractor.animation = ['move', [0, 1, 2, 3, 4], 4];
  71. }
  72. else {
  73. this.tractor.anchor(0, 0.5);
  74. this.tractor.animation = ['move', [5, 6, 7, 8, 9], 4];
  75. this.tractor.curFrame = 5;
  76. }
  77. // STACKED BLOCKS variables
  78. this.stck = {
  79. blocks: [], // Group of 'stacked' block objects
  80. labels: [], // Group of fraction labels on the side of 'stacked' blocks
  81. index: undefined, // (levelType 'B') index of 'stacked' block selected by player
  82. // Control variables for animation
  83. curIndex: 0, // (needs to be 0)
  84. curBlockEnd: undefined,
  85. // Correct values
  86. correctIndex: undefined, // (levelType 'B') index of the CORRECT 'stacked' block
  87. };
  88. // FLOOR BLOCKS variables
  89. this.floor = {
  90. blocks: [], // Group of 'floor' block objects
  91. index: undefined, // (levelType 'A') index of 'floor' block selected by player
  92. // Control variables for animation
  93. curIndex: -1, // (needs to be -1)
  94. // Correct values
  95. correctIndex: undefined, // (levelType 'A') index of the CORRECT 'floor' block
  96. correctX: undefined, // 'x' coordinate of CORRECT 'floor' block
  97. correctXA: undefined, // Temporary variable
  98. correctXB: undefined, // Temporary variable
  99. };
  100. // CREATING STACKED BLOCKS
  101. this.restart = this.func_createStckBlocks();
  102. // CREATING FLOOR BLOCKS
  103. this.func_createFloorBlocks();
  104. // SELECTION ARROW
  105. if (levelType == 'A') {
  106. this.arrow = game.add.image(this.startX + this.defaultBlockWidth * this.DIREC_LEVEL, 480, 'arrow_down');
  107. this.arrow.anchor(0.5, 0.5);
  108. this.arrow.alpha = 0.5;
  109. }
  110. // Help pointer
  111. this.help = game.add.image(0, 0, 'help_pointer', 0.5);
  112. this.help.anchor(0.5, 0);
  113. this.help.alpha = 0;
  114. if (!this.restart) {
  115. game.timer.start(); // Set a timer for the current level (used in postScore())
  116. game.event.add('click', this.func_onInputDown);
  117. game.event.add('mousemove', this.func_onInputOver);
  118. }
  119. },
  120. /**
  121. * Game loop
  122. */
  123. update: function () {
  124. // AFTER PLAYER SELECTION
  125. // Starts tractor moving animation
  126. if (self.animate) {
  127. const stck = self.stck;
  128. const floor = self.floor;
  129. // MANAGE HORIZONTAL MOVEMENT
  130. // Move 'tractor'
  131. self.tractor.x += self.animationSpeed;
  132. // Move 'stacked blocks'
  133. for (let i in stck.blocks) {
  134. stck.blocks[i].x += self.animationSpeed;
  135. }
  136. // MANAGE BLOCKS AND FLOOR GAPS
  137. // If block is 1/n (not 1/1) there's an extra block space to go through before the start of next block
  138. const restOfCurBlock = (self.defaultBlockWidth - stck.blocks[stck.curIndex].width) * self.DIREC_LEVEL;
  139. // Check if block falls
  140. if ((sublevelType == 'Plus' && stck.blocks[0].x >= (stck.curBlockEnd + restOfCurBlock)) ||
  141. (sublevelType == 'Minus' && stck.blocks[0].x <= (stck.curBlockEnd + restOfCurBlock))) {
  142. let lowerBlock = true;
  143. const curEnd = stck.blocks[0].x + stck.blocks[stck.curIndex].width * self.DIREC_LEVEL;
  144. // If current index is (A) last stacked index (correct index - fixed)
  145. // If current index is (B) selected stacked index
  146. if (stck.curIndex == stck.index) {
  147. // floor.index : (A) selected floor index
  148. // floor.index : (B) last floor index (correct index - fixed)
  149. const selectedEnd = floor.blocks[floor.index].x + floor.blocks[0].width * self.DIREC_LEVEL;
  150. // (A) last stacked block (fixed) doesnt fit selected gap AKA NOT ENOUGH FLOOR BLOCKS (DOESNT CHECK TOO MANY)
  151. // (B) selected stacked index doesnt fit last floor gap (fixed) AKA TOO MANY STACKED BLOCKS (DOESNT CHECK NOT ENOUGH)
  152. if ((sublevelType == 'Plus' && curEnd > selectedEnd) || (sublevelType == 'Minus' && curEnd < selectedEnd)) {
  153. lowerBlock = false;
  154. }
  155. }
  156. else {
  157. // Update to next block end
  158. stck.curBlockEnd += stck.blocks[stck.curIndex + 1].width * self.DIREC_LEVEL;
  159. }
  160. // Fill floor gap
  161. if (lowerBlock) {
  162. // Until (A) selected floor index
  163. // Until (B) last floor index (correct index - fixed)
  164. // Updates floor index to be equivalent to stacked index (and change alpha so floor appears to be filled)
  165. for (let i = 0; i <= floor.index; i++) {
  166. if ((sublevelType == 'Plus' && floor.blocks[i].x < curEnd) || (sublevelType == 'Minus' && floor.blocks[i].x > curEnd)) {
  167. floor.blocks[i].alpha = 0.2;
  168. floor.curIndex = i;
  169. }
  170. }
  171. // Lower
  172. stck.blocks[stck.curIndex].alpha = 0;
  173. stck.blocks.forEach(cur => { cur.y += self.defaultBlockHeight - 2; }); // Lower stacked blocks
  174. }
  175. stck.curIndex++;
  176. }
  177. // WHEN REACHED END POSITION
  178. if (stck.curIndex > stck.index || floor.curIndex == floor.index) {
  179. self.animate = false;
  180. self.checkAnswer = true;
  181. }
  182. }
  183. // When animation ends check answer
  184. if (self.checkAnswer) {
  185. game.timer.stop();
  186. game.animation.stop(self.tractor.animation[0]);
  187. if (levelType == 'A') {
  188. self.result = self.floor.index == self.floor.correctIndex;
  189. }
  190. else {
  191. self.result = self.stck.index == self.stck.correctIndex;
  192. }
  193. // Give feedback to player and turns on sprite animation
  194. if (self.result) { // Correct answer
  195. game.animation.play(self.tractor.animation[0]);
  196. // Displays feedback image and sound
  197. game.add.image(defaultWidth / 2, defaultHeight / 2, 'ok').anchor(0.5, 0.5);
  198. if (audioStatus) game.audio.okSound.play();
  199. completedLevels++; // Increases number os passed levels
  200. if (debugMode) console.log('completedLevels = ' + completedLevels);
  201. }
  202. else { // Incorrect answer
  203. // Displays feedback image and sound
  204. game.add.image(defaultWidth / 2, defaultHeight / 2, 'error').anchor(0.5, 0.5);
  205. if (audioStatus) game.audio.errorSound.play();
  206. }
  207. self.postScore();
  208. // AFTER CHECK ANSWER
  209. self.checkAnswer = false;
  210. self.animateEnding = true;
  211. }
  212. // Starts 'ending' tractor moving animation
  213. if (self.animateEnding) {
  214. // ANIMATE ENDING
  215. self.count++;
  216. // If CORRECT ANSWER runs final tractor animation (else tractor desn't move, just wait)
  217. if (self.result) self.tractor.x += self.animationSpeed;
  218. // WHEN REACHED END POSITION calls map state
  219. if (self.count >= 140) {
  220. // If CORRECT ANSWER, player goes to next level in map
  221. if (self.result) mapMove = true;
  222. else mapMove = false;
  223. game.state.start('map');
  224. }
  225. }
  226. game.render.all();
  227. },
  228. /* EVENT HANDLER */
  229. /**
  230. * Called by mouse click event
  231. *
  232. * @param {object} mouseEvent contains the mouse click coordinates
  233. */
  234. func_onInputDown: function (mouseEvent) {
  235. const x = mouseEvent.offsetX;
  236. const y = mouseEvent.offsetY;
  237. if (levelType == 'A') {
  238. self.floor.blocks.forEach(cur => {
  239. if (game.math.isOverIcon(x, y, cur)) self.func_clickSquare(cur);
  240. });
  241. }
  242. else {
  243. self.stck.blocks.forEach(cur => {
  244. if (game.math.isOverIcon(x, y, cur)) self.func_clickSquare(cur);
  245. });
  246. }
  247. navigationIcons.func_onInputDown(x, y);
  248. game.render.all();
  249. },
  250. /**
  251. * Called by mouse move event
  252. *
  253. * @param {object} mouseEvent contains the mouse move coordinates
  254. */
  255. func_onInputOver: function (mouseEvent) {
  256. const x = mouseEvent.offsetX;
  257. const y = mouseEvent.offsetY;
  258. let flagA = false;
  259. let flagB = false;
  260. if (levelType == 'A') {
  261. // Make arrow follow mouse
  262. if (!self.hasClicked && !self.animateEnding) {
  263. if (game.math.distanceToPointer(self.arrow.x, x, self.arrow.y, y) > 8) {
  264. self.arrow.x = (x < 250) ? 250 : x; // Limits the arrow left position to 250
  265. }
  266. }
  267. self.floor.blocks.forEach(cur => {
  268. if (game.math.isOverIcon(x, y, cur)) {
  269. flagA = true;
  270. self.func_overSquare(cur);
  271. }
  272. });
  273. if (!flagA) self.func_outSquare('A');
  274. }
  275. if (levelType == 'B') {
  276. self.stck.blocks.forEach(cur => {
  277. if (game.math.isOverIcon(x, y, cur)) {
  278. flagB = true;
  279. self.func_overSquare(cur);
  280. }
  281. });
  282. if (!flagB) self.func_outSquare('B');
  283. }
  284. navigationIcons.func_onInputOver(x, y);
  285. game.render.all();
  286. },
  287. /* CALLED BY EVENT HANDLER */
  288. /**
  289. * Function called when cursor is over a valid rectangle
  290. *
  291. * @param {object} cur rectangle the cursor is over
  292. */
  293. func_overSquare: function (cur) {
  294. if (!self.hasClicked) {
  295. document.body.style.cursor = 'pointer';
  296. // On leveltype A
  297. if (levelType == 'A') {
  298. for (let i in self.floor.blocks) {
  299. self.floor.blocks[i].alpha = (i <= cur.index) ? 1 : 0.5;
  300. }
  301. // Saves the index of the selected 'floor' block
  302. self.floor.index = cur.index;
  303. // On leveltype B
  304. }
  305. else {
  306. for (let i in self.stck.blocks) {
  307. self.stck.blocks[i].alpha = (i <= cur.index) ? 0.5 : 0.2;
  308. }
  309. // Saves the index of the selected 'stack' block
  310. self.stck.index = cur.index;
  311. }
  312. }
  313. },
  314. /**
  315. * Function called when cursos is out of a valid rectangle
  316. */
  317. func_outSquare: function () {
  318. if (!self.hasClicked) {
  319. document.body.style.cursor = 'auto';
  320. // On level type A
  321. if (levelType == 'A') {
  322. for (let i in self.floor.blocks) {
  323. self.floor.blocks[i].alpha = 0.5; // Back to normal
  324. }
  325. self.floor.index = -1;
  326. // On level type B
  327. }
  328. else {
  329. for (let i in self.stck.blocks) {
  330. self.stck.blocks[i].alpha = 0.5; // Back to normal
  331. }
  332. self.stck.index = -1;
  333. }
  334. }
  335. },
  336. /**
  337. * Function called when player clicks on a valid rectangle
  338. */
  339. func_clickSquare: function () {
  340. if (!self.hasClicked && !self.animateEnding) {
  341. document.body.style.cursor = 'auto';
  342. // On leveltype A
  343. if (levelType == 'A') {
  344. // Turns selection arrow completely visible
  345. self.arrow.alpha = 1;
  346. // Make the unselected blocks invisible (look like there's only the ground)
  347. for (let i in self.floor.blocks) {
  348. // (SELECTION : self.FLOOR.index)
  349. if (i > self.floor.index) self.floor.blocks[i].alpha = 0; // Make unselected 'floor' blocks invisible
  350. }
  351. // (FIXED : self.STCK.index) save the 'stacked' blocks index
  352. self.stck.index = self.stck.blocks.length - 1;
  353. // On leveltype B
  354. }
  355. else {
  356. for (let i in self.stck.blocks) {
  357. // (FIXED : self.STCK.index)
  358. if (i > self.stck.index) self.stck.blocks[i].alpha = 0; // Make unselected 'stacked' blocks invisible
  359. }
  360. // (SELECTION : self.FLOOR.index) save the 'floor' blocks index to compare to the stacked index in update
  361. self.floor.index = self.floor.blocks.length - 1;
  362. // Save the updated total stacked blocks to compare in update
  363. self.stck.blocks.length = self.stck.index + 1;
  364. }
  365. // Play beep sound
  366. if (audioStatus) game.audio.beepSound.play();
  367. // Hide labels
  368. if (fractionLabel) {
  369. self.stck.labels.forEach(cur => {
  370. cur.forEach(cur => { cur.alpha = 0; });
  371. });
  372. }
  373. // Hide solution pointer
  374. if (self.help != undefined) self.help.alpha = 0;
  375. // Turn tractir animation on
  376. game.animation.play(self.tractor.animation[0]);
  377. self.hasClicked = true;
  378. self.animate = true;
  379. }
  380. },
  381. /* GAME FUNCTIONS */
  382. /**
  383. * Create stacked blocks for the level (called in create())
  384. * @returns {boolean}
  385. */
  386. func_createStckBlocks: function () {
  387. let hasBaseDifficulty = false; // Will be true after next for loop if level has at least one '1/difficulty' fraction (if false, restart)
  388. const max = (levelType == 'B') ? 10 : mapPosition + 4; // Maximum number of stacked blocks for the level
  389. const total = game.math.randomInRange(mapPosition + 2, max); // Current number of stacked blocks for the level
  390. self.floor.correctXA = self.startX + self.defaultBlockWidth * self.DIREC_LEVEL;
  391. for (let i = 0; i < total; i++) { // For each stacked block
  392. let divisor = game.math.randomInRange(1, gameDifficulty); // Set divisor for fraction
  393. if (divisor == gameDifficulty) hasBaseDifficulty = true;
  394. if (divisor == 3) divisor = 4; // Make sure valid divisors are 1, 2 and 4 (not 3)
  395. self.divisorsList += divisor + ','; // List of divisors (for postScore())
  396. const curBlockWidth = self.defaultBlockWidth / divisor; // Current width is a fraction of the default
  397. self.floor.correctXA += curBlockWidth * self.DIREC_LEVEL;
  398. // Create stacked block (close to tractor)
  399. const lineColor = (sublevelType == 'Minus') ? colors.red : colors.darkBlue;
  400. const lineSize = 2;
  401. const block = game.add.graphic.rect(
  402. self.startX,
  403. 462 - i * (self.defaultBlockHeight - lineSize),
  404. curBlockWidth - lineSize,
  405. self.defaultBlockHeight - lineSize,
  406. lineColor,
  407. lineSize,
  408. colors.white,
  409. 1);
  410. const anchor = (sublevelType == 'Minus') ? 1 : 0;
  411. block.anchor(anchor, 0);
  412. // If game is type B, adding events to stacked blocks
  413. if (levelType == 'B') {
  414. block.alpha = 0.5;
  415. block.index = i;
  416. }
  417. self.stck.blocks.push(block);
  418. // If 'show fractions' is turned on, create labels that display the fractions on the side of each block
  419. if (fractionLabel) {
  420. const x = self.startX + (curBlockWidth + 15) * self.DIREC_LEVEL;
  421. const y = self.defaultBlockHeight - lineSize;
  422. const label = [];
  423. if (divisor == 1) {
  424. label[0] = game.add.text(x, 488 - i * y, divisor, textStyles.h2_blue);
  425. }
  426. else {
  427. label[0] = game.add.text(x, 479 - i * y + 16, divisor, textStyles.p_blue);
  428. label[1] = game.add.text(x, 479 - i * y, '1', textStyles.p_blue);
  429. label[2] = game.add.text(x, 479 - i * y, '_', textStyles.p_blue);
  430. }
  431. // Add current label to group of labels
  432. self.stck.labels.push(label);
  433. }
  434. }
  435. // Will be used as a counter in update, adding in the width of each stacked block to check if the end matches the floor selected position
  436. self.stck.curBlockEnd = self.startX + self.stck.blocks[0].width * self.DIREC_LEVEL;
  437. let restart = false;
  438. // Check for errors (level too easy for its difficulty or end position out of bounds)
  439. if (!hasBaseDifficulty ||
  440. (sublevelType == 'Plus' && (self.floor.correctXA < (self.startX + self.defaultBlockWidth) ||
  441. self.floor.correctXA > (self.startX + 8 * self.defaultBlockWidth))) ||
  442. (sublevelType == 'Minus' && (self.floor.correctXA < (self.startX - (8 * self.defaultBlockWidth)) ||
  443. self.floor.correctXA > (self.startX - self.defaultBlockWidth)))
  444. ) {
  445. restart = true; // If any error is found restart the level
  446. }
  447. if (debugMode) console.log('Stacked blocks: ' + total + ' (min: ' + (mapPosition + 2) + ', max: ' + max + ')');
  448. return restart;
  449. },
  450. /**
  451. * Create floor blocks for the level (called in create())
  452. */
  453. func_createFloorBlocks: function () { // For each floor block
  454. const divisor = (gameDifficulty == 3) ? 4 : gameDifficulty; // Make sure valid divisors are 1, 2 and 4 (not 3)
  455. let total = 8 * divisor; // Number of floor blocks
  456. const blockWidth = self.defaultBlockWidth / divisor; // Width of each floor block
  457. // If game is type B, selectiong a random floor x position
  458. if (levelType == 'B') {
  459. self.stck.correctIndex = game.math.randomInRange(0, (self.stck.blocks.length - 1)); // Correct stacked index
  460. self.floor.correctXB = self.startX + self.defaultBlockWidth * self.DIREC_LEVEL;
  461. for (let i = 0; i <= self.stck.correctIndex; i++) {
  462. self.floor.correctXB += self.stck.blocks[i].width * self.DIREC_LEVEL; // Equivalent x position on the floor
  463. }
  464. }
  465. let flag = true;
  466. for (let i = 0; i < total; i++) { // For each floor block
  467. // 'x' coordinate for floor block
  468. const x = self.startX + (self.defaultBlockWidth + i * blockWidth) * self.DIREC_LEVEL;
  469. if (flag && levelType == 'A') {
  470. if ( (sublevelType == 'Plus' && x >= self.floor.correctXA) || (sublevelType == 'Minus' && x <= self.floor.correctXA) ) {
  471. self.floor.correctIndex = i - 1; // Set index of correct floor block
  472. flag = false;
  473. }
  474. }
  475. if (levelType == 'B') {
  476. if ( (sublevelType == 'Plus' && x >= self.floor.correctXB) || (sublevelType == 'Minus' && x <= self.floor.correctXB) ) {
  477. total = i;
  478. break;
  479. }
  480. }
  481. // Create floor block
  482. const lineSize = 0.9;
  483. const block = game.add.graphic.rect(
  484. x,
  485. 462 + self.defaultBlockHeight - lineSize,
  486. blockWidth - lineSize,
  487. self.defaultBlockHeight - lineSize,
  488. colors.blueBckg,
  489. lineSize,
  490. colors.blueBckgInsideLevel,
  491. 1);
  492. const anchor = (sublevelType == 'Minus') ? 1 : 0;
  493. block.anchor(anchor, 0);
  494. // If game is type A, adding events to floor blocks
  495. if (levelType == 'A') {
  496. block.alpha = 0.5;
  497. block.index = i;
  498. }
  499. // Add current label to group of labels
  500. self.floor.blocks.push(block);
  501. }
  502. if (levelType == 'A') self.floor.correctX = self.floor.correctXA;
  503. else if (levelType == 'B') self.floor.correctX = self.floor.correctXB;
  504. // Creates labels on the floor to display the numbers
  505. for (let i = 1; i < 10; i++) {
  506. const x = self.startX + (i * self.defaultBlockWidth * self.DIREC_LEVEL);
  507. game.add.text(x, 462 + self.defaultBlockHeight + 58, i - 1, textStyles.h2_blue);
  508. }
  509. },
  510. /**
  511. * Display correct answer
  512. */
  513. func_viewHelp: function () {
  514. if (!self.hasClicked) {
  515. // On levelType A
  516. if (levelType == 'A') {
  517. const aux = self.floor.blocks[0];
  518. self.help.x = self.floor.correctX - aux.width / 2 * self.DIREC_LEVEL;
  519. self.help.y = 501;
  520. // On levelType B
  521. }
  522. else {
  523. const aux = self.stck.blocks[self.stck.correctIndex];
  524. self.help.x = aux.x + aux.width / 2 * self.DIREC_LEVEL;
  525. self.help.y = aux.y;
  526. }
  527. self.help.alpha = 0.7;
  528. }
  529. },
  530. /* METADATA FOR GAME */
  531. /**
  532. * Saves players data after level
  533. *
  534. * Attention: the "line_" prefix data table must be compatible to data table fields (MySQL server)
  535. * @see ./php/save.php
  536. */
  537. postScore: function () {
  538. // Saves player data to send to the database
  539. const data = '&line_game=' + gameShape
  540. + '&line_mode=' + levelType
  541. + '&line_oper=' + sublevelType
  542. + '&line_leve=' + gameDifficulty
  543. + '&line_posi=' + mapPosition
  544. + '&line_resu=' + self.result
  545. + '&line_time=' + game.timer.elapsed
  546. + '&line_deta='
  547. + 'numBlocks:' + self.stck.blocks.length
  548. + ', valBlocks: ' + self.divisorsList // Ends in ','
  549. + ' blockIndex: ' + self.stck.index
  550. + ', floorIndex: ' + self.floor.index;
  551. postScore(data);
  552. },
  553. };