/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Bubble = Container.expand(function () {
var self = Container.call(this);
// Set the color of the bubble to different shades of cyan
var colors = [0x00FFFF, 0x00E5EE, 0x00CED1, 0x00B2D2, 0x008B8B];
var color = colors[Math.floor(Math.random() * colors.length)];
// Create and attach the bubble graphic
var bubbleGraphic = self.attachAsset('bubble', {
anchorX: 0.5,
anchorY: 0.5,
tint: color
});
// Set random size (scale)
var scale = 0.5 + Math.random() * 1;
bubbleGraphic.scale.set(scale, scale);
// Set bubble properties
self.speed = 2 + Math.random() * 3; // Increase the speed range
self.active = true;
self.alpha = 0; // Start transparent
// Handle bubble tap/click
self.down = function (x, y, obj) {
if (self.active) {
self.popBubble();
}
};
// Pop the bubble
self.popBubble = function () {
// Prevent multiple pops
self.active = false;
// Play pop sound
LK.getSound('pop').play();
// Increment score
LK.setScore(LK.getScore() + 1);
// Create pop effect
var popEffect = LK.getAsset('bubblePop', {
anchorX: 0.5,
anchorY: 0.5,
x: bubbleGraphic.x,
y: bubbleGraphic.y,
alpha: 0.7,
tint: bubbleGraphic.tint
});
self.addChild(popEffect);
// Animate pop effect
tween(popEffect, {
alpha: 0,
scaleX: scale * 1.5,
scaleY: scale * 1.5
}, {
duration: 300,
onFinish: function onFinish() {
popEffect.destroy();
self.destroy();
}
});
// Hide original bubble immediately
bubbleGraphic.alpha = 0;
};
// Update bubble position
self.update = function () {
if (self.active) {
self.y -= self.speed;
// Fade in when first appearing
if (self.alpha < 1) {
self.alpha += 0.05;
}
// If bubble goes off screen, remove it
if (self.y < -200) {
self.destroy();
}
}
};
return self;
});
var RedBubble = Bubble.expand(function () {
var self = Bubble.call(this);
// Change the color of the bubble to red
self.attachAsset('bubble', {
anchorX: 0.5,
anchorY: 0.5,
tint: 0xFF0000
});
// Set bubble properties
self.speed = 5; // Increase the speed of red bubbles
self.active = true;
self.alpha = 0; // Start transparent
// Handle bubble tap/click
self.down = function (x, y, obj) {
if (self.active) {
self.popBubble();
}
};
// Update bubble position
self.update = function () {
if (self.active) {
self.y -= self.speed;
// Fade in when first appearing
if (self.alpha < 1) {
self.alpha += 0.05;
}
// If bubble goes off screen, remove it and end the game
if (self.y < -200) {
self.destroy();
LK.showGameOver();
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Set up game variables
var bubbles = [];
var lastBubbleTime = 0;
var bubbleInterval = 500; // ms between bubble spawns
var maxBubbles = 10; // Maximum number of bubbles on screen
var gradientColors = [0x87CEEB, 0x1E90FF]; // Sky blue gradient
// Set up score display
var scoreTxt = new Text2('0', {
size: 100,
fill: 0x000000
});
scoreTxt.anchor.set(0.5, 0);
scoreTxt.alpha = 0.7; // Make it slightly transparent for zen feel
LK.gui.top.addChild(scoreTxt);
// Create a "Bubbles Popped" label
var labelTxt = new Text2('Bubbles Popped', {
size: 40,
fill: 0xFFFFFF
});
labelTxt.anchor.set(0.5, 1);
labelTxt.alpha = 0.7;
labelTxt.y = -10; // Position it above the score
LK.gui.top.addChild(labelTxt);
// Play ambient music
LK.playMusic('ambientMusic', {
fade: {
start: 0,
end: 0.5,
duration: 2000
}
});
// Create a new bubble
function createBubble() {
// Don't create more bubbles if we're at the maximum
if (bubbles.length >= maxBubbles) {
return;
}
var bubble = new Bubble();
// Position bubble randomly along the bottom of the screen
bubble.x = Math.random() * 2048;
bubble.y = 2732 + 100; // Start below the screen
// Add to game and tracking array
game.addChild(bubble);
bubbles.push(bubble);
}
// Main game update loop
game.update = function () {
// Update time tracking for bubble creation
var currentTime = Date.now();
// Create new bubbles at the defined interval
if (currentTime - lastBubbleTime > bubbleInterval) {
createBubble();
lastBubbleTime = currentTime;
}
// Create a red bubble every 1 minute
if (currentTime - lastBubbleTime > 60000) {
var redBubble = new RedBubble();
// Position bubble randomly along the bottom of the screen
redBubble.x = Math.random() * 2048;
redBubble.y = 2732 + 100; // Start below the screen
// Add to game and tracking array
game.addChild(redBubble);
bubbles.push(redBubble);
lastBubbleTime = currentTime;
}
// Clean up destroyed bubbles from the array
for (var i = bubbles.length - 1; i >= 0; i--) {
if (!bubbles[i].parent) {
bubbles.splice(i, 1);
}
}
// Update score display
scoreTxt.setText(LK.getScore());
};
// Handle tap/click anywhere on the game (for bubbles that might be missed by direct targeting)
game.down = function (x, y, obj) {
// This is handled by each bubble individually
};
// Create initial bubbles
for (var i = 0; i < 5; i++) {
LK.setTimeout(function () {
createBubble();
}, i * 300);
} /****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
var storage = LK.import("@upit/storage.v1");
/****
* Classes
****/
var Bubble = Container.expand(function () {
var self = Container.call(this);
// Set the color of the bubble to different shades of cyan
var colors = [0x00FFFF, 0x00E5EE, 0x00CED1, 0x00B2D2, 0x008B8B];
var color = colors[Math.floor(Math.random() * colors.length)];
// Create and attach the bubble graphic
var bubbleGraphic = self.attachAsset('bubble', {
anchorX: 0.5,
anchorY: 0.5,
tint: color
});
// Set random size (scale)
var scale = 0.5 + Math.random() * 1;
bubbleGraphic.scale.set(scale, scale);
// Set bubble properties
self.speed = 2 + Math.random() * 3; // Increase the speed range
self.active = true;
self.alpha = 0; // Start transparent
// Handle bubble tap/click
self.down = function (x, y, obj) {
if (self.active) {
self.popBubble();
}
};
// Pop the bubble
self.popBubble = function () {
// Prevent multiple pops
self.active = false;
// Play pop sound
LK.getSound('pop').play();
// Increment score
LK.setScore(LK.getScore() + 1);
// Create pop effect
var popEffect = LK.getAsset('bubblePop', {
anchorX: 0.5,
anchorY: 0.5,
x: bubbleGraphic.x,
y: bubbleGraphic.y,
alpha: 0.7,
tint: bubbleGraphic.tint
});
self.addChild(popEffect);
// Animate pop effect
tween(popEffect, {
alpha: 0,
scaleX: scale * 1.5,
scaleY: scale * 1.5
}, {
duration: 300,
onFinish: function onFinish() {
popEffect.destroy();
self.destroy();
}
});
// Hide original bubble immediately
bubbleGraphic.alpha = 0;
};
// Update bubble position
self.update = function () {
if (self.active) {
self.y -= self.speed;
// Fade in when first appearing
if (self.alpha < 1) {
self.alpha += 0.05;
}
// If bubble goes off screen, remove it
if (self.y < -200) {
self.destroy();
}
}
};
return self;
});
var RedBubble = Bubble.expand(function () {
var self = Bubble.call(this);
// Change the color of the bubble to red
self.attachAsset('bubble', {
anchorX: 0.5,
anchorY: 0.5,
tint: 0xFF0000
});
// Set bubble properties
self.speed = 5; // Increase the speed of red bubbles
self.active = true;
self.alpha = 0; // Start transparent
// Handle bubble tap/click
self.down = function (x, y, obj) {
if (self.active) {
self.popBubble();
}
};
// Update bubble position
self.update = function () {
if (self.active) {
self.y -= self.speed;
// Fade in when first appearing
if (self.alpha < 1) {
self.alpha += 0.05;
}
// If bubble goes off screen, remove it and end the game
if (self.y < -200) {
self.destroy();
LK.showGameOver();
}
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB
});
/****
* Game Code
****/
// Set up game variables
var bubbles = [];
var lastBubbleTime = 0;
var bubbleInterval = 500; // ms between bubble spawns
var maxBubbles = 10; // Maximum number of bubbles on screen
var gradientColors = [0x87CEEB, 0x1E90FF]; // Sky blue gradient
// Set up score display
var scoreTxt = new Text2('0', {
size: 100,
fill: 0x000000
});
scoreTxt.anchor.set(0.5, 0);
scoreTxt.alpha = 0.7; // Make it slightly transparent for zen feel
LK.gui.top.addChild(scoreTxt);
// Create a "Bubbles Popped" label
var labelTxt = new Text2('Bubbles Popped', {
size: 40,
fill: 0xFFFFFF
});
labelTxt.anchor.set(0.5, 1);
labelTxt.alpha = 0.7;
labelTxt.y = -10; // Position it above the score
LK.gui.top.addChild(labelTxt);
// Play ambient music
LK.playMusic('ambientMusic', {
fade: {
start: 0,
end: 0.5,
duration: 2000
}
});
// Create a new bubble
function createBubble() {
// Don't create more bubbles if we're at the maximum
if (bubbles.length >= maxBubbles) {
return;
}
var bubble = new Bubble();
// Position bubble randomly along the bottom of the screen
bubble.x = Math.random() * 2048;
bubble.y = 2732 + 100; // Start below the screen
// Add to game and tracking array
game.addChild(bubble);
bubbles.push(bubble);
}
// Main game update loop
game.update = function () {
// Update time tracking for bubble creation
var currentTime = Date.now();
// Create new bubbles at the defined interval
if (currentTime - lastBubbleTime > bubbleInterval) {
createBubble();
lastBubbleTime = currentTime;
}
// Create a red bubble every 1 minute
if (currentTime - lastBubbleTime > 60000) {
var redBubble = new RedBubble();
// Position bubble randomly along the bottom of the screen
redBubble.x = Math.random() * 2048;
redBubble.y = 2732 + 100; // Start below the screen
// Add to game and tracking array
game.addChild(redBubble);
bubbles.push(redBubble);
lastBubbleTime = currentTime;
}
// Clean up destroyed bubbles from the array
for (var i = bubbles.length - 1; i >= 0; i--) {
if (!bubbles[i].parent) {
bubbles.splice(i, 1);
}
}
// Update score display
scoreTxt.setText(LK.getScore());
};
// Handle tap/click anywhere on the game (for bubbles that might be missed by direct targeting)
game.down = function (x, y, obj) {
// This is handled by each bubble individually
};
// Create initial bubbles
for (var i = 0; i < 5; i++) {
LK.setTimeout(function () {
createBubble();
}, i * 300);
}