|
@@ -1,24 +1,7 @@
|
|
/*
|
|
/*
|
|
- let gameSquareTwo = {
|
|
|
|
- create: function(){},
|
|
|
|
- update: function(){},
|
|
|
|
- ---------------------------- end of phaser functions
|
|
|
|
- func_overSquare: function(){},
|
|
|
|
- func_outSquare: function(){},
|
|
|
|
- func_clickSquare: function(){},
|
|
|
|
-
|
|
|
|
- //func_setPlace: function(){},
|
|
|
|
- //func_checkOverlap: function(){}
|
|
|
|
- func_getRndDivisor: function(){}
|
|
|
|
- //func_viewHelp: function(){},
|
|
|
|
-
|
|
|
|
- func_updateCounter: function(){},
|
|
|
|
- func_postScore: function(){},
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
GAME LEVELS - SQUARE III: fraction comparisson level
|
|
GAME LEVELS - SQUARE III: fraction comparisson level
|
|
|
|
|
|
- Name of game state : 'squareTwo'
|
|
|
|
|
|
+ Name of game state : 'SquareTwo'
|
|
Shape : square
|
|
Shape : square
|
|
Character : kid
|
|
Character : kid
|
|
Theme : (not themed)
|
|
Theme : (not themed)
|
|
@@ -41,28 +24,55 @@
|
|
bottom has more subdivisions
|
|
bottom has more subdivisions
|
|
*/
|
|
*/
|
|
|
|
|
|
-let gameSquareTwo = {
|
|
|
|
|
|
+const squareTwo = {
|
|
|
|
+
|
|
|
|
+ preload: function () {
|
|
|
|
+
|
|
|
|
+ document.body.style.cursor = "auto";
|
|
|
|
+ game.loop.stop();
|
|
|
|
+ game.event.clear();
|
|
|
|
+ game.animation.clear();
|
|
|
|
+
|
|
|
|
+ self = this;
|
|
|
|
+
|
|
|
|
+ // NOTHING TO LOAD HERE
|
|
|
|
+ squareTwo.create();
|
|
|
|
+
|
|
|
|
+ },
|
|
|
|
|
|
create: function () {
|
|
create: function () {
|
|
|
|
|
|
|
|
+ game.render.clear();
|
|
|
|
+
|
|
// CONTROL VARIABLES
|
|
// CONTROL VARIABLES
|
|
|
|
|
|
- self = this;
|
|
|
|
|
|
+ this.result = false; // Check if selected blocks are correct
|
|
|
|
+ this.delay = 0; // Counter for game dalays
|
|
|
|
+ this.endLevel = false;
|
|
|
|
|
|
- this.numBlocksA = 0; // Subdivision of top figure (A)
|
|
|
|
- this.numBlocksB = 0; // Subdivision of bottom figure (B)
|
|
|
|
- this.selectedA = 0; // Number of selected blocks for A
|
|
|
|
- this.selectedB = 0; // Number of selected blocks for B
|
|
|
|
- this.hasClickedA = false; // Check if player clicked blocks from A
|
|
|
|
- this.hasClickedB = false; // Check if player clicked blocks from B
|
|
|
|
- this.animateA = false; // Animate blocks from A
|
|
|
|
- this.animateB = false; // Animate blocks from B
|
|
|
|
- this.result = false; // Check if selected blocks are correct
|
|
|
|
- this.ending = null;
|
|
|
|
|
|
+ self.A = {
|
|
|
|
+ blocks: [], // List of selection blocks
|
|
|
|
+ auxBlocks: [], // List of shadow under selection blocks
|
|
|
|
+ fractions: [], // fraction numbers
|
|
|
|
|
|
- this.delay = 0; // Counter used in the animations
|
|
|
|
- this.endDelay = 60; // Maximum value for the counter
|
|
|
|
|
|
+ selected: 0, // Number of selected blocks for A
|
|
|
|
+ hasClicked: false, // Check if player clicked blocks from A
|
|
|
|
+ animate: false, // Animate blocks from A
|
|
|
|
+ warningText: undefined,
|
|
|
|
+ label: undefined,
|
|
|
|
+ };
|
|
|
|
|
|
|
|
+ self.B = {
|
|
|
|
+ blocks: [],
|
|
|
|
+ auxBlocks: [],
|
|
|
|
+ fractions: [],
|
|
|
|
+
|
|
|
|
+ selected: 0,
|
|
|
|
+ hasClicked: false,
|
|
|
|
+ animate: false,
|
|
|
|
+ warningText: undefined,
|
|
|
|
+ label: undefined,
|
|
|
|
+ };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -73,34 +83,19 @@ let gameSquareTwo = {
|
|
// Add clouds
|
|
// Add clouds
|
|
game.add.image(300, 100, 'cloud');
|
|
game.add.image(300, 100, 'cloud');
|
|
game.add.image(660, 80, 'cloud');
|
|
game.add.image(660, 80, 'cloud');
|
|
- game.add.image(110, 85, 'cloud').scale.setTo(0.8);
|
|
|
|
|
|
+ game.add.image(110, 85, 'cloud', 0.8);
|
|
|
|
|
|
// Add floor of grass
|
|
// Add floor of grass
|
|
for (let i = 0; i < 9; i++) { game.add.image(i * 100, 501, 'floor'); }
|
|
for (let i = 0; i < 9; i++) { game.add.image(i * 100, 501, 'floor'); }
|
|
|
|
|
|
// Calls function that loads navigation icons
|
|
// Calls function that loads navigation icons
|
|
- iconSettings.func_addIcons(true, true,
|
|
|
|
- true, true, false,
|
|
|
|
|
|
+ navigationIcons.func_addIcons(true, true, false,
|
|
true, false,
|
|
true, false,
|
|
- 'difficulty', false);
|
|
|
|
|
|
+ difficultyScreen, false);
|
|
|
|
|
|
//Add kid
|
|
//Add kid
|
|
- this.kid = game.add.sprite(100, 470, 'kid_lost');
|
|
|
|
- this.kid.scale.setTo(0.8);
|
|
|
|
- this.kid.anchor.setTo(0.5, 0.7);
|
|
|
|
- this.kid.animations.add('front', [3, 4, 5]);
|
|
|
|
- this.kid.animations.play('front', 6, false); // play kid animation once
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- // Group of blocks on A and B
|
|
|
|
- this.blocksA = game.add.group();
|
|
|
|
- this.blocksB = game.add.group();
|
|
|
|
-
|
|
|
|
- // Group of shadow on bottom of A and B
|
|
|
|
- this.auxBlocksA = game.add.group();
|
|
|
|
- this.auxBlocksB = game.add.group();
|
|
|
|
|
|
+ this.kidAnimation = game.add.sprite(100, 470, 'kid_standing', 5, 0.8);
|
|
|
|
+ this.kidAnimation.anchor(0.5, 0.7);
|
|
|
|
|
|
// Width and Height of A and B
|
|
// Width and Height of A and B
|
|
this.figureWidth = 400;
|
|
this.figureWidth = 400;
|
|
@@ -124,494 +119,417 @@ let gameSquareTwo = {
|
|
const points = [2, 4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20];
|
|
const points = [2, 4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20];
|
|
|
|
|
|
// Random index for 'points'
|
|
// Random index for 'points'
|
|
- const randomIndex = game.rnd.integerInRange((levelDifficulty - 1) * 2 + 1, (levelDifficulty - 1) * 2 + 3);
|
|
|
|
|
|
+ const randomIndex = game.math.randomInRange((gameDifficulty - 1) * 2 + 1, (gameDifficulty - 1) * 2 + 3);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
// number of subdivisions of A and B (blocks)
|
|
// number of subdivisions of A and B (blocks)
|
|
- this.numBlocksA = points[randomIndex];
|
|
|
|
- this.numBlocksB = this.func_getRndDivisor(this.numBlocksA);
|
|
|
|
|
|
+ const totalBlocksA = points[randomIndex];
|
|
|
|
+ const totalBlocksB = game.math.randomDivisor(totalBlocksA);
|
|
|
|
|
|
if (debugMode) {
|
|
if (debugMode) {
|
|
console.log("----------");
|
|
console.log("----------");
|
|
- console.log("Difficulty " + levelDifficulty + ", ini " + ((levelDifficulty - 1) * 2 + 1) + ", end " + ((levelDifficulty - 1) * 2 + 3));
|
|
|
|
- console.log("Rpoint " + randomIndex + ", val " + this.numBlocksA);
|
|
|
|
- console.log("total blocks A " + this.numBlocksA + ", total blocks B ");
|
|
|
|
|
|
+ console.log("Difficulty " + gameDifficulty + ", ini " + ((gameDifficulty - 1) * 2 + 1) + ", end " + ((gameDifficulty - 1) * 2 + 3));
|
|
|
|
+ console.log("Rpoint " + randomIndex + ", val " + totalBlocksA);
|
|
|
|
+ console.log("total blocks A " + totalBlocksA + ", total blocks B ");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
// CREATING TOP FIGURE (A)
|
|
// CREATING TOP FIGURE (A)
|
|
|
|
|
|
- let blockWidth = this.figureWidth / this.numBlocksA; // width of each block in A
|
|
|
|
|
|
+ let blockWidth = this.figureWidth / totalBlocksA; // width of each block in A
|
|
let lineColor = colors.darkGreen;
|
|
let lineColor = colors.darkGreen;
|
|
let fillColor = colors.lightGreen;
|
|
let fillColor = colors.lightGreen;
|
|
let fillColorAux = colors.lighterGreen;
|
|
let fillColorAux = colors.lighterGreen;
|
|
|
|
|
|
// Create blocks
|
|
// Create blocks
|
|
- for (let i = 0; i < this.numBlocksA; i++) {
|
|
|
|
|
|
+ for (let i = 0; i < totalBlocksA; i++) {
|
|
|
|
|
|
const x = xA + i * blockWidth;
|
|
const x = xA + i * blockWidth;
|
|
|
|
|
|
// Blocks
|
|
// Blocks
|
|
- let block = game.add.graphics(x, yA);
|
|
|
|
- block.anchor.setTo(0.5, 0.5);
|
|
|
|
- block.lineStyle(2, lineColor);
|
|
|
|
- block.beginFill(fillColor);
|
|
|
|
- block.drawRect(0, 0, blockWidth, figureHeight);
|
|
|
|
- block.alpha = 0.5;
|
|
|
|
- block.endFill();
|
|
|
|
-
|
|
|
|
- block.inputEnabled = true;
|
|
|
|
- block.input.useHandCursor = true;
|
|
|
|
- block.events.onInputDown.add(this.func_clickSquare, { figure: 'A', index: i, xA: xA, xB: xB });
|
|
|
|
- block.events.onInputOver.add(this.func_overSquare, { figure: 'A', index: i, xA: xA, xB: xB });
|
|
|
|
- block.events.onInputOut.add(this.func_outSquare, { figure: 'A', index: i });
|
|
|
|
-
|
|
|
|
- this.blocksA.add(block);
|
|
|
|
|
|
+ const block = game.add.graphic.rect(x, yA, blockWidth, figureHeight, lineColor, 2, fillColor, 0.5);
|
|
|
|
+ block.figure = 'A';
|
|
|
|
+ block.index = i;
|
|
|
|
+ block.finalX = xA;
|
|
|
|
+ self.A.blocks.push(block);
|
|
|
|
|
|
// Auxiliar blocks
|
|
// Auxiliar blocks
|
|
|
|
+ const alpha = (sublevelType == 'A') ? 0.2 : 0;
|
|
const yAux = yA + figureHeight + 10; // on the bottom of A
|
|
const yAux = yA + figureHeight + 10; // on the bottom of A
|
|
-
|
|
|
|
- block = game.add.graphics(x, yAux);
|
|
|
|
- block.anchor.setTo(0.5, 0.5);
|
|
|
|
- block.lineStyle(1, lineColor);
|
|
|
|
- block.beginFill(fillColorAux);
|
|
|
|
- block.drawRect(0, 0, blockWidth, figureHeight);
|
|
|
|
- block.alpha = (sublevelType == 'A') ? 0.2 : 0; // Only visible in sublevel A, but used as parameter is all
|
|
|
|
-
|
|
|
|
- this.auxBlocksA.add(block);
|
|
|
|
|
|
+ const auxBlock = game.add.graphic.rect(x, yAux, blockWidth, figureHeight, lineColor, 1, fillColorAux, alpha);
|
|
|
|
+ self.A.auxBlocks.push(auxBlock);
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
// 'total blocks' label for A : on the side of A
|
|
// 'total blocks' label for A : on the side of A
|
|
let xLabel = xA + this.figureWidth + 30;
|
|
let xLabel = xA + this.figureWidth + 30;
|
|
let yLabel = yA + figureHeight / 2;
|
|
let yLabel = yA + figureHeight / 2;
|
|
- this.labelA = game.add.text(xLabel, yLabel, this.numBlocksA, textStyles.valueLabelBlue2);
|
|
|
|
- this.labelA.anchor.setTo(0.5, 0.41);
|
|
|
|
|
|
+
|
|
|
|
+ this.A.label = game.add.text(xLabel, yLabel, this.A.blocks.length, textStyles.valueLabelBlue2);
|
|
|
|
|
|
// 'selected blocks/fraction' label for A : at the bottom of A
|
|
// 'selected blocks/fraction' label for A : at the bottom of A
|
|
yLabel = yA + figureHeight + 34;
|
|
yLabel = yA + figureHeight + 34;
|
|
- this.fractionA = game.add.text(xLabel, yLabel, "", textStyles.valueLabelBlue2);
|
|
|
|
- this.fractionA.anchor.setTo(0.5, 0.41);
|
|
|
|
- this.fractionA.alpha = 0;
|
|
|
|
- this.fractionLineA = game.add.sprite(xLabel, yLabel + 3, 'fractionLine');
|
|
|
|
- this.fractionLineA.anchor.setTo(0.5, 0.5);
|
|
|
|
- this.fractionLineA.alpha = 0;
|
|
|
|
|
|
|
|
|
|
+ self.A.fractions[0] = game.add.text(xLabel, yLabel, "", textStyles.valueLabelBlue2);
|
|
|
|
+ self.A.fractions[1] = game.add.text(xLabel, yLabel + 21, "", textStyles.valueLabelBlue2);
|
|
|
|
+ self.A.fractions[2] = game.add.text(xLabel, yLabel, "___", textStyles.valueLabelBlue2);
|
|
|
|
+ self.A.fractions[0].alpha = 0;
|
|
|
|
+ self.A.fractions[1].alpha = 0;
|
|
|
|
+ self.A.fractions[2].alpha = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// CREATING BOTTOM FIGURE (B)
|
|
// CREATING BOTTOM FIGURE (B)
|
|
|
|
|
|
- blockWidth = this.figureWidth / this.numBlocksB; // width of each block in B
|
|
|
|
- lineColor = colors.darkRed_;
|
|
|
|
|
|
+ blockWidth = this.figureWidth / totalBlocksB; // width of each block in B
|
|
|
|
+ lineColor = colors.darkRed;
|
|
fillColor = colors.lightRed;
|
|
fillColor = colors.lightRed;
|
|
fillColorAux = colors.lighterRed;
|
|
fillColorAux = colors.lighterRed;
|
|
|
|
|
|
// Blocks and auxiliar blocks
|
|
// Blocks and auxiliar blocks
|
|
- for (let i = 0; i < this.numBlocksB; i++) {
|
|
|
|
|
|
+ for (let i = 0; i < totalBlocksB; i++) {
|
|
|
|
|
|
const x = xB + i * blockWidth;
|
|
const x = xB + i * blockWidth;
|
|
|
|
|
|
// Blocks
|
|
// Blocks
|
|
- let block = game.add.graphics(x, yB);
|
|
|
|
- block.anchor.setTo(0.5, 0.5);
|
|
|
|
- block.lineStyle(2, lineColor);
|
|
|
|
- block.beginFill(fillColor);
|
|
|
|
- block.drawRect(0, 0, blockWidth, figureHeight);
|
|
|
|
- block.endFill();
|
|
|
|
-
|
|
|
|
- block.inputEnabled = true;
|
|
|
|
- block.input.useHandCursor = true;
|
|
|
|
- block.events.onInputDown.add(this.func_clickSquare, { figure: 'B', index: i, xA: xA, xB: xB });
|
|
|
|
- block.events.onInputOver.add(this.func_overSquare, { figure: 'B', index: i, xA: xA, xB: xB });
|
|
|
|
- block.events.onInputOut.add(this.func_outSquare, { figure: 'B', index: i });
|
|
|
|
|
|
|
|
- this.blocksB.add(block);
|
|
|
|
|
|
+ const block = game.add.graphic.rect(x, yB, blockWidth, figureHeight, lineColor, 2, fillColor, 0.5);
|
|
|
|
+ block.figure = 'B';
|
|
|
|
+ block.index = i;
|
|
|
|
+ block.finalX = xB;
|
|
|
|
+ self.B.blocks.push(block);
|
|
|
|
|
|
// Auxiliar blocks
|
|
// Auxiliar blocks
|
|
- let yAux = yB + figureHeight + 10; // on the bottom of B
|
|
|
|
-
|
|
|
|
- block = game.add.graphics(x, yAux);
|
|
|
|
- block.anchor.setTo(0.5, 0.5);
|
|
|
|
- block.lineStyle(1, lineColor);
|
|
|
|
- block.beginFill(fillColorAux);
|
|
|
|
- block.drawRect(0, 0, blockWidth, figureHeight);
|
|
|
|
- block.alpha = (sublevelType == 'A') ? 0.2 : 0; // Only visible in sublevel A, but used as parameter is all
|
|
|
|
-
|
|
|
|
- this.auxBlocksB.add(block);
|
|
|
|
|
|
+ const alpha = (sublevelType == 'A') ? 0.2 : 0;
|
|
|
|
+ const yAux = yB + figureHeight + 10; // on the bottom of B
|
|
|
|
+ const auxBlock = game.add.graphic.rect(x, yAux, blockWidth, figureHeight, lineColor, 1, fillColorAux, alpha);
|
|
|
|
+ self.B.auxBlocks.push(auxBlock);
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
// Label block B
|
|
// Label block B
|
|
xLabel = xB + this.figureWidth + 30;
|
|
xLabel = xB + this.figureWidth + 30;
|
|
yLabel = yB + figureHeight / 2;
|
|
yLabel = yB + figureHeight / 2;
|
|
- this.labelB = game.add.text(xLabel, yLabel, this.numBlocksB, textStyles.valueLabelBlue2);
|
|
|
|
- this.labelB.anchor.setTo(0.5, 0.41);
|
|
|
|
|
|
+
|
|
|
|
+ this.B.label = game.add.text(xLabel, yLabel, this.B.blocks.length, textStyles.valueLabelBlue2);
|
|
|
|
|
|
// Label fraction
|
|
// Label fraction
|
|
yLabel = yB + figureHeight + 34;
|
|
yLabel = yB + figureHeight + 34;
|
|
- this.fractionB = game.add.text(xLabel, yLabel, "", textStyles.valueLabelBlue2);
|
|
|
|
- this.fractionB.anchor.setTo(0.5, 0.41);
|
|
|
|
- this.fractionB.alpha = 0;
|
|
|
|
- this.fractionLineB = game.add.sprite(xLabel, yLabel + 3, 'fractionLine');
|
|
|
|
- this.fractionLineB.anchor.setTo(0.5, 0.5);
|
|
|
|
- this.fractionLineB.alpha = 0;
|
|
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- // OUTPUT ICONS AND TEXT
|
|
|
|
-
|
|
|
|
- // Ok image
|
|
|
|
- this.okImg = game.add.image(game.world.centerX, game.world.centerY, 'h_ok');
|
|
|
|
- this.okImg.anchor.setTo(0.5);
|
|
|
|
- this.okImg.visible = false;
|
|
|
|
-
|
|
|
|
- // Error image
|
|
|
|
- this.errorImg = game.add.image(game.world.centerX, game.world.centerY, 'h_error');
|
|
|
|
- this.errorImg.anchor.setTo(0.5);
|
|
|
|
- this.errorImg.visible = false;
|
|
|
|
|
|
+ self.B.fractions[0] = game.add.text(xLabel, yLabel, "", textStyles.valueLabelBlue2);
|
|
|
|
+ self.B.fractions[1] = game.add.text(xLabel, yLabel + 21, "", textStyles.valueLabelBlue2);
|
|
|
|
+ self.B.fractions[2] = game.add.text(xLabel, yLabel, "___", textStyles.valueLabelBlue2);
|
|
|
|
+ self.B.fractions[0].alpha = 0;
|
|
|
|
+ self.B.fractions[1].alpha = 0;
|
|
|
|
+ self.B.fractions[2].alpha = 0;
|
|
|
|
|
|
// Invalid selection text
|
|
// Invalid selection text
|
|
- this.warningTextA = game.add.text(game.world.centerX, game.world.centerY - 225, "", textStyles.overtitle);
|
|
|
|
- this.warningTextA.anchor.setTo(0.5, 0.5);
|
|
|
|
|
|
+ self.A.warningText = game.add.text(defaultWidth / 2, defaultHeight / 2 - 225, "", textStyles.overtitle);
|
|
|
|
+
|
|
|
|
+ self.B.warningText = game.add.text(defaultWidth / 2, defaultHeight / 2 - 45, "", textStyles.overtitle);
|
|
|
|
|
|
- this.warningTextB = game.add.text(game.world.centerX, game.world.centerY - 45, "", textStyles.overtitle);
|
|
|
|
- this.warningTextB.anchor.setTo(0.5, 0.5);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ game.render.all();
|
|
|
|
|
|
|
|
+ game.timer.start(); // Set a timer for the current level (used in func_postScore)
|
|
|
|
|
|
- // TIMER
|
|
|
|
|
|
+ game.event.add("click", squareTwo.func_onInputDown);
|
|
|
|
+ game.event.add("mousemove", squareTwo.func_onInputOver);
|
|
|
|
|
|
- // Set a timer for the current level
|
|
|
|
- this.totalTime = 0;
|
|
|
|
- this.timer = game.time.create(false);
|
|
|
|
- this.timer.loop(1000, this.func_updateCounter, this);
|
|
|
|
- this.timer.start();
|
|
|
|
|
|
+ game.loop.start(this);
|
|
|
|
|
|
},
|
|
},
|
|
|
|
|
|
update: function () {
|
|
update: function () {
|
|
|
|
|
|
- // If clicked A, animate A blocks
|
|
|
|
- if (this.animateA) {
|
|
|
|
|
|
+ // Animate blocks
|
|
|
|
+ if (self.A.animate || self.B.animate) {
|
|
|
|
|
|
- // Lower selected blocks
|
|
|
|
- for (let i = 0; i < this.selectedA; i++) {
|
|
|
|
- this.blocksA.children[i].y += 2;
|
|
|
|
- }
|
|
|
|
|
|
+ ['A', 'B'].forEach(cur => {
|
|
|
|
|
|
- // After fully lowering blocks, set fraction value
|
|
|
|
- if (this.blocksA.children[0].y >= this.auxBlocksA.children[0].y) {
|
|
|
|
|
|
+ if (self[cur].animate) {
|
|
|
|
|
|
- this.fractionA.alpha = 1;
|
|
|
|
- this.fractionA.setText(this.selectedA + "\n" + this.numBlocksA);
|
|
|
|
- this.fractionLineA.alpha = 1;
|
|
|
|
|
|
+ // Lower selected blocks
|
|
|
|
+ for (let i = 0; i < self[cur].selected; i++) {
|
|
|
|
+ self[cur].blocks[i].y += 2;
|
|
|
|
+ }
|
|
|
|
|
|
- this.animateA = false;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // If clicked B, animate B blocks
|
|
|
|
- if (this.animateB) {
|
|
|
|
-
|
|
|
|
- // Lower selected blocks
|
|
|
|
- for (let i = 0; i < this.selectedB; i++) {
|
|
|
|
- this.blocksB.children[i].y += 2;
|
|
|
|
- }
|
|
|
|
|
|
+ // After fully lowering blocks, set fraction value
|
|
|
|
+ if (self[cur].blocks[0].y >= self[cur].auxBlocks[0].y) {
|
|
|
|
+ self[cur].fractions[0].name = self[cur].selected;
|
|
|
|
+ self[cur].animate = false;
|
|
|
|
+ }
|
|
|
|
|
|
- // Sets fraction value
|
|
|
|
- if (this.blocksB.children[0].y >= this.auxBlocksB.children[0].y) {
|
|
|
|
- this.fractionB.alpha = 1;
|
|
|
|
- this.fractionB.setText(this.selectedB + "\n" + this.numBlocksB);
|
|
|
|
- this.fractionLineB.alpha = 1;
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- this.animateB = false;
|
|
|
|
- }
|
|
|
|
|
|
+ });
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
// if A and B are already clicked
|
|
// if A and B are already clicked
|
|
- if (this.hasClickedA && this.hasClickedB && !this.ending) {
|
|
|
|
|
|
+ if (self.A.hasClicked && self.B.hasClicked && !self.endLevel) {
|
|
|
|
|
|
- this.timer.stop();
|
|
|
|
|
|
+ game.timer.stop();
|
|
|
|
|
|
- // Wait a bit before showing result
|
|
|
|
- this.delay++;
|
|
|
|
|
|
+ self.delay++;
|
|
|
|
|
|
// After delay is over, check result
|
|
// After delay is over, check result
|
|
- if (this.delay > this.endDelay) {
|
|
|
|
|
|
+ if (self.delay > 50) {
|
|
|
|
|
|
- // fractions are equivalent : correct
|
|
|
|
- if ((this.selectedA / this.numBlocksA) == (this.selectedB / this.numBlocksB)) {
|
|
|
|
|
|
+ self.result = (self.A.selected / self.A.blocks.length) == (self.B.selected / self.B.blocks.length);
|
|
|
|
|
|
- if (audioStatus) sound.okSound.play();
|
|
|
|
|
|
+ // fractions are equivalent : CORRECT
|
|
|
|
+ if (self.result) {
|
|
|
|
|
|
- this.okImg.visible = true;
|
|
|
|
|
|
+ if (audioStatus) game.audio.okSound.play();
|
|
|
|
|
|
- this.result = true; // player answer is correct
|
|
|
|
|
|
+ game.add.image(defaultWidth / 2, defaultHeight / 2, 'ok').anchor(0.5, 0.5);
|
|
|
|
+
|
|
|
|
+ mapMove = true; // allow character to move to next level in map state
|
|
|
|
|
|
- mapCanMove = true; // allow character to move to next level in map state
|
|
|
|
completedLevels++;
|
|
completedLevels++;
|
|
- if (debugMode) console.log("completedLevels = " + completedLevels);
|
|
|
|
|
|
|
|
|
|
+ if (debugMode) console.log("completedLevels = " + completedLevels);
|
|
|
|
|
|
- // fractions are not equivalent : incorrect
|
|
|
|
|
|
+ // fractions are not equivalent : INCORRECT
|
|
} else {
|
|
} else {
|
|
|
|
|
|
- if (audioStatus) sound.errorSound.play();
|
|
|
|
-
|
|
|
|
- this.errorImg.visible = true;
|
|
|
|
|
|
+ if (audioStatus) game.audio.errorSound.play();
|
|
|
|
|
|
- this.result = false; // player answer is incorrect
|
|
|
|
|
|
+ game.add.image(defaultWidth / 2, defaultHeight / 2, 'error').anchor(0.5, 0.5);
|
|
|
|
|
|
- mapCanMove = false; // doesnt allow character to move to next level in map state
|
|
|
|
|
|
+ mapMove = false; // doesnt allow character to move to next level in map state
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- this.func_postScore();
|
|
|
|
- this.hasClickedA = false;
|
|
|
|
- this.hasClickedB = false;
|
|
|
|
|
|
+ self.func_postScore();
|
|
|
|
+
|
|
|
|
+ self.endLevel = true;
|
|
|
|
|
|
// reset delay values for next delay
|
|
// reset delay values for next delay
|
|
- this.delay = 0;
|
|
|
|
- this.endDelay = 100;
|
|
|
|
- this.ending = true;
|
|
|
|
|
|
+ self.delay = 0;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
// Wait a bit and go to map state
|
|
// Wait a bit and go to map state
|
|
- if (this.ending) {
|
|
|
|
|
|
+ if (self.endLevel) {
|
|
|
|
|
|
- this.delay++;
|
|
|
|
|
|
+ self.delay++;
|
|
|
|
|
|
- if (this.delay >= this.endDelay) {
|
|
|
|
- game.state.start('map');
|
|
|
|
|
|
+ if (self.delay >= 80) {
|
|
|
|
+ mapScreen.preload();
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ game.render.all();
|
|
|
|
+
|
|
},
|
|
},
|
|
|
|
|
|
- func_overSquare: function () {
|
|
|
|
|
|
|
|
- if (!self.hasClickedA && this.figure == "A") {
|
|
|
|
|
|
|
|
- // If over fraction 'n/n' shows warning message not allowing it
|
|
|
|
- if (this.index == self.numBlocksA - 1) {
|
|
|
|
|
|
+ /* EVENT HANDLER */
|
|
|
|
|
|
- self.warningTextA.setText(lang.error_msg);
|
|
|
|
- self.warningTextB.setText("");
|
|
|
|
|
|
+ func_onInputDown: function (mouseEvent) {
|
|
|
|
|
|
- } else {
|
|
|
|
|
|
+ const x = mouseEvent.offsetX;
|
|
|
|
+ const y = mouseEvent.offsetY;
|
|
|
|
|
|
- self.warningTextA.setText("");
|
|
|
|
- self.warningTextB.setText("");
|
|
|
|
|
|
+ // click block in A
|
|
|
|
+ self.A.blocks.forEach(cur => {
|
|
|
|
|
|
- // selected blocks become fully visible
|
|
|
|
- for (let i = 0; i < self.numBlocksA; i++) {
|
|
|
|
- self.blocksA.children[i].alpha = (i <= this.index) ? 1 : 0.5;
|
|
|
|
- }
|
|
|
|
|
|
+ const valid = y >= cur.yWithAnchor && y <= (cur.yWithAnchor + cur.height * cur.scaleHeight) && (x >= cur.xWithAnchor && x <= (cur.xWithAnchor + cur.width * cur.scaleWidth));
|
|
|
|
+ if (valid) self.func_clickSquare(cur);
|
|
|
|
+ });
|
|
|
|
|
|
- self.fractionA.x = this.xA + ((this.index + 1) * (self.figureWidth / self.numBlocksA)) + 25;
|
|
|
|
- self.fractionA.alpha = 1;
|
|
|
|
- self.fractionA.setText(this.index + 1);
|
|
|
|
|
|
+ // click block in B
|
|
|
|
+ self.B.blocks.forEach(cur => {
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ const valid = y >= cur.yWithAnchor && y <= (cur.yWithAnchor + cur.height * cur.scaleHeight) && (x >= cur.xWithAnchor && x <= (cur.xWithAnchor + cur.width * cur.scaleWidth));
|
|
|
|
+ if (valid) self.func_clickSquare(cur);
|
|
|
|
+ });
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ // click navigation icons
|
|
|
|
+ navigationIcons.func_onInputDown(x, y);
|
|
|
|
|
|
- if (!self.hasClickedB && this.figure == "B") {
|
|
|
|
|
|
+ game.render.all();
|
|
|
|
|
|
- // If over fraction 'n/n' shows warning message not allowing it
|
|
|
|
- if (this.index == self.numBlocksB - 1) {
|
|
|
|
|
|
+ },
|
|
|
|
|
|
- self.warningTextA.setText("");
|
|
|
|
- self.warningTextB.setText(lang.error_msg);
|
|
|
|
|
|
+ func_onInputOver: function (mouseEvent) {
|
|
|
|
|
|
- } else {
|
|
|
|
|
|
+ const x = mouseEvent.offsetX;
|
|
|
|
+ const y = mouseEvent.offsetY;
|
|
|
|
+ let flagA = false;
|
|
|
|
+ let flagB = false;
|
|
|
|
|
|
- self.warningTextA.setText("");
|
|
|
|
- self.warningTextB.setText("");
|
|
|
|
-
|
|
|
|
- // selected blocks become fully visible
|
|
|
|
- for (let i = 0; i < self.numBlocksB; i++) {
|
|
|
|
- self.blocksB.children[i].alpha = (i <= this.index) ? 1 : 0.5;
|
|
|
|
- }
|
|
|
|
|
|
+ // mouse over A : show fraction
|
|
|
|
+ self.A.blocks.forEach(cur => {
|
|
|
|
|
|
- self.fractionB.x = this.xB + ((this.index + 1) * (self.figureWidth / self.numBlocksB)) + 25;
|
|
|
|
- self.fractionB.alpha = 1;
|
|
|
|
- self.fractionB.setText(this.index + 1);
|
|
|
|
|
|
+ const valid = y >= cur.yWithAnchor && y <= (cur.yWithAnchor + cur.height * cur.scaleHeight) &&
|
|
|
|
+ (x >= cur.xWithAnchor && x <= (cur.xWithAnchor + cur.width * cur.scaleWidth));
|
|
|
|
|
|
|
|
+ if (valid) {
|
|
|
|
+ flagA = true;
|
|
|
|
+ self.func_overSquare(cur);
|
|
}
|
|
}
|
|
|
|
+ });
|
|
|
|
+ if (!flagA) self.func_outSquare('A');
|
|
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- },
|
|
|
|
|
|
+ // mouse over B : show fraction
|
|
|
|
+ self.B.blocks.forEach(cur => {
|
|
|
|
|
|
- func_outSquare: function () {
|
|
|
|
|
|
+ const valid = y >= cur.yWithAnchor && y <= (cur.yWithAnchor + cur.height * cur.scaleHeight) &&
|
|
|
|
+ (x >= cur.xWithAnchor && x <= (cur.xWithAnchor + cur.width * cur.scaleWidth));
|
|
|
|
|
|
- // On level type A
|
|
|
|
- if (!self.hasClickedA && this.figure == "A") {
|
|
|
|
-
|
|
|
|
- for (let i = 0; i <= this.index; i++) {
|
|
|
|
- self.blocksA.children[i].alpha = 0.5;
|
|
|
|
|
|
+ if (valid) {
|
|
|
|
+ flagB = true;
|
|
|
|
+ self.func_overSquare(cur);
|
|
}
|
|
}
|
|
- self.fractionA.alpha = 0;
|
|
|
|
|
|
+ });
|
|
|
|
+ if (!flagB) self.func_outSquare('B');
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ if (!flagA && !flagB) document.body.style.cursor = "auto";
|
|
|
|
|
|
- // On level type B
|
|
|
|
- if (!self.hasClickedB && this.figure == "B") {
|
|
|
|
|
|
|
|
- for (let i = 0; i <= this.index; i++) {
|
|
|
|
- self.blocksB.children[i].alpha = 0.5;
|
|
|
|
- }
|
|
|
|
- self.fractionB.alpha = 0;
|
|
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ // mouse over navigation icons : show name
|
|
|
|
+ navigationIcons.func_onInputOver(x, y);
|
|
|
|
+
|
|
|
|
+ game.render.all();
|
|
|
|
|
|
},
|
|
},
|
|
|
|
|
|
- func_clickSquare: function () {
|
|
|
|
|
|
|
|
- // On level type A
|
|
|
|
- if (!self.hasClickedA && this.figure == "A" && this.index != self.numBlocksA - 1) {
|
|
|
|
|
|
|
|
- for (let i = 0; i < self.numBlocksA; i++) {
|
|
|
|
- // desable block input
|
|
|
|
- self.blocksA.children[i].inputEnabled = false;
|
|
|
|
- // turn auxiliar blocks invisible
|
|
|
|
- if (i > this.index) self.auxBlocksA.children[i].alpha = 0;
|
|
|
|
- }
|
|
|
|
|
|
+ /* CALLED BY EVENT HANDLER */
|
|
|
|
|
|
- // turn value label invisible
|
|
|
|
- self.labelA.alpha = 0;
|
|
|
|
|
|
+ func_overSquare: function (curBlock) { // curBlock : self.A.blocks[i] || self.B.blocks[i]
|
|
|
|
|
|
- if (audioStatus) sound.beepSound.play();
|
|
|
|
|
|
+ const curSet = curBlock.figure; // "A" || "B"
|
|
|
|
|
|
- // Save number of selected blocks
|
|
|
|
- self.selectedA = this.index + 1;
|
|
|
|
|
|
+ if (!self[curSet].hasClicked) { // self.A.hasClicked || self.B.hasClicked
|
|
|
|
|
|
- // set fraction x position
|
|
|
|
- self.fractionA.x = this.xA + (self.selectedA * (self.figureWidth / self.numBlocksA)) + 25;
|
|
|
|
- self.fractionLineA.x = self.fractionA.x
|
|
|
|
|
|
+ // If over fraction 'n/n' shows warning message not allowing it
|
|
|
|
+ if (curBlock.index == self[curSet].blocks.length - 1) {
|
|
|
|
|
|
- self.hasClickedA = true;
|
|
|
|
- self.animateA = true;
|
|
|
|
|
|
+ const otherSet = (curSet == "A") ? "B" : "A";
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ self[curSet].warningText.name = game.lang.error_msg;
|
|
|
|
+ self[otherSet].warningText.name = "";
|
|
|
|
|
|
- // On level type B
|
|
|
|
- if (!self.hasClickedB && this.figure == "B" && this.index != self.numBlocksB - 1) {
|
|
|
|
|
|
+ self.func_outSquare(curSet);
|
|
|
|
|
|
- for (let i = 0; i < self.numBlocksB; i++) {
|
|
|
|
- // desable block input
|
|
|
|
- self.blocksB.children[i].inputEnabled = false;
|
|
|
|
- // turn auxiliar blocks invisible
|
|
|
|
- if (i > this.index) self.auxBlocksB.children[i].alpha = 0;
|
|
|
|
- }
|
|
|
|
|
|
+ } else {
|
|
|
|
|
|
- // turn value label invisible
|
|
|
|
- self.labelB.alpha = 0;
|
|
|
|
|
|
+ document.body.style.cursor = "pointer";
|
|
|
|
|
|
- if (audioStatus) sound.beepSound.play();
|
|
|
|
|
|
+ self.A.warningText.name = "";
|
|
|
|
+ self.B.warningText.name = "";
|
|
|
|
|
|
- // Save number of selected blocks
|
|
|
|
- self.selectedB = this.index + 1;
|
|
|
|
|
|
+ // selected blocks become fully visible
|
|
|
|
+ for (let i in self[curSet].blocks) {
|
|
|
|
+ self[curSet].blocks[i].alpha = (i <= curBlock.index) ? 1 : 0.5;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ self[curSet].fractions[0].name = curBlock.index + 1; // nominator : selected blocks
|
|
|
|
+ self[curSet].fractions[1].name = self[curSet].blocks.length; // denominator : total blocks
|
|
|
|
|
|
- // Set fraction x position
|
|
|
|
- self.fractionB.x = this.xB + (self.selectedB * (self.figureWidth / self.numBlocksB)) + 25;
|
|
|
|
- self.fractionLineB.x = self.fractionB.x
|
|
|
|
|
|
+ const newX = curBlock.finalX + ((curBlock.index + 1) * (self.figureWidth / self[curSet].blocks.length)) + 25;;
|
|
|
|
+ self[curSet].fractions[0].x = newX;
|
|
|
|
+ self[curSet].fractions[1].x = newX;
|
|
|
|
+ self[curSet].fractions[2].x = newX;
|
|
|
|
|
|
- self.hasClickedB = true;
|
|
|
|
- self.animateB = true;
|
|
|
|
|
|
+ self[curSet].fractions[0].alpha = 1;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
},
|
|
},
|
|
|
|
|
|
- func_getRndDivisor: function (number) { //Get random divisor for a number
|
|
|
|
|
|
+ func_outSquare: function (curSet) { // curSet : self.A || self.B
|
|
|
|
|
|
- let div = []; //Divisors found
|
|
|
|
- let p = 0; //current dividor index
|
|
|
|
|
|
+ if (!self[curSet].hasClicked) {
|
|
|
|
+
|
|
|
|
+ self[curSet].fractions[0].alpha = 0;
|
|
|
|
+ self[curSet].fractions[1].alpha = 0;
|
|
|
|
+ self[curSet].fractions[2].alpha = 0;
|
|
|
|
+
|
|
|
|
+ self[curSet].blocks.forEach(cur => {
|
|
|
|
+ cur.alpha = 0.5;
|
|
|
|
+ });
|
|
|
|
|
|
- for (let i = 2; i < number; i++) {
|
|
|
|
- if (number % i == 0) {
|
|
|
|
- div[p] = i;
|
|
|
|
- p++;
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
- let x = game.rnd.integerInRange(0, p - 1);
|
|
|
|
- return div[x];
|
|
|
|
|
|
|
|
},
|
|
},
|
|
|
|
|
|
- func_getRndDivisor: function (number) { //Get random divisor for a number
|
|
|
|
|
|
+ func_clickSquare: function (curBlock) { // curBlock : self.A.blocks[i] || self.B.blocks[i]
|
|
|
|
|
|
- let validDivs = []; // Divisors found
|
|
|
|
|
|
+ const curSet = curBlock.figure; // "A" || "B"
|
|
|
|
|
|
- for (let div = 2; div < number; div++) {
|
|
|
|
|
|
+ if (!self[curSet].hasClicked && curBlock.index != self[curSet].blocks.length - 1) {
|
|
|
|
|
|
- // if 'number' can be divided by 'div', add to list of 'validDivs'
|
|
|
|
- if (number % div == 0) validDivs.push(div);
|
|
|
|
|
|
+ document.body.style.cursor = "auto";
|
|
|
|
|
|
- }
|
|
|
|
|
|
+ // turn auxiliar blocks invisible
|
|
|
|
+ for (let i in self[curSet].blocks) {
|
|
|
|
+ if (i > curBlock.index) self[curSet].auxBlocks[i].alpha = 0;
|
|
|
|
+ }
|
|
|
|
|
|
- const randIndex = game.rnd.integerInRange(0, validDivs.length - 1);
|
|
|
|
|
|
+ // turn value label invisible
|
|
|
|
+ self[curSet].label.alpha = 0;
|
|
|
|
|
|
- return validDivs[randIndex];
|
|
|
|
|
|
+ if (audioStatus) game.audio.beepSound.play();
|
|
|
|
|
|
- },
|
|
|
|
|
|
+ // Save number of selected blocks
|
|
|
|
+ self[curSet].selected = curBlock.index + 1;
|
|
|
|
|
|
- // Game information
|
|
|
|
|
|
+ // set fraction x position
|
|
|
|
+ const newX = curBlock.finalX + (self[curSet].selected * (self.figureWidth / self[curSet].blocks.length)) + 25;
|
|
|
|
+ self[curSet].fractions[0].x = newX;
|
|
|
|
+ self[curSet].fractions[1].x = newX;
|
|
|
|
+ self[curSet].fractions[2].x = newX;
|
|
|
|
+
|
|
|
|
+ self[curSet].fractions[1].alpha = 1;
|
|
|
|
+ self[curSet].fractions[2].alpha = 1;
|
|
|
|
+
|
|
|
|
+ self[curSet].hasClicked = true; // inform player have clicked in current block set
|
|
|
|
+ self[curSet].animate = true; // let it initiate animation
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ game.render.all();
|
|
|
|
|
|
- func_updateCounter: function () {
|
|
|
|
- this.totalTime++;
|
|
|
|
},
|
|
},
|
|
|
|
|
|
- func_postScore: function () {
|
|
|
|
|
|
|
|
- let abst = "numBlocksA: " + this.numBlocksA
|
|
|
|
- + ", valueA: " + this.selectedA
|
|
|
|
- + ", numBlocksB: " + this.numBlocksB
|
|
|
|
- + ", valueB: " + this.selectedB;
|
|
|
|
|
|
|
|
- let hr = new XMLHttpRequest();
|
|
|
|
|
|
+ /* METADATA FOR GAME */
|
|
|
|
+
|
|
|
|
+ func_postScore: function () {
|
|
|
|
|
|
// Create some variables we need to send to our PHP file
|
|
// Create some variables we need to send to our PHP file
|
|
- let url = "php/save.php";
|
|
|
|
- let vars = "s_ip=" + hip
|
|
|
|
- + "&s_name=" + playerName
|
|
|
|
- + "&s_lang=" + langString
|
|
|
|
- + "&s_game=" + levelShape
|
|
|
|
- + "&s_mode=" + levelType;
|
|
|
|
- vars += "&s_oper=Equal"
|
|
|
|
- + "&s_leve=" + levelDifficulty
|
|
|
|
|
|
+ const data = "&s_game=" + gameShape
|
|
|
|
+ + "&s_mode=" + levelType
|
|
|
|
+ + "&s_oper=Equal"
|
|
|
|
+ + "&s_leve=" + gameDifficulty
|
|
+ "&s_posi=" + mapPosition
|
|
+ "&s_posi=" + mapPosition
|
|
- + "&s_resu=" + this.result
|
|
|
|
- + "&s_time=" + this.totalTime
|
|
|
|
- + "&s_deta=" + abst;
|
|
|
|
-
|
|
|
|
- hr.open("POST", url, true);
|
|
|
|
- hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
|
|
|
- hr.onreadystatechange = function () {
|
|
|
|
- if (debugMode) console.log(hr);
|
|
|
|
-
|
|
|
|
- if (hr.readyState == 4 && hr.status == 200) {
|
|
|
|
- let return_data = hr.responseText;
|
|
|
|
- if (debugMode) console.log(return_data);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- // Send the data to PHP now... and wait for response to update the status div
|
|
|
|
- hr.send(vars); // Actually execute the request
|
|
|
|
- if (debugMode) console.log("processing...");
|
|
|
|
- if (debugMode) console.log(vars);
|
|
|
|
|
|
+ + "&s_resu=" + self.result
|
|
|
|
+ + "&s_time=" + game.timer.elapsed
|
|
|
|
+ + "&s_deta="
|
|
|
|
+ + "numBlocksA: " + self.A.blocks.length
|
|
|
|
+ + ", valueA: " + self.A.selected
|
|
|
|
+ + ", numBlocksB: " + self.B.blocks.length
|
|
|
|
+ + ", valueB: " + self.B.selected;;
|
|
|
|
+
|
|
|
|
+ postScore(data);
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
};
|
|
};
|