/**** 
* Classes
****/ 
var ActiveBomb = Container.expand(function () {
	var self = Container.call(this);
	var bombGraphics = LK.getAsset('activeBomb', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	var cellSize = 2048 * 0.7 / 4;
	bombGraphics.width = cellSize * 0.9;
	bombGraphics.height = cellSize * 0.9;
	self.addChild(bombGraphics);
	self.isAnimating = false;
	self.visible = false;
	self.on('down', function () {
		if (self.visible) {
			self.hide();
			LK.score += 20;
			LK.experience += 100;
			if (LK.experience >= LK.experienceToNextLevel) {
				LK.level++;
				if (LK.level <= 35) {
					LK.experienceToNextLevel += 150;
				} else {
					LK.experienceToNextLevel += 180;
				}
				LK.experience = 0;
				var levelUpModal = self.parent.parent.parent.children.find(function (child) {
					return child instanceof LevelUpModal;
				});
				if (levelUpModal) {
					levelUpModal.visible = true;
				}
			}
			LK.gui.top.children[0].setText(LK.score.toString());
			self.parent.children.forEach(function (child) {
				if (child instanceof IdleBomb && typeof child.show === 'function') {
					child.show();
				}
			});
		}
	});
	self.show = function () {
		self.visible = true;
	};
	self.hide = function () {
		self.visible = false;
	};
});
var CriticalChance = Container.expand(function () {
	var self = Container.call(this);
	self.attachAsset('criticalChance', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.on('down', function () {
		LK.criticalChance += 0.1;
		self.visible = false;
	});
});
var DeadBomb = Container.expand(function () {
	var self = Container.call(this);
	var bombGraphics = LK.getAsset('deadBomb', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	var cellSize = 2048 * 0.7 / 4;
	bombGraphics.width = cellSize * 0.9;
	bombGraphics.height = cellSize * 0.9;
	self.addChild(bombGraphics);
	self.visible = false;
	self.show = function () {
		if (LK.gameState === 'LOST') {
			self.visible = true;
		}
	};
	self.hide = function () {
		self.visible = false;
	};
});
var Grid = Container.expand(function () {
	var self = Container.call(this);
	this.columns = 4;
	this.rows = 3;
	var cellSize = 2048 * 0.7 / this.columns;
	var cellWidth = cellSize * 0.9;
	var cellHeight = cellSize * 0.9;
	var cellSpacing = cellSize * 0.35;
	for (var i = 0; i < this.columns; i++) {
		for (var j = 0; j < this.rows; j++) {
			var gridGraphics = LK.getAsset('gridCell', {
				anchorX: 0.5,
				anchorY: 0.5
			});
			gridGraphics.width = cellWidth;
			gridGraphics.height = cellHeight;
			gridGraphics.tint = i % 2 === 0 ? 0x808080 : 0xFFFFFF;
			gridGraphics.x = (2048 - (this.columns * cellWidth + (this.columns - 1) * cellSpacing)) / 2 + i * (cellWidth + cellSpacing);
			gridGraphics.y = (2732 - this.rows * cellHeight) / 2 + j * (cellHeight + cellSpacing) + 200;
			self.addChild(gridGraphics);
			var cellLabel = new Text2(i + '.' + j, {
				size: cellSize * 0.2,
				fill: '#000000'
			});
			cellLabel.x = (2048 - (this.columns * cellWidth + (this.columns - 1) * cellSpacing)) / 2 + i * (cellWidth + cellSpacing) + cellWidth / 2;
			cellLabel.y = (2732 - this.rows * cellHeight) / 2 + j * (cellHeight + cellSpacing) + cellHeight / 2 + 200;
			cellLabel.anchor.set(0.5, 0.5);
			cellLabel.visible = LK.testMode;
			gridGraphics.addChild(cellLabel);
			var idleBomb = new IdleBomb();
			idleBomb.x = cellLabel.x;
			idleBomb.y = cellLabel.y;
			gridGraphics.addChild(idleBomb);
			var activeBomb = new ActiveBomb();
			activeBomb.x = cellLabel.x;
			activeBomb.y = cellLabel.y;
			gridGraphics.addChild(activeBomb);
			var deadBomb = new DeadBomb();
			deadBomb.x = cellLabel.x;
			deadBomb.y = cellLabel.y;
			gridGraphics.addChild(deadBomb);
		}
	}
});
var Health = Container.expand(function () {
	var self = Container.call(this);
	self.attachAsset('health', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.on('down', function () {
		LK.health += 100;
		self.visible = false;
	});
});
var IdleBomb = Container.expand(function () {
	var self = Container.call(this);
	var bombGraphics = LK.getAsset('idleBomb', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	var cellSize = 2048 * 0.7 / 4;
	bombGraphics.width = cellSize * 0.9;
	bombGraphics.height = cellSize * 0.9;
	self.addChild(bombGraphics);
	self.isAnimating = false;
	self.visibilityTimeout = null;
	self.on('down', function () {
		if (!self.isAnimating) {
			self.isAnimating = true;
			var originalScale = self.scale.x;
			var tweenScale = originalScale * 1.05;
			var interval = LK.setInterval(function () {
				if (self.scale.x < tweenScale) {
					self.scale.x += 0.01;
					self.scale.y += 0.01;
				} else {
					LK.clearInterval(interval);
					interval = LK.setInterval(function () {
						if (self.scale.x > originalScale) {
							self.scale.x -= 0.01;
							self.scale.y -= 0.01;
						} else {
							LK.clearInterval(interval);
							self.isAnimating = false;
						}
					}, 1000 / 60);
				}
			}, 1000 / 60);
		}
	});
	self.hide = function () {
		self.visible = false;
	};
	self.show = function () {
		if (self.visibilityTimeout) {
			LK.clearTimeout(self.visibilityTimeout);
			self.visibilityTimeout = null;
		}
		self.visible = true;
	};
});
var LevelUpModal = Container.expand(function () {
	var self = Container.call(this);
	self.rewards = [new ScoreMultiplier(), new Health(), new CriticalChance()];
	var rewardHeight = self.rewards[0].height;
	var modalHeight = rewardHeight * 1.15;
	var modalBackground = self.attachAsset('modalBackground', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	modalBackground.width = 2048;
	modalBackground.height = modalHeight;
	modalBackground.alpha = 0.8;
	modalBackground.y = (2732 - modalHeight) / 2;
	self.addChild(modalBackground);
	self.visible = false;
	var totalWidth = self.rewards.reduce(function (total, reward) {
		return total + reward.width + 20;
	}, -20);
	var rewardSpacing = 20;
	var totalRewardWidth = self.rewards.reduce(function (total, reward) {
		return total + reward.width;
	}, 0);
	var startRewardX = (2048 - totalRewardWidth - rewardSpacing * (self.rewards.length - 1)) / 2;
	var gridWidth = (self.rewards[0].width + rewardSpacing) * self.rewards.length - rewardSpacing;
	var gridStartX = (2048 - gridWidth) / 2;
	self.rewards.forEach(function (reward, index) {
		reward.x = gridStartX + index * (reward.width + rewardSpacing);
		reward.y = (2732 - modalHeight) / 2 + modalHeight / 2;
		reward.on('down', function () {
			self.visible = false;
		});
		self.addChild(reward);
	});
});
var ScoreMultiplier = Container.expand(function () {
	var self = Container.call(this);
	self.attachAsset('scoreMultiplier', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.on('down', function () {
		LK.score *= 2;
		self.visible = false;
	});
});
var StarField = Container.expand(function () {
	var self = Container.call(this);
	var starGraphics = LK.getAsset('star', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.addChild(starGraphics);
	self._move_migrated = function () {
		self.y += 1;
		if (self.y > 2732) {
			self.y = 0;
		}
	};
});
/**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0x000000
});
/**** 
* Game Code
****/ 
LK.gameState = 'IDLE';
LK.testMode = true;
var grid = new Grid();
var lastBombActivated = null;
var levelUpModal = new LevelUpModal();
game.addChild(grid);
game.addChild(levelUpModal);
var starField = [];
for (var i = 0; i < 100; i++) {
	var star = new StarField();
	star.x = Math.random() * 2048;
	star.y = Math.random() * 2732;
	starField.push(star);
	game.addChildAt(star, 0);
}
function handleTick() {
	if (LK.gameState === 'START') {
		starField.forEach(function (star) {
			star._move_migrated();
		});
		levelProgress.width = LK.experience / LK.experienceToNextLevel * levelBar.width;
	} else if (LK.gameState === 'LOST') {
		grid.children.forEach(function (cell) {
			cell.children.forEach(function (child) {
				if (child instanceof DeadBomb) {
					child.show();
				}
			});
		});
	} else if (LK.gameState === 'START' || LK.gameState === 'IDLE') {
		grid.children.forEach(function (cell) {
			cell.children.forEach(function (child) {
				if (child instanceof DeadBomb) {
					child.hide();
				}
			});
		});
	}
}
game.scoreTxt = new Text2('0', {
	size: 100,
	fill: '#ffff00'
});
game.scoreTxt.anchor.set(0.5, 0.5);
game.scoreTxt.x = LK.width / 2;
game.scoreTxt.y = 200;
LK.gui.top.addChild(game.scoreTxt);
LK.score = 0;
LK.level = 1;
LK.experience = 0;
LK.experienceToNextLevel = 50;
var levelUpModal = new LevelUpModal();
game.addChild(levelUpModal);
var levelBar = LK.getAsset('levelBar', {});
levelBar.width = game.width * 0.8;
levelBar.height = 100;
levelBar.y = 0;
levelBar.x = 2048 / 2 - levelBar.width / 2;
LK.gui.topLeft.addChild(levelBar);
var levelProgress = LK.getAsset('levelProgress', {});
levelProgress.width = 1;
levelProgress.height = 100;
levelProgress.y = 0;
levelProgress.x = 2048 / 2 - levelBar.width / 2;
LK.gui.topLeft.addChild(levelProgress);
var testButton = LK.getAsset('testButton', {
	anchorX: 0.5,
	anchorY: 0.5
});
testButton.x = 0;
testButton.y = LK.height - testButton.height;
LK.gui.bottomLeft.addChild(testButton);
testButton.on('down', function () {
	LK.testMode = !LK.testMode;
	console.log('Test Mode is: ', LK.testMode);
	testButton.alpha = LK.testMode ? 1 : 0;
	grid.children.forEach(function (cell) {
		cell.children.forEach(function (child) {
			if (child instanceof Text2) {
				child.visible = LK.testMode;
			}
			if (!LK.testMode) {
				cell.alpha = 0;
			} else {
				cell.alpha = 1;
			}
		});
	});
});
LK.on('tick', handleTick);
game.activateBomb = function () {
	if (LK.gameState === 'START') {
		var idleBombs = [];
		grid.children.forEach(function (cell) {
			cell.children.forEach(function (child) {
				if (child instanceof IdleBomb && child.visible) {
					var hasActiveBomb = false;
					child.parent.children.forEach(function (sibling) {
						if (sibling instanceof ActiveBomb && sibling.visible) {
							hasActiveBomb = true;
						}
					});
					if (!hasActiveBomb) {
						idleBombs.push(child);
					}
				}
			});
		});
		if (idleBombs.length > 0) {
			var bombToActivate;
			do {
				bombToActivate = idleBombs[Math.floor(Math.random() * idleBombs.length)];
			} while (bombToActivate === lastBombActivated);
			lastBombActivated = bombToActivate;
			bombToActivate.hide();
			bombToActivate.parent.children.forEach(function (child) {
				if (child instanceof ActiveBomb) {
					child.show();
					bombToActivate.visibilityTimeout = LK.setTimeout(function () {
						child.hide();
						bombToActivate.visibilityTimeout = null;
						bombToActivate.visible = true;
					}, 2000);
				}
			});
		}
	}
};
LK.setInterval(game.activateBomb, 450);
var startButton = LK.getAsset('startButton', {
	anchorX: 0.5,
	anchorY: 0.5
});
startButton.width = 200;
startButton.height = 100;
startButton.x = 2048 / 2 - startButton.width / 2;
startButton.y = 2732 - startButton.height;
game.addChild(startButton);
startButton.on('down', function () {
	if (LK.gameState === 'IDLE') {
		LK.gameState = 'START';
		var originalScale = startButton.scale.x;
		var tweenScale = originalScale * 1.05;
		var interval = LK.setInterval(function () {
			if (startButton.scale.x < tweenScale) {
				startButton.scale.x += 0.01;
				startButton.scale.y += 0.01;
			} else {
				LK.clearInterval(interval);
				interval = LK.setInterval(function () {
					if (startButton.scale.x > originalScale) {
						startButton.scale.x -= 0.01;
						startButton.scale.y -= 0.01;
					} else {
						LK.clearInterval(interval);
						var fadeOutInterval = LK.setInterval(function () {
							if (startButton.alpha > 0) {
								startButton.alpha -= 0.0668;
							} else {
								LK.clearInterval(fadeOutInterval);
								startButton.visible = false;
							}
						}, 1000 / 60);
					}
				}, 1000 / 60);
			}
		}, 1000 / 60);
	}
});
var angle = 0;
var radius = 50;
var centerX = 2048 / 2;
var centerY = 2732 - startButton.height - radius;
var circularInterval = LK.setInterval(function () {
	startButton.x = centerX + radius * Math.cos(angle);
	startButton.y = centerY + radius * Math.sin(angle);
	angle += 0.05;
	if (angle >= 2 * Math.PI) {
		angle = 0;
	}
}, 1000 / 60); /**** 
* Classes
****/ 
var ActiveBomb = Container.expand(function () {
	var self = Container.call(this);
	var bombGraphics = LK.getAsset('activeBomb', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	var cellSize = 2048 * 0.7 / 4;
	bombGraphics.width = cellSize * 0.9;
	bombGraphics.height = cellSize * 0.9;
	self.addChild(bombGraphics);
	self.isAnimating = false;
	self.visible = false;
	self.on('down', function () {
		if (self.visible) {
			self.hide();
			LK.score += 20;
			LK.experience += 100;
			if (LK.experience >= LK.experienceToNextLevel) {
				LK.level++;
				if (LK.level <= 35) {
					LK.experienceToNextLevel += 150;
				} else {
					LK.experienceToNextLevel += 180;
				}
				LK.experience = 0;
				var levelUpModal = self.parent.parent.parent.children.find(function (child) {
					return child instanceof LevelUpModal;
				});
				if (levelUpModal) {
					levelUpModal.visible = true;
				}
			}
			LK.gui.top.children[0].setText(LK.score.toString());
			self.parent.children.forEach(function (child) {
				if (child instanceof IdleBomb && typeof child.show === 'function') {
					child.show();
				}
			});
		}
	});
	self.show = function () {
		self.visible = true;
	};
	self.hide = function () {
		self.visible = false;
	};
});
var CriticalChance = Container.expand(function () {
	var self = Container.call(this);
	self.attachAsset('criticalChance', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.on('down', function () {
		LK.criticalChance += 0.1;
		self.visible = false;
	});
});
var DeadBomb = Container.expand(function () {
	var self = Container.call(this);
	var bombGraphics = LK.getAsset('deadBomb', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	var cellSize = 2048 * 0.7 / 4;
	bombGraphics.width = cellSize * 0.9;
	bombGraphics.height = cellSize * 0.9;
	self.addChild(bombGraphics);
	self.visible = false;
	self.show = function () {
		if (LK.gameState === 'LOST') {
			self.visible = true;
		}
	};
	self.hide = function () {
		self.visible = false;
	};
});
var Grid = Container.expand(function () {
	var self = Container.call(this);
	this.columns = 4;
	this.rows = 3;
	var cellSize = 2048 * 0.7 / this.columns;
	var cellWidth = cellSize * 0.9;
	var cellHeight = cellSize * 0.9;
	var cellSpacing = cellSize * 0.35;
	for (var i = 0; i < this.columns; i++) {
		for (var j = 0; j < this.rows; j++) {
			var gridGraphics = LK.getAsset('gridCell', {
				anchorX: 0.5,
				anchorY: 0.5
			});
			gridGraphics.width = cellWidth;
			gridGraphics.height = cellHeight;
			gridGraphics.tint = i % 2 === 0 ? 0x808080 : 0xFFFFFF;
			gridGraphics.x = (2048 - (this.columns * cellWidth + (this.columns - 1) * cellSpacing)) / 2 + i * (cellWidth + cellSpacing);
			gridGraphics.y = (2732 - this.rows * cellHeight) / 2 + j * (cellHeight + cellSpacing) + 200;
			self.addChild(gridGraphics);
			var cellLabel = new Text2(i + '.' + j, {
				size: cellSize * 0.2,
				fill: '#000000'
			});
			cellLabel.x = (2048 - (this.columns * cellWidth + (this.columns - 1) * cellSpacing)) / 2 + i * (cellWidth + cellSpacing) + cellWidth / 2;
			cellLabel.y = (2732 - this.rows * cellHeight) / 2 + j * (cellHeight + cellSpacing) + cellHeight / 2 + 200;
			cellLabel.anchor.set(0.5, 0.5);
			cellLabel.visible = LK.testMode;
			gridGraphics.addChild(cellLabel);
			var idleBomb = new IdleBomb();
			idleBomb.x = cellLabel.x;
			idleBomb.y = cellLabel.y;
			gridGraphics.addChild(idleBomb);
			var activeBomb = new ActiveBomb();
			activeBomb.x = cellLabel.x;
			activeBomb.y = cellLabel.y;
			gridGraphics.addChild(activeBomb);
			var deadBomb = new DeadBomb();
			deadBomb.x = cellLabel.x;
			deadBomb.y = cellLabel.y;
			gridGraphics.addChild(deadBomb);
		}
	}
});
var Health = Container.expand(function () {
	var self = Container.call(this);
	self.attachAsset('health', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.on('down', function () {
		LK.health += 100;
		self.visible = false;
	});
});
var IdleBomb = Container.expand(function () {
	var self = Container.call(this);
	var bombGraphics = LK.getAsset('idleBomb', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	var cellSize = 2048 * 0.7 / 4;
	bombGraphics.width = cellSize * 0.9;
	bombGraphics.height = cellSize * 0.9;
	self.addChild(bombGraphics);
	self.isAnimating = false;
	self.visibilityTimeout = null;
	self.on('down', function () {
		if (!self.isAnimating) {
			self.isAnimating = true;
			var originalScale = self.scale.x;
			var tweenScale = originalScale * 1.05;
			var interval = LK.setInterval(function () {
				if (self.scale.x < tweenScale) {
					self.scale.x += 0.01;
					self.scale.y += 0.01;
				} else {
					LK.clearInterval(interval);
					interval = LK.setInterval(function () {
						if (self.scale.x > originalScale) {
							self.scale.x -= 0.01;
							self.scale.y -= 0.01;
						} else {
							LK.clearInterval(interval);
							self.isAnimating = false;
						}
					}, 1000 / 60);
				}
			}, 1000 / 60);
		}
	});
	self.hide = function () {
		self.visible = false;
	};
	self.show = function () {
		if (self.visibilityTimeout) {
			LK.clearTimeout(self.visibilityTimeout);
			self.visibilityTimeout = null;
		}
		self.visible = true;
	};
});
var LevelUpModal = Container.expand(function () {
	var self = Container.call(this);
	self.rewards = [new ScoreMultiplier(), new Health(), new CriticalChance()];
	var rewardHeight = self.rewards[0].height;
	var modalHeight = rewardHeight * 1.15;
	var modalBackground = self.attachAsset('modalBackground', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	modalBackground.width = 2048;
	modalBackground.height = modalHeight;
	modalBackground.alpha = 0.8;
	modalBackground.y = (2732 - modalHeight) / 2;
	self.addChild(modalBackground);
	self.visible = false;
	var totalWidth = self.rewards.reduce(function (total, reward) {
		return total + reward.width + 20;
	}, -20);
	var rewardSpacing = 20;
	var totalRewardWidth = self.rewards.reduce(function (total, reward) {
		return total + reward.width;
	}, 0);
	var startRewardX = (2048 - totalRewardWidth - rewardSpacing * (self.rewards.length - 1)) / 2;
	var gridWidth = (self.rewards[0].width + rewardSpacing) * self.rewards.length - rewardSpacing;
	var gridStartX = (2048 - gridWidth) / 2;
	self.rewards.forEach(function (reward, index) {
		reward.x = gridStartX + index * (reward.width + rewardSpacing);
		reward.y = (2732 - modalHeight) / 2 + modalHeight / 2;
		reward.on('down', function () {
			self.visible = false;
		});
		self.addChild(reward);
	});
});
var ScoreMultiplier = Container.expand(function () {
	var self = Container.call(this);
	self.attachAsset('scoreMultiplier', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.on('down', function () {
		LK.score *= 2;
		self.visible = false;
	});
});
var StarField = Container.expand(function () {
	var self = Container.call(this);
	var starGraphics = LK.getAsset('star', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.addChild(starGraphics);
	self._move_migrated = function () {
		self.y += 1;
		if (self.y > 2732) {
			self.y = 0;
		}
	};
});
/**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0x000000
});
/**** 
* Game Code
****/ 
LK.gameState = 'IDLE';
LK.testMode = true;
var grid = new Grid();
var lastBombActivated = null;
var levelUpModal = new LevelUpModal();
game.addChild(grid);
game.addChild(levelUpModal);
var starField = [];
for (var i = 0; i < 100; i++) {
	var star = new StarField();
	star.x = Math.random() * 2048;
	star.y = Math.random() * 2732;
	starField.push(star);
	game.addChildAt(star, 0);
}
function handleTick() {
	if (LK.gameState === 'START') {
		starField.forEach(function (star) {
			star._move_migrated();
		});
		levelProgress.width = LK.experience / LK.experienceToNextLevel * levelBar.width;
	} else if (LK.gameState === 'LOST') {
		grid.children.forEach(function (cell) {
			cell.children.forEach(function (child) {
				if (child instanceof DeadBomb) {
					child.show();
				}
			});
		});
	} else if (LK.gameState === 'START' || LK.gameState === 'IDLE') {
		grid.children.forEach(function (cell) {
			cell.children.forEach(function (child) {
				if (child instanceof DeadBomb) {
					child.hide();
				}
			});
		});
	}
}
game.scoreTxt = new Text2('0', {
	size: 100,
	fill: '#ffff00'
});
game.scoreTxt.anchor.set(0.5, 0.5);
game.scoreTxt.x = LK.width / 2;
game.scoreTxt.y = 200;
LK.gui.top.addChild(game.scoreTxt);
LK.score = 0;
LK.level = 1;
LK.experience = 0;
LK.experienceToNextLevel = 50;
var levelUpModal = new LevelUpModal();
game.addChild(levelUpModal);
var levelBar = LK.getAsset('levelBar', {});
levelBar.width = game.width * 0.8;
levelBar.height = 100;
levelBar.y = 0;
levelBar.x = 2048 / 2 - levelBar.width / 2;
LK.gui.topLeft.addChild(levelBar);
var levelProgress = LK.getAsset('levelProgress', {});
levelProgress.width = 1;
levelProgress.height = 100;
levelProgress.y = 0;
levelProgress.x = 2048 / 2 - levelBar.width / 2;
LK.gui.topLeft.addChild(levelProgress);
var testButton = LK.getAsset('testButton', {
	anchorX: 0.5,
	anchorY: 0.5
});
testButton.x = 0;
testButton.y = LK.height - testButton.height;
LK.gui.bottomLeft.addChild(testButton);
testButton.on('down', function () {
	LK.testMode = !LK.testMode;
	console.log('Test Mode is: ', LK.testMode);
	testButton.alpha = LK.testMode ? 1 : 0;
	grid.children.forEach(function (cell) {
		cell.children.forEach(function (child) {
			if (child instanceof Text2) {
				child.visible = LK.testMode;
			}
			if (!LK.testMode) {
				cell.alpha = 0;
			} else {
				cell.alpha = 1;
			}
		});
	});
});
LK.on('tick', handleTick);
game.activateBomb = function () {
	if (LK.gameState === 'START') {
		var idleBombs = [];
		grid.children.forEach(function (cell) {
			cell.children.forEach(function (child) {
				if (child instanceof IdleBomb && child.visible) {
					var hasActiveBomb = false;
					child.parent.children.forEach(function (sibling) {
						if (sibling instanceof ActiveBomb && sibling.visible) {
							hasActiveBomb = true;
						}
					});
					if (!hasActiveBomb) {
						idleBombs.push(child);
					}
				}
			});
		});
		if (idleBombs.length > 0) {
			var bombToActivate;
			do {
				bombToActivate = idleBombs[Math.floor(Math.random() * idleBombs.length)];
			} while (bombToActivate === lastBombActivated);
			lastBombActivated = bombToActivate;
			bombToActivate.hide();
			bombToActivate.parent.children.forEach(function (child) {
				if (child instanceof ActiveBomb) {
					child.show();
					bombToActivate.visibilityTimeout = LK.setTimeout(function () {
						child.hide();
						bombToActivate.visibilityTimeout = null;
						bombToActivate.visible = true;
					}, 2000);
				}
			});
		}
	}
};
LK.setInterval(game.activateBomb, 450);
var startButton = LK.getAsset('startButton', {
	anchorX: 0.5,
	anchorY: 0.5
});
startButton.width = 200;
startButton.height = 100;
startButton.x = 2048 / 2 - startButton.width / 2;
startButton.y = 2732 - startButton.height;
game.addChild(startButton);
startButton.on('down', function () {
	if (LK.gameState === 'IDLE') {
		LK.gameState = 'START';
		var originalScale = startButton.scale.x;
		var tweenScale = originalScale * 1.05;
		var interval = LK.setInterval(function () {
			if (startButton.scale.x < tweenScale) {
				startButton.scale.x += 0.01;
				startButton.scale.y += 0.01;
			} else {
				LK.clearInterval(interval);
				interval = LK.setInterval(function () {
					if (startButton.scale.x > originalScale) {
						startButton.scale.x -= 0.01;
						startButton.scale.y -= 0.01;
					} else {
						LK.clearInterval(interval);
						var fadeOutInterval = LK.setInterval(function () {
							if (startButton.alpha > 0) {
								startButton.alpha -= 0.0668;
							} else {
								LK.clearInterval(fadeOutInterval);
								startButton.visible = false;
							}
						}, 1000 / 60);
					}
				}, 1000 / 60);
			}
		}, 1000 / 60);
	}
});
var angle = 0;
var radius = 50;
var centerX = 2048 / 2;
var centerY = 2732 - startButton.height - radius;
var circularInterval = LK.setInterval(function () {
	startButton.x = centerX + radius * Math.cos(angle);
	startButton.y = centerY + radius * Math.sin(angle);
	angle += 0.05;
	if (angle >= 2 * Math.PI) {
		angle = 0;
	}
}, 1000 / 60);