/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
var Bubble = Container.expand(function (bubbleType, points) {
var self = Container.call(this);
// Store bubble properties
self.bubbleType = bubbleType || 'normal';
self.points = points || 10;
self.maxLifetime = 4000; // 4 seconds
self.lifetime = 0;
self.isPopped = false;
// Create bubble graphics based on type
var assetId = 'bubble';
if (self.bubbleType === 'penalty') {
assetId = 'penaltyBubble';
} else if (self.bubbleType === 'golden') {
assetId = 'goldenBubble';
}
var bubbleGraphics = self.attachAsset(assetId, {
anchorX: 0.5,
anchorY: 0.5
});
// Add point text
var pointText = new Text2(self.points.toString(), {
size: 40,
fill: 0xFFFFFF
});
pointText.anchor.set(0.5, 0.5);
self.addChild(pointText);
// Set initial scale
self.scaleX = 1.0;
self.scaleY = 1.0;
self.update = function () {
if (self.isPopped) {
return;
}
self.lifetime += 16; // Approximately 60 FPS
// Calculate shrink factor based on lifetime
var shrinkFactor = 1.0 - self.lifetime / self.maxLifetime;
shrinkFactor = Math.max(0.3, shrinkFactor); // Don't shrink below 30%
self.scaleX = shrinkFactor;
self.scaleY = shrinkFactor;
// Fade out as it gets smaller
self.alpha = Math.max(0.4, shrinkFactor);
// Mark for removal if lifetime exceeded
if (self.lifetime >= self.maxLifetime) {
self.isPopped = true;
}
};
self.pop = function () {
if (self.isPopped) {
return false;
}
self.isPopped = true;
// Play appropriate sound
if (self.bubbleType === 'penalty') {
LK.getSound('penalty').play();
} else if (self.bubbleType === 'golden') {
LK.getSound('bonus').play();
} else {
LK.getSound('pop').play();
}
// Pop animation
tween(self, {
scaleX: 1.5,
scaleY: 1.5,
alpha: 0
}, {
duration: 200,
easing: tween.easeOut
});
return true;
};
self.down = function (x, y, obj) {
if (self.pop()) {
// Update score based on bubble type
if (self.bubbleType === 'penalty') {
currentScore = Math.max(0, currentScore - Math.abs(self.points));
penaltyCount++;
} else {
currentScore += self.points;
}
LK.setScore(currentScore);
updateScoreDisplay();
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2c3e50
});
/****
* Game Code
****/
// Add background image
var backgroundImage = game.attachAsset('Background', {
x: 0,
y: 0,
scaleX: 20.48,
// Scale to fit 2048 width (2048/100)
scaleY: 27.32 // Scale to fit 2732 height (2732/100)
});
// Bubble shapes for the game
// Sound effects
//Minimalistic tween library which should be used for animations over time, including tinting / colouring an object, scaling, rotating, or changing any game object property.
var bubbles = [];
var currentScore = 0;
var penaltyCount = 0;
var spawnTimer = 0;
var spawnInterval = 120; // Start spawning every 2 seconds at 60 FPS
var gameSpeed = 1;
// UI Elements
var scoreTxt = new Text2('Score: 0', {
size: 60,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
var gameOverTxt = new Text2('', {
size: 80,
fill: 0xFF0000
});
gameOverTxt.anchor.set(0.5, 0.5);
gameOverTxt.visible = false;
LK.gui.center.addChild(gameOverTxt);
function updateScoreDisplay() {
scoreTxt.setText('Score: ' + currentScore);
}
function getRandomBubbleType() {
var rand = Math.random();
if (rand < 0.15) {
// 15% chance for penalty
return 'penalty';
} else if (rand < 0.20) {
// 5% chance for golden
return 'golden';
} else {
return 'normal';
}
}
function getBubblePoints(type) {
switch (type) {
case 'penalty':
return -20;
case 'golden':
return 50;
case 'normal':
default:
return Math.floor(Math.random() * 20) + 10;
// 10-29 points
}
}
function spawnBubble() {
var bubbleType = getRandomBubbleType();
var points = getBubblePoints(bubbleType);
var bubble = new Bubble(bubbleType, points);
// Random position with margins
var margin = 100;
bubble.x = margin + Math.random() * (2048 - 2 * margin);
bubble.y = margin + Math.random() * (2732 - 2 * margin);
bubbles.push(bubble);
game.addChild(bubble);
}
function updateGameSpeed() {
// Increase speed based on score
gameSpeed = 1 + currentScore / 500;
spawnInterval = Math.max(30, 120 / gameSpeed); // Minimum 0.5 seconds between spawns
}
function checkGameOver() {
if (penaltyCount >= 5) {
gameOverTxt.setText('Game Over!\nToo many penalties!');
gameOverTxt.visible = true;
// Flash screen red
LK.effects.flashScreen(0xff0000, 1000);
// Show game over after delay
LK.setTimeout(function () {
LK.showGameOver();
}, 2000);
return true;
}
return false;
}
game.update = function () {
if (checkGameOver()) {
return;
}
// Update spawn timer
spawnTimer++;
if (spawnTimer >= spawnInterval) {
spawnBubble();
spawnTimer = 0;
}
// Update and clean up bubbles
for (var i = bubbles.length - 1; i >= 0; i--) {
var bubble = bubbles[i];
if (bubble.isPopped || bubble.lifetime >= bubble.maxLifetime) {
// Remove bubble that wasn't popped in time (missed opportunity)
if (bubble.lifetime >= bubble.maxLifetime && !bubble.isPopped && bubble.bubbleType !== 'penalty') {
// Small penalty for missing good bubbles
// This encourages active play
}
bubble.destroy();
bubbles.splice(i, 1);
}
}
// Update game speed based on score
updateGameSpeed();
// Spawn golden bubbles occasionally at higher scores
if (currentScore > 200 && Math.random() < 0.002) {
var goldenBubble = new Bubble('golden', 100);
goldenBubble.x = 200 + Math.random() * (2048 - 400);
goldenBubble.y = 200 + Math.random() * (2732 - 400);
bubbles.push(goldenBubble);
game.addChild(goldenBubble);
}
};
// Initialize first bubbles
for (var i = 0; i < 3; i++) {
LK.setTimeout(function () {
spawnBubble();
}, i * 500);
} ===================================================================
--- original.js
+++ change.js
@@ -101,11 +101,19 @@
/****
* Game Code
****/
-//Minimalistic tween library which should be used for animations over time, including tinting / colouring an object, scaling, rotating, or changing any game object property.
-// Sound effects
+// Add background image
+var backgroundImage = game.attachAsset('Background', {
+ x: 0,
+ y: 0,
+ scaleX: 20.48,
+ // Scale to fit 2048 width (2048/100)
+ scaleY: 27.32 // Scale to fit 2732 height (2732/100)
+});
// Bubble shapes for the game
+// Sound effects
+//Minimalistic tween library which should be used for animations over time, including tinting / colouring an object, scaling, rotating, or changing any game object property.
var bubbles = [];
var currentScore = 0;
var penaltyCount = 0;
var spawnTimer = 0;