circleOne.js 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467
  1. /******************************
  2. * This file holds game states.
  3. ******************************/
  4. /** [GAME STATE]
  5. *
  6. * .....circleOne.... = gameName
  7. * ....../...\.......
  8. * .....a.....b...... = gameMode
  9. * .......\./........
  10. * ........|.........
  11. * ....../.|.\.......
  12. * .plus.minus.mixed. = gameOperation
  13. * ......\.|./.......
  14. * ........|.........
  15. * ......1,2,3....... = gameDifficulty
  16. *
  17. * Character : kid/balloon
  18. * Theme : flying in a balloon
  19. * Concept : 'How much the kid has to walk to get to the balloon?'
  20. * Represent fractions as : circles/arcs
  21. *
  22. * Game modes can be :
  23. *
  24. * a : Player can place balloon position
  25. * Place balloon in position (so the kid can get to it)
  26. * b : Player can select # of circles
  27. * Selects number of circles (that represent distance kid needs to walk to get to the balloon)
  28. *
  29. * Operations can be :
  30. *
  31. * plus : addition of fractions
  32. * Represented by : kid going to the right (floor positions 0..5)
  33. * minus : subtraction of fractions
  34. * Represented by: kid going to the left (floor positions 5..0)
  35. * mixed : Mix addition and subtraction of fractions in same
  36. * Represented by: kid going to the left (floor positions 0..5)
  37. *
  38. * @namespace
  39. */
  40. const circleOne = {
  41. ui: undefined,
  42. control: undefined,
  43. animation: undefined,
  44. road: undefined,
  45. circles: undefined,
  46. kid: undefined,
  47. balloon: undefined,
  48. basket: undefined,
  49. walkedPath: undefined,
  50. /**
  51. * Main code
  52. */
  53. create: function () {
  54. this.ui = {
  55. help: undefined,
  56. message: undefined,
  57. continue: {
  58. // modal: undefined,
  59. button: undefined,
  60. text: undefined,
  61. },
  62. };
  63. this.road = {
  64. x: 150,
  65. y: context.canvas.height - game.image['floor_grass'].width * 1.5,
  66. width: 1620,
  67. };
  68. this.walkedPath = [];
  69. const pointWidth = (game.sprite['map_place'].width / 2) * 0.45;
  70. const distanceBetweenPoints =
  71. (context.canvas.width - this.road.x * 2 - pointWidth) / 5; // Distance between road points
  72. const y0 = this.road.y + 20;
  73. const x0 =
  74. gameOperation === 'minus'
  75. ? context.canvas.width - this.road.x - pointWidth / 2
  76. : this.road.x + pointWidth / 2; // Initial 'x' coordinate for the kid and the baloon
  77. const diameter =
  78. game.math.getRadiusFromCircunference(distanceBetweenPoints) * 2;
  79. this.circles = {
  80. diameter: diameter, // (Fixed) Circles Diameter
  81. cur: 0, // Current circle index
  82. list: [], // Circle objects
  83. };
  84. this.control = {
  85. correctX: x0, // Correct position (accumulative)
  86. nextX: undefined, // Next point position
  87. divisorsList: '', // used in postScore (Accumulative)
  88. hasClicked: false, // Checks if user has clicked
  89. checkAnswer: false, // Check kid inside ballon's basket
  90. isCorrect: false, // Informs answer is correct
  91. showEndInfo: false,
  92. endSignX: undefined,
  93. curWalkedPath: 0,
  94. // mode 'b' exclusive
  95. correctIndex: undefined,
  96. selectedIndex: -1, // Index of clicked circle (game (b))
  97. numberOfPlusFractions: undefined,
  98. };
  99. const walkOffsetX = 2;
  100. const walksPerDistanceBetweenPoints = distanceBetweenPoints / walkOffsetX;
  101. this.animation = {
  102. list: {
  103. left: undefined,
  104. right: undefined,
  105. },
  106. invertDirection: undefined,
  107. animateKid: false,
  108. animateBalloon: false,
  109. counter: undefined,
  110. walkOffsetX,
  111. angleOffset: 360 / walksPerDistanceBetweenPoints,
  112. };
  113. renderBackground('farmRoad');
  114. // Calls function that loads navigation icons
  115. // FOR MOODLE
  116. if (moodle) {
  117. navigation.add.right(['audio']);
  118. } else {
  119. navigation.add.left(['back', 'menu', 'show_answer'], 'customMenu');
  120. navigation.add.right(['audio']);
  121. }
  122. const validPath = { x0, y0, distanceBetweenPoints };
  123. // this.utils.renderRoadBlocks();
  124. this.utils.renderRoad(validPath);
  125. const [restart, balloonX] = this.utils.renderCircles(validPath);
  126. this.restart = restart;
  127. this.utils.renderCharacters(validPath, balloonX);
  128. this.utils.renderMainUI();
  129. if (!this.restart) {
  130. game.timer.start(); // Set a timer for the current level (used in postScore())
  131. game.event.add('click', this.events.onInputDown);
  132. game.event.add('mousemove', this.events.onInputOver);
  133. }
  134. },
  135. /**
  136. * Game loop
  137. */
  138. update: function () {
  139. // Starts kid animation
  140. if (self.animation.animateKid) {
  141. self.utils.animateKidHandler();
  142. }
  143. // Check if kid is inside the basket
  144. if (self.control.checkAnswer) {
  145. self.utils.checkAnswerHandler();
  146. }
  147. // Starts balloon flying animation
  148. if (self.animation.animateBalloon) {
  149. self.utils.animateBalloonHandler();
  150. }
  151. game.render.all();
  152. },
  153. utils: {
  154. renderRoadBlocks: function () {
  155. const pointWidth = (game.sprite['map_place'].width / 2) * 0.45;
  156. const roadX = self.road.x + pointWidth / 2;
  157. const roadWidth = self.road.width - pointWidth;
  158. const roadMainDivisions = 5;
  159. const roadSubdivisions = gameDifficulty === 3 ? 4 : gameDifficulty;
  160. const roadDivisions = roadMainDivisions * roadSubdivisions;
  161. const blockWidth = roadWidth / roadDivisions;
  162. const blockHeight = 50;
  163. const blockList = [];
  164. for (let i = 0; i < roadDivisions; i++) {
  165. const block = game.add.geom.rect(
  166. roadX + i * blockWidth,
  167. self.road.y,
  168. blockWidth,
  169. blockHeight,
  170. 'transparent',
  171. 0.5,
  172. colors.red,
  173. 2
  174. );
  175. block.info = { index: i };
  176. blockList.push(block);
  177. }
  178. console.log(blockList);
  179. },
  180. // RENDERS
  181. renderRoad: function (validPath) {
  182. const directionModifier = gameOperation === 'minus' ? -1 : 1;
  183. for (let i = 0; i <= 5; i++) {
  184. // Gray place
  185. game.add
  186. .sprite(
  187. validPath.x0 +
  188. i * validPath.distanceBetweenPoints * directionModifier,
  189. validPath.y0,
  190. 'map_place',
  191. 0,
  192. 0.45
  193. )
  194. .anchor(0.5, 0.5);
  195. // White circle behind number
  196. game.add.geom
  197. .circle(
  198. validPath.x0 +
  199. i * validPath.distanceBetweenPoints * directionModifier,
  200. validPath.y0 + 60,
  201. 60,
  202. undefined,
  203. 0,
  204. colors.white,
  205. 0.8
  206. )
  207. .anchor(0, 0.25);
  208. // Number
  209. game.add.text(
  210. validPath.x0 +
  211. i * validPath.distanceBetweenPoints * directionModifier,
  212. validPath.y0 + 60,
  213. i * directionModifier,
  214. {
  215. ...textStyles.h2_,
  216. font: 'bold ' + textStyles.h2_.font,
  217. fill: directionModifier === 1 ? colors.green : colors.red,
  218. }
  219. );
  220. }
  221. self.utils.renderWalkedPath(
  222. validPath.x0 - 1,
  223. validPath.y0 - 5,
  224. gameOperation === 'minus' ? colors.red : colors.green
  225. );
  226. },
  227. renderWalkedPath: function (x, y, color) {
  228. const path = game.add.geom.rect(x, y, 1, 1, 'transparent', 1, color, 4);
  229. self.walkedPath.push(path);
  230. return path;
  231. },
  232. renderCircles: function (validPath) {
  233. let restart = false;
  234. let hasBaseDifficulty = false;
  235. let balloonX = context.canvas.width / 2;
  236. const directionModifier = gameOperation === 'minus' ? -1 : 1;
  237. const fractionX =
  238. validPath.x0 - (self.circles.diameter - 10) * directionModifier;
  239. const font = {
  240. ...textStyles.h2_,
  241. font: 'bold ' + textStyles.h2_.font,
  242. };
  243. // Number of circles
  244. const max = gameOperation === 'mixed' ? 6 : curMapPosition + 1;
  245. const min =
  246. curMapPosition === 1 && (gameOperation === 'mixed' || gameMode === 'b')
  247. ? 2
  248. : curMapPosition; // Mixed level has at least 2 fractions
  249. const total = game.math.randomInRange(min, max); // Total number of circles
  250. // for mode 'b'
  251. self.control.numberOfPlusFractions = game.math.randomInRange(
  252. 1,
  253. total - 1
  254. );
  255. for (let i = 0; i < total; i++) {
  256. let curDirection = undefined;
  257. let curLineColor = undefined;
  258. let curFillColor = undefined;
  259. let curAngleDegree = undefined;
  260. let curIsCounterclockwise = undefined;
  261. let curFractionItems = undefined;
  262. let curCircle = undefined;
  263. const curCircleInfo = {
  264. direction: undefined,
  265. direc: undefined,
  266. distance: undefined,
  267. angle: undefined,
  268. fraction: {
  269. labels: [],
  270. nominator: undefined,
  271. denominator: undefined,
  272. },
  273. };
  274. const curDivisor = game.math.randomInRange(1, gameDifficulty); // Set fraction 'divisor' (depends on difficulty)
  275. if (curDivisor === gameDifficulty) hasBaseDifficulty = true; // True if after for ends has at least 1 '1/difficulty' fraction
  276. self.control.divisorsList += curDivisor + ','; // Add this divisor to the list of divisors (for postScore())
  277. // Set each circle direction
  278. switch (gameOperation) {
  279. case 'plus':
  280. curDirection = 'right';
  281. break;
  282. case 'minus':
  283. curDirection = 'left';
  284. break;
  285. case 'mixed':
  286. curDirection =
  287. i < self.control.numberOfPlusFractions ? 'right' : 'left';
  288. break;
  289. }
  290. curCircleInfo.direction = curDirection;
  291. // Set each circle visual info
  292. if (curDirection === 'right') {
  293. curIsCounterclockwise = true;
  294. curLineColor = colors.green;
  295. curFillColor = colors.greenLight;
  296. curCircleInfo.direc = 1;
  297. } else {
  298. curIsCounterclockwise = false;
  299. curLineColor = colors.red;
  300. curFillColor = colors.redLight;
  301. curCircleInfo.direc = -1;
  302. }
  303. font.fill = curLineColor;
  304. const curCircleY =
  305. validPath.y0 -
  306. 5 -
  307. self.circles.diameter / 2 -
  308. i * self.circles.diameter;
  309. // Draw circles
  310. if (curDivisor === 1) {
  311. curAngleDegree = 360;
  312. curCircle = game.add.geom.circle(
  313. validPath.x0,
  314. curCircleY,
  315. self.circles.diameter,
  316. curLineColor,
  317. 3,
  318. curFillColor,
  319. 1
  320. );
  321. curCircle.counterclockwise = curIsCounterclockwise;
  322. curCircleInfo.angleDegree = curAngleDegree;
  323. curFractionItems = [
  324. {
  325. x: fractionX,
  326. y: curCircleY + 10,
  327. text: '1',
  328. },
  329. {
  330. x: fractionX - 25,
  331. y: curCircleY + 10,
  332. text: curDirection === 'left' ? '-' : '',
  333. },
  334. null,
  335. ];
  336. } else {
  337. curAngleDegree = 360 / curDivisor;
  338. if (curDirection === 'right') curAngleDegree = 360 - curAngleDegree; // counterclockwise equivalent
  339. curCircle = game.add.geom.arc(
  340. validPath.x0,
  341. curCircleY,
  342. self.circles.diameter,
  343. 0,
  344. game.math.degreeToRad(curAngleDegree),
  345. curIsCounterclockwise,
  346. curLineColor,
  347. 3,
  348. curFillColor,
  349. 1
  350. );
  351. curCircleInfo.angleDegree = curAngleDegree;
  352. curFractionItems = [
  353. {
  354. x: fractionX,
  355. y: curCircleY - 2,
  356. text: `1\n${curDivisor}`,
  357. },
  358. {
  359. x: fractionX - 35,
  360. y: curCircleY + 15,
  361. text: curDirection === 'left' ? '-' : '',
  362. },
  363. {
  364. x0: fractionX,
  365. y0: curCircleY + 2,
  366. x1: fractionX + 25,
  367. y1: curCircleY + 2,
  368. lineWidth: 2,
  369. color: curLineColor,
  370. },
  371. ];
  372. }
  373. for (let i = 0; i < 2; i++) {
  374. const item = game.add.text(
  375. curFractionItems[i].x,
  376. curFractionItems[i].y,
  377. curFractionItems[i].text,
  378. font
  379. );
  380. item.lineHeight = 37;
  381. curCircleInfo.fraction.labels.push(item);
  382. }
  383. if (curFractionItems[2]) {
  384. const line = game.add.geom.line(
  385. curFractionItems[2].x0,
  386. curFractionItems[2].y0,
  387. curFractionItems[2].x1,
  388. curFractionItems[2].y1,
  389. curFractionItems[2].lineWidth,
  390. curFractionItems[2].color
  391. );
  392. line.anchor(0.5, 0);
  393. curCircleInfo.fraction.labels.push(line);
  394. } else {
  395. curCircleInfo.fraction.labels.push(null);
  396. }
  397. curCircleInfo.fraction.nominator = curCircleInfo.direc;
  398. curCircleInfo.fraction.denominator = curDivisor;
  399. if (!showFractions) {
  400. curCircleInfo.fraction.labels.forEach((label) => {
  401. if (label) label.alpha = 0;
  402. });
  403. }
  404. curCircle.rotate = 90;
  405. // If game is type (b) (select fractions)
  406. if (gameMode === 'b') {
  407. curCircle.index = i;
  408. }
  409. curCircleInfo.distance = Math.floor(
  410. validPath.distanceBetweenPoints / curDivisor
  411. );
  412. // Add to the list
  413. curCircle.info = curCircleInfo;
  414. self.circles.list.push(curCircle);
  415. self.control.correctX +=
  416. Math.floor(validPath.distanceBetweenPoints / curDivisor) *
  417. curCircle.info.direc;
  418. }
  419. // Restart if
  420. // Does not have at least one fraction of type 1/difficulty
  421. if (!hasBaseDifficulty) {
  422. restart = true;
  423. }
  424. // Calculate next circle
  425. self.control.nextX =
  426. validPath.x0 +
  427. self.circles.list[0].info.distance * self.circles.list[0].info.direc;
  428. let isBeforeMin = (isAfterMax = false);
  429. let finalPosition = self.control.correctX;
  430. // Restart if
  431. // In Game mode 'a' and 'b' : Balloon position is out of bounds
  432. if (gameOperation === 'minus') {
  433. isBeforeMin = finalPosition > validPath.x0;
  434. isAfterMax =
  435. finalPosition < validPath.x0 - 5 * validPath.distanceBetweenPoints;
  436. } else {
  437. isBeforeMin = finalPosition < validPath.x0;
  438. isAfterMax =
  439. finalPosition > validPath.x0 + 5 * validPath.distanceBetweenPoints;
  440. }
  441. if (isBeforeMin || isAfterMax) restart = true;
  442. if (gameMode === 'b') {
  443. // If game is type (b), select a random balloon place
  444. balloonX = validPath.x0;
  445. self.control.correctIndex = game.math.randomInRange(
  446. self.control.numberOfPlusFractions,
  447. self.circles.list.length
  448. );
  449. for (let i = 0; i < self.control.correctIndex; i++) {
  450. balloonX +=
  451. self.circles.list[i].info.distance *
  452. self.circles.list[i].info.direc;
  453. }
  454. finalPosition = balloonX;
  455. // Restart if
  456. // In Game mode 'b' : Top circle position is out of bounds (when on the ground)
  457. if (gameOperation === 'minus') {
  458. isBeforeMin = finalPosition > validPath.x0;
  459. isAfterMax =
  460. finalPosition < validPath.x0 - 5 * validPath.distanceBetweenPoints;
  461. } else {
  462. isBeforeMin = finalPosition < validPath.x0;
  463. isAfterMax =
  464. finalPosition > validPath.x0 + 5 * validPath.distanceBetweenPoints;
  465. }
  466. if (isBeforeMin || isAfterMax) restart = true;
  467. }
  468. return [restart, balloonX];
  469. },
  470. renderCharacters: function (validPath, balloonX) {
  471. // KID
  472. self.kid = game.add.sprite(
  473. validPath.x0,
  474. validPath.y0 - 32 - self.circles.list.length * self.circles.diameter,
  475. 'kid_walking',
  476. 0,
  477. 1.2
  478. );
  479. self.kid.anchor(0.5, 0.8);
  480. self.animation.list.right = [
  481. 'right',
  482. [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
  483. 4,
  484. ];
  485. self.animation.list.left = [
  486. 'left',
  487. [23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12],
  488. 4,
  489. ];
  490. if (gameOperation === 'minus') {
  491. self.kid.animation = self.animation.list.left;
  492. self.kid.curFrame = 23;
  493. } else {
  494. self.kid.animation = self.animation.list.right;
  495. }
  496. // BALLOON
  497. self.balloon = game.add.image(
  498. balloonX,
  499. validPath.y0 - 295,
  500. 'balloon',
  501. 1.5,
  502. 0.5
  503. );
  504. self.balloon.alpha = 0.5;
  505. self.balloon.anchor(0.5, 0.5);
  506. self.basket = game.add.image(
  507. balloonX,
  508. validPath.y0 - 95,
  509. 'balloon_basket',
  510. 1.5
  511. );
  512. self.basket.alpha = 0.8;
  513. self.basket.anchor(0.5, 0.5);
  514. },
  515. renderMainUI: function () {
  516. // Help pointer
  517. self.ui.help = game.add.image(0, 0, 'pointer', 2, 0);
  518. // Intro text
  519. const correctMessage =
  520. gameMode === 'a'
  521. ? game.lang.circleOne_intro_a
  522. : game.lang.circleOne_intro_b;
  523. const treatedMessage = correctMessage.split('\\n');
  524. self.ui.message = [];
  525. self.ui.message.push(
  526. game.add.text(
  527. context.canvas.width / 2,
  528. 170,
  529. treatedMessage[0] + '\n' + treatedMessage[1],
  530. textStyles.h1_
  531. )
  532. );
  533. },
  534. renderOperationUI: function () {
  535. /**
  536. * if game mode A:
  537. * - left: selected balloon position (user selection)
  538. * - right: line created from the stack of arcs (pre-set)
  539. *
  540. * if game mode B:
  541. * - left: line created from the stack of arcs (user selection)
  542. * - right: baloon position (pre-set)
  543. */
  544. let validCircles = self.circles.list;
  545. if (gameMode === 'b') {
  546. validCircles = [];
  547. for (let i = 0; i <= self.control.selectedIndex; i++) {
  548. validCircles.push(self.circles.list[i]);
  549. }
  550. }
  551. const font = textStyles.fraction;
  552. font.fill = colors.green;
  553. const nominators = [];
  554. const denominators = [];
  555. const renderList = [];
  556. const padding = 100;
  557. const offsetX = 100;
  558. const widthOfChar = 35;
  559. const x0 = padding;
  560. const y0 = context.canvas.height / 3;
  561. let nextX = x0;
  562. const cardHeight = 400;
  563. const cardX = x0 - padding;
  564. const cardY = y0;
  565. // Card
  566. const card = game.add.geom.rect(
  567. cardX,
  568. cardY,
  569. 0,
  570. cardHeight,
  571. colors.blueLight,
  572. 0.5,
  573. colors.blueDark,
  574. 8
  575. );
  576. card.id = 'card';
  577. card.anchor(0, 0.5);
  578. renderList.push(card);
  579. // Fraction list
  580. for (let i in validCircles) {
  581. const curFraction = validCircles[i].info.fraction;
  582. const curFractionString = curFraction.labels[0].name;
  583. let curFractionSign = i !== '0' ? '+' : '';
  584. if (curFraction.labels[1].name === '-') {
  585. curFractionSign = '-';
  586. font.fill = colors.red;
  587. }
  588. const fractionText = game.add.text(
  589. x0 + i * offsetX + offsetX / 2,
  590. curFractionString === '1' ? y0 + 40 : y0,
  591. curFractionString,
  592. font
  593. );
  594. fractionText.lineHeight = 70;
  595. renderList.push(
  596. game.add.text(x0 + i * offsetX, y0 + 35, curFractionSign, font)
  597. );
  598. renderList.push(fractionText);
  599. renderList.push(
  600. game.add.text(
  601. x0 + offsetX / 2 + i * offsetX,
  602. y0,
  603. curFractionString === '1' ? '' : '_',
  604. font
  605. )
  606. );
  607. nominators.push(curFraction.nominator);
  608. denominators.push(curFraction.denominator);
  609. }
  610. // Setup for fraction operation with least common multiple
  611. font.fill = colors.black;
  612. const updatedNominators = [];
  613. const mmc = game.math.mmcArray(denominators);
  614. let resultNominator = 0;
  615. for (let i in nominators) {
  616. const temp = nominators[i] * (mmc / denominators[i]);
  617. updatedNominators.push(temp);
  618. resultNominator += temp;
  619. }
  620. const resultNominatorUnsigned =
  621. resultNominator < 0 ? -resultNominator : resultNominator;
  622. const resultAux = resultNominator / mmc;
  623. const result =
  624. ('' + resultAux).length > 4 ? resultAux.toFixed(2) : resultAux;
  625. // Fraction operation with least common multiple
  626. nextX = x0 + validCircles.length * offsetX + 20;
  627. // Fraction result
  628. renderList.push(game.add.text(nextX, y0 + 35, '=', font));
  629. font.align = 'center';
  630. nextX += offsetX;
  631. if (result < 0) {
  632. nextX -= 30;
  633. renderList.push(game.add.text(nextX, y0 + 35, '-', font));
  634. nextX += 60;
  635. }
  636. const fractionResult = game.add.text(
  637. nextX,
  638. mmc === 1 || resultNominatorUnsigned === 0 ? y0 + 40 : y0,
  639. mmc === 1 || resultNominatorUnsigned === 0
  640. ? resultNominatorUnsigned
  641. : resultNominatorUnsigned + '\n' + mmc,
  642. font
  643. );
  644. fractionResult.lineHeight = 70;
  645. renderList.push(fractionResult);
  646. const fractionLine = game.add.geom.line(
  647. nextX,
  648. y0 + 15,
  649. nextX + 60,
  650. y0 + 15,
  651. 4,
  652. colors.black,
  653. mmc === 1 || resultNominatorUnsigned === 0 ? 0 : 1
  654. );
  655. fractionLine.anchor(0.5, 0);
  656. renderList.push(fractionLine);
  657. // Fraction result simplified setup
  658. const mdcAux = game.math.mdc(resultNominator, mmc);
  659. const mdc = mdcAux < 0 ? -mdcAux : mdcAux;
  660. if (mdc !== 1 && resultNominatorUnsigned !== 0) {
  661. // alert(mdc + ' ' + resultNominatorUnsigned);
  662. nextX += offsetX;
  663. renderList.push(game.add.text(nextX, y0 + 35, '=', font));
  664. nextX += offsetX;
  665. renderList.push(
  666. game.add.text(nextX - 50, y0 + 35, result > 0 ? '' : '-', font)
  667. );
  668. renderList.push(
  669. game.add.text(nextX, y0, resultNominatorUnsigned / mdc, font)
  670. );
  671. renderList.push(game.add.text(nextX, y0 + 70, mmc / mdc, font));
  672. const fractionLine = game.add.geom.line(
  673. nextX,
  674. y0 + 15,
  675. nextX + 60,
  676. y0 + 15,
  677. 4,
  678. colors.black
  679. );
  680. fractionLine.anchor(0.5, 0);
  681. renderList.push(fractionLine);
  682. }
  683. // Decimal result
  684. let resultWidth = '_'.length * widthOfChar;
  685. const cardWidth = nextX - x0 + resultWidth + padding * 2;
  686. card.width = cardWidth;
  687. const endSignX = (context.canvas.width - cardWidth) / 2 + cardWidth;
  688. // Center Card
  689. moveList(renderList, (context.canvas.width - cardWidth) / 2, 0);
  690. self.fractionOperationUI = renderList;
  691. return endSignX;
  692. },
  693. renderOperationUI_new: () => {
  694. /**
  695. * if game mode A:
  696. * - left: selected balloon position (user selection)
  697. * - right: correct sum of stack of arcs (pre-set)
  698. *
  699. * if game mode B:
  700. * - left: line created from the stack of arcs (user selection)
  701. * - right: baloon position (pre-set)
  702. */
  703. const divisor = gameDifficulty == 3 ? 4 : gameDifficulty;
  704. // const renderFloorFractions = (lastIndex, divisor) => {
  705. // const operator = gameOperation === 'minus' ? '-' : '+';
  706. // const index = lastIndex;
  707. // const blocks = index + 1;
  708. // const valueReal = blocks / divisor;
  709. // const valueFloor = Math.floor(valueReal);
  710. // const valueRest = valueReal - valueFloor;
  711. // let fracNomin = (fracDenomin = fracLine = '');
  712. // // adds sign on the left of the equation
  713. // if (gameOperation === 'minus') {
  714. // fracNomin += ' ';
  715. // fracDenomin += ' ';
  716. // fracLine += operator;
  717. // }
  718. // // 1 _ _
  719. // if (valueFloor) {
  720. // fracNomin += ' ';
  721. // fracDenomin += ' ';
  722. // fracLine += valueFloor;
  723. // }
  724. // // _ + _
  725. // if (valueFloor && valueRest) {
  726. // fracNomin += ' ';
  727. // fracDenomin += ' ';
  728. // fracLine += operator;
  729. // }
  730. // // _ _ 1/5
  731. // if (valueRest) {
  732. // fracNomin += `${valueRest * divisor}`;
  733. // fracDenomin += `${divisor}`;
  734. // fracLine += '-';
  735. // }
  736. // return [fracNomin, fracDenomin, fracLine, valueReal];
  737. // };
  738. const renderStackFractions = (lastIndex) => {
  739. const operator = gameOperation === 'minus' ? '-' : '+';
  740. const index = lastIndex;
  741. const blocks = index + 1;
  742. const nominators = [];
  743. const denominators = [];
  744. const values = [];
  745. let valueReal = 0;
  746. let fracNomin = (fracDenomin = fracLine = '');
  747. for (let i = 0; i < blocks; i++) {
  748. const m = self.circles.list[i].info.fraction.denominator || 1;
  749. const temp = self.circles.list[i].info.fraction.nominator || 0;
  750. const n = gameOperation === 'minus' ? -temp : +temp;
  751. const nm = n / m;
  752. nominators[i] = n + 0;
  753. denominators[i] = m + 0;
  754. values[i] = nm;
  755. valueReal += nm;
  756. }
  757. for (let i = 0; i < blocks; i++) {
  758. const valueReal = values[i];
  759. const valueFloor = Math.floor(valueReal);
  760. const valueRest = valueReal - valueFloor;
  761. if (i > 0 || gameOperation === 'minus') {
  762. fracNomin += ' ';
  763. fracDenomin += ' ';
  764. fracLine += operator;
  765. }
  766. if (valueFloor && !valueRest) {
  767. fracNomin += ' ';
  768. fracDenomin += ' ';
  769. fracLine += valueFloor;
  770. }
  771. if (valueRest) {
  772. fracNomin += `${nominators[i]}`;
  773. fracDenomin += `${denominators[i]}`;
  774. fracLine += '-';
  775. }
  776. }
  777. console.log(fracNomin, fracDenomin, fracLine, valueReal);
  778. return [fracNomin, fracDenomin, fracLine, valueReal];
  779. };
  780. const xyz = () => {
  781. const x0 = +self.road.x;
  782. // console.log(x0);
  783. const xEnd = +self.road.width;
  784. // console.log(xEnd);
  785. const blockWidth = +xEnd / 5;
  786. // console.log(blockWidth);
  787. const selectedX = +self.balloon.x;
  788. // console.log(selectedX);
  789. let count = (selectedX - x0) / blockWidth;
  790. count = Math.floor(count);
  791. // console.log(count);
  792. return count;
  793. };
  794. // Initial setup
  795. const font = textStyles.fraction;
  796. font.fill = colors.black;
  797. const padding = 100;
  798. const offsetX = 100;
  799. const widthOfChar = 35;
  800. const x0 = padding;
  801. const y0 = context.canvas.height / 3;
  802. let nextX = x0;
  803. const cardHeight = 400;
  804. const cardX = x0 - padding;
  805. const cardY = y0;
  806. const renderList = [];
  807. // Render Card
  808. const card = game.add.geom.rect(
  809. cardX,
  810. cardY,
  811. 0,
  812. cardHeight,
  813. colors.blueLight,
  814. 0.5,
  815. colors.blueDark,
  816. 8
  817. );
  818. card.id = 'card';
  819. card.anchor(0, 0.5);
  820. renderList.push(card);
  821. // Fraction setup
  822. // console.clear();
  823. // const [floorNominators, floorDenominators, floorLines, floorValue] =
  824. // renderFloorFractions(self.floor.selectedIndex, divisor);
  825. console.log(self);
  826. const [stackNominators, stackDenominators, stackLines, stackValue] =
  827. renderStackFractions(self.circles.cur - 1);
  828. const renderFloorOperationLine = (x) => {
  829. font.fill = colors.black;
  830. const floorNom = game.add.text(x + offsetX / 2, y0, '', font, 60);
  831. const floorDenom = game.add.text(
  832. x + offsetX / 2,
  833. y0 + 70,
  834. '',
  835. font,
  836. 60
  837. );
  838. const floorLin = game.add.text(
  839. x + offsetX / 2,
  840. y0 + 35,
  841. xyz(),
  842. font,
  843. 60
  844. );
  845. renderList.push(floorNom);
  846. renderList.push(floorDenom);
  847. renderList.push(floorLin);
  848. return;
  849. // font.fill = colors.black;
  850. // const floorNom = game.add.text(
  851. // x + offsetX / 2,
  852. // y0,
  853. // floorNominators,
  854. // font,
  855. // 60
  856. // );
  857. // const floorDenom = game.add.text(
  858. // x + offsetX / 2,
  859. // y0 + 70,
  860. // floorDenominators,
  861. // font,
  862. // 60
  863. // );
  864. // const floorLin = game.add.text(
  865. // x + offsetX / 2,
  866. // y0 + 35,
  867. // floorLines,
  868. // font,
  869. // 60
  870. // );
  871. // renderList.push(floorNom);
  872. // renderList.push(floorDenom);
  873. // renderList.push(floorLin);
  874. };
  875. const renderStackOperationLine = (x) => {
  876. font.fill = colors.black;
  877. const stackNom = game.add.text(
  878. x + offsetX / 2,
  879. y0,
  880. stackNominators,
  881. font,
  882. 60
  883. );
  884. const stackDenom = game.add.text(
  885. x + offsetX / 2,
  886. y0 + 70,
  887. stackDenominators,
  888. font,
  889. 60
  890. );
  891. const stackLin = game.add.text(
  892. x + offsetX / 2,
  893. y0 + 35,
  894. stackLines,
  895. font,
  896. 60
  897. );
  898. renderList.push(stackNom);
  899. renderList.push(stackDenom);
  900. renderList.push(stackLin);
  901. };
  902. // Render LEFT part of the operation
  903. // if (gameMode === 'a') renderFloorOperationLine(x0);
  904. // else renderStackOperationLine(x0);
  905. renderFloorOperationLine(x0);
  906. // let curNominators = gameMode === 'a' ? floorNominators : stackNominators;
  907. let curNominators = '1';
  908. nextX = x0 + (curNominators.length + 2) * widthOfChar;
  909. // Render middle sign - equal by default
  910. font.fill = colors.green;
  911. let comparisonSign = '=';
  912. // Render middle sign - if not equal
  913. // if (floorValue != stackValue) {
  914. // font.fill = colors.red;
  915. // let leftSideIsLarger = floorValue > stackValue;
  916. // if (gameMode === 'b') leftSideIsLarger = !leftSideIsLarger;
  917. // if (gameOperation === 'minus') leftSideIsLarger = !leftSideIsLarger;
  918. // comparisonSign = leftSideIsLarger ? '>' : '<';
  919. // }
  920. renderList.push(game.add.text(nextX, y0 + 35, comparisonSign, font));
  921. // Render RIGHT part of the operationf
  922. // if (gameMode === 'a')
  923. renderStackOperationLine(nextX);
  924. // else renderFloorOperationLine(nextX);
  925. curNominators = gameMode === 'a' ? stackNominators : floorNominators;
  926. const resultWidth = (curNominators.length + 2) * widthOfChar;
  927. const cardWidth = nextX - x0 + resultWidth + padding * 2;
  928. card.width = cardWidth;
  929. const endSignX = (context.canvas.width - cardWidth) / 2 + cardWidth;
  930. // Center Card
  931. moveList(renderList, (context.canvas.width - cardWidth) / 2, 0);
  932. self.fractionOperationUI = renderList;
  933. return endSignX;
  934. },
  935. renderEndUI: () => {
  936. let btnColor = colors.green;
  937. let btnText = game.lang.continue;
  938. if (!self.control.isCorrect) {
  939. btnColor = colors.red;
  940. btnText = game.lang.retry;
  941. }
  942. // continue button
  943. self.ui.continue.button = game.add.geom.rect(
  944. context.canvas.width / 2,
  945. context.canvas.height / 2 + 100,
  946. 450,
  947. 100,
  948. btnColor
  949. );
  950. self.ui.continue.button.anchor(0.5, 0.5);
  951. self.ui.continue.text = game.add.text(
  952. context.canvas.width / 2,
  953. context.canvas.height / 2 + 16 + 100,
  954. btnText,
  955. textStyles.btn
  956. );
  957. },
  958. // UPDATE
  959. animateKidHandler: function () {
  960. let canLowerCircles = undefined;
  961. let curCircle = self.circles.list[self.circles.cur];
  962. let curDirec = curCircle.info.direc;
  963. // Move
  964. self.circles.list.forEach((circle) => {
  965. circle.x += self.animation.walkOffsetX * curDirec;
  966. });
  967. self.kid.x += self.animation.walkOffsetX * curDirec;
  968. self.walkedPath[self.control.curWalkedPath].width +=
  969. self.animation.walkOffsetX * curDirec;
  970. // Update arc
  971. curCircle.info.angleDegree += self.animation.angleOffset * curDirec;
  972. curCircle.angleEnd = game.math.degreeToRad(curCircle.info.angleDegree);
  973. // When finish current circle
  974. if (curCircle.info.direction === 'right') {
  975. canLowerCircles = curCircle.x >= self.control.nextX;
  976. } else if (curCircle.info.direction === 'left') {
  977. canLowerCircles = curCircle.x <= self.control.nextX;
  978. // If just changed from 'right' to 'left' inform to change direction of kid animation
  979. if (
  980. self.animation.invertDirection === undefined &&
  981. self.circles.cur > 0 &&
  982. self.circles.list[self.circles.cur - 1].info.direction === 'right'
  983. ) {
  984. self.animation.invertDirection = true;
  985. }
  986. }
  987. // Change direction of kid animation
  988. if (self.animation.invertDirection) {
  989. self.animation.invertDirection = false;
  990. game.animation.stop(self.kid.animation[0]);
  991. self.kid.animation = self.animation.list.left;
  992. self.kid.curFrame = 23;
  993. game.animation.play('left');
  994. self.control.curWalkedPath = 1;
  995. self.utils.renderWalkedPath(
  996. curCircle.x,
  997. self.walkedPath[0].y + 8,
  998. colors.red
  999. );
  1000. }
  1001. if (canLowerCircles) {
  1002. // Hide current circle
  1003. curCircle.alpha = 0;
  1004. // Lowers kid and other circles
  1005. self.circles.list.forEach((circle) => {
  1006. circle.y += self.circles.diameter;
  1007. });
  1008. self.kid.y += self.circles.diameter;
  1009. self.circles.cur++; // Update index of current circle
  1010. if (self.circles.list[self.circles.cur]) {
  1011. curCircle = self.circles.list[self.circles.cur];
  1012. curDirec = curCircle.info.direc;
  1013. self.control.nextX += curCircle.info.distance * curDirec; // Update next position
  1014. }
  1015. }
  1016. // When finish all circles (final position)
  1017. if (
  1018. self.circles.cur === self.circles.list.length ||
  1019. curCircle.alpha === 0
  1020. ) {
  1021. self.animation.animateKid = false;
  1022. self.control.checkAnswer = true;
  1023. }
  1024. },
  1025. checkAnswerHandler: function () {
  1026. game.timer.stop();
  1027. game.animation.stop(self.kid.animation[0]);
  1028. self.control.isCorrect = game.math.isOverlap(self.basket, self.kid);
  1029. const x = self.utils.renderOperationUI();
  1030. if (self.control.isCorrect) {
  1031. completedLevels++;
  1032. self.kid.curFrame = self.kid.curFrame < 12 ? 24 : 25;
  1033. if (audioStatus) game.audio.okSound.play();
  1034. game.add
  1035. .image(x + 50, context.canvas.height / 3, 'answer_correct')
  1036. .anchor(0.5, 0.5);
  1037. if (isDebugMode) console.log('Completed Levels: ' + completedLevels);
  1038. } else {
  1039. if (audioStatus) game.audio.errorSound.play();
  1040. game.add
  1041. .image(x, context.canvas.height / 3, 'answer_wrong')
  1042. .anchor(0.5, 0.5);
  1043. }
  1044. self.fetch.postScore();
  1045. self.control.checkAnswer = false;
  1046. self.animation.counter = 0;
  1047. self.animation.animateBalloon = true;
  1048. },
  1049. animateBalloonHandler: function () {
  1050. self.animation.counter++;
  1051. self.balloon.y -= 2;
  1052. self.basket.y -= 2;
  1053. if (self.control.isCorrect) self.kid.y -= 2;
  1054. if (self.animation.counter === 100) {
  1055. self.utils.renderEndUI();
  1056. self.control.showEndInfo = true;
  1057. if (self.control.isCorrect) canGoToNextMapPosition = true;
  1058. else canGoToNextMapPosition = false;
  1059. }
  1060. },
  1061. endLevel: function () {
  1062. game.state.start('map');
  1063. },
  1064. // INFORMATION
  1065. /**
  1066. * Show correct answer
  1067. */
  1068. showAnswer: function () {
  1069. if (!self.control.hasClicked) {
  1070. // On gameMode (a)
  1071. if (gameMode === 'a') {
  1072. self.ui.help.x = self.control.correctX - 20;
  1073. self.ui.help.y = self.road.y;
  1074. // On gameMode (b)
  1075. } else {
  1076. self.ui.help.x = self.circles.list[self.control.correctIndex - 1].x;
  1077. self.ui.help.y = self.circles.list[self.control.correctIndex - 1].y; // - self.circles.diameter / 2;
  1078. }
  1079. self.ui.help.alpha = 1;
  1080. }
  1081. },
  1082. // HANDLERS
  1083. /**
  1084. * (in gameMode 'b') Function called when player clicked over a valid circle
  1085. *
  1086. * @param {number|object} cur clicked circle
  1087. */
  1088. clickCircleHandler: function (cur) {
  1089. if (!self.control.hasClicked) {
  1090. // On gameMode (a)
  1091. if (gameMode === 'a') {
  1092. self.balloon.x = cur;
  1093. self.basket.x = cur;
  1094. }
  1095. // On gameMode (b)
  1096. if (gameMode === 'b') {
  1097. document.body.style.cursor = 'auto';
  1098. for (let i in self.circles.list) {
  1099. if (i <= cur.index) {
  1100. self.circles.list[i].alpha = 1; // Keep selected circle
  1101. self.control.selectedIndex = cur.index;
  1102. } else {
  1103. self.circles.list[i].alpha = 0; // Hide unselected circle
  1104. self.kid.y += self.circles.diameter; // Lower kid to selected circle
  1105. }
  1106. }
  1107. }
  1108. if (audioStatus) game.audio.popSound.play();
  1109. // Hide fractions
  1110. if (showFractions) {
  1111. self.circles.list.forEach((circle) => {
  1112. circle.info.fraction.labels.forEach((labelPart) => {
  1113. if (labelPart) labelPart.alpha = 0;
  1114. });
  1115. });
  1116. }
  1117. // Hide solution pointer
  1118. if (self.ui.help != undefined) self.ui.help.alpha = 0;
  1119. self.ui.message[0].alpha = 0;
  1120. navigation.disableIcon(navigation.showAnswerIcon);
  1121. self.balloon.alpha = 1;
  1122. self.basket.alpha = 1;
  1123. self.walkedPath[self.control.curWalkedPath].alpha = 1;
  1124. self.control.hasClicked = true;
  1125. self.animation.animateKid = true;
  1126. game.animation.play(self.kid.animation[0]);
  1127. }
  1128. },
  1129. /**
  1130. * (in gameMode 'b') Function called when cursor is over a valid circle
  1131. *
  1132. * @param {object} cur circle the cursor is over
  1133. */
  1134. overCircleHandler: function (cur) {
  1135. if (!self.control.hasClicked) {
  1136. document.body.style.cursor = 'pointer';
  1137. for (let i in self.circles.list) {
  1138. const alpha = i <= cur.index ? 1 : 0.4;
  1139. self.circles.list[i].alpha = alpha;
  1140. if (showFractions) {
  1141. self.circles.list[i].info.fraction.labels.forEach((lbl) => {
  1142. if (lbl) lbl.alpha = alpha;
  1143. });
  1144. }
  1145. }
  1146. }
  1147. },
  1148. /**
  1149. * (in gameMode 'b') Function called when cursor leaves a valid circle
  1150. */
  1151. outCircleHandler: function () {
  1152. if (!self.control.hasClicked) {
  1153. document.body.style.cursor = 'auto';
  1154. const alpha = 1;
  1155. self.circles.list.forEach((circle) => {
  1156. circle.alpha = alpha;
  1157. if (showFractions) {
  1158. circle.info.fraction.labels.forEach((lbl) => {
  1159. if (lbl) lbl.alpha = alpha;
  1160. });
  1161. }
  1162. });
  1163. }
  1164. },
  1165. },
  1166. events: {
  1167. /**
  1168. * Called by mouse click event
  1169. *
  1170. * @param {object} mouseEvent contains the mouse click coordinates
  1171. */
  1172. onInputDown: function (mouseEvent) {
  1173. const x = game.math.getMouse(mouseEvent).x;
  1174. const y = game.math.getMouse(mouseEvent).y;
  1175. // GAME MODE A : click road
  1176. if (gameMode === 'a') {
  1177. const isValid =
  1178. y > 150 && x >= self.road.x && x <= self.road.x + self.road.width;
  1179. if (isValid) self.utils.clickCircleHandler(x);
  1180. }
  1181. // GAME MODE B : click circle
  1182. if (gameMode === 'b') {
  1183. self.circles.list.forEach((circle) => {
  1184. const isValid =
  1185. game.math.distanceToPointer(
  1186. x,
  1187. circle.xWithAnchor,
  1188. y,
  1189. circle.yWithAnchor
  1190. ) <=
  1191. (circle.diameter / 2) * circle.scale;
  1192. if (isValid) self.utils.clickCircleHandler(circle);
  1193. });
  1194. }
  1195. // Continue button
  1196. if (self.control.showEndInfo) {
  1197. if (game.math.isOverIcon(x, y, self.ui.continue.button)) {
  1198. if (audioStatus) game.audio.popSound.play();
  1199. self.utils.endLevel();
  1200. }
  1201. }
  1202. navigation.onInputDown(x, y);
  1203. game.render.all();
  1204. },
  1205. /**
  1206. * Called by mouse move event
  1207. *
  1208. * @param {object} mouseEvent contains the mouse move coordinates
  1209. */
  1210. onInputOver: function (mouseEvent) {
  1211. const x = game.math.getMouse(mouseEvent).x;
  1212. const y = game.math.getMouse(mouseEvent).y;
  1213. let isOverCircle = false;
  1214. // GAME MODE A : balloon follow mouse
  1215. if (gameMode === 'a' && !self.control.hasClicked) {
  1216. if (
  1217. game.math.distanceToPointer(x, self.balloon.x, y, self.balloon.y) > 8
  1218. ) {
  1219. self.balloon.x = x;
  1220. self.basket.x = x;
  1221. }
  1222. document.body.style.cursor = 'auto';
  1223. }
  1224. // GAME MODE B : hover circle
  1225. if (gameMode === 'b' && !self.control.hasClicked) {
  1226. self.circles.list.forEach((circle) => {
  1227. const isValid =
  1228. game.math.distanceToPointer(
  1229. x,
  1230. circle.xWithAnchor,
  1231. y,
  1232. circle.yWithAnchor
  1233. ) <=
  1234. (circle.diameter / 2) * circle.scale;
  1235. if (isValid) {
  1236. self.utils.overCircleHandler(circle);
  1237. isOverCircle = true;
  1238. }
  1239. });
  1240. if (!isOverCircle) self.utils.outCircleHandler();
  1241. }
  1242. // Continue button
  1243. if (self.control.showEndInfo) {
  1244. if (game.math.isOverIcon(x, y, self.ui.continue.button)) {
  1245. // If pointer is over icon
  1246. document.body.style.cursor = 'pointer';
  1247. self.ui.continue.button.scale =
  1248. self.ui.continue.button.initialScale * 1.1;
  1249. self.ui.continue.text.style = textStyles.btnLg;
  1250. } else {
  1251. // If pointer is not over icon
  1252. document.body.style.cursor = 'auto';
  1253. self.ui.continue.button.scale =
  1254. self.ui.continue.button.initialScale * 1;
  1255. self.ui.continue.text.style = textStyles.btn;
  1256. }
  1257. }
  1258. navigation.onInputOver(x, y);
  1259. game.render.all();
  1260. },
  1261. },
  1262. fetch: {
  1263. /**
  1264. * Saves players data after level ends - to be sent to database <br>
  1265. *
  1266. * Attention: the 'line_' prefix data table must be compatible to data table fields (MySQL server)
  1267. *
  1268. * @see /php/squareOne.js
  1269. */
  1270. postScore: function () {
  1271. // Creates string that is going to be sent to db
  1272. const data =
  1273. '&line_game=' +
  1274. gameShape +
  1275. '&line_mode=' +
  1276. gameMode +
  1277. '&line_oper=' +
  1278. gameOperation +
  1279. '&line_leve=' +
  1280. gameDifficulty +
  1281. '&line_posi=' +
  1282. curMapPosition +
  1283. '&line_resu=' +
  1284. self.control.isCorrect +
  1285. '&line_time=' +
  1286. game.timer.elapsed +
  1287. '&line_deta=' +
  1288. 'numCircles:' +
  1289. self.circles.list.length +
  1290. ', valCircles: ' +
  1291. self.control.divisorsList +
  1292. ' balloonX: ' +
  1293. self.basket.x +
  1294. ', selIndex: ' +
  1295. self.control.selectedIndex;
  1296. // FOR MOODLE
  1297. sendToDatabase(data);
  1298. },
  1299. },
  1300. };