From cd554828b989f0cadb084024dff5d955bd75f258 Mon Sep 17 00:00:00 2001
From: Mark <mark@remarkablemark.org>
Date: Sat, 25 Jan 2025 16:46:39 -0500
Subject: [PATCH] chore(gameobjects): allow bubbles to combine and get bigger
 and pop

---
 src/gameobjects/bubble.ts | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/gameobjects/bubble.ts b/src/gameobjects/bubble.ts
index 9aef560..17d8d4c 100644
--- a/src/gameobjects/bubble.ts
+++ b/src/gameobjects/bubble.ts
@@ -25,7 +25,7 @@ export function addBubble(player: Player) {
 
     if (hasBubble(currentEnemy)) {
       const childBubble = currentEnemy.get(Tag.Bubbled)[0] as Bubble
-      childBubble.scaleTo(childBubble.scale.x * 1.1)
+      childBubble.scaleBy(1.1)
     } else {
       currentEnemy.add([
         sprite(Sprite.BubbleGood),
@@ -37,6 +37,24 @@ export function addBubble(player: Player) {
     }
   })
 
+  bubble.onCollide(Tag.Bubble, (otherBubble) => {
+    let currentBubble: Bubble
+
+    if (bubble.scale.x >= (otherBubble as Bubble).scale.x) {
+      currentBubble = bubble
+      otherBubble.destroy()
+    } else {
+      currentBubble = otherBubble as Bubble
+      bubble.destroy()
+    }
+
+    if (currentBubble.scale.x > 0.2) {
+      currentBubble.destroy()
+    } else {
+      currentBubble.scaleBy(1.1)
+    }
+  })
+
   bubble.onCollide(Tag.Projectile, () => {
     play(Sound.Hit)
     bubble.destroy()