123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601 |
- const circleOne = {
-
- create: function () {
-
- this.availableAnimations = [];
- this.changeAnimationFrames = undefined;
- this.checkAnswer = false;
- this.animate = false;
- this.animateEnding = false;
- this.hasClicked = false;
- this.result = false;
- this.count = 0;
- this.divisorsList = '';
- let hasBaseDifficulty = false;
- const startX = (sublevelType == 'Minus') ? 66 + 5 * 156 : 66;
- this.correctX = startX;
-
-
- game.add.image(0, 0, 'bgimage');
-
- game.add.image(300, 100, 'cloud');
- game.add.image(660, 80, 'cloud');
- game.add.image(110, 85, 'cloud', 0.8);
-
- for (let i = 0; i < 9; i++) { game.add.image(i * 100, 501, 'floor'); }
-
- this.road = game.add.image(47, 515, 'road', 1.01, 0.94);
-
- const distanceBetweenPoints = 156;
- for (let i = 0; i <= 5; i++) {
- game.add.image(66 + i * distanceBetweenPoints, 526, 'place_off', 0.3).anchor(0.5, 0.5);
- game.add.text(66 + i * distanceBetweenPoints, 560, i, textStyles.h2_blue);
- }
- this.trace = game.add.graphic.rect(startX - 1, 526, 1, 1, undefined, 1);
- this.trace.alpha = 0;
-
- navigationIcons.func_addIcons(
- true, true, true,
- true, false,
- 'customMenu', this.func_viewHelp
- );
-
- this.circles = {
- all: [],
- label: [],
- diameter: 60,
- cur: 0,
- direction: [],
- distance: [],
- angle: [],
- lineColor: [],
- direc: [],
- };
- this.balloonPlace = defaultWidth / 2;
-
- const max = (sublevelType == 'Mixed' || levelType == 'B') ? 6 : mapPosition + 1;
- const min = (sublevelType == 'Mixed' && mapPosition < 2) ? 2 : mapPosition;
- const total = game.math.randomInRange(min, max);
-
- this.fractionIndex = -1;
- this.numberOfPlusFractions = game.math.randomInRange(1, total - 1);
-
- const levelDirection = (sublevelType == 'Minus') ? -1 : 1;
- const x = startX + 65 * levelDirection;
- for (let i = 0; i < total; i++) {
- const divisor = game.math.randomInRange(1, gameDifficulty);
- if (divisor == gameDifficulty) hasBaseDifficulty = true;
- this.divisorsList += divisor + ',';
-
- let direction;
- switch (sublevelType) {
- case 'Plus': direction = 'Right'; break;
- case 'Minus': direction = 'Left'; break;
- case 'Mixed':
- if (i < this.numberOfPlusFractions) direction = 'Right';
- else direction = 'Left';
- break;
- }
- this.circles.direction[i] = direction;
-
- let lineColor, anticlockwise;
- if (direction == 'Right') {
- lineColor = colors.darkBlue;
- this.circles.direc[i] = 1;
- anticlockwise = true;
- } else {
- lineColor = colors.red;
- this.circles.direc[i] = -1;
- anticlockwise = false;
- }
- this.circles.lineColor[i] = lineColor;
-
- let circle, label = [];
- if (divisor == 1) {
- circle = game.add.graphic.circle(startX, 490 - i * this.circles.diameter, this.circles.diameter,
- lineColor, 2, colors.white, 1);
- circle.anticlockwise = anticlockwise;
- this.circles.angle.push(360);
- if (fractionLabel) {
- label[0] = game.add.text(x, 490 - i * this.circles.diameter, divisor, textStyles.h2_blue);
- this.circles.label.push(label);
- }
- } else {
- let degree = 360 / divisor;
- if (direction == 'Right') degree = 360 - degree;
- circle = game.add.graphic.arc(startX, 490 - i * this.circles.diameter, this.circles.diameter,
- 0, game.math.degreeToRad(degree), anticlockwise,
- lineColor, 2, colors.white, 1);
- this.circles.angle.push(degree);
- if (fractionLabel) {
- label[0] = game.add.text(x, 480 - i * this.circles.diameter + 32, divisor, textStyles.h4_blue);
- label[1] = game.add.text(x, 488 - i * this.circles.diameter, '1', textStyles.h4_blue);
- label[2] = game.add.text(x, 488 - i * this.circles.diameter, '___', textStyles.h4_blue);
- this.circles.label.push(label);
- }
- }
- circle.rotate = 90;
-
- if (levelType == 'B') {
- circle.alpha = 0.5;
- circle.index = i;
- }
- this.circles.distance.push(Math.floor(distanceBetweenPoints / divisor));
- this.circles.all.push(circle);
- this.correctX += Math.floor(distanceBetweenPoints / divisor) * this.circles.direc[i];
- }
-
- this.nextX = startX + this.circles.distance[0] * this.circles.direc[0];
-
- this.restart = false;
-
- if (this.correctX < 66 || this.correctX > 66 + 3 * 260 || !hasBaseDifficulty) {
- this.restart = true;
- }
-
- if (levelType == 'B') {
- this.balloonPlace = startX;
- this.endIndex = game.math.randomInRange(this.numberOfPlusFractions, this.circles.all.length);
- for (let i = 0; i < this.endIndex; i++) {
- this.balloonPlace += this.circles.distance[i] * this.circles.direc[i];
- }
-
- if (this.balloonPlace < 66 || this.balloonPlace > 66 + 5 * distanceBetweenPoints) {
- this.restart = true;
- }
- }
-
- this.availableAnimations['Right'] = ['Right', [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], 4];
- this.availableAnimations['Left'] = ['Left', [23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12], 4];
- this.kid = game.add.sprite(startX, 495 - this.circles.all.length * this.circles.diameter, 'kid_walk', 0, 0.8);
- this.kid.anchor(0.5, 0.8);
- if (sublevelType == 'Minus') {
- this.kid.animation = this.availableAnimations['Left'];
- this.kid.curFrame = 23;
- } else {
- this.kid.animation = this.availableAnimations['Right'];
- }
-
- this.balloon = game.add.image(this.balloonPlace, 350, 'balloon', 1, 0.5);
- this.balloon.alpha = 0.5;
- this.balloon.anchor(0.5, 0.5);
- this.basket = game.add.image(this.balloonPlace, 472, 'balloon_basket');
- this.basket.anchor(0.5, 0.5);
-
- this.help = game.add.image(0, 0, 'help_pointer', 0.5);
- this.help.anchor(0.5, 0);
- this.help.alpha = 0;
- if (!this.restart) {
- game.timer.start();
- game.event.add('click', this.func_onInputDown);
- game.event.add('mousemove', this.func_onInputOver);
- }
- },
-
- update: function () {
- self.count++;
-
- if (self.animate) {
- let cur = self.circles.cur;
- let DIREC = self.circles.direc[cur];
- if (self.count % 2 == 0) {
-
- self.kid.x += 2 * DIREC;
-
- for (let i in self.circles.all) {
- self.circles.all[i].x += 2 * DIREC;
- }
-
- self.trace.width += 2 * DIREC;
- self.trace.lineColor = self.circles.all[cur].lineColor;
-
- self.circles.angle[cur] += 4.6 * DIREC;
- self.circles.all[cur].angleEnd = game.math.degreeToRad(self.circles.angle[cur]);
-
- let lowerCircles;
- if (self.circles.direction[cur] == 'Right') {
- lowerCircles = self.circles.all[cur].x >= self.nextX;
- }
- else if (self.circles.direction[cur] == 'Left') {
- lowerCircles = self.circles.all[cur].x <= self.nextX;
-
- if (self.changeAnimationFrames == undefined && cur > 0 && self.circles.direction[cur - 1] == 'Right') {
- self.changeAnimationFrames = true;
- }
- }
-
- if (self.changeAnimationFrames) {
- self.changeAnimationFrames = false;
- game.animation.stop(self.kid.animation[0]);
- self.kid.animation = self.availableAnimations['Left'];
- self.kid.curFrame = 23;
- game.animation.play(self.kid.animation[0]);
- }
- if (lowerCircles) {
- self.circles.all[cur].alpha = 0;
- self.circles.all.forEach(cur => {
- cur.y += self.circles.diameter;
- });
- self.kid.y += self.circles.diameter;
- self.circles.cur++;
- cur = self.circles.cur;
- DIREC = self.circles.direc[cur];
- self.nextX += self.circles.distance[cur] * DIREC;
- }
-
- if (cur == self.circles.all.length || self.circles.all[cur].alpha == 0) {
- self.animate = false;
- self.checkAnswer = true;
- }
- }
- }
-
- if (self.checkAnswer) {
- game.timer.stop();
- game.animation.stop(self.kid.animation[0]);
- if (self.func_checkOverlap(self.basket, self.kid)) {
- self.result = true;
- self.kid.curFrame = (self.kid.curFrame < 12) ? 24 : 25;
- if (audioStatus) game.audio.okSound.play();
- game.add.image(defaultWidth / 2, defaultHeight / 2, 'ok').anchor(0.5, 0.5);
- completedLevels++;
- if (debugMode) console.log('completedLevels = ' + completedLevels);
- } else {
- self.result = false;
- if (audioStatus) game.audio.errorSound.play();
- game.add.image(defaultWidth / 2, defaultHeight / 2, 'error').anchor(0.5, 0.5);
- }
- self.postScore();
- self.animateEnding = true;
- self.checkAnswer = false;
- self.count = 0;
- }
-
- if (self.animateEnding) {
- self.balloon.y -= 2;
- self.basket.y -= 2;
- if (self.result) self.kid.y -= 2;
- if (self.count >= 140) {
- if (self.result) mapMove = true;
- else mapMove = false;
- game.state.start('map');
- }
- }
- game.render.all();
- },
-
-
- func_onInputDown: function (mouseEvent) {
- const x = mouseEvent.offsetX;
- const y = mouseEvent.offsetY;
-
- if (levelType == 'A') {
- const cur = self.road;
- const valid = y > 60 && (x >= cur.xWithAnchor && x <= (cur.xWithAnchor + cur.width * cur.scale));
- if (valid) self.func_clicked(x);
- }
-
- if (levelType == 'B') {
- self.circles.all.forEach(cur => {
- const valid = game.math.distanceToPointer(x, cur.xWithAnchor, y, cur.yWithAnchor) <= (cur.diameter / 2) * cur.scale;
- if (valid) self.func_clicked(cur);
- });
- }
- navigationIcons.func_onInputDown(x, y);
- game.render.all();
- },
-
- func_onInputOver: function (mouseEvent) {
- const x = mouseEvent.offsetX;
- const y = mouseEvent.offsetY;
- let flag = false;
-
- if (levelType == 'A' && !self.hasClicked) {
- if (game.math.distanceToPointer(x, self.balloon.x, y, self.balloon.y) > 8) {
- self.balloon.x = x;
- self.basket.x = x;
- }
- document.body.style.cursor = 'auto';
- }
-
- if (levelType == 'B' && !self.hasClicked) {
- self.circles.all.forEach(cur => {
- const valid = game.math.distanceToPointer(x, cur.xWithAnchor, y, cur.yWithAnchor) <= (cur.diameter / 2) * cur.scale;
- if (valid) {
- self.func_overCircle(cur);
- flag = true;
- }
- });
- if (!flag) self.func_outCircle();
- }
- navigationIcons.func_onInputOver(x, y);
- game.render.all();
- },
-
-
- func_overCircle: function (cur) {
- if (!self.hasClicked) {
- document.body.style.cursor = 'pointer';
- for (let i in self.circles.all) {
- self.circles.all[i].alpha = (i <= cur.index) ? 1 : 0.5;
- }
- }
- },
-
- func_outCircle: function () {
- if (!self.hasClicked) {
- document.body.style.cursor = 'auto';
- self.circles.all.forEach(cur => {
- cur.alpha = 0.5;
- });
- }
- },
-
- func_clicked: function (cur) {
- if (!self.hasClicked) {
-
- if (levelType == 'A') {
- self.balloon.x = cur;
- self.basket.x = cur;
-
- }
- else if (levelType == 'B') {
- document.body.style.cursor = 'auto';
- for (let i in self.circles.all) {
- if (i <= cur.index) {
- self.circles.all[i].alpha = 1;
- self.fractionIndex = cur.index;
- } else {
- self.circles.all[i].alpha = 0;
- self.kid.y += self.circles.diameter;
- }
- }
- }
- if (audioStatus) game.audio.beepSound.play();
-
- if (fractionLabel) {
- self.circles.label.forEach(cur => {
- cur.forEach(cur => { cur.alpha = 0; });
- });
- }
-
- if (self.help != undefined) self.help.alpha = 0;
- self.balloon.alpha = 1;
- self.trace.alpha = 1;
- self.hasClicked = true;
- self.animate = true;
- game.animation.play(this.kid.animation[0]);
- }
- },
-
-
- func_checkOverlap: function (spriteA, spriteB) {
- const xA = spriteA.x;
- const xB = spriteB.x;
-
- if (Math.abs(xA - xB) > 14) return false;
- else return true;
- },
-
- func_viewHelp: function () {
- if (!self.hasClicked) {
-
- if (levelType == 'A') {
- self.help.x = self.correctX;
- self.help.y = 490;
-
- } else {
- self.help.x = self.circles.all[self.endIndex - 1].x;
- self.help.y = self.circles.all[self.endIndex - 1].y - self.circles.diameter / 2;
- }
- self.help.alpha = 0.7;
- }
- },
-
-
- postScore: function () {
-
- const data = '&line_game=' + gameShape
- + '&line_mode=' + levelType
- + '&line_oper=' + sublevelType
- + '&line_leve=' + gameDifficulty
- + '&line_posi=' + mapPosition
- + '&line_resu=' + self.result
- + '&line_time=' + game.timer.elapsed
- + '&line_deta='
- + 'numCircles:' + self.circles.all.length
- + ', valCircles: ' + self.divisorsList
- + ' balloonX: ' + self.basket.x
- + ', selIndex: ' + self.fractionIndex;
- sendToDB(data);
- }
- };
|