===================================================================
--- original.js
+++ change.js
@@ -1,20 +1,7 @@
-var Line = Container.expand(function (startX, startY, endX, endY) {
- var self = Container.call(this);
- var lineGraphics = self.createAsset('line', 'Line Graphics', 0, 0);
- lineGraphics.width = Math.sqrt(Math.pow(endX - startX, 2) + Math.pow(endY - startY, 2));
- lineGraphics.rotation = Math.atan2(endY - startY, endX - startX);
- lineGraphics.x = startX;
- lineGraphics.y = startY;
- self.addChild(lineGraphics);
- return self;
-});
-var Picture = Container.expand(function (index) {
- var self = Container.call(this);
- self.index = index;
- var pictureGraphics = self.createAsset('picture' + self.index, 'Picture Graphics', .5, .5);
- return self;
-});
+/****
+* Classes
+****/
var Card = Container.expand(function (context, uid, index) {
var self = Container.call(this);
self.row = 0;
self.col = 0;
@@ -26,9 +13,11 @@
}
self.isMatched = false;
nbCardsLeft++;
self.shakeAnimation = function (card) {
- if (!card) return;
+ if (!card) {
+ return;
+ }
var shakeCount = 0;
var shakeTimes = 9;
var shakeStrength = 70;
var originalX = card.x;
@@ -42,17 +31,21 @@
card.x = originalX;
card.y = originalY;
card.scale.x = 1;
card.scale.y = 1;
- if (card === selectedCard1) selectedCard1 = null;
- if (card === selectedCard2) selectedCard2 = null;
+ if (card === selectedCard1) {
+ selectedCard1 = null;
+ }
+ if (card === selectedCard2) {
+ selectedCard2 = null;
+ }
isAnimating = false;
}
}
shake();
};
self.id = index;
- self.on('down', function (obj) {
+ self.on('down', function (x, y, obj) {
if (!self.isMatched && !isAnimating) {
if (!selectedCard1 || selectedCard1 && selectedCard2) {
if (selectedCard1) {
selectedCard1.scale.x = 1;
@@ -91,15 +84,18 @@
}
}
}
});
- var cardGraphics = self.createAsset('card', 'Card Graphics', .5, .5);
+ var cardGraphics = self.attachAsset('card', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
self.match = function (otherCard) {
if (checkGameEndTimeout) {
LK.clearTimeout(checkGameEndTimeout);
}
var line = new Line(self.x, self.y, otherCard.x, otherCard.y);
- LK.stage.addChild(line);
+ game.addChild(line);
var tadaAnimationSteps = 10;
var tadaAnimationCount = 0;
var scaleDelta = 0.2;
var tadaDelay = 0;
@@ -147,16 +143,38 @@
picture.x = 0;
picture.y = 0;
return self;
});
+var Line = Container.expand(function (startX, startY, endX, endY) {
+ var self = Container.call(this);
+ var lineGraphics = self.attachAsset('line', {});
+ lineGraphics.width = Math.sqrt(Math.pow(endX - startX, 2) + Math.pow(endY - startY, 2));
+ lineGraphics.rotation = Math.atan2(endY - startY, endX - startX);
+ lineGraphics.x = startX;
+ lineGraphics.y = startY;
+ self.addChild(lineGraphics);
+ return self;
+});
+var Picture = Container.expand(function (index) {
+ var self = Container.call(this);
+ self.index = index;
+ var pictureGraphics = self.createAsset('picture' + self.index, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ return self;
+});
var TimerLine = Container.expand(function (width, height) {
var self = Container.call(this);
- var timerGraphics = self.createAsset('timerLine', 'Timer Line Graphics', 0.5, 0.5);
+ var timerGraphics = self.attachAsset('timerLine', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
timerGraphics.width = width;
timerGraphics.height = height;
timerGraphics.tint = 0x00FF00;
self.addChild(timerGraphics);
- self.update = function (elapsedTime) {
+ self._update_migrated = function (elapsedTime) {
var totalTicks = levelDurationInSeconds * 1000;
var deltaWidth = this.initialWidth / totalTicks;
timerGraphics.width = Math.max(0, timerGraphics.width - deltaWidth * elapsedTime);
if (timerGraphics.width / this.initialWidth < 0.25) {
@@ -164,8 +182,83 @@
}
};
return self;
});
+
+/****
+* Initialize Game
+****/
+var game = new LK.Game({
+ backgroundColor: 0x000000
+});
+
+/****
+* Game Code
+****/
+function _slicedToArray(r, e) {
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
+}
+function _nonIterableRest() {
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
+}
+function _unsupportedIterableToArray(r, a) {
+ if (r) {
+ if ("string" == typeof r) {
+ return _arrayLikeToArray(r, a);
+ }
+ var t = {}.toString.call(r).slice(8, -1);
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
+ }
+}
+function _arrayLikeToArray(r, a) {
+ (null == a || a > r.length) && (a = r.length);
+ for (var e = 0, n = Array(a); e < a; e++) {
+ n[e] = r[e];
+ }
+ return n;
+}
+function _iterableToArrayLimit(r, l) {
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
+ if (null != t) {
+ var e,
+ n,
+ i,
+ u,
+ a = [],
+ f = !0,
+ o = !1;
+ try {
+ if (i = (t = t.call(r)).next, 0 === l) {
+ if (Object(t) !== t) {
+ return;
+ }
+ f = !1;
+ } else {
+ for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0) {
+ ;
+ }
+ }
+ } catch (r) {
+ o = !0, n = r;
+ } finally {
+ try {
+ if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) {
+ return;
+ }
+ } finally {
+ if (o) {
+ throw n;
+ }
+ }
+ }
+ return a;
+ }
+}
+function _arrayWithHoles(r) {
+ if (Array.isArray(r)) {
+ return r;
+ }
+}
var level = 0;
var levels = [{
'rows': 2,
'cols': 2,
@@ -233,9 +326,11 @@
function prepareConfig(level) {
cardPairs = [];
cards.forEach(function (row) {
row.forEach(function (card) {
- if (card) card.destroy();
+ if (card) {
+ card.destroy();
+ }
});
});
cards = [];
nbRows = levels[level].rows + 2;
@@ -325,9 +420,11 @@
return false;
}
var visited = Array.from({
length: nbRows
- }, () => Array(nbCols).fill(false));
+ }, function () {
+ return Array(nbCols).fill(false);
+ });
function dfs(card, bends, direction) {
if (!card || visited[card.row][card.col] || bends > 2) {
return false;
}
@@ -335,17 +432,25 @@
return true;
}
visited[card.row][card.col] = true;
var directions = [[-1, 0], [1, 0], [0, -1], [0, 1]];
- for (let [di, dj] of directions) {
- var ni = card.row + di, nj = card.col + dj;
+ for (var _i = 0, _directions = directions; _i < _directions.length; _i++) {
+ var _directions$_i = _slicedToArray(_directions[_i], 2),
+ di = _directions$_i[0],
+ dj = _directions$_i[1];
+ var ni = card.row + di,
+ nj = card.col + dj;
if (ni >= 0 && ni < nbRows && nj >= 0 && nj < nbCols) {
var nextCard = cards[ni][nj];
if (!nextCard || !nextCard.id || nextCard.isMatched || nextCard === card2) {
if (di !== 0) {
- if (dfs(nextCard, bends + (direction === -1), 1)) return true;
+ if (dfs(nextCard, bends + (direction === -1), 1)) {
+ return true;
+ }
} else if (dj !== 0) {
- if (dfs(nextCard, bends + (direction === 1), -1)) return true;
+ if (dfs(nextCard, bends + (direction === 1), -1)) {
+ return true;
+ }
}
}
}
}
@@ -393,9 +498,9 @@
}
}
unmatchedCards.forEach(function (card, index) {
var newPos = reorderedPosition[index];
- var moveCard = function () {
+ var _moveCard = function moveCard() {
var dx = 0;
var dy = 0;
if (newPos) {
dx = newPos.x - card.x;
@@ -413,15 +518,15 @@
}
card.col = newCol;
card.row = newRow;
cards[newRow][newCol] = card;
- LK.off('tick', moveCard);
+ LK.off('tick', _moveCard);
} else {
card.x += dx * 0.05;
card.y += dy * 0.05;
}
};
- LK.on('tick', moveCard);
+ LK.on('tick', _moveCard);
});
LK.setTimeout(function () {
isRemixing = false;
if (callback) {
@@ -565,9 +670,12 @@
}
function showConfettiAnimation(self, callback, isFinal) {
var confettiCount = 50 + 5 * level + (isFinal ? 50 : 0);
var confettiGraphics;
- var backgroundImage = self.createAsset('background' + (level + (isFinal ? 1 : 0)), 'Level Background', 0.5, 0.5);
+ var backgroundImage = self.createAsset('background' + (level + (isFinal ? 1 : 0)), {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
backgroundImage.x = 2048 / 2;
backgroundImage.y = 2732 / 2;
self.addChild(backgroundImage);
var congratulationsText = new Text2('Congratulations!', {
@@ -577,12 +685,12 @@
if (isFinal) {
congratulationsText.anchor.set(0.5, 0);
congratulationsText.x = 0;
congratulationsText.y = 20;
- LK.gui.topCenter.addChild(congratulationsText);
+ LK.gui.top.addChild(congratulationsText);
}
for (var i = 0; i < confettiCount; i++) {
- confettiGraphics = self.createAsset('picture' + (1 + i % (nbPairs - 1)), 'Confetti Graphics', Math.random(), Math.random());
+ confettiGraphics = self.createAsset('picture' + (1 + i % (nbPairs - 1)), {});
confettiGraphics.x = Math.random() * 2048;
confettiGraphics.y = -30 - Math.random() * 2000;
confettiGraphics.rotation = Math.random() * Math.PI * 2;
self.addChild(confettiGraphics);
@@ -633,9 +741,12 @@
LK.gui.addChild(loadingText);
var assetsToLoad = ['line', 'picture1', 'picture2', 'picture3', 'picture8', 'picture7', 'picture24', 'picture17', 'picture16', 'picture4', 'picture29', 'picture6', 'picture14', 'picture15', 'picture20', 'picture9', 'picture10', 'picture27', 'picture12', 'picture19', 'picture26', 'picture22', 'picture18', 'picture28', 'picture23', 'picture13', 'picture21', 'picture5', 'picture11', 'picture25', 'picture30', 'picture32', 'picture31', 'picture37', 'picture39', 'picture44', 'picture38', 'picture48', 'picture47', 'picture50', 'picture42', 'picture46', 'picture45', 'picture43', 'picture49', 'picture34', 'picture33', 'picture40', 'picture36', 'picture35', 'picture41', 'picture55', 'picture52', 'picture54', 'picture53', 'picture51', 'picture56', 'picture59', 'picture60', 'picture57', 'picture58', 'picture64', 'picture63', 'picture61', 'picture62', 'picture65', 'card', 'timerLine', 'background1', 'background2', 'background3', 'background4', 'background5', 'background6', 'background7'];
var loadedAssets = 0;
assetsToLoad.forEach(function (asset) {
- var assetInstance = LK.getAsset(asset, 'Loading ' + asset, 0.5, 0.5);
+ var assetInstance = LK.getAsset(asset, {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
loadedAssets++;
if (loadedAssets === assetsToLoad.length) {
LK.setTimeout(function () {
loadingText.destroy();
@@ -644,32 +755,29 @@
}, 1200);
}
});
}
-var Game = Container.expand(function () {
- var self = Container.call(this);
- preload(self);
- if (debug) {
- this.timerLine = new TimerLine(1400, 20);
- this.timerLine.initialWidth = 1400;
- this.timerLine.x = 710;
- this.timerLine.y = this.timerLine.y;
- LK.gui.topLeft.addChild(this.timerLine);
- var tickTime = Date.now();
- LK.on('tick', function () {
- if (isPlaying && !isRemixing) {
- var elapsedTime = Date.now() - tickTime;
- self.timerLine.update(elapsedTime);
- tickTime = Date.now();
- }
- });
- var matchDebugText = new Text2('Match:', {
- size: 50,
- fill: '#ffffff'
- });
- matchDebugText.anchor.set(0, 0);
- LK.gui.topLeft.addChild(matchDebugText);
- LK.on('tick', function () {
- matchDebugText.setText('Level: ' + (level + 1) + ' Solved: ' + currentNbSolved + '/' + lastNbPossible + ' / isPlaying=' + isPlaying + ' / time=' + levelDurationInSeconds);
- });
- }
-});
+preload(game);
+if (debug) {
+ game.timerLine = new TimerLine(1400, 20);
+ game.timerLine.initialWidth = 1400;
+ game.timerLine.x = 710;
+ game.timerLine.y = game.timerLine.y;
+ LK.gui.topLeft.addChild(game.timerLine);
+ var tickTime = Date.now();
+ LK.on('tick', function () {
+ if (isPlaying && !isRemixing) {
+ var elapsedTime = Date.now() - tickTime;
+ game.timerLine._update_migrated(elapsedTime);
+ tickTime = Date.now();
+ }
+ });
+ var matchDebugText = new Text2('Match:', {
+ size: 50,
+ fill: '#ffffff'
+ });
+ matchDebugText.anchor.set(0, 0);
+ LK.gui.topLeft.addChild(matchDebugText);
+ LK.on('tick', function () {
+ matchDebugText.setText('Level: ' + (level + 1) + ' Solved: ' + currentNbSolved + '/' + lastNbPossible + ' / isPlaying=' + isPlaying + ' / time=' + levelDurationInSeconds);
+ });
+}
\ No newline at end of file
a photo realistic top view of empty flat beige plastic square. Single Game Texture. In-Game asset. 2d. No background. High contrast. No shadows.
a christmas tree. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas gift. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas ball. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a golden christmas tree star. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas hat. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas leaf. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas holly leaf. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas snow flake. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas snow man. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas reindeer. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas candy cane. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas green ball . plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas gingerbrean man. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas pine cone. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas present green. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas boe tie. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas socks. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas penguin. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas decorated blue present. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas scarf. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas gloves. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas blue decorated ball. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas candle. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas snow globe. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
an christmas elongated cuboid present. plastic style. No shadow. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a round christmas gift.plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a round christmas gift.plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
one cute christmas elf. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
one cute christmas elf. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
one cute christmas reindeer head. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
one cute christmas reindeer head with a red nose. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
one christmas bell. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a couple of christmas bells. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas gifts bag. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas candle. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a cute santa clauss. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Santa's sleigh. Side view. Plastic style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Reimagine the cute teddy bear sitting without background. Plastic style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
Christmas Rocking Horse. Plastic style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
One Christmas Matryoshka Doll. Plastic style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A christmas Miniature Train. Plastic style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A christmas Toy Soldier. Plastic style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A christmas Music Box . Plastic style Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a cute polar bear cub. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a sled plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas gingerbread girl. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas gingerbread house. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a cute christmas jack in the box. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a cute christmas cookie. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas log cacke. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a christmas donut. plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a cute christmas owl. Plastic style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a feeric christmas landscape at night with decorated trees Background image
a feeric christmas landscape at night with snow men and snow flakes Background image
a feeric christmas landscape at night with a snow man , candy canes ,holly leafs and snow flakes, Background image
a feeric christmas landscape at night with a snow man , candy canes ,holly leafs and snow flakes, Santa's reindeers, green, red and blue presents Background image
a feeric christmas landscape at night with a snow man , candy canes ,holly leafs and snow flakes, cute penguin, Santa's reindeers, green, red and blue presents and a lot of toys, a sled, gingerbread boy and girl, snow globes, a cute polar bear cub. a gingerbread house Background image
A Magical feeric starry christmas landscape at night with a snow man , candy canes ,holly leafs and snow flakes, cute penguin, Santa's reindeers, green, red and blue presents and a lot of toys, a sled, gingerbread boy and girl, snow globes, cute polar bears cub and a gingerbread house. Realistic. Plastic style. Background image