User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'includes')' in or related to this line: 'if (!storage.levelsDiscovered.includes(currentLevel.uid)) {' Line Number: 1054
Code edit (16 edits merged)
Please save this source code
User prompt
please implement the helpbutton blink method, so it makes the 12 blinkers appear and disappear 5 times in a blnking fashion
Code edit (1 edits merged)
Please save this source code
User prompt
in the helpbutton class, please place the 8 blinkers assets in a cicular pattern around the button.
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'instructionsScreen.scale is not a function' in or related to this line: 'if (Math.random() < 0.12) {' Line Number: 429
User prompt
Please fix the bug: 'instructionsScreen.scale is not a function' in or related to this line: 'instructionsScreen.scale(1.2, 1.2);' Line Number: 1033
Code edit (14 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Unable to load plugin: @upit/tween.v1' in or related to this line: 'var tween = LK.import("@upit/tween.v1");' Line Number: 32 ↪💡 Consider importing and using the following plugins: @upit/tween.v1, @upit/storage.v1, @upit/tween.v1
Code edit (1 edits merged)
Please save this source code
User prompt
Please creata container class for the closebutton asset and add one to the helpscreen, in the top right corner
Code edit (1 edits merged)
Please save this source code
Code edit (3 edits merged)
Please save this source code
User prompt
Please fix the bug: 'levelNameLabel is not defined' in or related to this line: 'if (Math.random() < 0.12) {' Line Number: 403
User prompt
Please fix the bug: 'levelNameLabel is not defined' in or related to this line: 'levelNameLabel.setText(a.name, ' ', a.uid);' Line Number: 984
Code edit (9 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading '0')' in or related to this line: 'var n = source[0].length;' Line Number: 1219
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'length')' in or related to this line: 'var m = source.length;' Line Number: 1218
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading '0')' in or related to this line: 'var gridSize = currentLevel.d.length;' Line Number: 1087
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading '0')' in or related to this line: 'for (var j = 0; j < a.d[0].length; j++) {' Line Number: 965
User prompt
Please fix the bug: 'levels[currentLevelID].map is not a function' in or related to this line: 'for (var i = 0; i < a.d.length; i++) {' Line Number: 964
User prompt
Please fix the bug: 'levels[currentLevelID].map is not a function' in or related to this line: 'var currentLevel = levels[currentLevelID].map(function (arr) {' Line Number: 935
Code edit (1 edits merged)
Please save this source code
Code edit (5 edits merged)
Please save this source code
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Arrow = Container.expand(function () {
var self = Container.call(this);
var arrowGraphics = self.attachAsset('arrow', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0 //0.75
});
});
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
var Board = Container.expand(function () {
var self = Container.call(this);
self.boxGraphics = self.attachAsset('board', {
anchorX: 0.5,
anchorY: 0.5
});
self.paint = function () {
//self.boxGraphics.width = boardSize;
//self.boxGraphics.height = boardSize;
var startX = -boardSize / 2; //-self.width / 2;
var startY = -boardSize / 2; //-self.height / 2;
var boxSize = calculateTileSize();
var boxSpacing = boxSize * spacingRatio;
var offset = boxSize / 2 + boxSpacing;
for (var i = 0; i < gridSize; i++) {
for (var j = 0; j < gridSize; j++) {
var box = self.addChild(new Box());
box.width = box.height = boxSize;
box.x = offset + startX + i * (boxSize + boxSpacing);
box.y = offset + startY + j * (boxSize + boxSpacing);
box.setAlpha(0.075);
}
}
// Paint arrows at edges of board.
for (var i = 0; i < gridSize; i++) {
for (var j = 0; j < gridSize; j++) {
if (i == 0) {
var arrow = new Arrow();
arrow.rotation = Math.PI / 2;
arrow.scale.x = arrow.scale.y = boxSize / 100;
arrow.x = offset + startX + j * (boxSize + boxSpacing);
arrow.y = startY - 2 * boxSpacing;
self.addChild(arrow);
} else if (i == gridSize - 1) {
var arrow = new Arrow();
arrow.rotation = -Math.PI / 2;
arrow.scale.x = arrow.scale.y = boxSize / 100;
arrow.x = offset + startX + j * (boxSize + boxSpacing);
arrow.y = -startY + 2 * boxSpacing;
self.addChild(arrow);
}
if (j == 0) {
var arrow = new Arrow();
arrow.scale.x = arrow.scale.y = boxSize / 100;
arrow.x = startX - 2 * boxSpacing;
arrow.y = offset + startY + i * (boxSize + boxSpacing);
self.addChild(arrow);
} else if (j == gridSize - 1) {
var arrow = new Arrow();
arrow.rotation = Math.PI;
arrow.scale.x = arrow.scale.y = boxSize / 100;
arrow.x = -startX + 2 * boxSpacing;
arrow.y = offset + startY + i * (boxSize + boxSpacing);
self.addChild(arrow);
}
}
}
};
self.paint();
self.paintArrows = function () {};
self.paintArrows();
});
var Box = Container.expand(function () {
var self = Container.call(this);
var boxGraphics = self.attachAsset('box', {
anchorX: 0.5,
anchorY: 0.5
});
self.setAlpha = function (i) {
self.alpha = i;
};
});
var ColorBox = Container.expand(function (colorIndex) {
var self = Container.call(this);
self.colorIndex = colorIndex;
/*var boxGraphics = self.attachAsset('box', {
anchorX: 0.5,
anchorY: 0.5,
tint: colors[colorIndex]
});*/
var boxGraphics = self.attachAsset(tileTypes[colorIndex], {
anchorX: 0.5,
anchorY: 0.5
//tint: colors[colorIndex]
});
self.gridX = 0;
self.gridY = 0;
self.speed = 10;
self.outlier = false;
self.down = function (x, y, obj) {
if (GAME_IS_CLICKABLE) {
if (!self.outlier) {
GAME_IS_CLICKABLE = false;
colorBoxClicked(self);
}
}
};
self.mouseover = function () {
if (!self.outlier) {
self.width = self.height = tileSize * 1.1;
}
};
self.mouseout = function () {
if (!self.outlier) {
self.width = self.height = tileSize;
}
};
self.remove = function (delay) {
numRunningTweens++;
currentLevel[self.gridY][self.gridX] = 0;
tween(self, {
scaleX: 0.5,
scaleY: 0.5,
rotation: Math.PI,
alpha: 0
}, {
duration: BASE_TWEEN_SPEED,
delay: delay,
easing: tween.easeInOut,
onFinish: function onFinish() {
//console.log("Animation complete!");
//console.log('currentLevel:', currentLevel);
//console.log('levelContainer:', levelContainer);
playerScore++;
var t = new Star(levelContainer.x + self.x, levelContainer.y + self.y, 1900, 50, 0, colors[self.colorIndex]);
//console.log('startx and y:', t.x, t.y);
game.addChild(t);
stars.push(t);
updateScoreLabels();
numRunningTweens--;
self.destroy();
}
});
//self.destroy();
};
self.fadeIn = function () {
numRunningTweens++;
self.alpha = 0;
tween(self, {
alpha: 1
}, {
duration: BASE_TWEEN_SPEED,
delay: 0,
easing: tween.easeInOut,
onFinish: function onFinish() {
numRunningTweens--;
//console.log('faded in:', self);
}
});
};
self.flyOut = function () {
numRunningTweens++;
//console.log(self, self.gridX, self.gridY);
var destY,
destX = 0;
if (self.gridX == 999) {
destY = self.y;
destX = self.x > 0 ? -1500 : 1500;
} else if (self.gridY == 999) {
destY = self.y > 0 ? -1500 : 1500;
destX = self.x;
}
tween(self, {
x: destX,
y: destY
}, {
duration: BASE_TWEEN_SPEED * 2.5,
delay: 0,
easing: tween.easeInOut,
onFinish: function onFinish() {
numRunningTweens--;
//console.log('faded out:', self);
self.destroy();
}
});
};
self.blinkRed = function () {
tween(self, {
width: tileSize * 1.5,
height: tileSize * 1.5
}, {
duration: 150,
easing: tween.easeInOut,
onFinish: function onFinish() {
//self.width = tileSize;
//self.height = tileSize;
tween(self, {
width: tileSize,
height: tileSize
}, {
duration: 150,
easing: tween.easeInOut
});
}
});
};
self.moveInPosition = function () {
var startX = -boardSize / 2;
var startY = -boardSize / 2;
var boxSize = tileSize; //calculateTileSize();
var boxSpacing = boxSize * spacingRatio;
var offset = boxSize / 2 + boxSpacing;
var destX = offset + startX + self.gridX * (boxSize + boxSpacing);
var destY = offset + startY + self.gridY * (boxSize + boxSpacing);
numRunningTweens++;
tween(self, {
x: destX,
y: destY
}, {
duration: BASE_TWEEN_SPEED,
delay: 0,
easing: tween.easeInOut,
onFinish: function onFinish() {
numRunningTweens--;
currentLevel[self.gridY][self.gridX] = self.colorIndex;
self.outlier = false;
//console.log('done moving into position');
}
});
};
});
var Firework = Container.expand(function () {
var self = Container.call(this);
//var starGraphics = self.attachAsset('star', {
var starGraphics = self.attachAsset('particle', {
anchorX: 0.5,
anchorY: 0.5,
tint: Math.random() * 0xffffff
});
starGraphics.scale.set(2, 2);
self.addChild(starGraphics);
self.x = 0;
self.y = 0;
self.dx = 15 - Math.random() * 30;
self.dy = 2 + Math.random() * 40;
self.drot = 0.11 - Math.random() * 0.22;
self.isDead = false;
self.counter = 0;
self._move_migrated = function () {
self.rotation += self.drot;
self.x += self.dx;
self.y -= self.dy;
self.dy -= 1;
if (++self.counter > 500) {
self.destroy();
self.isDead = true;
}
};
});
var HelpButton = Container.expand(function () {
var self = Container.call(this);
var arrowGraphics = self.attachAsset('helpButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.down = function () {
showInstructions();
};
});
var InstructionsScreen = Container.expand(function () {
var self = Container.call(this);
var arrowGraphics = self.attachAsset('levelCompleteBg', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.75
});
});
var LevelComplete = Container.expand(function () {
var self = Container.call(this);
var bgGraphics = self.attachAsset('levelCompleteBg', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.75
});
var label = new Text2('Level Cleared!', {
size: 100,
fill: 0xdddddd,
align: 'center',
font: 'Georgia'
});
label.anchor.set(0.5, 0.5);
label.x = 0;
label.y = -100;
self.addChild(label);
// Add fireworks explosion effect
for (var i = 0; i < 40; i++) {
var firework = new Firework();
self.addChild(firework);
stars.push(firework);
}
});
var Particle = Container.expand(function () {
var self = Container.call(this);
var particleGraphics = self.attachAsset('particle', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.5 + Math.random() * 0.5
//tint: Math.random() * 0xffffff
});
var sc = 1 + Math.random() * 1;
particleGraphics.scale.set(sc, sc);
self.addChild(particleGraphics);
var amplitude = 50 + Math.random() * 100;
var speedY = 2 + Math.random() * 5;
self.update = function () {
if (self.y > 0) {
self.y -= speedY;
self.x += Math.sin(self.y / amplitude) * 10; // Wavy movement
self.x -= self.parent.wind;
} else {
self.x = Math.random() * 2048;
self.y = 2732;
amplitude = 50 + Math.random() * 100;
}
};
});
var ParticleContainer = Container.expand(function () {
var self = Container.call(this);
self.particles = [];
self.particlesMax = 50;
self.wind = 0;
self.update = function () {
self.wind += Math.sin(LK.ticks) * 1;
if (self.particles.length < self.particlesMax) {
if (Math.random() < 0.12) {
var p = new Particle();
p.x = Math.random() * 2048;
p.y = 2732;
self.particles.push(p);
self.addChild(p);
}
}
};
});
var Star = Container.expand(function (startX, startY, endX, endY, delay, boxTint) {
var self = Container.call(this);
//GoldCoin.delayIncrement = 0;
//self.game = this;
var starGraphics = self.attachAsset('star', {
anchorX: 0.5,
anchorY: 0.5,
tint: boxTint
});
self.addChild(starGraphics);
self.x = startX;
self.y = startY;
self.isDead = false;
var distance = Math.sqrt(Math.pow(endX - startX, 2) + Math.pow(endY - startY, 2));
self.delayCounter = delay * 2;
var duration = 30 + delay;
//var vx = (endX - startX) / duration;
//var vy = (endY - startY) / duration;
self.alpha = 0;
//self.path = createQuadraticBezierArcPoints(startX, startY, endX, startY - 100, endX, endY, 60);
self.path = createQuadraticBezierArcPoints(startX, startY, endX, startY + 200, endX, endY, 30);
self._move_migrated = function () {
if (self.delayCounter > 0) {
self.delayCounter--;
} else {
self.alpha = 1;
self.rotation += 0.11;
if (self.path[duration]) {
self.x = self.path[duration - self.delayCounter][0];
self.y = self.path[duration - self.delayCounter][1];
}
}
if (--duration <= 0) {
self.destroy();
self.isDead = true;
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000022
});
/****
* Game Code
****/
var lerp = function lerp(start, end, t) {
return start * (1 - t) + end * t;
};
// Play test music in a loop
LK.playMusic('testmusic', {
loop: true
});
var createQuadraticBezierArcPoints = function createQuadraticBezierArcPoints(p0x, p0y, p1x, p1y, p2x, p2y, numberOfSteps) {
var points_along_axis = new Array(numberOfSteps).fill(null).map(function () {
return [0, 0];
});
var stepping_constant = 1 / numberOfSteps;
for (var i = 0; i < numberOfSteps; i++) {
var i_p0_p1x = lerp(p0x, p1x, i * stepping_constant);
var i_p0_p1y = lerp(p0y, p1y, i * stepping_constant);
var i_p1_p2x = lerp(p1x, p2x, i * stepping_constant);
var i_p1_p2y = lerp(p1y, p2y, i * stepping_constant);
if (false) {
points_along_axis.push(lerp(i_p0_p1x, i_p1_p2x, i * stepping_constant), lerp(i_p0_p1y, i_p1_p2y, i * stepping_constant));
}
points_along_axis[i][0] = lerp(i_p0_p1x, i_p1_p2x, i * stepping_constant);
points_along_axis[i][1] = lerp(i_p0_p1y, i_p1_p2y, i * stepping_constant);
}
if (false) {
console.log('path: ' + points_along_axis);
console.log('path[2]: ' + points_along_axis[2]);
}
return points_along_axis.reverse();
};
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 _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;
}
}
function _createForOfIteratorHelper(r, e) {
var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
if (!t) {
if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
t && (r = t);
var _n = 0,
F = function F() {};
return {
s: F,
n: function n() {
return _n >= r.length ? {
done: !0
} : {
done: !1,
value: r[_n++]
};
},
e: function e(r) {
throw r;
},
f: F
};
}
throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
var o,
a = !0,
u = !1;
return {
s: function s() {
t = t.call(r);
},
n: function n() {
var r = t.next();
return a = r.done, r;
},
e: function e(r) {
u = !0, o = r;
},
f: function f() {
try {
a || null == t["return"] || t["return"]();
} finally {
if (u) {
throw o;
}
}
}
};
}
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;
}
var BASE_TWEEN_SPEED = 200;
var GAME_IS_CLICKABLE = true; // flag for when board is clickable and when not.
var numRunningTweens = 0; // input is blocked while tweens running, so increment this when a tween starts, nd decrement when tween ends.
var outlierDirectionCounter = 0; //0; // increment to allow outliers spawning on different side each turn.
var playerScore = 0;
var highScore = storage.highScore || 0;
// Add background image
var backgroundImage = LK.getAsset('backgroundImage', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.7,
x: 1024,
y: 1366
});
game.addChild(backgroundImage);
// Add game logo to the center top of the screen
var gameLogo = LK.getAsset('gameLogo', {
anchorX: 0.5,
anchorY: 0.5,
x: 1024,
y: 300,
tint: 0x22ddff
});
game.addChild(gameLogo);
var helpButton = new HelpButton();
helpButton.x = 2048 - 150;
helpButton.y = 2732 - 150;
game.addChild(helpButton);
// Create and position the score label
var scoreLabel = new Text2('Score\n0', {
size: 60,
fill: 0xFFFFFF,
align: 'center',
font: 'Georgia'
});
scoreLabel.anchor.set(1, 0); // Anchor to the right
scoreLabel.x = 2048 - 50; // Position near the right edge
scoreLabel.y = 140; //50; // Position at the top
//LK.gui.topRight.addChild(scoreLabel);
game.addChild(scoreLabel);
// Create and position the high score label
var highScoreLabel = new Text2('Best\n0', {
size: 50,
fill: 0xdddddd,
align: 'center',
font: 'Georgia'
});
highScoreLabel.anchor.set(1, 0); // Anchor to the right
highScoreLabel.x = 2048 - 75; // Position near the right edge
highScoreLabel.y = 300; //220; // Position below the score label
//LK.gui.topRight.addChild(highScoreLabel);
game.addChild(highScoreLabel);
var levelLabel = new Text2('Level 1', {
size: 60,
//120,
fill: 0xFFFFFF,
align: 'center',
font: 'Georgia'
});
//levelLabel.anchor.set(0.5, 0.5);
levelLabel.anchor.set(1, 0);
levelLabel.x = 2048 - 30; // Position near the right edge
levelLabel.y = 50; //300;
//LK.gui.topRight.addChild(scoreLabel);
game.addChild(levelLabel);
var gridSize = 5;
var spacingRatio = 0.2; //0.2;
var boardSize = 1300;
var boardCenterY = 2732 / 2 + 250;
function calculateTileSize() {
// Example of getting desired tileSize depending on gridSize (for different size grids)
// maintaining 1300px board size and 0.2 gutter between tiles.
var tileSize = boardSize / ((gridSize + 1) * spacingRatio + gridSize);
return tileSize;
console.log(tileSize);
}
var tileSize = calculateTileSize();
var particleContainer = new ParticleContainer();
game.addChild(particleContainer);
var board = new Board();
board.x = 1024;
board.y = boardCenterY; //2732 / 2 + 200;
game.addChild(board);
// 0 black 1 white 2 yellow 3 red 4 blue 5 green 6 purple 7 grey 8 brown 9 skin
var colors = ['0x000000', '0xffffff', '0xffff00', '0xff0000', '0x0000dd', '0x00ff00', '0xff00ff', '0xbbbbbb', '0x827364', '0xecbcb4'];
var tileSprites = ['box', 'tileWhite', 'tileYellow', 'tileRed', 'tileBlue', 'tileGreen', 'tilePurple', 'tileGray', 'tileBrown', 'tileBeige'];
var tileTypes = tileSprites; // Define tileTypes to fix the error
// 5x5 levels.
var l1a = [[0, 0, 0, 0, 0], [0, 0, 1, 0, 0], [0, 1, 2, 1, 0], [0, 0, 1, 0, 0], [0, 0, 0, 0, 0]];
var l1b = [[0, 0, 0, 0, 0], [0, 0, 4, 0, 0], [0, 5, 4, 5, 0], [0, 5, 0, 5, 0], [0, 0, 0, 0, 0]];
var l1c = [[0, 0, 0, 0, 0], [0, 3, 0, 3, 0], [0, 0, 2, 0, 0], [0, 3, 0, 3, 0], [0, 0, 0, 0, 0]];
var l1d = [[0, 0, 0, 0, 0], [0, 6, 4, 6, 0], [0, 4, 0, 4, 0], [0, 6, 4, 6, 0], [0, 0, 0, 0, 0]];
var l1e = [[0, 0, 0, 0, 0], [0, 0, 0, 5, 0], [0, 0, 5, 3, 0], [0, 5, 3, 3, 0], [0, 0, 0, 0, 0]];
var l1f = [[0, 0, 7, 7, 7], [0, 0, 0, 8, 7], [0, 0, 8, 0, 7], [0, 8, 0, 0, 0], [0, 0, 0, 0, 0]];
var l1g = [[0, 0, 1, 0, 0], [0, 0, 3, 0, 0], [0, 3, 3, 3, 0], [0, 1, 1, 1, 0], [0, 0, 0, 0, 0]];
// 6x6 levels
var l2a = [[0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 0, 0], [0, 4, 1, 1, 4, 0], [0, 0, 2, 2, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]];
var l2b = [[0, 0, 0, 0, 0, 0], [0, 0, 8, 8, 0, 0], [0, 8, 8, 8, 6, 0], [0, 8, 8, 8, 8, 0], [0, 9, 0, 0, 9, 0], [0, 0, 0, 0, 0, 0]];
var l2c = [[0, 0, 0, 0, 0, 0], [0, 9, 9, 9, 9, 0], [0, 4, 9, 9, 4, 0], [0, 9, 6, 6, 9, 0], [0, 9, 9, 9, 9, 0], [0, 0, 0, 0, 0, 0]];
var l2d = [[0, 0, 0, 0, 0, 0], [0, 4, 2, 2, 4, 0], [0, 0, 3, 2, 0, 0], [0, 2, 2, 2, 2, 0], [0, 2, 2, 2, 0, 0], [0, 0, 0, 0, 0, 0]];
var l2e = [[0, 0, 0, 0, 0, 0], [0, 5, 5, 6, 0, 0], [0, 5, 6, 3, 6, 0], [0, 6, 3, 6, 3, 0], [0, 0, 6, 3, 6, 0], [0, 0, 0, 0, 0, 0]];
var l2f = [[0, 0, 0, 0, 0, 0], [0, 7, 0, 7, 0, 0], [0, 7, 4, 7, 4, 0], [0, 7, 7, 3, 7, 0], [0, 0, 7, 7, 0, 0], [0, 0, 0, 0, 0, 0]];
var l2g = [[0, 0, 0, 0, 0, 0], [0, 3, 0, 3, 2, 0], [0, 3, 3, 2, 9, 0], [0, 3, 3, 2, 0, 0], [0, 3, 0, 3, 0, 0], [0, 0, 0, 0, 0, 0]];
// 7x7 levels
var l3a = [[0, 0, 0, 0, 0, 0, 0], [0, 0, 8, 0, 8, 0, 0], [0, 8, 8, 0, 8, 8, 0], [0, 0, 7, 7, 7, 0, 0], [0, 0, 4, 7, 4, 0, 0], [0, 0, 0, 3, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]];
var l3b = [[0, 0, 0, 0, 0, 0, 0], [0, 3, 3, 3, 3, 3, 0], [0, 3, 3, 9, 9, 3, 0], [0, 3, 4, 9, 4, 3, 0], [0, 3, 9, 9, 9, 3, 0], [0, 3, 9, 9, 9, 3, 0], [0, 0, 0, 0, 0, 0, 0]];
var l3c = [[0, 0, 0, 0, 0, 0, 0], [0, 7, 9, 9, 9, 7, 0], [0, 7, 5, 9, 5, 7, 0], [0, 9, 9, 9, 9, 9, 0], [0, 9, 6, 6, 6, 9, 0], [0, 0, 9, 9, 9, 0, 0], [0, 0, 0, 0, 0, 0, 0]];
var l3d = [[0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 2, 0], [0, 2, 1, 0, 2, 2, 0], [0, 2, 2, 2, 2, 2, 0], [0, 3, 8, 3, 8, 3, 0], [0, 8, 2, 2, 2, 8, 0], [0, 0, 0, 0, 0, 0, 0]];
var l3e = [[0, 0, 0, 0, 0, 0, 0], [0, 0, 6, 6, 6, 0, 0], [0, 6, 3, 2, 3, 6, 0], [0, 6, 2, 2, 2, 6, 0], [0, 6, 3, 2, 3, 6, 0], [0, 0, 6, 6, 6, 0, 0], [0, 0, 0, 0, 0, 0, 0]];
var l3f = [[0, 0, 0, 0, 0, 0, 0], [0, 0, 9, 8, 9, 0, 0], [0, 0, 2, 9, 2, 0, 0], [0, 9, 8, 8, 8, 9, 0], [0, 0, 8, 8, 8, 0, 0], [0, 0, 7, 0, 7, 0, 0], [0, 0, 0, 0, 0, 0, 0]];
var l3g = [[0, 0, 0, 0, 0, 0, 0], [0, 0, 5, 5, 5, 0, 0], [0, 5, 3, 5, 3, 5, 0], [0, 5, 5, 3, 5, 5, 0], [0, 0, 0, 8, 0, 0, 0], [0, 0, 0, 8, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0]];
// 8x8 levels
//var l4 = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 1, 1, 0, 0, 0], [0, 0, 2, 2, 0, 0, 0, 0], [0, 0, 1, 1, 0, 0, 0, 0], [0, 0, 2, 2, 0, 0, 0, 0], [0, 2, 2, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]];
var l4a = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 4, 4, 0, 0, 0], [0, 0, 4, 4, 4, 4, 0, 0], [0, 2, 7, 2, 7, 2, 7, 0], [0, 0, 4, 4, 4, 4, 0, 0], [0, 4, 0, 0, 0, 0, 4, 0], [0, 4, 0, 0, 0, 0, 4, 0], [0, 0, 0, 0, 0, 0, 0, 0]];
var l4b = [[0, 2, 2, 2, 2, 2, 2, 0], [0, 2, 1, 3, 3, 3, 2, 0], [0, 2, 1, 3, 3, 3, 2, 0], [0, 0, 2, 2, 2, 2, 0, 0], [0, 0, 0, 1, 2, 0, 0, 0], [0, 0, 0, 1, 2, 0, 0, 0], [0, 0, 1, 2, 1, 2, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]];
var l4c = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 5, 5, 0, 0, 0, 0], [0, 5, 4, 4, 5, 5, 5, 0], [0, 5, 5, 5, 1, 3, 1, 0], [0, 5, 5, 3, 3, 1, 3, 0], [0, 5, 5, 5, 5, 5, 5, 0], [0, 0, 5, 5, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]];
var l4d = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 9, 1, 1, 9, 1, 0], [0, 9, 4, 9, 9, 4, 9, 0], [0, 1, 1, 9, 9, 1, 1, 0], [0, 9, 1, 1, 1, 1, 9, 0], [0, 1, 1, 3, 3, 1, 1, 0], [0, 0, 1, 1, 1, 1, 0, 0], [0, 0, 0, 1, 1, 0, 0, 0]];
var l4e = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 4, 3, 2, 4, 0, 0], [0, 3, 0, 3, 2, 0, 3, 0], [0, 0, 2, 3, 3, 2, 0, 0], [0, 0, 0, 3, 3, 0, 0, 0], [0, 0, 0, 3, 2, 0, 0, 0], [0, 0, 3, 0, 0, 2, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]];
var l4f = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 2, 0, 2, 0, 2, 0], [0, 1, 1, 1, 1, 1, 1, 0], [0, 6, 6, 6, 6, 6, 6, 0], [0, 2, 2, 2, 2, 2, 2, 0], [0, 6, 6, 6, 6, 6, 6, 0], [0, 3, 3, 3, 3, 3, 3, 0], [0, 0, 0, 0, 0, 0, 0, 0]];
var l4g = [[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 3, 3, 0, 0, 0], [0, 0, 3, 4, 4, 3, 0, 0], [0, 3, 4, 2, 2, 4, 3, 0], [0, 4, 4, 4, 4, 4, 4, 0], [0, 2, 4, 6, 6, 4, 2, 0], [0, 4, 4, 6, 6, 4, 4, 0], [0, 0, 0, 0, 0, 0, 0, 0]];
// 9x9 levels
var l5a = [[0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 2, 8, 8, 0, 0, 0], [0, 0, 2, 0, 0, 0, 8, 0, 0], [0, 8, 8, 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 5, 5, 5, 8, 0], [0, 0, 9, 8, 8, 8, 8, 0, 8, 0], [0, 0, 0, 5, 5, 5, 5, 0, 8, 0], [0, 0, 0, 5, 0, 0, 5, 8, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]];
var l6f = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 2, 0, 2, 0, 0, 0, 2, 0], [0, 2, 0, 0, 8, 2, 2, 2, 8, 0], [0, 2, 0, 0, 2, 5, 2, 5, 2, 0], [0, 2, 2, 2, 8, 2, 8, 2, 2, 0], [0, 8, 2, 2, 2, 8, 8, 8, 0, 0], [0, 2, 8, 8, 2, 2, 2, 2, 0, 0], [0, 8, 0, 8, 0, 8, 0, 8, 0, 0], [0, 6, 0, 6, 0, 6, 0, 6, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]];
var l6g = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 5, 0, 5, 0, 0, 0, 0, 0], [0, 5, 2, 5, 2, 5, 0, 0, 0, 0], [0, 5, 5, 5, 5, 5, 0, 0, 5, 0], [0, 0, 1, 0, 1, 0, 0, 5, 0, 0], [0, 0, 0, 5, 0, 0, 0, 5, 0, 0], [0, 0, 4, 5, 5, 5, 5, 4, 0, 0], [0, 0, 0, 4, 4, 4, 4, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]];
// Levels ordered by grid size, for shuffling while maintining difficulty ramping.
var levels5 = [l1a, l1b, l1c, l1d, l1e, l1f, l1g];
var levels6 = [l2a, l2b, l2c, l2d, l2e, l2f, l2g];
var levels7 = [l3a, l3b, l3c, l3d, l3e, l3f, l3g];
var levels8 = [l4a, l4b, l4c, l4d, l4e, l4f, l4g];
var levels9 = [l5a, l5b, l5c, l5d, l5e, l5f, l5g];
var levels10 = [l6a, l6b, l6c, l6d, l6e, l6f, l6g];
// All levels in one array.
//var levels = levels5.concat(levels6, levels7, levels8, levels9, levels10);
//var levels = [l1a, l6g, l6b, l6c, l6d, l1b, l1c, l1d, l1e, l1f, l1g, l2a, l2b, l2c, l2d, l2e, l2f, l2g, l3a, l3b, l3c, l3d, l3e, l3f, l3g, l4a, l4b, l4c, l4d, l4e, l4f, l4g, l5a, l5b, l5c, l5d, l5e, l5f, l5g, l6a, l6b, l6c, l6d, l6e, l6f, l6g];
var levels = randomLevelSelection();
var currentLevelID = 0;
// Copy without reference, so we have original for retry/level reset.
var currentLevel = levels[currentLevelID].map(function (arr) {
return Array.isArray(arr) ? arr.slice() : [];
});
var stars = [];
var levelContainer = new Container();
levelContainer.x = 1024;
levelContainer.y = boardCenterY; //2732 / 2 + 200;
game.addChild(levelContainer);
function randomLevelSelection() {
var levelsPerGridSize = 2; // how many levels do we want with each size grid in the final levels array?
var t = [levels5, levels6, levels7, levels8, levels9, levels10];
var c = [];
for (var i = 0; i < t.length; i++) {
for (var j = 0; j < levelsPerGridSize; j++) {
var id = Math.floor(Math.random() * t[i].length);
c.push(t[i][id]);
t[i].splice(id, 1);
}
}
return c;
}
function paintLevel(a) {
var startX = -boardSize / 2;
var startY = -boardSize / 2;
var boxSize = tileSize;
var boxSpacing = boxSize * spacingRatio;
var offset = boxSize / 2 + boxSpacing;
for (var i = 0; i < a.length; i++) {
for (var j = 0; j < a[0].length; j++) {
if (a[j][i] != 0) {
var cBox = levelContainer.addChild(new ColorBox(a[j][i]));
cBox.width = cBox.height = boxSize;
cBox.x = offset + startX + i * (boxSize + boxSpacing);
cBox.y = offset + startY + j * (boxSize + boxSpacing);
cBox.gridX = i;
cBox.gridY = j;
}
}
}
}
paintLevel(currentLevel);
if (!storage.instructionsShown) {
storage.instructionsShown = true;
showInstructions();
}
;
var instructionsScreen = new InstructionsScreen();
instructionsScreen.x = 3000;
instructionsScreen.alpha = 0;
game.addChild(instructionsScreen);
function showInstructions() {
if (instructionsScreen.alpha == 0) {
instructionsScreen.x = 1024;
instructionsScreen.y = boardCenterY;
instructionsScreen.alpha = 1;
game.addChild(instructionsScreen);
} else {
instructionsScreen.alpha = 0;
instructionsScreen.x = 3000;
}
}
;
// Click handler
game.down = function (x, y, obj) {
//board.scale.x *= 1.2;
//board.scale.y *= 1.2;
//console.log(x, y, obj);
};
function findConnectedSameColorTiles(startBox) {
var connectedTiles = [];
var visited = [];
var queue = [startBox];
var targetColor = startBox.colorIndex;
while (queue.length > 0) {
var currentBox = queue.shift(); // Use pop() for DFS
var _currentBox = currentBox,
x = _currentBox.gridX; //x,
y = _currentBox.gridY; //y; // Assuming each box has x, y properties
if (visited.indexOf(currentBox) === -1) {
visited.push(currentBox);
connectedTiles.push(currentBox);
// Check all adjacent tiles
var neighbors = getAdjacentTiles(x, y);
//console.log("neighbors:", neighbors);
var _iterator = _createForOfIteratorHelper(neighbors),
_step;
try {
for (_iterator.s(); !(_step = _iterator.n()).done;) {
var neighbor = _step.value;
//if (neighbor.colorIndex === targetColor && !visited.has(neighbor)) {
if (neighbor.colorIndex === targetColor && !visited.includes(neighbor)) {
queue.push(neighbor);
}
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
}
}
return connectedTiles;
}
function getAdjacentTiles(x, y) {
var adjacentTiles = [];
var directions = [[-1, 0], [1, 0], [0, -1], [0, 1]]; // left, right, up, down
for (var _i = 0, _directions = directions; _i < _directions.length; _i++) {
var _directions$_i = _slicedToArray(_directions[_i], 2),
dx = _directions$_i[0],
dy = _directions$_i[1];
var newX = x + dx;
var newY = y + dy;
// Check if the new position is within the grid boundaries
if (newX >= 0 && newX < currentLevel.length && newY >= 0 && newY < currentLevel[0].length) {
var colorBox = levelContainer.children.find(function (child) {
//return child.gridX === newX && child.gridY === newY;
return !child.outlier && child.gridX === newX && child.gridY === newY;
});
if (colorBox) {
adjacentTiles.push(colorBox);
}
}
}
return adjacentTiles;
}
function colorBoxClicked(b) {
console.log('colorbox clicked:', b);
// Find connected tiles with same color
var t = findConnectedSameColorTiles(b);
//console.log(t);
for (var i = 0; i < t.length; i++) {
//t[i].destroy();
t[i].remove(i * 30);
}
}
function placeOutliers() {
// Determine colors left on the board to choose from.
var colorsPresent = [];
var gridSize = currentLevel.length;
for (var i = 0; i < gridSize; i++) {
for (var j = 0; j < gridSize; j++) {
var t = currentLevel[i][j];
if (t != 0 && !colorsPresent.includes(t)) {
colorsPresent.push(t);
}
}
}
//console.log('Game still includes these colors:', colorsPresent);
// Determine what rows and cols contain colorboxes.
// Horizontal rows
var availableRows = [];
for (var i = 0; i < gridSize; i++) {
if (currentLevel[i].some(checkNonZero)) {
//console.log('there are non-zero values in row:', i);
availableRows.push(i);
}
}
// Vertical columns
var availableCols = [];
var cols = rotateMatrix90C(currentLevel);
for (var i = 0; i < gridSize; i++) {
if (cols[i].some(checkNonZero)) {
//console.log('there are non-zero values in col:', i);
availableCols.push(i);
}
}
// If no available rows or cols left, level cleared!
var n = availableRows.length + availableCols.length;
//console.log(n);
if (n === 0) {
console.log('level cleared!');
return false;
} else {
var startX = -boardSize / 2;
var startY = -boardSize / 2;
var boxSize = tileSize;
var boxSpacing = boxSize * spacingRatio;
var offset = boxSize / 2 + boxSpacing;
// Place an outlier tile at 50% (and minimum one) of the available positions.
var placedAtLeastOne = false;
var placedCounter = 0;
var maxPlaced = 2;
//console.log('ac:', availableCols);
availableCols = shuffleArray(availableCols);
availableRows = shuffleArray(availableRows);
//console.log('ac:', availableCols);
var currentDirection = outlierDirectionCounter % 4;
outlierDirectionCounter++; // increment, so we get a new direction next turn.
if (currentDirection == 1 || currentDirection == 3) {
for (var i = 0; i < availableRows.length; i++) {
//if (Math.random() < 0.5 || !placedAtLeastOne) {
//if (true || !placedAtLeastOne) {
//if (!placedAtLeastOne) {
if (placedCounter < maxPlaced) {
// place it, either side will do.
var cIndex = colorsPresent[Math.floor(Math.random() * colorsPresent.length)];
var b = new ColorBox(cIndex);
b.outlier = true;
b.width = b.height = tileSize;
if (currentDirection == 3) {
b.x = -900;
b.y = offset + startY + availableRows[i] * (boxSize + boxSpacing);
b.gridX = -1;
b.gridY = availableRows[i];
} else {
b.x = 900;
b.y = offset + startY + availableRows[i] * (boxSize + boxSpacing);
b.gridX = 99;
b.gridY = availableRows[i];
}
b.fadeIn();
//console.log('b is:', b);
levelContainer.addChild(b);
//console.log('levelContainer is now:', levelContainer);
placedAtLeastOne = true;
placedCounter++;
}
}
} else {
for (var i = 0; i < availableCols.length; i++) {
//if (Math.random() < 0.5 || !placedAtLeastOne) {
//if (true || !placedAtLeastOne) {
//if (!placedAtLeastOne) {
if (placedCounter < maxPlaced) {
// place it, either side will do
var cIndex = colorsPresent[Math.floor(Math.random() * colorsPresent.length)];
var b = new ColorBox(cIndex);
b.outlier = true;
b.width = b.height = tileSize;
if (currentDirection == 0) {
b.x = offset + startX + availableCols[i] * (boxSize + boxSpacing);
b.y = -900;
b.gridX = availableCols[i];
//console.log(availableCols[i]);
b.gridY = -1;
} else {
b.x = offset + startX + availableCols[i] * (boxSize + boxSpacing);
b.y = 900;
b.gridX = availableCols[i];
b.gridY = 99;
}
b.fadeIn();
//console.log('b is:', b);
levelContainer.addChild(b);
//console.log('levelContainer is now:', levelContainer);
placedAtLeastOne = true;
placedCounter++;
}
}
}
}
// And place them. (Animate them in from sides.)
return true;
}
function shuffleArray(arr) {
var j, x, index;
for (index = arr.length - 1; index > 0; index--) {
j = Math.floor(Math.random() * (index + 1));
x = arr[index];
arr[index] = arr[j];
arr[j] = x;
}
return arr;
}
function checkNonZero(i) {
return i != 0;
}
function rotateMatrix90C(source) {
// get the dimensions of the source matrix
var m = source.length;
var n = source[0].length;
// create a new NxM destination array
var destination = new Array(n);
for (var i = 0; i < n; i++) {
destination[i] = new Array(m);
}
// start copying from source into destination
for (var i = 0; i < n; i++) {
for (var j = 0; j < m; j++) {
destination[i][j] = source[m - j - 1][i];
}
}
// return the destination matrix
return destination;
}
placeOutliers();
updateScoreLabels();
function moveIn() {
// Move all outliers onto stage
var outliers = levelContainer.children.filter(function (child) {
return child.outlier;
});
//console.log('there are ', outliers.length, 'outliers');
var isGameOver = false;
for (var i = 0; i < outliers.length; i++) {
var t = outliers[i];
//console.log(t);
var newPos = 999;
// Determine direction the outlier is moving in, in order to determine position to tween to.
if (t.gridX == -1) {
for (var j = gridSize - 1; j >= 0; j--) {
//console.log('j entry is', currentLevel[t.gridY][j]);
if (currentLevel[t.gridY][j] != 0) {
newPos = j - 1;
}
}
//console.log(t, 'would move to position', newPos);
t.gridX = newPos;
//t.moveInPosition();
} else if (t.gridX == 99) {
for (var j = 0; j < gridSize; j++) {
//console.log('j entry is', currentLevel[t.gridY][j]);
if (currentLevel[t.gridY][j] != 0) {
newPos = j + 1;
}
}
//console.log(t, 'would move to position', newPos);
t.gridX = newPos;
//t.moveInPosition();
} else if (t.gridY == -1) {
for (var j = gridSize - 1; j >= 0; j--) {
//console.log('j entry is', currentLevel[j][t.gridX]);
if (currentLevel[j][t.gridX] != 0) {
newPos = j - 1;
}
}
//console.log(t, 'would move to position', newPos);
t.gridY = newPos;
//t.moveInPosition();
} else if (t.gridY == 99) {
// do something, fix this
for (var j = 0; j < gridSize; j++) {
//console.log('j entry is', currentLevel[j][t.gridX]);
if (currentLevel[j][t.gridX] != 0) {
newPos = j + 1;
}
}
t.gridY = newPos;
//t.moveInPosition();
}
console.log(t, 'would move to position', newPos);
if (newPos == -1 || newPos == gridSize) {
// Game Over, lost
var highScore = storage.highScore || 0;
if (playerScore > highScore) {
storage.highScore = playerScore;
}
//console.log('highscore is now:', storage.highScore);
t.tint = 0xFF0000;
isGameOver = true;
t.blinkRed();
/*
tween(t, {
width: tileSize * 1.5,
height: tileSize * 1.5
}, {
duration: 150,
easing: tween.easeInOut,
onFinish: function onFinish() {
//t.width = tileSize;
//t.height = tileSize;
tween(t, {
width: tileSize,
height: tileSize
}, {
duration: 150,
easing: tween.easeInOut
});
}
});*/
LK.setScore(playerScore);
//LK.showGameOver();
} else if (newPos != 999) {
t.moveInPosition();
} else {
t.flyOut();
}
}
if (isGameOver) {
GAME_STATE = 5;
}
}
function updateScoreLabels() {
scoreLabel.setText('Score\n' + playerScore);
if (playerScore > highScore) {
highScore = playerScore;
}
highScoreLabel.setText('Best\n' + highScore);
}
//moveIn();
var showingLevelCompleteCounter = 0;
var showingLevelCompleteCounterMax = 120;
var levelCompleteScreen = new LevelComplete();
var GAME_STATE = -1;
// -1: INIT
// 0: Waiting for input
// 1: Removing tiles
// 2: Moving outliers in
// 3: Generating new outliers.
// 4: level cleared
// 5: Game over
game.update = function () {
if (GAME_STATE == -1) {
if (numRunningTweens == 0) {
GAME_STATE = 0;
GAME_IS_CLICKABLE = true;
}
} else if (GAME_STATE == 0) {
// awaiting user input
if (numRunningTweens > 0) {
GAME_STATE = 1;
}
} else if (GAME_STATE == 1) {
// removing tiles
if (numRunningTweens == 0) {
GAME_STATE = 2;
moveIn();
}
} else if (GAME_STATE == 2) {
// moving outliers in
if (numRunningTweens == 0) {
if (placeOutliers()) {
GAME_STATE = 3;
} else {
GAME_STATE = 4;
showingLevelCompleteCounter = 0;
}
}
} else if (GAME_STATE == 3) {
// generating new outliers
if (numRunningTweens == 0) {
GAME_IS_CLICKABLE = true;
GAME_STATE = 0;
}
} else if (GAME_STATE == 4) {
// go to next level or game completed.
// If we haven't run out of levels, fo to the next one.
if (currentLevelID != levels.length - 1) {
if (showingLevelCompleteCounter == 0) {
showingLevelCompleteCounter++;
// show level complete screen.
levelCompleteScreen = new LevelComplete();
levelCompleteScreen.x = 1024;
levelCompleteScreen.y = boardCenterY;
game.addChild(levelCompleteScreen);
} else if (showingLevelCompleteCounter < showingLevelCompleteCounterMax) {
showingLevelCompleteCounter++;
} else {
//TODO: remove levelcomplete screen and stat next level.
levelCompleteScreen.destroy();
currentLevelID++;
//currentLevel = levels[currentLevelID].slice(0);
currentLevel = levels[currentLevelID].map(function (arr) {
return arr.slice();
});
console.log('new level is', currentLevel);
gridSize = currentLevel.length;
tileSize = calculateTileSize();
board.destroy();
board = new Board();
board.x = 1024;
board.y = boardCenterY; //2732 / 2;
game.addChild(board);
levelContainer.destroy();
levelContainer = new Container();
levelContainer.x = 1024;
levelContainer.y = boardCenterY; //2732 / 2;
game.addChild(levelContainer);
//levelContainer = new Container();
paintLevel(currentLevel);
levelLabel.setText('Level ' + (currentLevelID + 1));
placeOutliers();
GAME_STATE = -1;
}
} else {
//TODO: Show game over - all levels completed!
}
} else if (GAME_STATE == 5) {
LK.setTimeout(function () {
LK.showGameOver();
}, 1300);
}
for (var l = stars.length - 1; l >= 0; l--) {
if (stars[l].isDead) {
stars[l].destroy();
stars.splice(l, 1);
} else {
stars[l]._move_migrated();
}
}
};
A large calm background drawing for a puzzle game, in dark calm blueish colors and non-confusing content. High definition. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A quadratic polished dark blue marble slate. Front perspective with right angles. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A white question mark in a circle, like for a help button in a game.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A white X in a circle, like for a close window button in a game. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A white questionmark on a black background. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A green check mark on a dark background. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.