/**** 
* Classes
****/ 
//<Assets used in the game will automatically appear here>
// Block class representing each block in the game
var Block = Container.expand(function () {
	var self = Container.call(this);
	var blockGraphics = self.attachAsset('block', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.update = function () {
		// Blocks do not have any specific update logic for now
	};
});
var BlueBlock = Container.expand(function () {
	var self = Container.call(this);
	var blockGraphics = self.attachAsset('blueBlock', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.update = function () {
		// Blocks do not have any specific update logic for now
	};
});
var BrownBlock = Container.expand(function () {
	var self = Container.call(this);
	var blockGraphics = self.attachAsset('brownBlock', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.update = function () {
		// Blocks do not have any specific update logic for now
	};
});
var Explosion = Container.expand(function () {
	var self = Container.call(this);
	var explosionGraphics = self.attachAsset('explosion', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.update = function () {
		// Explosion specific logic can be added here
	};
});
var PinkBlock = Container.expand(function () {
	var self = Container.call(this);
	var blockGraphics = self.attachAsset('pinkBlock', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.update = function () {
		// Blocks do not have any specific update logic for now
	};
});
var PurpleBlock = Container.expand(function () {
	var self = Container.call(this);
	var blockGraphics = self.attachAsset('purpleBlock', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.update = function () {
		// Blocks do not have any specific update logic for now
	};
});
var RedBlock = Container.expand(function () {
	var self = Container.call(this);
	var blockGraphics = self.attachAsset('redStackedBlock', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.update = function () {
		for (var i = blocks.length - 1; i >= 0; i--) {
			if (self !== blocks[i] && self.intersects(blocks[i])) {
				var explosion = new Explosion();
				explosion.x = self.x;
				explosion.y = self.y;
				game.addChild(explosion);
				LK.getSound('explosionSound').play();
				LK.getSound('evilLaugh').play();
				// Animation: fade in, zoom in, then zoom out and fade out
				explosion.alpha = 0;
				explosion.scale.set(0.5, 0.5);
				LK.effects.fadeIn(explosion, 500, function () {
					LK.effects.scaleTo(explosion, 10.0, 10.0, 700, function () {
						LK.effects.scaleTo(explosion, 0.5, 0.5, 500, function () {
							LK.effects.fadeOut(explosion, 500, function () {
								explosion.destroy();
							});
						});
					});
				});
				blocks[i].destroy();
				blocks.splice(i, 1);
				self.destroy();
				blocks.splice(blocks.indexOf(self), 1);
				break;
			}
		}
	};
});
var RedStackedBlock = Container.expand(function () {
	var self = Container.call(this);
	var blockGraphics = self.attachAsset('redStackedBlock', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.update = function () {
		// Blocks do not have any specific update logic for now
	};
});
var YellowStackedBlock = Container.expand(function () {
	var self = Container.call(this);
	var blockGraphics = self.attachAsset('yellowStackedBlock', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.update = function () {
		// Blocks do not have any specific update logic for now
	};
});
/**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0x800080 //Init game with purple background
});
/**** 
* Game Code
****/ 
var background = LK.getAsset('purpleSunRays', {
	anchorX: 0.5,
	anchorY: 0.5,
	scaleX: 1.5,
	scaleY: 1.5,
	x: 2048 / 2,
	y: 2732 / 2
});
game.addChild(background);
LK.effects.fadeIn = function (obj, duration, callback) {
	var step = 1 / (duration / 16.67); // 16.67ms per frame at 60FPS
	var interval = LK.setInterval(function () {
		obj.alpha += step;
		if (obj.alpha >= 1) {
			obj.alpha = 1;
			LK.clearInterval(interval);
			if (callback) {
				callback();
			}
		}
	}, 16.67);
};
LK.effects.fadeOut = function (obj, duration, callback) {
	var step = 1 / (duration / 16.67); // 16.67ms per frame at 60FPS
	var interval = LK.setInterval(function () {
		obj.alpha -= step;
		if (obj.alpha <= 0) {
			obj.alpha = 0;
			LK.clearInterval(interval);
			if (callback) {
				callback();
			}
		}
	}, 16.67);
};
LK.effects.scaleTo = function (obj, scaleX, scaleY, duration, callback) {
	var startX = obj.scale.x;
	var startY = obj.scale.y;
	var stepX = (scaleX - startX) / (duration / 16.67); // 16.67ms per frame at 60FPS
	var stepY = (scaleY - startY) / (duration / 16.67); // 16.67ms per frame at 60FPS
	var interval = LK.setInterval(function () {
		obj.scale.x += stepX;
		obj.scale.y += stepY;
		if (stepX > 0 && obj.scale.x >= scaleX || stepX < 0 && obj.scale.x <= scaleX) {
			obj.scale.x = scaleX;
			obj.scale.y = scaleY;
			LK.clearInterval(interval);
			if (callback) {
				callback();
			}
		}
	}, 16.67);
};
var redFlashInterval = null;
function startRedFlash() {
	if (redFlashInterval === null) {
		redFlashInterval = LK.setInterval(function () {
			LK.effects.flashScreen(0xff0000, 500);
		}, 500);
	}
}
function stopRedFlash() {
	if (redFlashInterval !== null) {
		LK.clearInterval(redFlashInterval);
		redFlashInterval = null;
	}
}
LK.playMusic('epicTechno');
gameSpeed += 0.1;
function checkForMatchingBlocks() {
	var blockGroups = {};
	// Group blocks by their tint color
	blocks.forEach(function (block) {
		var color = block.children[0].tint;
		if (!blockGroups[color]) {
			blockGroups[color] = [];
		}
		blockGroups[color].push(block);
	});
	// Check each group for 5 or more touching blocks
	for (var color in blockGroups) {
		var group = blockGroups[color];
		for (var i = 0; i < group.length; i++) {
			var block = group[i];
			var touchingBlocks = [block];
			// Check for touching blocks in the group
			for (var j = 0; j < group.length; j++) {
				if (i !== j && block.intersects(group[j])) {
					touchingBlocks.push(group[j]);
				}
			}
			// If 5 or more blocks are touching, remove them
			if (touchingBlocks.length >= 5) {
				touchingBlocks.forEach(function (touchingBlock) {
					var explosion = new Explosion();
					explosion.x = touchingBlock.x;
					explosion.y = touchingBlock.y;
					game.addChild(explosion);
					LK.getSound('explosionSound').play();
					LK.getSound('evilLaugh').play();
					// Animation: fade in, zoom in, then zoom out and fade out
					explosion.alpha = 0;
					explosion.scale.set(0.5, 0.5);
					LK.effects.fadeIn(explosion, 500, function () {
						LK.effects.scaleTo(explosion, 10.0, 10.0, 700, function () {
							LK.effects.scaleTo(explosion, 0.5, 0.5, 500, function () {
								LK.effects.fadeOut(explosion, 500, function () {
									explosion.destroy();
								});
							});
						});
					});
					touchingBlock.destroy();
					blocks = blocks.filter(function (b) {
						return b !== touchingBlock;
					});
				});
			}
		}
	}
}
// Initialize variables
var blocks = [];
var currentBlock = null;
var stackHeight = 0;
var gameSpeed = 2.0;
var score = 0;
var scoreTxt = new Text2('0', {
	size: 150,
	fill: "#ffffff"
});
// Event listeners for WASD keys
game.keydown = function (event) {
	if (currentBlock) {
		if (event.key === 'ArrowLeft' || event.key === 'a') {
			currentBlock.x -= 50;
		} else if (event.key === 'ArrowRight' || event.key === 'd') {
			currentBlock.x += 50;
		} else if (event.key === 'ArrowUp' || event.key === 'w') {
			currentBlock.y -= 50;
		} else if (event.key === 'ArrowDown' || event.key === 's') {
			currentBlock.y += 50;
		}
	}
};
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Function to create a new block
function createBlock() {
	var block;
	var randomValue = Math.random();
	if (randomValue < 0.15) {
		block = new Block();
		block.children[0].tint = getRandomColor();
	} else if (randomValue < 0.3) {
		block = new BlueBlock();
	} else if (randomValue < 0.45) {
		block = new YellowStackedBlock();
	} else if (randomValue < 0.6) {
		block = new PurpleBlock();
	} else if (randomValue < 0.75) {
		block = new PinkBlock();
	} else if (randomValue < 0.9) {
		block = new BrownBlock();
	} else {
		block = new RedBlock();
		LK.getSound('alarm').play();
		LK.getSound('evilLaugh').play();
		startRedFlash();
	}
	block.x = 2048 / 2;
	block.y = 100;
	blocks.push(block);
	game.addChild(block);
	currentBlock = block;
}
// Function to handle block placement
function placeBlock() {
	if (currentBlock) {
		gameSpeed += 0.2;
		checkForMatchingBlocks();
		// Check if the current block is red
		if (currentBlock instanceof RedBlock) {
			// Destroy all blocks except red blocks
			for (var i = blocks.length - 1; i >= 0; i--) {
				if (!(blocks[i] instanceof RedBlock)) {
					var blockToDestroy = blocks[i];
					blockToDestroy.destroy();
					blocks.splice(i, 1);
				}
			}
			// Stop red flash screen when red block touches another block
			stopRedFlash();
		}
		if (blocks.length === 0) {
			LK.stopMusic();
			LK.effects.flashScreen(0x00ff00, 1000); // Flash screen green for 1 second
			LK.showGameWin();
			return;
		}
		if (blocks.length === 0) {
			LK.stopMusic();
			LK.effects.flashScreen(0x00ff00, 1000); // Flash screen green for 1 second
			LK.showYouWin();
			LK.stopMusic();
			return;
		}
		if (score >= 50) {
			LK.getSound('gameOverBuzzer').play();
			LK.getSound('alarm').stop();
			stopRedFlash();
			LK.showGameOver();
			return;
		}
		if (blocks.length >= 100) {
			LK.getSound('gameOverBuzzer').play();
			LK.getSound('alarm').stop();
			stopRedFlash();
			stopRedFlash();
			LK.showGameOver();
			return;
		}
		currentBlock.y = 2732 - (stackHeight + 1) * currentBlock.height + currentBlock.height / 2;
		LK.getSound('bellDing').play();
		currentBlock = null;
		blocks = blocks.filter(function (block) {
			return block !== currentBlock;
		});
		currentBlock = null;
		stackHeight++;
		score++;
		scoreTxt.setText(score);
		createBlock();
		// gameSpeed increment removed
	}
}
// Initialize the first block with a random color
createBlock();
LK.getSound('alarm').play();
// Event listener for touch down
game.down = function (x, y, obj) {
	if (currentBlock) {
		currentBlock.startX = currentBlock.x;
		currentBlock.startY = currentBlock.y;
		currentBlock.startTouchX = x;
		currentBlock.startTouchY = y;
	}
};
// Event listener for touch move
game.move = function (x, y, obj) {
	if (currentBlock) {
		var deltaX = x - currentBlock.startTouchX;
		currentBlock.x = currentBlock.startX + deltaX;
	}
};
// Update function called every game tick
game.update = function () {
	if (currentBlock) {
		currentBlock.y += gameSpeed * 4.0;
		for (var i = blocks.length - 1; i >= 0; i--) {
			if (currentBlock !== blocks[i] && currentBlock.intersects(blocks[i])) {
				if (currentBlock instanceof RedBlock) {
					stopRedFlash();
					var explosion = new Explosion();
					explosion.x = currentBlock.x;
					explosion.y = currentBlock.y;
					game.addChild(explosion);
					LK.getSound('explosionSound').play();
					// Animation: fade in, zoom in, then zoom out and fade out
					explosion.alpha = 0;
					explosion.scale.set(0.5, 0.5);
					LK.effects.fadeIn(explosion, 500, function () {
						LK.effects.scaleTo(explosion, 10.0, 10.0, 700, function () {
							LK.effects.scaleTo(explosion, 0.5, 0.5, 500, function () {
								LK.effects.fadeOut(explosion, 500, function () {
									explosion.destroy();
								});
							});
						});
					});
					blocks[i].destroy();
					blocks.splice(i, 1);
					currentBlock.destroy();
					blocks.splice(blocks.indexOf(currentBlock), 1);
				} else {
					blocks = blocks.filter(function (block) {
						return block !== currentBlock;
					});
					LK.getSound('bellDing').play();
					placeBlock();
				}
				break;
			}
		}
		if (currentBlock.y > 2732) {
			if (score >= 50) {
				LK.getSound('gameOverBuzzer').play();
				LK.getSound('alarm').stop();
				LK.showGameOver();
				return;
			}
			if (blocks.length >= 100) {
				LK.getSound('gameOverBuzzer').play();
				LK.getSound('alarm').stop();
				LK.showGameOver();
				return;
			}
			currentBlock.y = 2732 - (stackHeight + 1) * currentBlock.height + currentBlock.height / 2;
			stackHeight++;
			score++;
			scoreTxt.setText(score);
			currentBlock = null;
			blocks = blocks.filter(function (block) {
				return block !== currentBlock;
			});
			createBlock();
			// gameSpeed increment removed
		}
	}
};
// Function to generate a random color
function getRandomColor() {
	return Math.floor(Math.random() * 16777215);
} /**** 
* Classes
****/ 
//<Assets used in the game will automatically appear here>
// Block class representing each block in the game
var Block = Container.expand(function () {
	var self = Container.call(this);
	var blockGraphics = self.attachAsset('block', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.update = function () {
		// Blocks do not have any specific update logic for now
	};
});
var BlueBlock = Container.expand(function () {
	var self = Container.call(this);
	var blockGraphics = self.attachAsset('blueBlock', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.update = function () {
		// Blocks do not have any specific update logic for now
	};
});
var BrownBlock = Container.expand(function () {
	var self = Container.call(this);
	var blockGraphics = self.attachAsset('brownBlock', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.update = function () {
		// Blocks do not have any specific update logic for now
	};
});
var Explosion = Container.expand(function () {
	var self = Container.call(this);
	var explosionGraphics = self.attachAsset('explosion', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.update = function () {
		// Explosion specific logic can be added here
	};
});
var PinkBlock = Container.expand(function () {
	var self = Container.call(this);
	var blockGraphics = self.attachAsset('pinkBlock', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.update = function () {
		// Blocks do not have any specific update logic for now
	};
});
var PurpleBlock = Container.expand(function () {
	var self = Container.call(this);
	var blockGraphics = self.attachAsset('purpleBlock', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.update = function () {
		// Blocks do not have any specific update logic for now
	};
});
var RedBlock = Container.expand(function () {
	var self = Container.call(this);
	var blockGraphics = self.attachAsset('redStackedBlock', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.update = function () {
		for (var i = blocks.length - 1; i >= 0; i--) {
			if (self !== blocks[i] && self.intersects(blocks[i])) {
				var explosion = new Explosion();
				explosion.x = self.x;
				explosion.y = self.y;
				game.addChild(explosion);
				LK.getSound('explosionSound').play();
				LK.getSound('evilLaugh').play();
				// Animation: fade in, zoom in, then zoom out and fade out
				explosion.alpha = 0;
				explosion.scale.set(0.5, 0.5);
				LK.effects.fadeIn(explosion, 500, function () {
					LK.effects.scaleTo(explosion, 10.0, 10.0, 700, function () {
						LK.effects.scaleTo(explosion, 0.5, 0.5, 500, function () {
							LK.effects.fadeOut(explosion, 500, function () {
								explosion.destroy();
							});
						});
					});
				});
				blocks[i].destroy();
				blocks.splice(i, 1);
				self.destroy();
				blocks.splice(blocks.indexOf(self), 1);
				break;
			}
		}
	};
});
var RedStackedBlock = Container.expand(function () {
	var self = Container.call(this);
	var blockGraphics = self.attachAsset('redStackedBlock', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.update = function () {
		// Blocks do not have any specific update logic for now
	};
});
var YellowStackedBlock = Container.expand(function () {
	var self = Container.call(this);
	var blockGraphics = self.attachAsset('yellowStackedBlock', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	self.update = function () {
		// Blocks do not have any specific update logic for now
	};
});
/**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0x800080 //Init game with purple background
});
/**** 
* Game Code
****/ 
var background = LK.getAsset('purpleSunRays', {
	anchorX: 0.5,
	anchorY: 0.5,
	scaleX: 1.5,
	scaleY: 1.5,
	x: 2048 / 2,
	y: 2732 / 2
});
game.addChild(background);
LK.effects.fadeIn = function (obj, duration, callback) {
	var step = 1 / (duration / 16.67); // 16.67ms per frame at 60FPS
	var interval = LK.setInterval(function () {
		obj.alpha += step;
		if (obj.alpha >= 1) {
			obj.alpha = 1;
			LK.clearInterval(interval);
			if (callback) {
				callback();
			}
		}
	}, 16.67);
};
LK.effects.fadeOut = function (obj, duration, callback) {
	var step = 1 / (duration / 16.67); // 16.67ms per frame at 60FPS
	var interval = LK.setInterval(function () {
		obj.alpha -= step;
		if (obj.alpha <= 0) {
			obj.alpha = 0;
			LK.clearInterval(interval);
			if (callback) {
				callback();
			}
		}
	}, 16.67);
};
LK.effects.scaleTo = function (obj, scaleX, scaleY, duration, callback) {
	var startX = obj.scale.x;
	var startY = obj.scale.y;
	var stepX = (scaleX - startX) / (duration / 16.67); // 16.67ms per frame at 60FPS
	var stepY = (scaleY - startY) / (duration / 16.67); // 16.67ms per frame at 60FPS
	var interval = LK.setInterval(function () {
		obj.scale.x += stepX;
		obj.scale.y += stepY;
		if (stepX > 0 && obj.scale.x >= scaleX || stepX < 0 && obj.scale.x <= scaleX) {
			obj.scale.x = scaleX;
			obj.scale.y = scaleY;
			LK.clearInterval(interval);
			if (callback) {
				callback();
			}
		}
	}, 16.67);
};
var redFlashInterval = null;
function startRedFlash() {
	if (redFlashInterval === null) {
		redFlashInterval = LK.setInterval(function () {
			LK.effects.flashScreen(0xff0000, 500);
		}, 500);
	}
}
function stopRedFlash() {
	if (redFlashInterval !== null) {
		LK.clearInterval(redFlashInterval);
		redFlashInterval = null;
	}
}
LK.playMusic('epicTechno');
gameSpeed += 0.1;
function checkForMatchingBlocks() {
	var blockGroups = {};
	// Group blocks by their tint color
	blocks.forEach(function (block) {
		var color = block.children[0].tint;
		if (!blockGroups[color]) {
			blockGroups[color] = [];
		}
		blockGroups[color].push(block);
	});
	// Check each group for 5 or more touching blocks
	for (var color in blockGroups) {
		var group = blockGroups[color];
		for (var i = 0; i < group.length; i++) {
			var block = group[i];
			var touchingBlocks = [block];
			// Check for touching blocks in the group
			for (var j = 0; j < group.length; j++) {
				if (i !== j && block.intersects(group[j])) {
					touchingBlocks.push(group[j]);
				}
			}
			// If 5 or more blocks are touching, remove them
			if (touchingBlocks.length >= 5) {
				touchingBlocks.forEach(function (touchingBlock) {
					var explosion = new Explosion();
					explosion.x = touchingBlock.x;
					explosion.y = touchingBlock.y;
					game.addChild(explosion);
					LK.getSound('explosionSound').play();
					LK.getSound('evilLaugh').play();
					// Animation: fade in, zoom in, then zoom out and fade out
					explosion.alpha = 0;
					explosion.scale.set(0.5, 0.5);
					LK.effects.fadeIn(explosion, 500, function () {
						LK.effects.scaleTo(explosion, 10.0, 10.0, 700, function () {
							LK.effects.scaleTo(explosion, 0.5, 0.5, 500, function () {
								LK.effects.fadeOut(explosion, 500, function () {
									explosion.destroy();
								});
							});
						});
					});
					touchingBlock.destroy();
					blocks = blocks.filter(function (b) {
						return b !== touchingBlock;
					});
				});
			}
		}
	}
}
// Initialize variables
var blocks = [];
var currentBlock = null;
var stackHeight = 0;
var gameSpeed = 2.0;
var score = 0;
var scoreTxt = new Text2('0', {
	size: 150,
	fill: "#ffffff"
});
// Event listeners for WASD keys
game.keydown = function (event) {
	if (currentBlock) {
		if (event.key === 'ArrowLeft' || event.key === 'a') {
			currentBlock.x -= 50;
		} else if (event.key === 'ArrowRight' || event.key === 'd') {
			currentBlock.x += 50;
		} else if (event.key === 'ArrowUp' || event.key === 'w') {
			currentBlock.y -= 50;
		} else if (event.key === 'ArrowDown' || event.key === 's') {
			currentBlock.y += 50;
		}
	}
};
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Function to create a new block
function createBlock() {
	var block;
	var randomValue = Math.random();
	if (randomValue < 0.15) {
		block = new Block();
		block.children[0].tint = getRandomColor();
	} else if (randomValue < 0.3) {
		block = new BlueBlock();
	} else if (randomValue < 0.45) {
		block = new YellowStackedBlock();
	} else if (randomValue < 0.6) {
		block = new PurpleBlock();
	} else if (randomValue < 0.75) {
		block = new PinkBlock();
	} else if (randomValue < 0.9) {
		block = new BrownBlock();
	} else {
		block = new RedBlock();
		LK.getSound('alarm').play();
		LK.getSound('evilLaugh').play();
		startRedFlash();
	}
	block.x = 2048 / 2;
	block.y = 100;
	blocks.push(block);
	game.addChild(block);
	currentBlock = block;
}
// Function to handle block placement
function placeBlock() {
	if (currentBlock) {
		gameSpeed += 0.2;
		checkForMatchingBlocks();
		// Check if the current block is red
		if (currentBlock instanceof RedBlock) {
			// Destroy all blocks except red blocks
			for (var i = blocks.length - 1; i >= 0; i--) {
				if (!(blocks[i] instanceof RedBlock)) {
					var blockToDestroy = blocks[i];
					blockToDestroy.destroy();
					blocks.splice(i, 1);
				}
			}
			// Stop red flash screen when red block touches another block
			stopRedFlash();
		}
		if (blocks.length === 0) {
			LK.stopMusic();
			LK.effects.flashScreen(0x00ff00, 1000); // Flash screen green for 1 second
			LK.showGameWin();
			return;
		}
		if (blocks.length === 0) {
			LK.stopMusic();
			LK.effects.flashScreen(0x00ff00, 1000); // Flash screen green for 1 second
			LK.showYouWin();
			LK.stopMusic();
			return;
		}
		if (score >= 50) {
			LK.getSound('gameOverBuzzer').play();
			LK.getSound('alarm').stop();
			stopRedFlash();
			LK.showGameOver();
			return;
		}
		if (blocks.length >= 100) {
			LK.getSound('gameOverBuzzer').play();
			LK.getSound('alarm').stop();
			stopRedFlash();
			stopRedFlash();
			LK.showGameOver();
			return;
		}
		currentBlock.y = 2732 - (stackHeight + 1) * currentBlock.height + currentBlock.height / 2;
		LK.getSound('bellDing').play();
		currentBlock = null;
		blocks = blocks.filter(function (block) {
			return block !== currentBlock;
		});
		currentBlock = null;
		stackHeight++;
		score++;
		scoreTxt.setText(score);
		createBlock();
		// gameSpeed increment removed
	}
}
// Initialize the first block with a random color
createBlock();
LK.getSound('alarm').play();
// Event listener for touch down
game.down = function (x, y, obj) {
	if (currentBlock) {
		currentBlock.startX = currentBlock.x;
		currentBlock.startY = currentBlock.y;
		currentBlock.startTouchX = x;
		currentBlock.startTouchY = y;
	}
};
// Event listener for touch move
game.move = function (x, y, obj) {
	if (currentBlock) {
		var deltaX = x - currentBlock.startTouchX;
		currentBlock.x = currentBlock.startX + deltaX;
	}
};
// Update function called every game tick
game.update = function () {
	if (currentBlock) {
		currentBlock.y += gameSpeed * 4.0;
		for (var i = blocks.length - 1; i >= 0; i--) {
			if (currentBlock !== blocks[i] && currentBlock.intersects(blocks[i])) {
				if (currentBlock instanceof RedBlock) {
					stopRedFlash();
					var explosion = new Explosion();
					explosion.x = currentBlock.x;
					explosion.y = currentBlock.y;
					game.addChild(explosion);
					LK.getSound('explosionSound').play();
					// Animation: fade in, zoom in, then zoom out and fade out
					explosion.alpha = 0;
					explosion.scale.set(0.5, 0.5);
					LK.effects.fadeIn(explosion, 500, function () {
						LK.effects.scaleTo(explosion, 10.0, 10.0, 700, function () {
							LK.effects.scaleTo(explosion, 0.5, 0.5, 500, function () {
								LK.effects.fadeOut(explosion, 500, function () {
									explosion.destroy();
								});
							});
						});
					});
					blocks[i].destroy();
					blocks.splice(i, 1);
					currentBlock.destroy();
					blocks.splice(blocks.indexOf(currentBlock), 1);
				} else {
					blocks = blocks.filter(function (block) {
						return block !== currentBlock;
					});
					LK.getSound('bellDing').play();
					placeBlock();
				}
				break;
			}
		}
		if (currentBlock.y > 2732) {
			if (score >= 50) {
				LK.getSound('gameOverBuzzer').play();
				LK.getSound('alarm').stop();
				LK.showGameOver();
				return;
			}
			if (blocks.length >= 100) {
				LK.getSound('gameOverBuzzer').play();
				LK.getSound('alarm').stop();
				LK.showGameOver();
				return;
			}
			currentBlock.y = 2732 - (stackHeight + 1) * currentBlock.height + currentBlock.height / 2;
			stackHeight++;
			score++;
			scoreTxt.setText(score);
			currentBlock = null;
			blocks = blocks.filter(function (block) {
				return block !== currentBlock;
			});
			createBlock();
			// gameSpeed increment removed
		}
	}
};
// Function to generate a random color
function getRandomColor() {
	return Math.floor(Math.random() * 16777215);
}