User prompt
You should also write the scores of other players on the end-game screen.
User prompt
game hangs
User prompt
add this to the game
User prompt
Don't burn the character when hitting the edges
User prompt
the game lags a lot
User prompt
The character gives an error after a certain point, please fix it
User prompt
Health bar decreases when bomb hits
User prompt
add health bar
User prompt
add user-friendly gameplay elements
User prompt
add sound to game
User prompt
Add different fruits that give beautiful features
User prompt
try again
User prompt
fixed
User prompt
fix please
User prompt
Adjust the falling of stones according to human reflexes
User prompt
Basket does not work after a certain point
User prompt
Let the background be a nice 2d background
User prompt
add a lot of features add at least 10 features
User prompt
add different features
User prompt
diğer kullanıcıların puanlarınında olduğu bir tablo olmalı
User prompt
liderlik tablosunu oyunun sonunda göster
User prompt
add leaderboard
User prompt
Please fix the bug: 'Timeout.tick error: LK.showLeaderBoard is not a function' in or related to this line: 'LK.showLeaderBoard();' Line Number: 423
User prompt
Please fix the bug: 'Timeout.tick error: LK.showLeaderboard is not a function' in or related to this line: 'LK.showLeaderboard();' Line Number: 372
User prompt
add something for competition
/**** 
* Plugins
****/ 
var tween = LK.import("@upit/tween.v1");
/**** 
* Classes
****/ 
// Ball class
var Ball = Container.expand(function () {
	var self = Container.call(this);
	var ballAsset = self.attachAsset('ball', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	// Neon color palette for balls
	var colors = [0x00ffff, 0xff00ff, 0xffff00, 0x00ff00, 0xff8800, 0x00ffea, 0xff0088];
	ballAsset.color = colors[Math.floor(Math.random() * colors.length)];
	ballAsset.tint = ballAsset.color;
	// Neon glow effect: animate alpha for a pulsing glow
	tween(ballAsset, {
		alpha: 0.7
	}, {
		duration: 400,
		yoyo: true,
		repeat: Infinity,
		easing: tween.easeInOut
	});
	self.speed = 18 + Math.random() * 6; // px per frame, increases with score
	self.update = function () {
		self.y += self.speed;
	};
	return self;
});
// Basket class
var Basket = Container.expand(function () {
	var self = Container.call(this);
	var basketAsset = self.attachAsset('basket', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	// Neon basket: random neon color and glow
	var basketColors = [0x00ffff, 0xff00ff, 0xffff00, 0x00ff00, 0xff8800, 0x00ffea, 0xff0088];
	basketAsset.tint = basketColors[Math.floor(Math.random() * basketColors.length)];
	tween(basketAsset, {
		alpha: 0.7
	}, {
		duration: 600,
		yoyo: true,
		repeat: Infinity,
		easing: tween.easeInOut
	});
	return self;
});
// Bomb class
var Bomb = Container.expand(function () {
	var self = Container.call(this);
	var bombAsset = self.attachAsset('bomb', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	// Neon bomb: magenta or cyan
	var bombColors = [0xff00ff, 0x00ffff, 0xffff00];
	bombAsset.tint = bombColors[Math.floor(Math.random() * bombColors.length)];
	tween(bombAsset, {
		alpha: 0.6
	}, {
		duration: 400,
		yoyo: true,
		repeat: Infinity,
		easing: tween.easeInOut
	});
	self.speed = 20 + Math.random() * 8;
	self.update = function () {
		self.y += self.speed;
	};
	return self;
});
// PowerUp class (neon star)
var PowerUp = Container.expand(function () {
	var self = Container.call(this);
	// Use a ball asset for now, but tint and scale to look like a power-up
	var starAsset = self.attachAsset('ball', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	// Neon star color
	var starColors = [0xFFD700, 0x00ffea, 0xff00ff, 0x00ff00];
	starAsset.tint = starColors[Math.floor(Math.random() * starColors.length)];
	starAsset.scaleX = 1.3;
	starAsset.scaleY = 1.3;
	// Animate alpha for a pulsing glow
	tween(starAsset, {
		alpha: 0.8
	}, {
		duration: 300,
		yoyo: true,
		repeat: Infinity,
		easing: tween.easeInOut
	});
	self.speed = 16 + Math.random() * 4;
	self.type = "score"; // default type
	self.update = function () {
		self.y += self.speed;
	};
	return self;
});
// ShieldPowerUp class (neon blue ring)
var ShieldPowerUp = Container.expand(function () {
	var self = Container.call(this);
	var shieldAsset = self.attachAsset('ball', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	shieldAsset.tint = 0x00ffff;
	shieldAsset.scaleX = 1.5;
	shieldAsset.scaleY = 1.5;
	tween(shieldAsset, {
		alpha: 0.6
	}, {
		duration: 200,
		yoyo: true,
		repeat: Infinity,
		easing: tween.easeInOut
	});
	self.speed = 15 + Math.random() * 3;
	self.type = "shield";
	self.update = function () {
		self.y += self.speed;
	};
	return self;
});
/**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0x000000
});
/**** 
* Game Code
****/ 
// Game area: 2048x2732
// Basket: wide rectangle
// Ball: colored ellipse
// Bomb: black ellipse
// Sound for catching a ball
// Sound for catching a bomb
// Sound for missing a ball
game.setBackgroundColor(0x000000);
// Neon-style game objective text at the start (small, English, subtle neon)
var objectiveTxt = new Text2('Goal: Catch the balls, avoid the bombs!', {
	size: 54,
	// smaller text
	fill: 0x00ffff,
	stroke: 0x222222,
	strokeThickness: 8,
	dropShadow: true,
	dropShadowColor: 0x00ffff,
	dropShadowBlur: 12,
	dropShadowDistance: 0,
	align: "center"
});
objectiveTxt.anchor.set(0.5, 0);
objectiveTxt.y = 90;
LK.gui.top.addChild(objectiveTxt);
// Add leaderboard button for competition
var leaderboardBtn = new Text2('🏆 Leaderboard', {
	size: 60,
	fill: 0xFFD700,
	stroke: 0x00ffff,
	strokeThickness: 8,
	dropShadow: true,
	dropShadowColor: 0xFFD700,
	dropShadowBlur: 10,
	dropShadowDistance: 0,
	align: "center"
});
leaderboardBtn.anchor.set(0.5, 0);
leaderboardBtn.x = 2048 - 250;
leaderboardBtn.y = 90;
leaderboardBtn.interactive = true;
leaderboardBtn.buttonMode = true;
leaderboardBtn.down = function () {
	LK.showLeaderboard();
};
LK.gui.top.addChild(leaderboardBtn);
// Hide objective after 2.5 seconds
LK.setTimeout(function () {
	objectiveTxt.visible = false;
}, 2500);
// Score text
var scoreTxt = new Text2('0', {
	size: 120,
	fill: 0x00FFEA,
	stroke: 0xFF00FF,
	strokeThickness: 18,
	dropShadow: true,
	dropShadowColor: 0x00FFFF,
	dropShadowBlur: 24,
	dropShadowDistance: 0,
	align: "center"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Misses text (shows "Missed!" when a ball is missed)
var missTxt = new Text2('', {
	size: 90,
	fill: 0x00FFFF,
	stroke: 0xFF00FF,
	strokeThickness: 14,
	dropShadow: true,
	dropShadowColor: 0x00FFFF,
	dropShadowBlur: 18,
	dropShadowDistance: 0,
	align: "center"
});
missTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(missTxt);
missTxt.visible = false;
// Basket
var basket = new Basket();
game.addChild(basket);
basket.y = 2732 - 180;
basket.x = 2048 / 2;
// Ball, bomb, and power-up arrays
var balls = [];
var bombs = [];
var powerups = [];
// Dragging
var dragNode = null;
// Spawning control
var spawnTimer = 0;
var spawnInterval = 55; // frames between spawns, will decrease as score increases
// State
var lastScore = 0;
var gameOver = false;
// Helper: spawn a ball, bomb, or power-up
function spawnFallingObject() {
	// 80% ball, 20% bomb, 5% power-up, 3% shield power-up
	var rand = Math.random();
	var x = 150 + Math.random() * (2048 - 300);
	if (rand < 0.2) {
		var bomb = new Bomb();
		bomb.x = x;
		bomb.y = -60;
		bomb.lastIntersecting = false;
		bombs.push(bomb);
		game.addChild(bomb);
	} else if (rand > 0.97) {
		// 3% chance for shield power-up
		var shield = new ShieldPowerUp();
		shield.x = x;
		shield.y = -60;
		shield.lastIntersecting = false;
		powerups.push(shield);
		game.addChild(shield);
	} else if (rand > 0.92) {
		// 5% chance for score power-up
		var powerup = new PowerUp();
		powerup.x = x;
		powerup.y = -60;
		powerup.lastIntersecting = false;
		powerups.push(powerup);
		game.addChild(powerup);
	} else {
		var ball = new Ball();
		ball.x = x;
		ball.y = -60;
		ball.lastIntersecting = false;
		balls.push(ball);
		game.addChild(ball);
	}
}
// Move handler for dragging basket
function handleMove(x, y, obj) {
	if (dragNode) {
		// Clamp basket within screen
		var halfWidth = dragNode.width / 2;
		var minX = halfWidth;
		var maxX = 2048 - halfWidth;
		dragNode.x = Math.max(minX, Math.min(maxX, x));
	}
}
// Touch/mouse events
game.down = function (x, y, obj) {
	// Allow drag from anywhere in lower 1/3 of screen for easier control
	if (y > 2732 * 2 / 3) {
		dragNode = basket;
		handleMove(x, y, obj);
	}
};
game.move = handleMove;
game.up = function (x, y, obj) {
	dragNode = null;
};
// Main update loop
game.update = function () {
	if (gameOver) return;
	// Change background color at each 5 points (neon palette)
	var neonBgColors = [0x000000, 0x0ff0fc, 0x1a0033, 0x3b6eea, 0x00ffea, 0xff00ff, 0x00ff00, 0xf75e5e, 0xf7c325];
	var score = LK.getScore();
	var bgIndex = Math.floor(score / 5) % neonBgColors.length;
	game.setBackgroundColor(neonBgColors[bgIndex]);
	// Spawn balls/bombs
	spawnTimer++;
	// Decrease interval as score increases (min 25)
	var interval = Math.max(25, spawnInterval - Math.floor(LK.getScore() / 10) * 3);
	if (spawnTimer >= interval) {
		spawnFallingObject();
		spawnTimer = 0;
	}
	// Update balls
	for (var i = balls.length - 1; i >= 0; i--) {
		var ball = balls[i];
		if (ball.lastY === undefined) ball.lastY = ball.y;
		if (ball.lastIntersecting === undefined) ball.lastIntersecting = false;
		ball.update();
		// Check for catch
		var intersecting = ball.intersects(basket);
		if (!ball.lastIntersecting && intersecting) {
			// Caught!
			LK.setScore(LK.getScore() + 1);
			scoreTxt.setText(LK.getScore());
			LK.getSound('catch').play();
			// Flash screen with a random color for fun
			var flashColors = [0x4ad991, 0xf75e5e, 0x3b6eea, 0xf7a325, 0xFFD700];
			LK.effects.flashScreen(flashColors[Math.floor(Math.random() * flashColors.length)], 200);
			// Animate ball to basket and fade out
			LK.effects.flashObject(basket, 0x4ad991, 200); // Flash basket green
			tween(ball, {
				y: basket.y,
				alpha: 0
			}, {
				duration: 200,
				easing: tween.easeIn,
				onFinish: function onFinish() {
					ball.destroy();
				}
			});
			balls.splice(i, 1);
			continue;
		}
		// Missed (goes below basket)
		if (ball.lastY < 2732 && ball.y >= 2732 - 80) {
			// Missed!
			LK.getSound('miss').play();
			missTxt.setText('Missed!');
			missTxt.visible = true;
			// Flash screen
			LK.effects.flashScreen(0xff0000, 600);
			// End game after short delay
			LK.setTimeout(function () {
				LK.showGameOver();
				LK.showLeaderboard();
			}, 600);
			gameOver = true;
			return;
		}
		// Off screen (cleanup)
		if (ball.y > 2800) {
			ball.destroy();
			balls.splice(i, 1);
			continue;
		}
		ball.lastY = ball.y;
		ball.lastIntersecting = intersecting;
	}
	// Update bombs
	for (var j = bombs.length - 1; j >= 0; j--) {
		var bomb = bombs[j];
		if (bomb.lastY === undefined) bomb.lastY = bomb.y;
		if (bomb.lastIntersecting === undefined) bomb.lastIntersecting = false;
		bomb.update();
		// Check for catch
		var intersecting = bomb.intersects(basket);
		if (!bomb.lastIntersecting && intersecting) {
			if (basket.hasShield) {
				// Consume shield, no game over
				basket.hasShield = false;
				// Remove shield visual effect if present
				if (basket.shieldTween) {
					basket.shieldTween.stop();
					basket.shieldTween = null;
				}
				LK.effects.flashObject(basket, 0x00ffff, 400);
				LK.effects.flashScreen(0x00ffff, 200);
				// Destroy bomb
				bomb.destroy();
				bombs.splice(j, 1);
				continue;
			}
			// Caught bomb: game over
			LK.getSound('boom').play();
			// Flash basket red
			LK.effects.flashObject(basket, 0xff0000, 600);
			// Flash screen
			LK.effects.flashScreen(0x000000, 600);
			// End game after short delay
			LK.setTimeout(function () {
				LK.showGameOver();
				LK.showLeaderboard();
			}, 600);
			gameOver = true;
			return;
		}
		// Off screen (cleanup)
		if (bomb.y > 2800) {
			bomb.destroy();
			bombs.splice(j, 1);
			continue;
		}
		bomb.lastY = bomb.y;
		bomb.lastIntersecting = intersecting;
	}
	// Update power-ups
	for (var k = powerups.length - 1; k >= 0; k--) {
		var powerup = powerups[k];
		if (powerup.lastY === undefined) powerup.lastY = powerup.y;
		if (powerup.lastIntersecting === undefined) powerup.lastIntersecting = false;
		powerup.update();
		// Check for catch
		var intersecting = powerup.intersects(basket);
		if (!powerup.lastIntersecting && intersecting) {
			if (powerup.type === "shield" || powerup instanceof ShieldPowerUp) {
				// Caught shield: activate shield
				basket.hasShield = true;
				// Visual feedback: blue flash and basket glow
				LK.effects.flashObject(basket, 0x00ffff, 400);
				LK.effects.flashScreen(0x00ffff, 200);
				// Add a neon blue outline to basket (simulate with a pulsing alpha tween)
				if (!basket.shieldTween) {
					basket.shieldTween = tween(basket, {
						alpha: 1
					}, {
						duration: 200,
						yoyo: true,
						repeat: Infinity,
						easing: tween.easeInOut
					});
				}
				// Show shield icon (optional: could add a small blue ball above basket)
				// Animate power-up to basket and fade out
				tween(powerup, {
					y: basket.y,
					alpha: 0
				}, {
					duration: 200,
					easing: tween.easeIn,
					onFinish: function onFinish() {
						powerup.destroy();
					}
				});
				powerups.splice(k, 1);
				continue;
			} else {
				// Caught score power-up: double points!
				LK.setScore(LK.getScore() + 2);
				scoreTxt.setText(LK.getScore());
				LK.getSound('catch').play();
				// Flash screen with a bright gold
				LK.effects.flashScreen(0xFFD700, 350);
				// Animate power-up to basket and fade out
				LK.effects.flashObject(basket, 0xFFD700, 300);
				tween(powerup, {
					y: basket.y,
					alpha: 0
				}, {
					duration: 200,
					easing: tween.easeIn,
					onFinish: function onFinish() {
						powerup.destroy();
					}
				});
				powerups.splice(k, 1);
				continue;
			}
		}
		// Off screen (cleanup)
		if (powerup.y > 2800) {
			powerup.destroy();
			powerups.splice(k, 1);
			continue;
		}
		powerup.lastY = powerup.y;
		powerup.lastIntersecting = intersecting;
	}
	// Hide miss text after a short time
	if (missTxt.visible) {
		if (!missTxt.hideTimeout) {
			missTxt.hideTimeout = LK.setTimeout(function () {
				missTxt.visible = false;
				missTxt.hideTimeout = null;
			}, 900);
		}
	}
	// Draw shield icon above basket if shield is active
	if (basket.hasShield) {
		if (!basket.shieldIcon) {
			basket.shieldIcon = LK.getAsset('ball', {
				anchorX: 0.5,
				anchorY: 0.5
			});
			basket.shieldIcon.tint = 0x00ffff;
			basket.shieldIcon.scaleX = 0.5;
			basket.shieldIcon.scaleY = 0.5;
			game.addChild(basket.shieldIcon);
		}
		basket.shieldIcon.x = basket.x;
		basket.shieldIcon.y = basket.y - 70;
		basket.shieldIcon.visible = true;
	} else if (basket.shieldIcon) {
		basket.shieldIcon.visible = false;
	}
};
// Reset state on new game
LK.on('gameStart', function () {
	// Remove all balls, bombs, and powerups
	for (var i = 0; i < balls.length; i++) balls[i].destroy();
	for (var j = 0; j < bombs.length; j++) bombs[j].destroy();
	for (var k = 0; k < powerups.length; k++) powerups[k].destroy();
	balls = [];
	bombs = [];
	powerups = [];
	basket.x = 2048 / 2;
	basket.y = 2732 - 180;
	// Reset shield state
	basket.hasShield = false;
	if (basket.shieldTween) {
		basket.shieldTween.stop();
		basket.shieldTween = null;
	}
	// Randomize basket color on new game
	var basketColors = [0x3b6eea, 0x4ad991, 0xf75e5e, 0xf7a325, 0xFFD700];
	if (basket.children && basket.children.length > 0) {
		basket.children[0].tint = basketColors[Math.floor(Math.random() * basketColors.length)];
	}
	LK.setScore(0);
	scoreTxt.setText('0');
	missTxt.setText('');
	missTxt.visible = false;
	if (missTxt.hideTimeout) {
		LK.clearTimeout(missTxt.hideTimeout);
		missTxt.hideTimeout = null;
	}
	spawnTimer = 0;
	gameOver = false;
}); /**** 
* Plugins
****/ 
var tween = LK.import("@upit/tween.v1");
/**** 
* Classes
****/ 
// Ball class
var Ball = Container.expand(function () {
	var self = Container.call(this);
	var ballAsset = self.attachAsset('ball', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	// Neon color palette for balls
	var colors = [0x00ffff, 0xff00ff, 0xffff00, 0x00ff00, 0xff8800, 0x00ffea, 0xff0088];
	ballAsset.color = colors[Math.floor(Math.random() * colors.length)];
	ballAsset.tint = ballAsset.color;
	// Neon glow effect: animate alpha for a pulsing glow
	tween(ballAsset, {
		alpha: 0.7
	}, {
		duration: 400,
		yoyo: true,
		repeat: Infinity,
		easing: tween.easeInOut
	});
	self.speed = 18 + Math.random() * 6; // px per frame, increases with score
	self.update = function () {
		self.y += self.speed;
	};
	return self;
});
// Basket class
var Basket = Container.expand(function () {
	var self = Container.call(this);
	var basketAsset = self.attachAsset('basket', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	// Neon basket: random neon color and glow
	var basketColors = [0x00ffff, 0xff00ff, 0xffff00, 0x00ff00, 0xff8800, 0x00ffea, 0xff0088];
	basketAsset.tint = basketColors[Math.floor(Math.random() * basketColors.length)];
	tween(basketAsset, {
		alpha: 0.7
	}, {
		duration: 600,
		yoyo: true,
		repeat: Infinity,
		easing: tween.easeInOut
	});
	return self;
});
// Bomb class
var Bomb = Container.expand(function () {
	var self = Container.call(this);
	var bombAsset = self.attachAsset('bomb', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	// Neon bomb: magenta or cyan
	var bombColors = [0xff00ff, 0x00ffff, 0xffff00];
	bombAsset.tint = bombColors[Math.floor(Math.random() * bombColors.length)];
	tween(bombAsset, {
		alpha: 0.6
	}, {
		duration: 400,
		yoyo: true,
		repeat: Infinity,
		easing: tween.easeInOut
	});
	self.speed = 20 + Math.random() * 8;
	self.update = function () {
		self.y += self.speed;
	};
	return self;
});
// PowerUp class (neon star)
var PowerUp = Container.expand(function () {
	var self = Container.call(this);
	// Use a ball asset for now, but tint and scale to look like a power-up
	var starAsset = self.attachAsset('ball', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	// Neon star color
	var starColors = [0xFFD700, 0x00ffea, 0xff00ff, 0x00ff00];
	starAsset.tint = starColors[Math.floor(Math.random() * starColors.length)];
	starAsset.scaleX = 1.3;
	starAsset.scaleY = 1.3;
	// Animate alpha for a pulsing glow
	tween(starAsset, {
		alpha: 0.8
	}, {
		duration: 300,
		yoyo: true,
		repeat: Infinity,
		easing: tween.easeInOut
	});
	self.speed = 16 + Math.random() * 4;
	self.type = "score"; // default type
	self.update = function () {
		self.y += self.speed;
	};
	return self;
});
// ShieldPowerUp class (neon blue ring)
var ShieldPowerUp = Container.expand(function () {
	var self = Container.call(this);
	var shieldAsset = self.attachAsset('ball', {
		anchorX: 0.5,
		anchorY: 0.5
	});
	shieldAsset.tint = 0x00ffff;
	shieldAsset.scaleX = 1.5;
	shieldAsset.scaleY = 1.5;
	tween(shieldAsset, {
		alpha: 0.6
	}, {
		duration: 200,
		yoyo: true,
		repeat: Infinity,
		easing: tween.easeInOut
	});
	self.speed = 15 + Math.random() * 3;
	self.type = "shield";
	self.update = function () {
		self.y += self.speed;
	};
	return self;
});
/**** 
* Initialize Game
****/ 
var game = new LK.Game({
	backgroundColor: 0x000000
});
/**** 
* Game Code
****/ 
// Game area: 2048x2732
// Basket: wide rectangle
// Ball: colored ellipse
// Bomb: black ellipse
// Sound for catching a ball
// Sound for catching a bomb
// Sound for missing a ball
game.setBackgroundColor(0x000000);
// Neon-style game objective text at the start (small, English, subtle neon)
var objectiveTxt = new Text2('Goal: Catch the balls, avoid the bombs!', {
	size: 54,
	// smaller text
	fill: 0x00ffff,
	stroke: 0x222222,
	strokeThickness: 8,
	dropShadow: true,
	dropShadowColor: 0x00ffff,
	dropShadowBlur: 12,
	dropShadowDistance: 0,
	align: "center"
});
objectiveTxt.anchor.set(0.5, 0);
objectiveTxt.y = 90;
LK.gui.top.addChild(objectiveTxt);
// Add leaderboard button for competition
var leaderboardBtn = new Text2('🏆 Leaderboard', {
	size: 60,
	fill: 0xFFD700,
	stroke: 0x00ffff,
	strokeThickness: 8,
	dropShadow: true,
	dropShadowColor: 0xFFD700,
	dropShadowBlur: 10,
	dropShadowDistance: 0,
	align: "center"
});
leaderboardBtn.anchor.set(0.5, 0);
leaderboardBtn.x = 2048 - 250;
leaderboardBtn.y = 90;
leaderboardBtn.interactive = true;
leaderboardBtn.buttonMode = true;
leaderboardBtn.down = function () {
	LK.showLeaderboard();
};
LK.gui.top.addChild(leaderboardBtn);
// Hide objective after 2.5 seconds
LK.setTimeout(function () {
	objectiveTxt.visible = false;
}, 2500);
// Score text
var scoreTxt = new Text2('0', {
	size: 120,
	fill: 0x00FFEA,
	stroke: 0xFF00FF,
	strokeThickness: 18,
	dropShadow: true,
	dropShadowColor: 0x00FFFF,
	dropShadowBlur: 24,
	dropShadowDistance: 0,
	align: "center"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Misses text (shows "Missed!" when a ball is missed)
var missTxt = new Text2('', {
	size: 90,
	fill: 0x00FFFF,
	stroke: 0xFF00FF,
	strokeThickness: 14,
	dropShadow: true,
	dropShadowColor: 0x00FFFF,
	dropShadowBlur: 18,
	dropShadowDistance: 0,
	align: "center"
});
missTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(missTxt);
missTxt.visible = false;
// Basket
var basket = new Basket();
game.addChild(basket);
basket.y = 2732 - 180;
basket.x = 2048 / 2;
// Ball, bomb, and power-up arrays
var balls = [];
var bombs = [];
var powerups = [];
// Dragging
var dragNode = null;
// Spawning control
var spawnTimer = 0;
var spawnInterval = 55; // frames between spawns, will decrease as score increases
// State
var lastScore = 0;
var gameOver = false;
// Helper: spawn a ball, bomb, or power-up
function spawnFallingObject() {
	// 80% ball, 20% bomb, 5% power-up, 3% shield power-up
	var rand = Math.random();
	var x = 150 + Math.random() * (2048 - 300);
	if (rand < 0.2) {
		var bomb = new Bomb();
		bomb.x = x;
		bomb.y = -60;
		bomb.lastIntersecting = false;
		bombs.push(bomb);
		game.addChild(bomb);
	} else if (rand > 0.97) {
		// 3% chance for shield power-up
		var shield = new ShieldPowerUp();
		shield.x = x;
		shield.y = -60;
		shield.lastIntersecting = false;
		powerups.push(shield);
		game.addChild(shield);
	} else if (rand > 0.92) {
		// 5% chance for score power-up
		var powerup = new PowerUp();
		powerup.x = x;
		powerup.y = -60;
		powerup.lastIntersecting = false;
		powerups.push(powerup);
		game.addChild(powerup);
	} else {
		var ball = new Ball();
		ball.x = x;
		ball.y = -60;
		ball.lastIntersecting = false;
		balls.push(ball);
		game.addChild(ball);
	}
}
// Move handler for dragging basket
function handleMove(x, y, obj) {
	if (dragNode) {
		// Clamp basket within screen
		var halfWidth = dragNode.width / 2;
		var minX = halfWidth;
		var maxX = 2048 - halfWidth;
		dragNode.x = Math.max(minX, Math.min(maxX, x));
	}
}
// Touch/mouse events
game.down = function (x, y, obj) {
	// Allow drag from anywhere in lower 1/3 of screen for easier control
	if (y > 2732 * 2 / 3) {
		dragNode = basket;
		handleMove(x, y, obj);
	}
};
game.move = handleMove;
game.up = function (x, y, obj) {
	dragNode = null;
};
// Main update loop
game.update = function () {
	if (gameOver) return;
	// Change background color at each 5 points (neon palette)
	var neonBgColors = [0x000000, 0x0ff0fc, 0x1a0033, 0x3b6eea, 0x00ffea, 0xff00ff, 0x00ff00, 0xf75e5e, 0xf7c325];
	var score = LK.getScore();
	var bgIndex = Math.floor(score / 5) % neonBgColors.length;
	game.setBackgroundColor(neonBgColors[bgIndex]);
	// Spawn balls/bombs
	spawnTimer++;
	// Decrease interval as score increases (min 25)
	var interval = Math.max(25, spawnInterval - Math.floor(LK.getScore() / 10) * 3);
	if (spawnTimer >= interval) {
		spawnFallingObject();
		spawnTimer = 0;
	}
	// Update balls
	for (var i = balls.length - 1; i >= 0; i--) {
		var ball = balls[i];
		if (ball.lastY === undefined) ball.lastY = ball.y;
		if (ball.lastIntersecting === undefined) ball.lastIntersecting = false;
		ball.update();
		// Check for catch
		var intersecting = ball.intersects(basket);
		if (!ball.lastIntersecting && intersecting) {
			// Caught!
			LK.setScore(LK.getScore() + 1);
			scoreTxt.setText(LK.getScore());
			LK.getSound('catch').play();
			// Flash screen with a random color for fun
			var flashColors = [0x4ad991, 0xf75e5e, 0x3b6eea, 0xf7a325, 0xFFD700];
			LK.effects.flashScreen(flashColors[Math.floor(Math.random() * flashColors.length)], 200);
			// Animate ball to basket and fade out
			LK.effects.flashObject(basket, 0x4ad991, 200); // Flash basket green
			tween(ball, {
				y: basket.y,
				alpha: 0
			}, {
				duration: 200,
				easing: tween.easeIn,
				onFinish: function onFinish() {
					ball.destroy();
				}
			});
			balls.splice(i, 1);
			continue;
		}
		// Missed (goes below basket)
		if (ball.lastY < 2732 && ball.y >= 2732 - 80) {
			// Missed!
			LK.getSound('miss').play();
			missTxt.setText('Missed!');
			missTxt.visible = true;
			// Flash screen
			LK.effects.flashScreen(0xff0000, 600);
			// End game after short delay
			LK.setTimeout(function () {
				LK.showGameOver();
				LK.showLeaderboard();
			}, 600);
			gameOver = true;
			return;
		}
		// Off screen (cleanup)
		if (ball.y > 2800) {
			ball.destroy();
			balls.splice(i, 1);
			continue;
		}
		ball.lastY = ball.y;
		ball.lastIntersecting = intersecting;
	}
	// Update bombs
	for (var j = bombs.length - 1; j >= 0; j--) {
		var bomb = bombs[j];
		if (bomb.lastY === undefined) bomb.lastY = bomb.y;
		if (bomb.lastIntersecting === undefined) bomb.lastIntersecting = false;
		bomb.update();
		// Check for catch
		var intersecting = bomb.intersects(basket);
		if (!bomb.lastIntersecting && intersecting) {
			if (basket.hasShield) {
				// Consume shield, no game over
				basket.hasShield = false;
				// Remove shield visual effect if present
				if (basket.shieldTween) {
					basket.shieldTween.stop();
					basket.shieldTween = null;
				}
				LK.effects.flashObject(basket, 0x00ffff, 400);
				LK.effects.flashScreen(0x00ffff, 200);
				// Destroy bomb
				bomb.destroy();
				bombs.splice(j, 1);
				continue;
			}
			// Caught bomb: game over
			LK.getSound('boom').play();
			// Flash basket red
			LK.effects.flashObject(basket, 0xff0000, 600);
			// Flash screen
			LK.effects.flashScreen(0x000000, 600);
			// End game after short delay
			LK.setTimeout(function () {
				LK.showGameOver();
				LK.showLeaderboard();
			}, 600);
			gameOver = true;
			return;
		}
		// Off screen (cleanup)
		if (bomb.y > 2800) {
			bomb.destroy();
			bombs.splice(j, 1);
			continue;
		}
		bomb.lastY = bomb.y;
		bomb.lastIntersecting = intersecting;
	}
	// Update power-ups
	for (var k = powerups.length - 1; k >= 0; k--) {
		var powerup = powerups[k];
		if (powerup.lastY === undefined) powerup.lastY = powerup.y;
		if (powerup.lastIntersecting === undefined) powerup.lastIntersecting = false;
		powerup.update();
		// Check for catch
		var intersecting = powerup.intersects(basket);
		if (!powerup.lastIntersecting && intersecting) {
			if (powerup.type === "shield" || powerup instanceof ShieldPowerUp) {
				// Caught shield: activate shield
				basket.hasShield = true;
				// Visual feedback: blue flash and basket glow
				LK.effects.flashObject(basket, 0x00ffff, 400);
				LK.effects.flashScreen(0x00ffff, 200);
				// Add a neon blue outline to basket (simulate with a pulsing alpha tween)
				if (!basket.shieldTween) {
					basket.shieldTween = tween(basket, {
						alpha: 1
					}, {
						duration: 200,
						yoyo: true,
						repeat: Infinity,
						easing: tween.easeInOut
					});
				}
				// Show shield icon (optional: could add a small blue ball above basket)
				// Animate power-up to basket and fade out
				tween(powerup, {
					y: basket.y,
					alpha: 0
				}, {
					duration: 200,
					easing: tween.easeIn,
					onFinish: function onFinish() {
						powerup.destroy();
					}
				});
				powerups.splice(k, 1);
				continue;
			} else {
				// Caught score power-up: double points!
				LK.setScore(LK.getScore() + 2);
				scoreTxt.setText(LK.getScore());
				LK.getSound('catch').play();
				// Flash screen with a bright gold
				LK.effects.flashScreen(0xFFD700, 350);
				// Animate power-up to basket and fade out
				LK.effects.flashObject(basket, 0xFFD700, 300);
				tween(powerup, {
					y: basket.y,
					alpha: 0
				}, {
					duration: 200,
					easing: tween.easeIn,
					onFinish: function onFinish() {
						powerup.destroy();
					}
				});
				powerups.splice(k, 1);
				continue;
			}
		}
		// Off screen (cleanup)
		if (powerup.y > 2800) {
			powerup.destroy();
			powerups.splice(k, 1);
			continue;
		}
		powerup.lastY = powerup.y;
		powerup.lastIntersecting = intersecting;
	}
	// Hide miss text after a short time
	if (missTxt.visible) {
		if (!missTxt.hideTimeout) {
			missTxt.hideTimeout = LK.setTimeout(function () {
				missTxt.visible = false;
				missTxt.hideTimeout = null;
			}, 900);
		}
	}
	// Draw shield icon above basket if shield is active
	if (basket.hasShield) {
		if (!basket.shieldIcon) {
			basket.shieldIcon = LK.getAsset('ball', {
				anchorX: 0.5,
				anchorY: 0.5
			});
			basket.shieldIcon.tint = 0x00ffff;
			basket.shieldIcon.scaleX = 0.5;
			basket.shieldIcon.scaleY = 0.5;
			game.addChild(basket.shieldIcon);
		}
		basket.shieldIcon.x = basket.x;
		basket.shieldIcon.y = basket.y - 70;
		basket.shieldIcon.visible = true;
	} else if (basket.shieldIcon) {
		basket.shieldIcon.visible = false;
	}
};
// Reset state on new game
LK.on('gameStart', function () {
	// Remove all balls, bombs, and powerups
	for (var i = 0; i < balls.length; i++) balls[i].destroy();
	for (var j = 0; j < bombs.length; j++) bombs[j].destroy();
	for (var k = 0; k < powerups.length; k++) powerups[k].destroy();
	balls = [];
	bombs = [];
	powerups = [];
	basket.x = 2048 / 2;
	basket.y = 2732 - 180;
	// Reset shield state
	basket.hasShield = false;
	if (basket.shieldTween) {
		basket.shieldTween.stop();
		basket.shieldTween = null;
	}
	// Randomize basket color on new game
	var basketColors = [0x3b6eea, 0x4ad991, 0xf75e5e, 0xf7a325, 0xFFD700];
	if (basket.children && basket.children.length > 0) {
		basket.children[0].tint = basketColors[Math.floor(Math.random() * basketColors.length)];
	}
	LK.setScore(0);
	scoreTxt.setText('0');
	missTxt.setText('');
	missTxt.visible = false;
	if (missTxt.hideTimeout) {
		LK.clearTimeout(missTxt.hideTimeout);
		missTxt.hideTimeout = null;
	}
	spawnTimer = 0;
	gameOver = false;
});