/****
* Classes
****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Bubble class to represent each bubble in the game
var Bubble = Container.expand(function () {
var self = Container.call(this);
var bubbleGraphics = attachAsset('bubble', {
anchorX: 0.5,
anchorY: 0.5
});
// Randomize bubble position and speed
self.x = Math.random() * 2048;
self.y = 2732 + Math.random() * 500; // Start off-screen
self.speed = 2 + Math.random() * 3; // Random speed
// Update function to move the bubble upwards
self.update = function () {
self.y -= self.speed;
if (self.y < -100) {
self.resetPosition();
}
};
// Reset bubble position to the bottom of the screen
self.resetPosition = function () {
self.x = Math.random() * 2048;
self.y = 2732 + Math.random() * 500;
};
// Event handler for popping the bubble
self.down = function (x, y, obj) {
self.resetPosition();
LK.setScore(LK.getScore() + 1);
scoreTxt.setText(LK.getScore());
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x87CEEB // Light blue background
});
/****
* Game Code
****/
// Initialize score display
var scoreTxt = new Text2('0', {
size: 150,
fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Array to hold all bubbles
var bubbles = [];
// Create initial bubbles
for (var i = 0; i < 20; i++) {
var bubble = new Bubble();
bubbles.push(bubble);
game.addChild(bubble);
}
// Update function for the game
game.update = function () {
for (var i = 0; i < bubbles.length; i++) {
bubbles[i].update();
}
};
// Handle touch/mouse down events on the game
game.down = function (x, y, obj) {
for (var i = 0; i < bubbles.length; i++) {
if (bubbles[i].intersects(obj)) {
bubbles[i].down(x, y, obj);
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -1,75 +1,75 @@
-/****
+/****
* Classes
-****/
+****/
//<Assets used in the game will automatically appear here>
//<Write imports for supported plugins here>
// Bubble class to represent each bubble in the game
var Bubble = Container.expand(function () {
- var self = Container.call(this);
- var bubbleGraphics = self.attachAsset('bubble', {
- anchorX: 0.5,
- anchorY: 0.5
- });
- // Randomize bubble position and speed
- self.x = Math.random() * 2048;
- self.y = 2732 + Math.random() * 500; // Start off-screen
- self.speed = 2 + Math.random() * 3; // Random speed
- // Update function to move the bubble upwards
- self.update = function () {
- self.y -= self.speed;
- if (self.y < -100) {
- self.resetPosition();
- }
- };
- // Reset bubble position to the bottom of the screen
- self.resetPosition = function () {
- self.x = Math.random() * 2048;
- self.y = 2732 + Math.random() * 500;
- };
- // Event handler for popping the bubble
- self.down = function (x, y, obj) {
- self.resetPosition();
- LK.setScore(LK.getScore() + 1);
- scoreTxt.setText(LK.getScore());
- };
+ var self = Container.call(this);
+ var bubbleGraphics = attachAsset('bubble', {
+ anchorX: 0.5,
+ anchorY: 0.5
+ });
+ // Randomize bubble position and speed
+ self.x = Math.random() * 2048;
+ self.y = 2732 + Math.random() * 500; // Start off-screen
+ self.speed = 2 + Math.random() * 3; // Random speed
+ // Update function to move the bubble upwards
+ self.update = function () {
+ self.y -= self.speed;
+ if (self.y < -100) {
+ self.resetPosition();
+ }
+ };
+ // Reset bubble position to the bottom of the screen
+ self.resetPosition = function () {
+ self.x = Math.random() * 2048;
+ self.y = 2732 + Math.random() * 500;
+ };
+ // Event handler for popping the bubble
+ self.down = function (x, y, obj) {
+ self.resetPosition();
+ LK.setScore(LK.getScore() + 1);
+ scoreTxt.setText(LK.getScore());
+ };
});
-/****
+/****
* Initialize Game
-****/
+****/
var game = new LK.Game({
- backgroundColor: 0x87CEEB // Light blue background
+ backgroundColor: 0x87CEEB // Light blue background
});
-/****
+/****
* Game Code
-****/
+****/
// Initialize score display
var scoreTxt = new Text2('0', {
- size: 150,
- fill: 0xFFFFFF
+ size: 150,
+ fill: 0xFFFFFF
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Array to hold all bubbles
var bubbles = [];
// Create initial bubbles
for (var i = 0; i < 20; i++) {
- var bubble = new Bubble();
- bubbles.push(bubble);
- game.addChild(bubble);
+ var bubble = new Bubble();
+ bubbles.push(bubble);
+ game.addChild(bubble);
}
// Update function for the game
game.update = function () {
- for (var i = 0; i < bubbles.length; i++) {
- bubbles[i].update();
- }
+ for (var i = 0; i < bubbles.length; i++) {
+ bubbles[i].update();
+ }
};
// Handle touch/mouse down events on the game
game.down = function (x, y, obj) {
- for (var i = 0; i < bubbles.length; i++) {
- if (bubbles[i].intersects(obj)) {
- bubbles[i].down(x, y, obj);
- }
- }
+ for (var i = 0; i < bubbles.length; i++) {
+ if (bubbles[i].intersects(obj)) {
+ bubbles[i].down(x, y, obj);
+ }
+ }
};
\ No newline at end of file