User prompt
no the bubbles should also dissapear
User prompt
make a pop effect when you click the bubbles
User prompt
no need a shop gui then. you may remove it.
User prompt
Fix Bug: 'Uncaught ReferenceError: gui is not defined' in or related to this line: 'gui;' Line Number: 136
Code edit (1 edits merged)
Please save this source code
User prompt
put a gui to open shop
User prompt
there should also be a shop menu that has. auto click-5 points
User prompt
make it so if you click on the asset it will give you one point
User prompt
they keep disappearing... the balls should dissapear after 1 minute
User prompt
make then pop and give a point
User prompt
Fix Bug: 'TypeError: bubbles[i].containsPoint is not a function' in or related to this line: 'if (bubbles[i].containsPoint(pos)) {' Line Number: 76
User prompt
make me code that if you touch the blue squares they will disappear and give you a point
Initial prompt
bubble pop
/****
* Classes
****/
// Bubble class
var Bubble = Container.expand(function () {
var self = Container.call(this);
var bubbleGraphics = self.attachAsset('bubble', {
anchorX: 0.5,
anchorY: 0.5
});
// Set bubble properties
self.speed = Math.random() * 2 + 1; // Random speed between 1 and 3
self.direction = Math.random() * Math.PI * 2; // Random direction
// Move bubble
self.move = function () {
self.x += Math.cos(self.direction) * self.speed;
self.y += Math.sin(self.direction) * self.speed;
};
// Check if bubble is out of bounds
self.isOutOfBounds = function () {
return self.x < 0 || self.x > 2048 || self.y < 0 || self.y > 2732;
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x000000 // Init game with black background
});
/****
* Game Code
****/
// Initialize bubbles array
// Initialize bubble asset
var bubbles = [];
// Create a score text
var scoreTxt = new Text2('0', {
size: 150,
fill: "#ffffff"
});
scoreTxt.anchor.set(0.5, 0);
LK.gui.top.addChild(scoreTxt);
// Score variable
var score = 0;
// Function to update score
function updateScore(value) {
score += value;
scoreTxt.setText(score.toString());
}
// Function to create a new bubble
function createBubble() {
var bubble = new Bubble();
// Random position within the game area
bubble.x = Math.random() * 2048;
bubble.y = Math.random() * 2732;
bubbles.push(bubble);
game.addChild(bubble);
}
// Function to handle bubble popping
function popBubble(bubble, index) {
updateScore(1); // Increase score
bubble.destroy(); // Remove bubble from game
bubbles.splice(index, 1); // Remove bubble from array
}
// Touch event to check for bubble pops
game.on('down', function (obj) {
var pos = obj.event.getLocalPosition(game);
for (var i = bubbles.length - 1; i >= 0; i--) {
if (bubbles[i].containsPoint(pos)) {
popBubble(bubbles[i], i);
break; // Stop checking after the first pop
}
}
});
// Game tick event
LK.on('tick', function () {
// Move bubbles
for (var i = bubbles.length - 1; i >= 0; i--) {
bubbles[i].move();
// Check if bubble is out of bounds
if (bubbles[i].isOutOfBounds()) {
bubbles[i].destroy(); // Remove bubble from game
bubbles.splice(i, 1); // Remove bubble from array
}
}
// Create new bubble every 60 frames (1 second)
if (LK.ticks % 60 === 0) {
createBubble();
}
});