/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ var Bubble = Container.expand(function (bubbleType) { var self = Container.call(this); self.bubbleType = bubbleType || 'blue'; self.pointValue = 20; self.speed = 4; self.isGolden = false; // Set properties based on bubble type var assetId = 'basketball'; switch (self.bubbleType) { case 'red': assetId = 'redBasketball'; self.pointValue = 10; self.speed = 5; break; case 'blue': assetId = 'basketball'; self.pointValue = 20; self.speed = 4; break; case 'green': assetId = 'greenBasketball'; self.pointValue = 50; self.speed = 3; break; case 'golden': assetId = 'goldenBasketball'; self.pointValue = 100; self.speed = 8; self.isGolden = true; break; } var bubbleGraphics = self.attachAsset(assetId, { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { self.y -= self.speed * gameSpeedMultiplier; // Add subtle floating animation self.x += Math.sin(LK.ticks * 0.02 + self.y * 0.01) * 0.5; }; self.down = function (x, y, obj) { self.pop(); }; self.pop = function () { // Add to score var scoreToAdd = self.pointValue; if (streakMultiplier > 1) { scoreToAdd = Math.floor(scoreToAdd * streakMultiplier); } LK.setScore(LK.getScore() + scoreToAdd); // Update streak streakCount++; if (streakCount >= 5) { streakMultiplier = Math.min(streakMultiplier + 0.5, 3); } // Play sound if (self.isGolden) { LK.getSound('swish').play(); } else { LK.getSound('bounce').play(); } // Pop animation tween(self, { scaleX: 1.5, scaleY: 1.5, alpha: 0 }, { duration: 200, easing: tween.easeOut, onFinish: function onFinish() { self.destroy(); } }); // Remove from bubbles array for (var i = bubbles.length - 1; i >= 0; i--) { if (bubbles[i] === self) { bubbles.splice(i, 1); break; } } // Flash effect LK.effects.flashObject(self, 0xFFFFFF, 150); }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x001122 }); /**** * Game Code ****/ var bubbles = []; var escapedBubbles = 0; var maxEscapedBubbles = 10; var gameSpeedMultiplier = 1; var spawnRate = 60; // Spawn every 60 ticks for fewer basketballs var streakCount = 0; var streakMultiplier = 1; var gameTime = 0; var difficultyTimer = 0; // UI Elements var scoreTxt = new Text2('0', { size: 80, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); var escapedTxt = new Text2('Escaped: 0/' + maxEscapedBubbles, { size: 50, fill: 0xFF6666 }); escapedTxt.anchor.set(0, 0); escapedTxt.x = 150; escapedTxt.y = 50; LK.gui.topLeft.addChild(escapedTxt); var multiplierTxt = new Text2('', { size: 40, fill: 0xFFFF00 }); multiplierTxt.anchor.set(1, 0); multiplierTxt.y = 50; LK.gui.topRight.addChild(multiplierTxt); // Spawn bubble function function spawnBubble() { var bubbleType = 'blue'; var rand = Math.random(); if (rand < 0.15) { bubbleType = 'golden'; } else if (rand < 0.3) { bubbleType = 'green'; } else if (rand < 0.6) { bubbleType = 'red'; } var bubble = new Bubble(bubbleType); bubble.x = Math.random() * (2048 - 200) + 100; bubble.y = 2732 + 100; bubbles.push(bubble); game.addChild(bubble); } // Handle missed bubbles function handleMissedBubble() { escapedBubbles++; streakCount = 0; streakMultiplier = 1; if (escapedBubbles >= maxEscapedBubbles) { LK.effects.flashScreen(0xFF0000, 1000); LK.showGameOver(); } } // Update difficulty function updateDifficulty() { difficultyTimer++; // Increase difficulty every 10 seconds (600 ticks) if (difficultyTimer % 600 === 0) { gameSpeedMultiplier += 0.2; spawnRate = Math.max(spawnRate - 3, 45); // Flash screen to indicate difficulty increase LK.effects.flashScreen(0x00FFFF, 300); } } game.update = function () { gameTime++; // Update difficulty updateDifficulty(); // Spawn new bubbles if (gameTime % spawnRate === 0) { spawnBubble(); } // Update bubbles and check for escaped ones for (var i = bubbles.length - 1; i >= 0; i--) { var bubble = bubbles[i]; // Check if bubble escaped if (bubble.y < -100) { handleMissedBubble(); bubble.destroy(); bubbles.splice(i, 1); } } // Update UI scoreTxt.setText(LK.getScore()); escapedTxt.setText('Escaped: ' + escapedBubbles + '/' + maxEscapedBubbles); if (streakMultiplier > 1) { multiplierTxt.setText('x' + streakMultiplier.toFixed(1)); } else { multiplierTxt.setText(''); } }; // Start background music LK.playMusic('bgmusic'); // Initial bubble spawn for (var i = 0; i < 3; i++) { LK.setTimeout(function () { spawnBubble(); }, i * 100); }
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Bubble = Container.expand(function (bubbleType) {
var self = Container.call(this);
self.bubbleType = bubbleType || 'blue';
self.pointValue = 20;
self.speed = 4;
self.isGolden = false;
// Set properties based on bubble type
var assetId = 'basketball';
switch (self.bubbleType) {
case 'red':
assetId = 'redBasketball';
self.pointValue = 10;
self.speed = 5;
break;
case 'blue':
assetId = 'basketball';
self.pointValue = 20;
self.speed = 4;
break;
case 'green':
assetId = 'greenBasketball';
self.pointValue = 50;
self.speed = 3;
break;
case 'golden':
assetId = 'goldenBasketball';
self.pointValue = 100;
self.speed = 8;
self.isGolden = true;
break;
}
var bubbleGraphics = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
self.y -= self.speed * gameSpeedMultiplier;
// Add subtle floating animation
self.x += Math.sin(LK.ticks * 0.02 + self.y * 0.01) * 0.5;
};
self.down = function (x, y, obj) {
self.pop();
};
self.pop = function () {
// Add to score
var scoreToAdd = self.pointValue;
if (streakMultiplier > 1) {
scoreToAdd = Math.floor(scoreToAdd * streakMultiplier);
}
LK.setScore(LK.getScore() + scoreToAdd);
// Update streak
streakCount++;
if (streakCount >= 5) {
streakMultiplier = Math.min(streakMultiplier + 0.5, 3);
}
// Play sound
if (self.isGolden) {
LK.getSound('swish').play();
} else {
LK.getSound('bounce').play();
}
// Pop animation
tween(self, {
scaleX: 1.5,
scaleY: 1.5,
alpha: 0
}, {
duration: 200,
easing: tween.easeOut,
onFinish: function onFinish() {
self.destroy();
}
});
// Remove from bubbles array
for (var i = bubbles.length - 1; i >= 0; i--) {
if (bubbles[i] === self) {
bubbles.splice(i, 1);
break;
}
}
// Flash effect
LK.effects.flashObject(self, 0xFFFFFF, 150);
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x001122
});
/****
* Game Code
****/
var bubbles = [];
var escapedBubbles = 0;
var maxEscapedBubbles = 10;
var gameSpeedMultiplier = 1;
var spawnRate = 60; // Spawn every 60 ticks for fewer basketballs
var streakCount = 0;
var streakMultiplier = 1;
var gameTime = 0;
var difficultyTimer = 0;
// UI Elements
var scoreTxt = new Text2('0', {
size: 80,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var escapedTxt = new Text2('Escaped: 0/' + maxEscapedBubbles, {
size: 50,
fill: 0xFF6666
});
escapedTxt.anchor.set(0, 0);
escapedTxt.x = 150;
escapedTxt.y = 50;
LK.gui.topLeft.addChild(escapedTxt);
var multiplierTxt = new Text2('', {
size: 40,
fill: 0xFFFF00
});
multiplierTxt.anchor.set(1, 0);
multiplierTxt.y = 50;
LK.gui.topRight.addChild(multiplierTxt);
// Spawn bubble function
function spawnBubble() {
var bubbleType = 'blue';
var rand = Math.random();
if (rand < 0.15) {
bubbleType = 'golden';
} else if (rand < 0.3) {
bubbleType = 'green';
} else if (rand < 0.6) {
bubbleType = 'red';
}
var bubble = new Bubble(bubbleType);
bubble.x = Math.random() * (2048 - 200) + 100;
bubble.y = 2732 + 100;
bubbles.push(bubble);
game.addChild(bubble);
}
// Handle missed bubbles
function handleMissedBubble() {
escapedBubbles++;
streakCount = 0;
streakMultiplier = 1;
if (escapedBubbles >= maxEscapedBubbles) {
LK.effects.flashScreen(0xFF0000, 1000);
LK.showGameOver();
}
}
// Update difficulty
function updateDifficulty() {
difficultyTimer++;
// Increase difficulty every 10 seconds (600 ticks)
if (difficultyTimer % 600 === 0) {
gameSpeedMultiplier += 0.2;
spawnRate = Math.max(spawnRate - 3, 45);
// Flash screen to indicate difficulty increase
LK.effects.flashScreen(0x00FFFF, 300);
}
}
game.update = function () {
gameTime++;
// Update difficulty
updateDifficulty();
// Spawn new bubbles
if (gameTime % spawnRate === 0) {
spawnBubble();
}
// Update bubbles and check for escaped ones
for (var i = bubbles.length - 1; i >= 0; i--) {
var bubble = bubbles[i];
// Check if bubble escaped
if (bubble.y < -100) {
handleMissedBubble();
bubble.destroy();
bubbles.splice(i, 1);
}
}
// Update UI
scoreTxt.setText(LK.getScore());
escapedTxt.setText('Escaped: ' + escapedBubbles + '/' + maxEscapedBubbles);
if (streakMultiplier > 1) {
multiplierTxt.setText('x' + streakMultiplier.toFixed(1));
} else {
multiplierTxt.setText('');
}
};
// Start background music
LK.playMusic('bgmusic');
// Initial bubble spawn
for (var i = 0; i < 3; i++) {
LK.setTimeout(function () {
spawnBubble();
}, i * 100);
}