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, scale: 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) { LK.getSound('Bubpop').play(); if (self.isRed) { // Game over if red bubble is popped LK.effects.flashScreen(0xff0000, 500); LK.showGameOver(); } else { // 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); // Create blue bubbles for (var i = 0; i < numBubbles - 1; i++) { var bubble = new Bubble(); bubble.setup(false); // false = blue bubble // Random position on screen bubble.x = Math.random() * 1848 + 100; // Keep away from edges bubble.y = Math.random() * 2532 + 100; // Keep away from edges game.addChild(bubble); bubbles.push(bubble); } // Create one red bubble var redBubble = new Bubble(); redBubble.setup(true); // true = red bubble // Random position on screen redBubble.x = Math.random() * 1848 + 100; // Keep away from edges redBubble.y = Math.random() * 2532 + 100; // Keep away from edges game.addChild(redBubble); bubbles.push(redBubble); } // Update game every frame game.update = function () { // Update all bubbles for (var i = 0; i < bubbles.length; i++) { bubbles[i].update(); } // Only create bubbles if game has started if (gameStarted && bubbles.length === 0) { createBubbleWave(); } }; // 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; // Start the game createBubbleWave(); // Hide instructions after 3 seconds LK.setTimeout(function () { instructionsTxt.alpha = 0; }, 3000); } };
===================================================================
--- original.js
+++ change.js
@@ -73,8 +73,10 @@
/****
* 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', {
@@ -82,8 +84,15 @@
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--) {
@@ -116,10 +125,10 @@
// Update all bubbles
for (var i = 0; i < bubbles.length; i++) {
bubbles[i].update();
}
- // Create initial wave of bubbles on first frame
- if (LK.ticks === 1) {
+ // Only create bubbles if game has started
+ if (gameStarted && bubbles.length === 0) {
createBubbleWave();
}
};
// Create instructions text
@@ -128,8 +137,20 @@
fill: 0xFFFFFF
});
instructionsTxt.anchor.set(0.5, 1);
LK.gui.bottom.addChild(instructionsTxt);
-// Hide instructions after 3 seconds
-LK.setTimeout(function () {
- instructionsTxt.alpha = 0;
-}, 3000);
\ No newline at end of file
+// 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;
+ // Start the game
+ createBubbleWave();
+ // Hide instructions after 3 seconds
+ LK.setTimeout(function () {
+ instructionsTxt.alpha = 0;
+ }, 3000);
+ }
+};
\ No newline at end of file