squareOne.js 26 KB

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