|
@@ -0,0 +1,776 @@
|
|
|
+
|
|
|
+ * This file holds game states.
|
|
|
+ ******************************/
|
|
|
+
|
|
|
+
|
|
|
+ *
|
|
|
+ * ....scale..... = gameType
|
|
|
+ * ..../...\.....
|
|
|
+ * ...A.....B.... = gameMode
|
|
|
+ * .....\./......
|
|
|
+ * ......|.......
|
|
|
+ * ...../.\......
|
|
|
+ * .Plus...Minus. = gameOperation
|
|
|
+ * .....\./......
|
|
|
+ * ......|.......
|
|
|
+ * ....1,2,3..... = gameDifficulty
|
|
|
+ *
|
|
|
+ * Character : tractor
|
|
|
+ * Theme : farm
|
|
|
+ * Concept : Player associates 'blocks carried by the tractor' and 'floor spaces to be filled by them'
|
|
|
+ * Represent fractions as : blocks/rectangles
|
|
|
+ *
|
|
|
+ * Game modes can be :
|
|
|
+ *
|
|
|
+ * A : Player can select # of 'floor blocks' (hole in the ground)
|
|
|
+ * Selects size of hole to be made in the ground (to fill with the blocks in front of the truck)
|
|
|
+ * B : Player can select # of 'stacked blocks' (in front of the truck)
|
|
|
+ * Selects number of blocks in front of the truck (to fill the hole on the ground)
|
|
|
+ *
|
|
|
+ * Operations can be :
|
|
|
+ *
|
|
|
+ * Plus : addition of fractions
|
|
|
+ * Represented by : tractor going to the right (floor positions 0..8)
|
|
|
+ * Minus : subtraction of fractions
|
|
|
+ * Represented by: tractor going to the left (floor positions 8..0)
|
|
|
+ *
|
|
|
+ * @namespace
|
|
|
+ */
|
|
|
+const scaleOne = {
|
|
|
+
|
|
|
+ * Main code
|
|
|
+ */
|
|
|
+ create: function () {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ renderBackground();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ this.help = game.add.image(0, 0, 'help_pointer', 1.7);
|
|
|
+ this.help.anchor(0.5, 0);
|
|
|
+ this.help.alpha = 0;
|
|
|
+
|
|
|
+ if (!this.restart) {
|
|
|
+ game.timer.start();
|
|
|
+ game.event.add('click', this.onInputDown);
|
|
|
+ game.event.add('mousemove', this.onInputOver);
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ * Game loop
|
|
|
+ */
|
|
|
+ update: function () {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (self.animate) {
|
|
|
+ const stck = self.stck;
|
|
|
+ const floor = self.floor;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ self.tractor.x += self.animationSpeed;
|
|
|
+
|
|
|
+
|
|
|
+ for (let i in stck.blocks) {
|
|
|
+ stck.blocks[i].x += self.animationSpeed;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ const restOfCurBlock =
|
|
|
+ (self.defaultBlockWidth - stck.blocks[stck.curIndex].width) *
|
|
|
+ self.direc_level;
|
|
|
+
|
|
|
+
|
|
|
+ if (
|
|
|
+ (gameOperation == 'Plus' &&
|
|
|
+ stck.blocks[0].x >= stck.curBlockEnd + restOfCurBlock) ||
|
|
|
+ (gameOperation == 'Minus' &&
|
|
|
+ stck.blocks[0].x <= stck.curBlockEnd + restOfCurBlock)
|
|
|
+ ) {
|
|
|
+ let lowerBlock = true;
|
|
|
+
|
|
|
+ const curEnd =
|
|
|
+ stck.blocks[0].x +
|
|
|
+ stck.blocks[stck.curIndex].width * self.direc_level;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (stck.curIndex == stck.index) {
|
|
|
+
|
|
|
+
|
|
|
+ const selectedEnd =
|
|
|
+ floor.blocks[floor.index].x +
|
|
|
+ floor.blocks[0].width * self.direc_level;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (
|
|
|
+ (gameOperation == 'Plus' && curEnd > selectedEnd) ||
|
|
|
+ (gameOperation == 'Minus' && curEnd < selectedEnd)
|
|
|
+ ) {
|
|
|
+ lowerBlock = false;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+
|
|
|
+ stck.curBlockEnd +=
|
|
|
+ stck.blocks[stck.curIndex + 1].width * self.direc_level;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (lowerBlock) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ for (let i = 0; i <= floor.index; i++) {
|
|
|
+ if (
|
|
|
+ (gameOperation == 'Plus' && floor.blocks[i].x < curEnd) ||
|
|
|
+ (gameOperation == 'Minus' && floor.blocks[i].x > curEnd)
|
|
|
+ ) {
|
|
|
+ floor.blocks[i].alpha = 0.2;
|
|
|
+ floor.curIndex = i;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ stck.blocks[stck.curIndex].alpha = 0;
|
|
|
+ stck.blocks.forEach((cur) => {
|
|
|
+ cur.y += self.defaultBlockHeight - 2;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ stck.curIndex++;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (stck.curIndex > stck.index || floor.curIndex == floor.index) {
|
|
|
+ self.animate = false;
|
|
|
+ self.checkAnswer = true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (self.checkAnswer) {
|
|
|
+ game.timer.stop();
|
|
|
+
|
|
|
+ game.animation.stop(self.tractor.animation[0]);
|
|
|
+
|
|
|
+ if (gameMode == 'A') {
|
|
|
+ self.result = self.floor.index == self.floor.correctIndex;
|
|
|
+ } else {
|
|
|
+ self.result = self.stck.index == self.stck.correctIndex;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (self.result) {
|
|
|
+
|
|
|
+ game.animation.play(self.tractor.animation[0]);
|
|
|
+
|
|
|
+
|
|
|
+ game.add
|
|
|
+ .image(context.canvas.width / 2, context.canvas.height / 2, 'ok')
|
|
|
+ .anchor(0.5, 0.5);
|
|
|
+ if (audioStatus) game.audio.okSound.play();
|
|
|
+
|
|
|
+ completedLevels++;
|
|
|
+ if (debugMode) console.log('Completed Levels: ' + completedLevels);
|
|
|
+ } else {
|
|
|
+
|
|
|
+
|
|
|
+ game.add
|
|
|
+ .image(context.canvas.width / 2, context.canvas.height / 2, 'error')
|
|
|
+ .anchor(0.5, 0.5);
|
|
|
+ if (audioStatus) game.audio.errorSound.play();
|
|
|
+ }
|
|
|
+
|
|
|
+ self.postScore();
|
|
|
+
|
|
|
+
|
|
|
+ self.checkAnswer = false;
|
|
|
+ self.animateEnding = true;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (self.animateEnding) {
|
|
|
+
|
|
|
+
|
|
|
+ self.count++;
|
|
|
+
|
|
|
+
|
|
|
+ if (self.result) self.tractor.x += self.animationSpeed;
|
|
|
+
|
|
|
+
|
|
|
+ if (self.count >= 140) {
|
|
|
+
|
|
|
+ if (self.result) mapMove = true;
|
|
|
+ else mapMove = false;
|
|
|
+
|
|
|
+ game.state.start('map');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ game.render.all();
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ * Function called by self.onInputOver() when cursor is over a valid rectangle
|
|
|
+ *
|
|
|
+ * @param {object} cur rectangle the cursor is over
|
|
|
+ */
|
|
|
+ overSquare: function (cur) {
|
|
|
+ if (!self.hasClicked) {
|
|
|
+ document.body.style.cursor = 'pointer';
|
|
|
+
|
|
|
+
|
|
|
+ if (gameMode == 'A') {
|
|
|
+ for (let i in self.floor.blocks) {
|
|
|
+ self.floor.blocks[i].alpha = i <= cur.index ? 1 : 0.5;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ self.floor.index = cur.index;
|
|
|
+
|
|
|
+
|
|
|
+ } else {
|
|
|
+ for (let i in self.stck.blocks) {
|
|
|
+ self.stck.blocks[i].alpha = i <= cur.index ? 0.5 : 0.2;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ self.stck.index = cur.index;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ * Function called by self.onInputOver() when cursos is out of a valid rectangle
|
|
|
+ */
|
|
|
+ outSquare: function () {
|
|
|
+ if (!self.hasClicked) {
|
|
|
+ document.body.style.cursor = 'auto';
|
|
|
+
|
|
|
+
|
|
|
+ if (gameMode == 'A') {
|
|
|
+ for (let i in self.floor.blocks) {
|
|
|
+ self.floor.blocks[i].alpha = 0.5;
|
|
|
+ }
|
|
|
+
|
|
|
+ self.floor.index = -1;
|
|
|
+
|
|
|
+ } else {
|
|
|
+ for (let i in self.stck.blocks) {
|
|
|
+ self.stck.blocks[i].alpha = 0.5;
|
|
|
+ }
|
|
|
+
|
|
|
+ self.stck.index = -1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ * Function called by self.onInputDown() when player clicks on a valid rectangle.
|
|
|
+ */
|
|
|
+ clickSquare: function () {
|
|
|
+ if (!self.hasClicked && !self.animateEnding) {
|
|
|
+ document.body.style.cursor = 'auto';
|
|
|
+
|
|
|
+
|
|
|
+ if (gameMode == 'A') {
|
|
|
+
|
|
|
+ self.arrow.alpha = 1;
|
|
|
+
|
|
|
+
|
|
|
+ for (let i in self.floor.blocks) {
|
|
|
+
|
|
|
+ if (i > self.floor.index) self.floor.blocks[i].alpha = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ self.stck.index = self.stck.blocks.length - 1;
|
|
|
+
|
|
|
+ } else {
|
|
|
+ for (let i in self.stck.blocks) {
|
|
|
+
|
|
|
+ if (i > self.stck.index) self.stck.blocks[i].alpha = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ self.floor.index = self.floor.blocks.length - 1;
|
|
|
+
|
|
|
+
|
|
|
+ self.stck.blocks.length = self.stck.index + 1;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ if (audioStatus) game.audio.popSound.play();
|
|
|
+
|
|
|
+
|
|
|
+ if (fractionLabel) {
|
|
|
+ self.stck.labels.forEach((cur) => {
|
|
|
+ cur.forEach((cur) => {
|
|
|
+ cur.alpha = 0;
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ if (self.help != undefined) self.help.alpha = 0;
|
|
|
+
|
|
|
+
|
|
|
+ game.animation.play(self.tractor.animation[0]);
|
|
|
+
|
|
|
+ self.hasClicked = true;
|
|
|
+ self.animate = true;
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ * Create stacked blocks for the level in create()
|
|
|
+ *
|
|
|
+ * @returns {boolean}
|
|
|
+ */
|
|
|
+ createStckBlocks: function () {
|
|
|
+ let hasBaseDifficulty = false;
|
|
|
+ const max = gameMode == 'B' ? 10 : mapPosition + 4;
|
|
|
+
|
|
|
+ const total = game.math.randomInRange(mapPosition + 2, max);
|
|
|
+
|
|
|
+ self.floor.correctXA =
|
|
|
+ self.startX + self.defaultBlockWidth * self.direc_level;
|
|
|
+
|
|
|
+ for (let i = 0; i < total; i++) {
|
|
|
+
|
|
|
+ let divisor = game.math.randomInRange(1, gameDifficulty);
|
|
|
+ if (divisor == gameDifficulty) hasBaseDifficulty = true;
|
|
|
+ if (divisor == 3) divisor = 4;
|
|
|
+ self.divisorsList += divisor + ',';
|
|
|
+
|
|
|
+ const curBlockWidth = self.defaultBlockWidth / divisor;
|
|
|
+
|
|
|
+ self.floor.correctXA += curBlockWidth * self.direc_level;
|
|
|
+
|
|
|
+
|
|
|
+ const lineColor = gameOperation == 'Minus' ? colors.red : colors.blueDark;
|
|
|
+ const lineSize = 2;
|
|
|
+ const block = game.add.geom.rect(
|
|
|
+ self.startX,
|
|
|
+ self.startY + 17 - i * (self.defaultBlockHeight - lineSize),
|
|
|
+ curBlockWidth - lineSize,
|
|
|
+ self.defaultBlockHeight - lineSize,
|
|
|
+ lineColor,
|
|
|
+ lineSize,
|
|
|
+ colors.white,
|
|
|
+ 1
|
|
|
+ );
|
|
|
+ const anchor = gameOperation == 'Minus' ? 1 : 0;
|
|
|
+ block.anchor(anchor, 0);
|
|
|
+
|
|
|
+
|
|
|
+ if (gameMode == 'B') {
|
|
|
+ block.alpha = 0.5;
|
|
|
+ block.index = i;
|
|
|
+ }
|
|
|
+
|
|
|
+ self.stck.blocks.push(block);
|
|
|
+
|
|
|
+
|
|
|
+ if (fractionLabel) {
|
|
|
+ const x = self.startX + (curBlockWidth + 15) * self.direc_level;
|
|
|
+ const y = self.defaultBlockHeight - lineSize;
|
|
|
+
|
|
|
+ const label = [];
|
|
|
+
|
|
|
+ if (divisor == 1) {
|
|
|
+ label[0] = game.add.text(
|
|
|
+ x,
|
|
|
+ self.startY - (i - 1) * y,
|
|
|
+ divisor,
|
|
|
+ textStyles.h2_blueDark
|
|
|
+ );
|
|
|
+ } else {
|
|
|
+ label[0] = game.add.text(
|
|
|
+ x,
|
|
|
+ self.startY + 45 - i * y + 23,
|
|
|
+ divisor,
|
|
|
+ textStyles.p_blueDark
|
|
|
+ );
|
|
|
+ label[1] = game.add.text(
|
|
|
+ x,
|
|
|
+ self.startY + 40 - i * y,
|
|
|
+ '1',
|
|
|
+ textStyles.p_blueDark
|
|
|
+ );
|
|
|
+ label[2] = game.add.text(
|
|
|
+ x,
|
|
|
+ self.startY + 40 - i * y,
|
|
|
+ '_',
|
|
|
+ textStyles.p_blueDark
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ self.stck.labels.push(label);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ self.stck.curBlockEnd =
|
|
|
+ self.startX + self.stck.blocks[0].width * self.direc_level;
|
|
|
+
|
|
|
+ let restart = false;
|
|
|
+
|
|
|
+
|
|
|
+ if (
|
|
|
+ !hasBaseDifficulty ||
|
|
|
+ (gameOperation == 'Plus' &&
|
|
|
+ (self.floor.correctXA < self.startX + self.defaultBlockWidth ||
|
|
|
+ self.floor.correctXA > self.startX + 8 * self.defaultBlockWidth)) ||
|
|
|
+ (gameOperation == 'Minus' &&
|
|
|
+ (self.floor.correctXA < self.startX - 8 * self.defaultBlockWidth ||
|
|
|
+ self.floor.correctXA > self.startX - self.defaultBlockWidth))
|
|
|
+ ) {
|
|
|
+ restart = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (debugMode)
|
|
|
+ console.log(
|
|
|
+ 'Stacked blocks: ' +
|
|
|
+ total +
|
|
|
+ ' (min: ' +
|
|
|
+ (mapPosition + 2) +
|
|
|
+ ', max: ' +
|
|
|
+ max +
|
|
|
+ ')'
|
|
|
+ );
|
|
|
+
|
|
|
+ return restart;
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ * Create floor blocks for the level in create()
|
|
|
+ */
|
|
|
+ createFloorBlocks: function () {
|
|
|
+
|
|
|
+ const divisor = gameDifficulty == 3 ? 4 : gameDifficulty;
|
|
|
+
|
|
|
+ let total = 8 * divisor;
|
|
|
+
|
|
|
+ const blockWidth = self.defaultBlockWidth / divisor;
|
|
|
+
|
|
|
+
|
|
|
+ if (gameMode == 'B') {
|
|
|
+ self.stck.correctIndex = game.math.randomInRange(
|
|
|
+ 0,
|
|
|
+ self.stck.blocks.length - 1
|
|
|
+ );
|
|
|
+
|
|
|
+ self.floor.correctXB =
|
|
|
+ self.startX + self.defaultBlockWidth * self.direc_level;
|
|
|
+
|
|
|
+ for (let i = 0; i <= self.stck.correctIndex; i++) {
|
|
|
+ self.floor.correctXB += self.stck.blocks[i].width * self.direc_level;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ let flag = true;
|
|
|
+
|
|
|
+ for (let i = 0; i < total; i++) {
|
|
|
+
|
|
|
+
|
|
|
+ const x =
|
|
|
+ self.startX +
|
|
|
+ (self.defaultBlockWidth + i * blockWidth) * self.direc_level;
|
|
|
+
|
|
|
+ if (flag && gameMode == 'A') {
|
|
|
+ if (
|
|
|
+ (gameOperation == 'Plus' && x >= self.floor.correctXA) ||
|
|
|
+ (gameOperation == 'Minus' && x <= self.floor.correctXA)
|
|
|
+ ) {
|
|
|
+ self.floor.correctIndex = i - 1;
|
|
|
+ flag = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (gameMode == 'B') {
|
|
|
+ if (
|
|
|
+ (gameOperation == 'Plus' && x >= self.floor.correctXB) ||
|
|
|
+ (gameOperation == 'Minus' && x <= self.floor.correctXB)
|
|
|
+ ) {
|
|
|
+ total = i;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ const lineSize = 0.9;
|
|
|
+ const block = game.add.geom.rect(
|
|
|
+ x,
|
|
|
+ self.startY + 17 + self.defaultBlockHeight - lineSize,
|
|
|
+ blockWidth - lineSize,
|
|
|
+ self.defaultBlockHeight - lineSize,
|
|
|
+ colors.blueBg,
|
|
|
+ lineSize,
|
|
|
+ colors.blueBgInsideLevel,
|
|
|
+ 1
|
|
|
+ );
|
|
|
+ const anchor = gameOperation == 'Minus' ? 1 : 0;
|
|
|
+ block.anchor(anchor, 0);
|
|
|
+
|
|
|
+
|
|
|
+ if (gameMode == 'A') {
|
|
|
+ block.alpha = 0.5;
|
|
|
+ block.index = i;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ self.floor.blocks.push(block);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (gameMode == 'A') self.floor.correctX = self.floor.correctXA;
|
|
|
+ else if (gameMode == 'B') self.floor.correctX = self.floor.correctXB;
|
|
|
+
|
|
|
+
|
|
|
+ for (let i = 1; i < 10; i++) {
|
|
|
+ const x = self.startX + i * self.defaultBlockWidth * self.direc_level;
|
|
|
+ game.add.text(
|
|
|
+ x,
|
|
|
+ self.startY + self.defaultBlockHeight + 78 * 1.5,
|
|
|
+ i - 1,
|
|
|
+ textStyles.h2_blueDark
|
|
|
+ );
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ * Display correct answer
|
|
|
+ */
|
|
|
+ viewHelp: function () {
|
|
|
+ if (!self.hasClicked) {
|
|
|
+
|
|
|
+ if (gameMode == 'A') {
|
|
|
+ const aux = self.floor.blocks[0];
|
|
|
+ self.help.x = self.floor.correctX - (aux.width / 2) * self.direc_level;
|
|
|
+ self.help.y = 501;
|
|
|
+
|
|
|
+ } else {
|
|
|
+ const aux = self.stck.blocks[self.stck.correctIndex];
|
|
|
+ self.help.x = aux.x + (aux.width / 2) * self.direc_level;
|
|
|
+ self.help.y = aux.y;
|
|
|
+ }
|
|
|
+
|
|
|
+ self.help.alpha = 0.7;
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ * Called by mouse click event
|
|
|
+ *
|
|
|
+ * @param {object} mouseEvent contains the mouse click coordinates
|
|
|
+ */
|
|
|
+ onInputDown: function (mouseEvent) {
|
|
|
+ const x = game.math.getMouse(mouseEvent).x;
|
|
|
+ const y = game.math.getMouse(mouseEvent).y;
|
|
|
+
|
|
|
+ if (gameMode == 'A') {
|
|
|
+ self.floor.blocks.forEach((cur) => {
|
|
|
+ if (game.math.isOverIcon(x, y, cur)) self.clickSquare(cur);
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ self.stck.blocks.forEach((cur) => {
|
|
|
+ if (game.math.isOverIcon(x, y, cur)) self.clickSquare(cur);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ navigationIcons.onInputDown(x, y);
|
|
|
+
|
|
|
+ game.render.all();
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ * Called by mouse move event
|
|
|
+ *
|
|
|
+ * @param {object} mouseEvent contains the mouse move coordinates
|
|
|
+ */
|
|
|
+ onInputOver: function (mouseEvent) {
|
|
|
+ const x = game.math.getMouse(mouseEvent).x;
|
|
|
+ const y = game.math.getMouse(mouseEvent).y;
|
|
|
+ let flagA = false;
|
|
|
+ let flagB = false;
|
|
|
+
|
|
|
+ if (gameMode == 'A') {
|
|
|
+
|
|
|
+ if (!self.hasClicked && !self.animateEnding) {
|
|
|
+ if (game.math.distanceToPointer(self.arrow.x, x, self.arrow.y, y) > 8) {
|
|
|
+ self.arrow.x = x < 250 ? 250 : x;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ self.floor.blocks.forEach((cur) => {
|
|
|
+ if (game.math.isOverIcon(x, y, cur)) {
|
|
|
+ flagA = true;
|
|
|
+ self.overSquare(cur);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ if (!flagA) self.outSquare('A');
|
|
|
+ }
|
|
|
+
|
|
|
+ if (gameMode == 'B') {
|
|
|
+ self.stck.blocks.forEach((cur) => {
|
|
|
+ if (game.math.isOverIcon(x, y, cur)) {
|
|
|
+ flagB = true;
|
|
|
+ self.overSquare(cur);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ if (!flagB) self.outSquare('B');
|
|
|
+ }
|
|
|
+
|
|
|
+ navigationIcons.onInputOver(x, y);
|
|
|
+
|
|
|
+ game.render.all();
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ * Saves players data after level ends - to be sent to database <br>
|
|
|
+ *
|
|
|
+ * Attention: the 'line_' prefix data table must be compatible to data table fields (MySQL server)
|
|
|
+ *
|
|
|
+ * @see /php/save.php
|
|
|
+ */
|
|
|
+ postScore: function () {
|
|
|
+
|
|
|
+ const data =
|
|
|
+ '&line_game=' +
|
|
|
+ gameShape +
|
|
|
+ '&line_mode=' +
|
|
|
+ gameMode +
|
|
|
+ '&line_oper=' +
|
|
|
+ gameOperation +
|
|
|
+ '&line_leve=' +
|
|
|
+ gameDifficulty +
|
|
|
+ '&line_posi=' +
|
|
|
+ mapPosition +
|
|
|
+ '&line_resu=' +
|
|
|
+ self.result +
|
|
|
+ '&line_time=' +
|
|
|
+ game.timer.elapsed +
|
|
|
+ '&line_deta=' +
|
|
|
+ 'numBlocks:' +
|
|
|
+ self.stck.blocks.length +
|
|
|
+ ', valBlocks: ' +
|
|
|
+ self.divisorsList +
|
|
|
+ ' blockIndex: ' +
|
|
|
+ self.stck.index +
|
|
|
+ ', floorIndex: ' +
|
|
|
+ self.floor.index;
|
|
|
+
|
|
|
+
|
|
|
+ sendToDatabase(data);
|
|
|
+ },
|
|
|
+};
|