User prompt
For some reason the last bubbles, the super small ones, don't get destroyed when intersecting with the trail.
User prompt
Make sure the harpoon trail / line attached to it also pops bubbles. Do only necessary changes.
User prompt
Please remove the showDifficultyAnnouncement
User prompt
Please fix the bug: 'TypeError: Cannot set properties of undefined (setting 'fill')' in or related to this line: 'difficultyIndicator.style.fill = '#' + textColor.toString(16).padStart(6, '0');' Line Number: 439
User prompt
Please fix the bug: 'TypeError: Cannot set properties of undefined (setting 'fill')' in or related to this line: 'difficultyIndicator.style.fill = '#' + textColor.toString(16).padStart(6, '0');' Line Number: 439
User prompt
Please fix the bug: 'TypeError: Cannot set properties of undefined (setting 'fill')' in or related to this line: 'difficultyIndicator.style.fill = textColor.toString(16).padStart(6, '0');' Line Number: 439
User prompt
"Getting started" has just made my game stuck. There is something nasty there. Please fix.
User prompt
"Getting started" has just made my game stuck. There is something nasty there. Please fix.
User prompt
Please fix the bug: 'TypeError: Cannot set properties of undefined (setting 'fill')' in or related to this line: 'difficultyIndicator.style.fill = textColor;' Line Number: 436
User prompt
Make that the balls pop also when the train/line intersects with them, not only the harpoon. Don't change anything else.
Code edit (1 edits merged)
Please save this source code
User prompt
It's still too difficult: create bubbles much less frequently
User prompt
Bubbles are created too frequently. Reduce it at start and only increase how frequently bubbles are created depending maybe on the "balloons popped" score? The higher the more frequently. But keep it easy at start.
User prompt
Then the player blinks because of being hit, it should blink three times and be tinted to red during that time.
User prompt
Start with much less bubbles, like half.
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'length')' in or related to this line: 'for (var k = 0; k < boxes.length; k++) {' Line Number: 526
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'length')' in or related to this line: 'for (var k = 0; k < boxes.length; k++) {' Line Number: 526
User prompt
When you pop a ball with the harpoon, it should split in two halfs, evidently each one should be half the size. Also they should have opposite trajectories ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Make the player blink when a bubble hits him
User prompt
Remove the red tint from bubbles by removing the tint application code
User prompt
Bubbles should bounce of the ground as well up.
User prompt
Reduce even more the speed of the bubbles. Also, their trajectory should be more left or more right, I want them to bounce of the walls always.
User prompt
Reduce a bit the speed of the bubbles
User prompt
The balls should fall with a gravity acceleration emulating real fall behaviours
User prompt
Balls should bounce off the left and right margins
/****
* Plugins
****/
var tween = LK.import("@upit/tween.v1");
/****
* Classes
****/
// Box class
var Box = Container.expand(function () {
var self = Container.call(this);
var boxGraphics = self.attachAsset('box', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.2,
// Increase the scale to enlarge the bounding box
scaleY: 1.2
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
// Box1 class
var Box1 = Container.expand(function () {
var self = Container.call(this);
var boxGraphics = self.attachAsset('box1', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.2,
// Increase the scale to enlarge the bounding box
scaleY: 1.2
});
self.speed = 5;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
// Box2 class
var Box2 = Container.expand(function () {
var self = Container.call(this);
var boxGraphics = self.attachAsset('box2', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.2,
// Increase the scale to enlarge the bounding box
scaleY: 1.2
});
self.speed = 7;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
// Box3 class
var Box3 = Container.expand(function () {
var self = Container.call(this);
var boxGraphics = self.attachAsset('box3', {
anchorX: 0.5,
anchorY: 0.5,
scaleX: 1.2,
// Increase the scale to enlarge the bounding box
scaleY: 1.2
});
self.speed = 9;
self.update = function () {
self.y += self.speed;
if (self.y > 2732) {
self.destroy();
}
};
});
// The assets will be automatically created and loaded by the LK engine.
// Bubble class
var Bubble = Container.expand(function () {
var self = Container.call(this);
var bubbleGraphics = self.attachAsset('bubble', {
anchorX: 0.5,
anchorY: 0.5,
alpha: 1 // Start fully visible instead of transparent
});
// Allow for different bubble sizes (original size = 1.0)
self.size = 1.0;
// Update bubble size based on the size property
bubbleGraphics.scale.set(self.size);
// Physics constants for more consistent behavior
self.gravity = 0.2; // Gravity constant
self.bounceFactor = 0.7; // Energy loss on bounce (30% loss)
self.friction = 0.98; // Air/ground friction
self.speed = 3; // Vertical speed (significantly reduced initial speed)
// Track last position for collision detection
self.lastY = 0;
self.lastIntersecting = false;
// Method to split the bubble into two smaller ones
self.split = function () {
// Only split if bubble is not too small
if (self.size <= 0.3) {
return false;
}
// Create two new smaller bubbles
var halfSize = self.size * 0.5;
// Create left bubble
var leftBubble = new Bubble();
leftBubble.x = self.x;
leftBubble.y = self.y;
leftBubble.size = halfSize;
leftBubble.speedX = -Math.abs(self.speedX) * 1.2; // Move left, slightly faster
leftBubble.speed = -5 - Math.random() * 3; // Jump up
leftBubble.lastY = leftBubble.y;
leftBubble.lastIntersecting = false;
if (leftBubble.children && leftBubble.children.length > 0) {
leftBubble.children[0].scale.set(halfSize);
}
// Create right bubble
var rightBubble = new Bubble();
rightBubble.x = self.x;
rightBubble.y = self.y;
rightBubble.size = halfSize;
rightBubble.speedX = Math.abs(self.speedX) * 1.2; // Move right, slightly faster
rightBubble.speed = -5 - Math.random() * 3; // Jump up
rightBubble.lastY = rightBubble.y;
rightBubble.lastIntersecting = false;
if (rightBubble.children && rightBubble.children.length > 0) {
rightBubble.children[0].scale.set(halfSize);
}
// Add both bubbles to the game
game.addChild(leftBubble);
game.addChild(rightBubble);
return true;
};
self.update = function () {
// Track last position before moving
self.lastY = self.y;
self.lastIntersecting = self.intersects(player);
self.speed += 0.2; // Further reduced gravity acceleration from 0.3 to 0.2
self.y += self.speed;
self.x += self.speedX; // Update horizontal position based on speedX
// Bounce off the left and right margins with a small boost to ensure movement
if (self.x <= 100 && self.speedX < 0 || self.x >= 1948 && self.speedX > 0) {
self.speedX *= -1.1; // Reverse horizontal direction with a slight boost to ensure movement
}
// Bounce off the ground (bottom of the screen)
if (self.y >= 2732 - 100) {
// Account for bubble size/radius
self.y = 2732 - 100; // Reset position to prevent sinking below ground
self.speed = -self.speed * 0.7; // Reverse vertical direction with dampening (70% of original speed)
// Add a small random horizontal impulse on bounce for more natural movement
self.speedX += (Math.random() - 0.5) * 2;
}
// Removed tint application when reaching a certain Y position
// Only destroy bubble when hit by player
if (!self.lastIntersecting && self.intersects(player)) {
// Blink the player by tweening alpha to 0 and back to 1
if (player.children && player.children.length > 0) {
var playerGraphics = player.children[0];
tween(playerGraphics, {
alpha: 0
}, {
duration: 100,
onFinish: function onFinish() {
tween(playerGraphics, {
alpha: 1
}, {
duration: 100
});
}
});
}
self.destroy();
lives -= 1;
// Remove a heart icon when a life is lost
if (hearts.length > lives) {
var heartToRemove = hearts.pop();
if (heartToRemove) {
tween(heartToRemove.scale, {
x: 0,
y: 0
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
heartToRemove.destroy();
}
});
}
}
if (lives < 0) {
LK.showGameOver();
}
}
};
});
// Explosion class
var Explosion = Container.expand(function () {
var self = Container.call(this);
var explosionGraphics = self.attachAsset('explosion', {
anchorX: 0.5,
anchorY: 0.5
});
tween(explosionGraphics, {
scaleX: explosionGraphics.scaleX + 1,
scaleY: explosionGraphics.scaleY + 1
}, {
duration: 1000,
easing: tween.bounceOut,
onFinish: function onFinish() {
self.destroy();
}
});
self.update = function () {
// The explosion will disappear after a while
if (self.alpha > 0) {
self.alpha -= 0.02;
} else {
self.destroy();
}
};
});
// Harpoon class
var Harpoon = Container.expand(function () {
var self = Container.call(this);
var harpoonGraphics = self.attachAsset('harpoon', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = -20;
self.trail = game.addChild(new Trail());
self.update = function () {
self.y += self.speed;
self.trail.height = 2732 - self.y;
self.trail.y = self.y + self.trail.height / 2;
if (self.y < 0 || self.y < 2732 * (1 / 3)) {
self.destroy();
self.trail.destroy();
}
};
});
// Player class
var Player = Container.expand(function () {
var self = Container.call(this);
var playerGraphics = self.attachAsset('player', {
anchorX: 0.5,
anchorY: 0.5
});
self.speed = 5;
self.update = function () {
if (self.direction && self.direction === 'left') {
self.x -= self.speed;
} else if (self.direction === 'right') {
self.x += self.speed;
}
};
self.shoot = function () {
var harpoon = new Harpoon();
harpoon.x = player.x;
harpoon.y = player.y - 200;
harpoon.trail.x = player.x;
harpoon.trail.y = player.y - 200;
game.addChild(harpoon);
LK.getSound('crossbow').play();
};
});
// PowerUpText class
var PowerUpText = Container.expand(function () {
var self = Container.call(this);
var textGraphics = self.attachAsset('PowerUpText', {
anchorX: 0.5,
anchorY: 0.5
});
self.update = function () {
self.y -= 2;
if (self.y < 0) {
self.destroy();
}
};
});
// Trail class
var Trail = Container.expand(function () {
var self = Container.call(this);
var trailGraphics = self.attachAsset('line', {
anchorX: 0.5,
anchorY: 0.5,
width: 18
});
self.update = function () {
self.y += 10;
if (self.y > 2732) {
self.destroy();
}
};
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0xFFFFFFFF // Init game with black background
});
/****
* Game Code
****/
var background = game.attachAsset('Landscape', {
anchorX: 0,
anchorY: 0,
x: 0,
y: 0
});
game.setChildIndex(background, 0);
var player = new Player();
player.x = 2048 / 2;
player.y = 2732 - 180;
game.addChild(player); // Add player after trail to ensure correct rendering order
game.move = function (x, y, obj) {
player.x = x;
if (x < 2048 / 2 && player.scaleX > 0 || x >= 2048 / 2 && player.scaleX < 0) {
player.scaleX *= -1; // Mirror the player image
}
};
var score = 0;
var lives = 3;
var scoreBackground = new Container();
var scoreBgGraphics = scoreBackground.attachAsset('scoreBg', {
anchorX: 0.5,
anchorY: 0.1,
scaleX: 5,
scaleY: 5,
alpha: 1
});
scoreBackground.addChild(scoreBgGraphics);
scoreBackground.x = 0;
scoreBackground.y = 0;
LK.gui.top.addChild(scoreBackground);
var scoreTxt = new Text2('Balloons popped: 0', {
size: 30,
fill: 0xFF3659,
font: "'Comic Sans MS', cursive, sans-serif"
});
scoreTxt.anchor.set(0.5, -0.1);
scoreBackground.addChild(scoreTxt);
var hearts = [];
for (var i = 0; i < lives; i++) {
var heart = LK.getAsset('heart', {
anchorX: 0.5,
anchorY: 0.5,
x: -1 * (i + 1) * 50,
// Position hearts with some spacing
y: 50
});
LK.gui.topRight.addChild(heart);
hearts.push(heart);
}
var lastShot = -999;
game.down = function (x, y, obj) {
if (LK.ticks - lastShot > 30) {
player.shoot();
lastShot = LK.ticks;
}
};
// Start the music 'chinese' upon starting the game
LK.playMusic('arcade');
game.update = function () {
if (LK.ticks % 50 == 0) {
var newBubble = new Bubble();
newBubble.x = Math.random() * 2048;
newBubble.y = 0;
// Stronger horizontal trajectory - minimum speed of 5 in either direction
// Ensures bubbles will always reach walls before falling too far
var minSpeed = 5;
var maxSpeed = 8;
var randomSpeed = minSpeed + Math.random() * (maxSpeed - minSpeed);
newBubble.speedX = Math.random() < 0.5 ? -randomSpeed : randomSpeed;
// Give bubbles a small initial vertical speed for more natural physics
newBubble.speed = 2 + Math.random() * 2;
// Set bounce count to track how many times the bubble has bounced
newBubble.bounceCount = 0;
newBubble.maxBounces = 3 + Math.floor(Math.random() * 3); // Random number of max bounces
// Initialize tracking properties for the bubble
newBubble.lastY = newBubble.y;
newBubble.lastIntersecting = false;
game.addChild(newBubble);
// No tweening for horizontal movement - bubbles now fall straight down
}
var bubbles = game.children.filter(function (child) {
return child instanceof Bubble;
});
var harpoons = game.children.filter(function (child) {
return child instanceof Harpoon;
});
for (var i = 0; i < bubbles.length; i++) {
var bubble = bubbles[i];
// Check for collision only if there wasn't one in the previous frame
if (!bubble.lastIntersecting && bubble.intersects(player)) {
bubble.destroy();
lives -= 1;
// Remove a heart icon when a life is lost
if (hearts.length > lives) {
var heartToRemove = hearts.pop();
if (heartToRemove) {
tween(heartToRemove.scale, {
x: 0,
y: 0
}, {
duration: 1000,
easing: tween.easeInOut,
onFinish: function onFinish() {
heartToRemove.destroy();
}
});
}
}
if (lives < 0) {
LK.showGameOver();
}
}
for (var j = 0; j < harpoons.length; j++) {
var harpoon = harpoons[j];
if (bubble.intersects(harpoon)) {
// Store current position and data for explosion
var bubbleX = bubble.x;
var bubbleY = bubble.y;
var bubbleSize = bubble.size || 1.0;
var bubbleSpeedX = bubble.speedX;
// Try to split the bubble
var wasSplit = false;
if (bubbleSize > 0.3) {
// Call split method to create two smaller bubbles
wasSplit = bubble.split();
var boxes = game.children.filter(function (child) {
return child instanceof Box || child instanceof Box1 || child instanceof Box2 || child instanceof Box3;
});
// Remove the original bubble
bubble.destroy();
// Play explosion sound
LK.getSound('explosion').play();
// Remove the harpoon
harpoon.trail.destroy(); // Destroy the harpoon trail
harpoon.destroy();
bubbles.splice(i, 1); // Remove bubble from the array
// Update score and UI
score += 1;
scoreTxt.setText("Balloons popped: " + score.toString());
tween(scoreTxt.scale, {
x: 2,
y: 2
}, {
duration: 500,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(scoreTxt.scale, {
x: 1,
y: 1
}, {
duration: 500,
easing: tween.easeInOut
});
}
});
harpoons.splice(j, 1); // Remove harpoon from the array
// Create an explosion at the intersection point
var explosion = new Explosion();
explosion.x = bubbleX;
explosion.y = bubbleY;
game.addChild(explosion);
// Create a box at the intersection point with a 10% probability, but only if bubble wasn't split
// and if there are no other boxes in the game
if (!wasSplit && !game.children.some(function (child) {
return child instanceof Box || child instanceof Box1 || child instanceof Box2 || child instanceof Box3;
})) {
if (Math.random() < 1) {
var boxType = Math.floor(Math.random() * 4);
var box;
switch (boxType) {
case 0:
box = new Box();
break;
case 1:
box = new Box1();
break;
case 2:
box = new Box2();
break;
case 3:
box = new Box3();
break;
}
box.x = bubbleX;
box.y = bubbleY;
game.addChild(box);
}
}
break; // Break out of the loop since we're deleting the bubble
}
}
}
for (var k = 0; k < boxes.length; k++) {
var box = boxes[k];
for (var l = 0; l < harpoons.length; l++) {
var harpoon = harpoons[l];
if (box.intersects(harpoon)) {
box.destroy();
LK.getSound('powerup').play();
harpoon.trail.destroy();
harpoon.destroy();
// Display toast text based on the type of box destroyed
var toastText = new Text2('', {
size: 250,
fill: 0xFFC0CB,
font: "'Comic Sans MS', cursive, sans-serif"
});
var toastTextBg = new Text2('', {
size: 255,
fill: 0xFF00AA,
font: "'Comic Sans MS', cursive, sans-serif"
});
toastText.anchor.set(0.5, 0.5);
toastText.x = 2048 / 2;
toastText.y = 2732 / 2;
toastTextBg.anchor.set(0.5, 0.5);
toastTextBg.x = 2048 / 2;
toastTextBg.y = 2732 / 2;
game.addChild(toastText);
game.addChild(toastTextBg);
if (box instanceof Box1) {
toastText.setText("Smash!");
toastTextBg.setText("Smash!");
} else if (box instanceof Box2) {
toastText.setText("Destruction!");
toastTextBg.setText("Destruction!");
} else if (box instanceof Box) {
toastText.setText("Less madness!");
toastTextBg.setText("Less madness!");
} else if (box instanceof Box3) {
toastText.setText("Life up!");
toastTextBg.setText("Life up!");
}
// Tween the toast text to fade out and destroy after 2 seconds
tween(toastText, {
alpha: 0
}, {
duration: 500,
onFinish: function onFinish() {
toastText.destroy();
}
});
tween(toastTextBg, {
alpha: 0
}, {
duration: 500,
onFinish: function onFinish() {
toastTextBg.destroy();
}
});
boxes.splice(k, 1);
harpoons.splice(l, 1);
// Check if the destroyed box is an instance of Box1
if (box instanceof Box1) {
// Create six additional harpoons and trails
for (var i = 1; i <= 3; i++) {
var leftHarpoon = new Harpoon();
leftHarpoon.x = player.x - i * 150;
leftHarpoon.y = player.y;
leftHarpoon.trail.x = player.x - i * 150;
leftHarpoon.trail.y = player.y;
game.addChild(leftHarpoon);
var rightHarpoon = new Harpoon();
rightHarpoon.x = player.x + i * 150;
rightHarpoon.y = player.y;
rightHarpoon.trail.x = player.x + i * 150;
rightHarpoon.trail.y = player.y;
game.addChild(rightHarpoon);
// Set a timeout to remove the additional harpoons after 5 seconds
LK.setTimeout(function (lh, rh) {
lh.destroy();
lh.trail.destroy();
rh.destroy();
rh.trail.destroy();
}.bind(null, leftHarpoon, rightHarpoon), 5000);
}
}
// Check if the destroyed box is an instance of Box and reduce bubble speed
if (box instanceof Box) {
var bubbles = game.children.filter(function (child) {
return child instanceof Bubble;
});
bubbles.forEach(function (bubble) {
bubble.speed /= 2;
});
LK.setTimeout(function () {
bubbles.forEach(function (bubble) {
bubble.speed *= 2;
});
}, 5000);
}
// Check if the destroyed box is an instance of Box3 and lives are less than 3
if (box instanceof Box3 && lives < 3) {
lives += 1;
var heart = LK.getAsset('heart', {
anchorX: 0.5,
anchorY: 0.5,
x: -1 * lives * 50,
y: 50
});
LK.gui.topRight.addChild(heart);
hearts.push(heart);
}
// Check if the destroyed box is an instance of Box2
if (box instanceof Box2) {
var bubbles = game.children.filter(function (child) {
return child instanceof Bubble;
});
var bubblesDestroyed = bubbles.length;
bubbles.forEach(function (bubble) {
bubble.destroy();
});
score += bubblesDestroyed;
scoreTxt.setText("Balloons popped: " + score.toString());
tween(scoreTxt.scale, {
x: 2,
y: 2
}, {
duration: 500,
easing: tween.easeInOut,
onFinish: function onFinish() {
tween(scoreTxt.scale, {
x: 1,
y: 1
}, {
duration: 500,
easing: tween.easeInOut
});
}
});
}
break;
}
}
}
}
}; ===================================================================
--- original.js
+++ change.js
@@ -86,16 +86,57 @@
anchorX: 0.5,
anchorY: 0.5,
alpha: 1 // Start fully visible instead of transparent
});
+ // Allow for different bubble sizes (original size = 1.0)
+ self.size = 1.0;
+ // Update bubble size based on the size property
+ bubbleGraphics.scale.set(self.size);
// Physics constants for more consistent behavior
self.gravity = 0.2; // Gravity constant
self.bounceFactor = 0.7; // Energy loss on bounce (30% loss)
self.friction = 0.98; // Air/ground friction
self.speed = 3; // Vertical speed (significantly reduced initial speed)
// Track last position for collision detection
self.lastY = 0;
self.lastIntersecting = false;
+ // Method to split the bubble into two smaller ones
+ self.split = function () {
+ // Only split if bubble is not too small
+ if (self.size <= 0.3) {
+ return false;
+ }
+ // Create two new smaller bubbles
+ var halfSize = self.size * 0.5;
+ // Create left bubble
+ var leftBubble = new Bubble();
+ leftBubble.x = self.x;
+ leftBubble.y = self.y;
+ leftBubble.size = halfSize;
+ leftBubble.speedX = -Math.abs(self.speedX) * 1.2; // Move left, slightly faster
+ leftBubble.speed = -5 - Math.random() * 3; // Jump up
+ leftBubble.lastY = leftBubble.y;
+ leftBubble.lastIntersecting = false;
+ if (leftBubble.children && leftBubble.children.length > 0) {
+ leftBubble.children[0].scale.set(halfSize);
+ }
+ // Create right bubble
+ var rightBubble = new Bubble();
+ rightBubble.x = self.x;
+ rightBubble.y = self.y;
+ rightBubble.size = halfSize;
+ rightBubble.speedX = Math.abs(self.speedX) * 1.2; // Move right, slightly faster
+ rightBubble.speed = -5 - Math.random() * 3; // Jump up
+ rightBubble.lastY = rightBubble.y;
+ rightBubble.lastIntersecting = false;
+ if (rightBubble.children && rightBubble.children.length > 0) {
+ rightBubble.children[0].scale.set(halfSize);
+ }
+ // Add both bubbles to the game
+ game.addChild(leftBubble);
+ game.addChild(rightBubble);
+ return true;
+ };
self.update = function () {
// Track last position before moving
self.lastY = self.y;
self.lastIntersecting = self.intersects(player);
@@ -112,10 +153,8 @@
self.y = 2732 - 100; // Reset position to prevent sinking below ground
self.speed = -self.speed * 0.7; // Reverse vertical direction with dampening (70% of original speed)
// Add a small random horizontal impulse on bounce for more natural movement
self.speedX += (Math.random() - 0.5) * 2;
- // Play a sound effect for the bounce (optional)
- // LK.getSound('bounce').play();
}
// Removed tint application when reaching a certain Y position
// Only destroy bubble when hit by player
if (!self.lastIntersecting && self.intersects(player)) {
@@ -384,68 +423,85 @@
}
for (var j = 0; j < harpoons.length; j++) {
var harpoon = harpoons[j];
if (bubble.intersects(harpoon)) {
- bubble.destroy();
- LK.getSound('explosion').play();
- harpoon.trail.destroy(); // Destroy the harpoon trail
- harpoon.destroy();
- bubbles.splice(i, 1); // Remove bubble from the array
- score += 1;
- scoreTxt.setText("Balloons popped: " + score.toString());
- tween(scoreTxt.scale, {
- x: 2,
- y: 2
- }, {
- duration: 500,
- easing: tween.easeInOut,
- onFinish: function onFinish() {
- tween(scoreTxt.scale, {
- x: 1,
- y: 1
- }, {
- duration: 500,
- easing: tween.easeInOut
- });
- }
- });
- harpoons.splice(j, 1); // Remove harpoon from the array
- // Create an explosion at the intersection point
- var explosion = new Explosion();
- explosion.x = bubble.x;
- explosion.y = bubble.y;
- game.addChild(explosion);
- // Create a box at the intersection point with a 10% probability
- if (!game.children.some(function (child) {
- return child instanceof Box || child instanceof Box1 || child instanceof Box2 || child instanceof Box3;
- })) {
- if (Math.random() < 1) {
- var boxType = Math.floor(Math.random() * 4);
- var box;
- switch (boxType) {
- case 0:
- box = new Box();
- break;
- case 1:
- box = new Box1();
- break;
- case 2:
- box = new Box2();
- break;
- case 3:
- box = new Box3();
- break;
+ // Store current position and data for explosion
+ var bubbleX = bubble.x;
+ var bubbleY = bubble.y;
+ var bubbleSize = bubble.size || 1.0;
+ var bubbleSpeedX = bubble.speedX;
+ // Try to split the bubble
+ var wasSplit = false;
+ if (bubbleSize > 0.3) {
+ // Call split method to create two smaller bubbles
+ wasSplit = bubble.split();
+ var boxes = game.children.filter(function (child) {
+ return child instanceof Box || child instanceof Box1 || child instanceof Box2 || child instanceof Box3;
+ });
+ // Remove the original bubble
+ bubble.destroy();
+ // Play explosion sound
+ LK.getSound('explosion').play();
+ // Remove the harpoon
+ harpoon.trail.destroy(); // Destroy the harpoon trail
+ harpoon.destroy();
+ bubbles.splice(i, 1); // Remove bubble from the array
+ // Update score and UI
+ score += 1;
+ scoreTxt.setText("Balloons popped: " + score.toString());
+ tween(scoreTxt.scale, {
+ x: 2,
+ y: 2
+ }, {
+ duration: 500,
+ easing: tween.easeInOut,
+ onFinish: function onFinish() {
+ tween(scoreTxt.scale, {
+ x: 1,
+ y: 1
+ }, {
+ duration: 500,
+ easing: tween.easeInOut
+ });
}
- box.x = bubble.x;
- box.y = bubble.y;
- game.addChild(box);
+ });
+ harpoons.splice(j, 1); // Remove harpoon from the array
+ // Create an explosion at the intersection point
+ var explosion = new Explosion();
+ explosion.x = bubbleX;
+ explosion.y = bubbleY;
+ game.addChild(explosion);
+ // Create a box at the intersection point with a 10% probability, but only if bubble wasn't split
+ // and if there are no other boxes in the game
+ if (!wasSplit && !game.children.some(function (child) {
+ return child instanceof Box || child instanceof Box1 || child instanceof Box2 || child instanceof Box3;
+ })) {
+ if (Math.random() < 1) {
+ var boxType = Math.floor(Math.random() * 4);
+ var box;
+ switch (boxType) {
+ case 0:
+ box = new Box();
+ break;
+ case 1:
+ box = new Box1();
+ break;
+ case 2:
+ box = new Box2();
+ break;
+ case 3:
+ box = new Box3();
+ break;
+ }
+ box.x = bubbleX;
+ box.y = bubbleY;
+ game.addChild(box);
+ }
}
+ break; // Break out of the loop since we're deleting the bubble
}
}
}
- var boxes = game.children.filter(function (child) {
- return child instanceof Box || child instanceof Box1 || child instanceof Box2 || child instanceof Box3;
- });
for (var k = 0; k < boxes.length; k++) {
var box = boxes[k];
for (var l = 0; l < harpoons.length; l++) {
var harpoon = harpoons[l];
a green cross, icon, pixel style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a sand clock pixel style.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a bomb, pixel style. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
a pixel harpoon, vertical and looking up, retro like in pang games.. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A banner to show a message, pixel art. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
two harpoons looking up, retro, pixel. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
A Mount fuji background with a big rainbow crossing from side to side in the sky, pixel style, colourful. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows
A Boom! explosion, pixel retro style. In-Game asset. 2d. High contrast. No shadows