Code edit (1 edits merged)
Please save this source code
User prompt
in the progressminiature's down method, when alpha is set to 1, make it return to alpha 0 after 2 seconds
Code edit (3 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught ReferenceError: elf is not defined' in or related to this line: 'if (elf.la.alpha == 0) {' Line Number: 525
Code edit (4 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught TypeError: event.stopPropagation is not a function' in or related to this line: 'event.stopPropagation();' Line Number: 540
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: 'la is not defined' in or related to this line: 'self.x -= self.parent.wind;' Line Number: 454
User prompt
Please fix the bug: 'la is not defined' in or related to this line: 'la.anchor.set(0.5, 0.5);' Line Number: 517
Code edit (11 edits merged)
Please save this source code
User prompt
Please fix the bug: 'i is not defined' in or related to this line: 'if (Math.random() < 0.12) {' Line Number: 470
User prompt
Please fix the bug: 'i is not defined' in or related to this line: 'var la = new Text2(levelsAll[i].name, {' Line Number: 511
User prompt
Please fix the bug: 'levelAll is not defined' in or related to this line: 'var la = new Text2(levelsAll[i].name, {' Line Number: 511
User prompt
Please fix the bug: 'levelAll is not defined' in or related to this line: 'var t = new ProgressMiniature(levelAll[i], true);' Line Number: 558
Code edit (3 edits merged)
Please save this source code
User prompt
please ensure the progressScreen paint method removes any preexisting instances of label, checkmarkand quesitonmark before it repaints them.
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (7 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Uncaught ReferenceError: progressScreen is not defined' in or related to this line: 'if (progressScreen.alpha == 0) {' Line Number: 1130
User prompt
Please fix the bug: 'Uncaught ReferenceError: progressScreen is not defined' in or related to this line: 'if (progressScreen.alpha == 0) {' Line Number: 1130
Code edit (1 edits merged)
Please save this source code
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
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
/****
* 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 CloseButton = Container.expand(function () {
var self = Container.call(this);
var closeButtonGraphics = self.attachAsset('closeButton', {
anchorX: 0.5,
anchorY: 0.5
});
self.down = function () {
// Define what happens when the close button is pressed
showInstructions();
};
});
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.05;
}
};
self.mouseout = function () {
if (!self.outlier) {
self.width = self.height = tileSize;
}
};
self.remove = function (delay) {
numRunningTweens++;
currentLevel.d[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++;
playerScore += latestRemoveCount;
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 () {
var delayBy = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
numRunningTweens++;
self.alpha = 0;
tween(self, {
alpha: 1
}, {
duration: BASE_TWEEN_SPEED,
delay: delayBy,
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.enterBoard = function (destX, destY, delayFactor) {
numRunningTweens++;
self.width = 0;
self.height = 0;
self.x = destX;
self.y = destY;
tween(self, {
width: tileSize,
height: tileSize
}, {
duration: BASE_TWEEN_SPEED,
delay: delayFactor,
easing: tween.easeInOut,
onFinish: function onFinish() {
numRunningTweens--;
}
});
/*
tween(self, {
x: destX,
y: destY
}, {
duration: BASE_TWEEN_SPEED,
delay: delayFactor,
easing: tween.easeInOut,
onFinish: function onFinish() {
numRunningTweens--;
}
});*/
};
self.moveInPosition = function () {
var startX = -boardSize / 2;
var startY = -boardSize / 2;
var boxSize = tileSize;
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.d[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.blinkers = [];
var radius = 50; // Distance from the center of the button
for (var i = 0; i < 12; i++) {
var angle = i / 12 * Math.PI * 2; // Calculate angle for each blinker
var t = self.attachAsset('blinker', {
anchorX: 0.5,
anchorY: 0.5,
x: Math.cos(angle) * 1.65 * radius,
y: Math.sin(angle) * 1.65 * radius,
rotation: angle + Math.PI / 2,
alpha: 0
});
self.blinkers.push(t);
}
self.down = function () {
showInstructions();
};
self.blink = function () {
var blinkCount = 0;
var maxBlinks = 8;
var blinkInterval = 250; // Time in milliseconds for each blink
function toggleBlinkers() {
blinkCount++;
var newAlpha = blinkCount % 2 === 0 ? 0 : 1; // Toggle between 0 and 1
for (var i = 0; i < self.blinkers.length; i++) {
self.blinkers[i].alpha = newAlpha;
}
if (blinkCount < maxBlinks * 2) {
LK.setTimeout(toggleBlinkers, blinkInterval);
}
}
toggleBlinkers();
};
});
var InstructionsScreen = Container.expand(function () {
var self = Container.call(this);
var arrowGraphics = self.attachAsset('levelCompleteBg', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 0.87
});
var closeButton = new CloseButton();
closeButton.x = self.width / 2 - 75; // Position close button at the top right corner
closeButton.y = -self.height / 2 + 75;
self.addChild(closeButton);
var label = new Text2('HOW TO PLAY\n\n\n1. Tap a tile to remove all similar\n connected tiles\n\n2. New tiles will enter from the sides.\n\n3. Clear the board to complete the level.\n\n\nHint: Clear more blocks in one click\n for combo bonuses.', {
size: 60,
fill: 0xdddddd,
align: 'center',
font: 'Georgia'
});
label.anchor.set(0.5, 0.5);
label.x = 0;
label.y = -100;
self.addChild(label);
});
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) {
// Ensure Math.random() is used correctly
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);
*/
var plusLabel = new Text2('+' + latestRemoveCount, {
size: 120,
fill: 0xFFFFFF,
align: 'center',
font: 'Georgia'
});
plusLabel.anchor.set(0.5, 0.5); // Anchor to the right
plusLabel.x = 0;
plusLabel.y = 0;
self.addChild(plusLabel);
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 = 40 + delay; //30 + delay;
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.y -= 4;
/*
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
****/
//LK.init.sound('testmusic', {volume:1, start:0, end:0.995, id:'676c4b01fd1ad619bb4ea263'})
//LK.init.music('backgroundMusic')
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: 0x55eeff
});
game.addChild(gameLogo);
var helpButton = new HelpButton();
helpButton.x = 2048 - 150;
helpButton.y = 2732 - 150;
game.addChild(helpButton);
helpButton.blink();
var levelLabel = new Text2('Level 1', {
size: 60,
//120,
fill: 0xFFFFFF,
align: 'center',
font: 'Georgia'
});
levelLabel.anchor.set(0.5, 0.5);
levelLabel.x = 2048 - 350; // - 30; // Position near the right edge
levelLabel.y = 90; //300;
game.addChild(levelLabel);
var levelNameLabel = new Text2('', {
size: 56,
fill: 0xFFFFFF,
align: 'center',
font: 'Georgia'
});
levelNameLabel.anchor.set(0.5, 0.5);
levelNameLabel.x = 2048 - 350;
levelNameLabel.y = 170; //2732 - 200;
game.addChild(levelNameLabel);
// Create and position the score label
var scoreLabel = new Text2('Score\n0', {
size: 55,
fill: 0xFFFFFF,
align: 'center',
font: 'Georgia'
});
scoreLabel.anchor.set(0.5, 0.5); // Anchor to the right
scoreLabel.x = 2048 - 350; // - 50; // Position near the right edge
scoreLabel.y = 290; //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(0.5, 0.5); // Anchor to the right
highScoreLabel.x = 2048 - 350; //- 75; // Position near the right edge
highScoreLabel.y = 440; //300; //220; // Position below the score label
//LK.gui.topRight.addChild(highScoreLabel);
game.addChild(highScoreLabel);
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 = {
name: 'Jasmine Blossom',
uid: 101,
d: [[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 = {
name: 'Rocket Science',
uid: 102,
d: [[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 = {
name: "Dahlia's Maze",
uid: 103,
d: [[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 = {
name: 'Cornflower Field',
uid: 104,
d: [[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 = {
name: 'Ruby Summit',
uid: 105,
d: [[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 = {
name: "The Archer's Mark",
uid: 106,
d: [[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 = {
name: "Santa's Topper",
uid: 107,
d: [[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 = {
name: 'Duck Dive',
uid: 201,
d: [[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 = {
name: 'Critter Crawl',
uid: 202,
d: [[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 = {
name: 'The Little Oinker',
uid: 203,
d: [[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 = {
name: 'Mellow Crawl',
uid: 204,
d: [[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 = {
name: 'Berry Hunt',
uid: 205,
d: [[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 = {
name: 'Koala Nap',
uid: 206,
d: [[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 = {
name: 'Monkey Business',
uid: 207,
d: [[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 = {
name: "Rudolph's Glow",
uid: 301,
d: [[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 = {
name: 'Fiery Redhead',
uid: 302,
d: [[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 = {
name: "Grump's Gambit",
uid: 303,
d: [[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 = {
name: 'The Crown Jewels',
uid: 304,
d: [[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 = {
name: 'Petal Puzzle',
uid: 305,
d: [[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 = {
name: 'Forest Guardian',
uid: 306,
d: [[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 = {
name: 'The Apple Orchard',
uid: 307,
d: [[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 = {
name: 'UFO Spotting',
uid: 401,
d: [[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 = {
name: 'Holy Grail',
uid: 402,
d: [[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 = {
name: 'Dino Discovery',
uid: 403,
d: [[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 = {
name: "Santa's Smile",
uid: 404,
d: [[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 = {
name: "Salamander's Flame",
uid: 405,
d: [[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 = {
name: 'The Birthday Cake',
uid: 406,
d: [[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 = {
name: 'Home Sweet Home',
uid: 407,
d: [[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 = {
name: 'Bag of Tricks',
uid: 501,
d: [[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, 8, 8, 8, 8, 8, 0], [0, 3, 3, 3, 8, 3, 3, 3, 0], [0, 8, 8, 8, 2, 8, 8, 4, 0], [0, 8, 8, 8, 8, 8, 8, 4, 0], [0, 4, 4, 4, 4, 4, 4, 4, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]]
};
var l5b = {
name: 'Trophy Case',
uid: 502,
d: [[0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 2, 2, 8, 8, 8, 0, 0], [0, 2, 8, 2, 4, 8, 8, 2, 0], [0, 2, 0, 2, 4, 8, 0, 2, 0], [0, 0, 8, 2, 4, 8, 2, 0, 0], [0, 0, 0, 8, 2, 8, 0, 0, 0], [0, 0, 0, 0, 8, 0, 0, 0, 0], [0, 0, 0, 8, 8, 8, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]]
};
var l5c = {
name: 'Monitor Watch',
uid: 503,
d: [[0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 7, 7, 7, 7, 7, 7, 7, 0], [0, 7, 4, 4, 4, 4, 4, 7, 0], [0, 7, 4, 4, 3, 3, 4, 7, 0], [0, 7, 3, 3, 3, 3, 3, 7, 0], [0, 7, 7, 7, 7, 7, 2, 7, 0], [0, 0, 0, 4, 4, 4, 0, 0, 0], [0, 0, 7, 7, 7, 7, 7, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]]
};
var l5d = {
name: 'The Melty Bite',
uid: 504,
d: [[0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 8, 8, 8, 8, 8, 0, 0], [0, 8, 8, 8, 8, 8, 8, 8, 0], [0, 0, 5, 5, 3, 3, 5, 0, 0], [0, 2, 2, 5, 2, 3, 2, 0, 0], [0, 0, 3, 2, 5, 2, 5, 5, 0], [0, 8, 8, 8, 8, 2, 8, 8, 0], [0, 0, 8, 8, 8, 8, 8, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]]
};
var l5e = {
name: 'Flag of Denmark',
uid: 505,
d: [[0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 0, 0], [0, 3, 3, 1, 3, 3, 3, 3, 0], [0, 3, 3, 1, 3, 3, 3, 0, 0], [0, 1, 1, 1, 1, 1, 1, 0, 0], [0, 3, 3, 1, 3, 3, 3, 0, 0], [0, 3, 3, 1, 3, 3, 3, 3, 0], [0, 8, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]]
};
var l5f = {
name: 'Global Explorer',
uid: 506,
d: [[0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 5, 4, 1, 1, 4, 0, 0], [0, 5, 5, 4, 4, 4, 5, 4, 0], [0, 8, 5, 5, 4, 4, 5, 5, 0], [0, 5, 8, 4, 4, 5, 5, 2, 0], [0, 4, 5, 4, 4, 4, 5, 8, 0], [0, 4, 4, 5, 4, 4, 4, 4, 0], [0, 0, 4, 4, 4, 1, 4, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]]
};
var l5g = {
name: "Cheshire Cat",
uid: 507,
d: [[0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 7, 7, 0, 0, 0, 7, 7, 0], [0, 8, 7, 7, 8, 7, 7, 8, 0], [0, 7, 2, 4, 7, 2, 4, 7, 0], [0, 7, 2, 4, 7, 2, 4, 7, 0], [0, 8, 7, 7, 8, 7, 7, 8, 0], [0, 7, 7, 8, 8, 8, 7, 7, 0], [0, 0, 8, 7, 7, 7, 8, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0]]
};
// 10x10 levels
var l6a = {
name: 'Orb of Wisdom',
uid: 601,
d: [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 4, 4, 5, 6, 0, 0, 0], [0, 0, 8, 4, 5, 6, 7, 8, 0, 0], [0, 2, 8, 4, 4, 5, 6, 7, 8, 0], [0, 8, 4, 4, 5, 5, 6, 7, 8, 0], [0, 4, 4, 5, 6, 7, 8, 2, 2, 0], [0, 4, 5, 6, 7, 8, 2, 2, 8, 0], [0, 0, 6, 7, 8, 2, 2, 8, 0, 0], [0, 0, 0, 7, 8, 2, 2, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
};
var l6b = {
name: "Donald's Quack",
uid: 602,
d: [[0, 0, 4, 4, 4, 4, 4, 4, 0, 0], [0, 4, 4, 4, 4, 4, 4, 4, 4, 0], [0, 0, 8, 8, 8, 8, 8, 8, 0, 0], [0, 1, 1, 1, 1, 1, 1, 1, 1, 0], [0, 1, 1, 4, 1, 1, 4, 1, 1, 0], [0, 2, 2, 2, 2, 2, 2, 2, 2, 0], [0, 0, 0, 4, 3, 3, 4, 0, 0, 0], [0, 0, 0, 4, 4, 4, 4, 0, 0, 0], [0, 0, 0, 1, 1, 1, 1, 0, 0, 0], [0, 0, 0, 2, 0, 0, 2, 0, 0, 0]]
};
var l6c = {
name: 'Block Party',
uid: 603,
d: [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 5, 0, 0, 0, 0, 0, 0, 0, 0], [0, 5, 5, 0, 0, 0, 0, 0, 0, 0], [0, 5, 0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 1, 1, 6, 6, 0, 0, 0], [0, 0, 0, 1, 2, 2, 6, 6, 3, 0], [0, 4, 0, 0, 2, 2, 5, 0, 3, 0], [0, 4, 0, 0, 3, 5, 5, 0, 3, 0], [0, 4, 4, 3, 3, 3, 5, 0, 3, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
};
var l6d = {
name: 'Chomp Champ',
uid: 604,
d: [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 8, 8, 8, 8, 0, 0, 0], [0, 0, 8, 2, 2, 2, 2, 8, 0, 0], [0, 8, 2, 2, 4, 2, 0, 0, 0, 0], [0, 8, 2, 2, 2, 0, 0, 0, 0, 0], [0, 8, 2, 2, 2, 2, 2, 2, 8, 0], [0, 0, 8, 2, 2, 2, 2, 8, 0, 0], [0, 0, 0, 8, 8, 8, 8, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
};
var l6e = {
name: 'Elven Sharpshot',
uid: 605,
d: [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 5, 5, 5, 5, 0, 8, 0, 0], [0, 5, 0, 5, 5, 5, 5, 0, 8, 0], [0, 0, 0, 5, 4, 9, 4, 0, 8, 0], [0, 0, 0, 5, 9, 3, 9, 0, 9, 0], [0, 0, 5, 5, 5, 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 = {
name: "The Cat's Purr",
uid: 606,
d: [[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 = {
name: "Serpent's Trail",
uid: 607,
d: [[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 = [l1a, l4f, l5b, l5d, l5f, l5g, l6f];
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 currentLevel = levels[currentLevelID];
var stars = [];
var latestRemoveCount = 0;
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;
var delayCounter = 0;
for (var i = 0; i < a.d.length; i++) {
for (var j = 0; j < a.d[0].length; j++) {
if (a.d[j][i] != 0) {
var cBox = levelContainer.addChild(new ColorBox(a.d[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;
var destX = offset + startX + i * (boxSize + boxSpacing);
var destY = offset + startY + j * (boxSize + boxSpacing);
var delayFactor = delayCounter;
delayCounter += 60;
//cBox.x = -1500;
//cBox.y = destY;
cBox.enterBoard(destX, destY, delayFactor);
}
}
}
//levelNameLabel.setText(a.name + ' ' + a.uid);
levelNameLabel.setText('"' + a.name + '"');
if (!storage.levelsDiscovered.includes(currentLevel.uid)) {
storage.levelsDiscovered.push(currentLevel.uid);
}
console.log('storage.levelsDiscovered is now:' + storage.levelsDiscovered);
return delayCounter;
}
var initDelay = paintLevel(currentLevel);
/*if (!storage.instructionsShown) {
storage.instructionsShown = true;
showInstructions();
}
;*/
var instructionsScreen = new InstructionsScreen();
instructionsScreen.x = 3000;
instructionsScreen.alpha = 0;
instructionsScreen.scale.set(1.2, 1.2);
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;
}
}
;
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.d.length && newY >= 0 && newY < currentLevel.d[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);
latestRemoveCount = t.length;
for (var i = 0; i < t.length; i++) {
//t[i].destroy();
t[i].remove(i * 30);
}
}
function placeOutliers(delayBy) {
// Determine colors left on the board to choose from.
var colorsPresent = [];
var gridSize = currentLevel.d.length;
for (var i = 0; i < gridSize; i++) {
for (var j = 0; j < gridSize; j++) {
var t = currentLevel.d[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.d[i].some(checkNonZero)) {
//console.log('there are non-zero values in row:', i);
availableRows.push(i);
}
}
// Vertical columns
var availableCols = [];
var cols = rotateMatrix90C(currentLevel.d);
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(delayBy);
//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(delayBy);
//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(initDelay);
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.d[t.gridY][j] != 0) {
newPos = j - 1;
}
}
//console.log(t, 'would move to position', newPos);
t.gridX = newPos;
} else if (t.gridX == 99) {
for (var j = 0; j < gridSize; j++) {
//console.log('j entry is', currentLevel[t.gridY][j]);
if (currentLevel.d[t.gridY][j] != 0) {
newPos = j + 1;
}
}
//console.log(t, 'would move to position', newPos);
t.gridX = newPos;
} else if (t.gridY == -1) {
for (var j = gridSize - 1; j >= 0; j--) {
//console.log('j entry is', currentLevel[j][t.gridX]);
if (currentLevel.d[j][t.gridX] != 0) {
newPos = j - 1;
}
}
//console.log(t, 'would move to position', newPos);
t.gridY = newPos;
} 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.d[j][t.gridX] != 0) {
newPos = j + 1;
}
}
t.gridY = newPos;
}
//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();
function initLevelsDiscovered() {
if (!storage.levelsDiscovered) {
storage.levelsDiscovered = [];
} else if (!Array.isArray(storage.levelsDiscovered)) {
storage.levelsDiscovered = [];
}
}
initLevelsDiscovered();
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();
//});
currentLevel = levels[currentLevelID];
console.log('new level is', currentLevel);
gridSize = currentLevel.d.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();
var entranceDelay = paintLevel(currentLevel);
levelLabel.setText('Level ' + (currentLevelID + 1));
placeOutliers(entranceDelay);
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.