User prompt
Play the lse sound when the red bubble is popped
User prompt
When the red bubble is tapped play the lose sound effect
User prompt
Make sure the bubble pop sound plays right after the bubble is tapped
User prompt
When the player gets a game over the background music stops
User prompt
When the red bubble is popped play the lose sound effect
User prompt
When the player receives the game over message play the lose sound effect
User prompt
Make sure the background music plays
User prompt
Make sure when the red bubble is taped the player will lose
User prompt
Insert the bubble sprites
User prompt
Make sure the bubbles show up on screen when the game starts
User prompt
Ensure that the bubbles appear correctly
User prompt
The game really begins with the screen is clicked
User prompt
Make several bubbles appear on screen most are blue but one red bubble
User prompt
Bubble Trouble: Pop the Blues
Initial prompt
Several bubbles will appear on screen most of them blue except for one the non blue bubble will be red the player must pop the blue bubbles but if they pop the red bubble the player loses
/**** * Classes ****/ var Bubble = Container.expand(function () { var self = Container.call(this); self.isRed = false; self.speed = { x: 0, y: 0 }; self.bubbleGraphics = null; self.setup = function (isRed) { self.isRed = isRed; // Choose asset based on bubble type var assetId = isRed ? 'R0' : 'B0'; self.bubbleGraphics = self.attachAsset(assetId, { anchorX: 0.5, anchorY: 0.5, scaleX: 1.5, scaleY: 1.5 }); // Set random speed self.speed = { x: Math.random() * 4 - 2, y: Math.random() * 4 - 2 }; }; self.update = function () { // Move bubble self.x += self.speed.x; self.y += self.speed.y; // Bounce off walls if (self.x < 0 || self.x > 2048) { self.speed.x *= -1; } if (self.y < 0 || self.y > 2732) { self.speed.y *= -1; } }; // Handle tap/click on bubble self.down = function (x, y, obj) { if (self.isRed) { // Game over if red bubble is tapped LK.getSound('De').play(); LK.effects.flashScreen(0xff0000, 500); LK.showGameOver(); return; } LK.getSound('Bubpop').play(); // Increase score if blue bubble is popped LK.setScore(LK.getScore() + 1); scoreTxt.setText(LK.getScore()); // Remove this bubble self.destroy(); // Find and remove from bubbles array var index = bubbles.indexOf(self); if (index > -1) { bubbles.splice(index, 1); } // If all blue bubbles are popped, create a new wave if (bubbles.length === 1 && bubbles[0].isRed) { createBubbleWave(); } }; return self; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ game.setBackgroundColor(0x87CEEB); // Light blue background // Track game state var gameStarted = false; // Array to hold all bubble instances var bubbles = []; // Create score text var scoreTxt = new Text2('0', { size: 100, fill: 0xFFFFFF }); scoreTxt.anchor.set(0.5, 0); LK.gui.top.addChild(scoreTxt); // Create welcome message var welcomeTxt = new Text2('Tap to Start', { size: 120, fill: 0xFFFFFF }); welcomeTxt.anchor.set(0.5, 0.5); LK.gui.center.addChild(welcomeTxt); // Function to create a new wave of bubbles function createBubbleWave() { // Clear existing bubbles if any for (var i = bubbles.length - 1; i >= 0; i--) { bubbles[i].destroy(); } bubbles = []; // Determine number of bubbles based on score var numBubbles = Math.min(5 + Math.floor(LK.getScore() / 5), 20); // Helper to avoid overlapping bubbles at spawn function getNonOverlappingPosition(existingBubbles, radius) { var maxTries = 100; for (var t = 0; t < maxTries; t++) { var x = Math.random() * (2048 - 2 * radius - 100) + radius + 50; var y = Math.random() * (2732 - 2 * radius - 100) + radius + 50; var overlap = false; for (var j = 0; j < existingBubbles.length; j++) { var dx = x - existingBubbles[j].x; var dy = y - existingBubbles[j].y; var dist = Math.sqrt(dx * dx + dy * dy); if (dist < radius * 2 + 10) { // 10px buffer overlap = true; break; } } if (!overlap) return { x: x, y: y }; } // fallback: just return a random position return { x: Math.random() * (2048 - 2 * radius - 100) + radius + 50, y: Math.random() * (2732 - 2 * radius - 100) + radius + 50 }; } // Get bubble radius from asset size (assuming all bubbles same size) var tempBubble = new Bubble(); tempBubble.setup(false); var bubbleRadius = tempBubble.bubbleGraphics.width * 1.5 / 2; tempBubble.destroy(); // Create blue bubbles for (var i = 0; i < numBubbles - 1; i++) { var bubble = new Bubble(); bubble.setup(false); // false = blue bubble var pos = getNonOverlappingPosition(bubbles, bubbleRadius); bubble.x = pos.x; bubble.y = pos.y; game.addChild(bubble); bubbles.push(bubble); } // Create one red bubble var redBubble = new Bubble(); redBubble.setup(true); // true = red bubble var posRed = getNonOverlappingPosition(bubbles, bubbleRadius); redBubble.x = posRed.x; redBubble.y = posRed.y; game.addChild(redBubble); bubbles.push(redBubble); } // Update game every frame game.update = function () { // Only update and create bubbles if game has started if (gameStarted) { // Update all bubbles for (var i = 0; i < bubbles.length; i++) { bubbles[i].update(); } // Create bubbles if none exist if (bubbles.length === 0) { createBubbleWave(); } } // Play lose sound effect when game over message is shown if (typeof LK !== "undefined" && typeof LK.isGameOver === "function" && LK.isGameOver()) { if (!game._loseSoundPlayed) { LK.getSound('De').play(); LK.stopMusic(); game._loseSoundPlayed = true; } } else { game._loseSoundPlayed = false; } }; // Create instructions text var instructionsTxt = new Text2('Pop the BLUE bubbles\nAvoid the RED one!', { size: 80, fill: 0xFFFFFF }); instructionsTxt.anchor.set(0.5, 1); LK.gui.bottom.addChild(instructionsTxt); // Hide instructions until game starts instructionsTxt.alpha = 0; // Add click event to start game game.down = function (x, y, obj) { if (!gameStarted) { gameStarted = true; welcomeTxt.alpha = 0; instructionsTxt.alpha = 1; // Play background music LK.playMusic('Jb'); // Start the game createBubbleWave(); // Hide instructions after 3 seconds LK.setTimeout(function () { instructionsTxt.alpha = 0; }, 3000); } };
===================================================================
--- original.js
+++ change.js
@@ -171,8 +171,9 @@
// Play lose sound effect when game over message is shown
if (typeof LK !== "undefined" && typeof LK.isGameOver === "function" && LK.isGameOver()) {
if (!game._loseSoundPlayed) {
LK.getSound('De').play();
+ LK.stopMusic();
game._loseSoundPlayed = true;
}
} else {
game._loseSoundPlayed = false;