From a2fbfd9f159ff66878a6e2f5a037c95e32e0b982 Mon Sep 17 00:00:00 2001 From: Mark Date: Sat, 25 Jan 2025 16:32:10 -0500 Subject: [PATCH] chore(gameobjects): increase bubble size on hit --- src/constants/tags.ts | 2 +- src/gameobjects/bubble.ts | 26 ++++++++++++++++++-------- src/gameobjects/hole.ts | 2 +- src/gameobjects/projectile.ts | 2 +- 4 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/constants/tags.ts b/src/constants/tags.ts index 474c04d..42064ae 100644 --- a/src/constants/tags.ts +++ b/src/constants/tags.ts @@ -1,7 +1,7 @@ export enum Tag { Bubble = 'Bubble', + Bubbled = 'Bubbled', Enemy = 'Enemy', - EnemyBubble = 'EnemyBubble', Hole = 'Hole', Player = 'Player', Projectile = 'Projectile', diff --git a/src/gameobjects/bubble.ts b/src/gameobjects/bubble.ts index dd97dba..5f1f34e 100644 --- a/src/gameobjects/bubble.ts +++ b/src/gameobjects/bubble.ts @@ -1,6 +1,6 @@ import { Sound, Sprite, Tag } from '../constants' import { getDirection } from '../helpers' -import type { Enemy, Player } from '../types' +import type { Bubble, Enemy, Player } from '../types' const SPEED = 200 const DAMAGE = 20 @@ -22,13 +22,19 @@ export function addBubble(player: Player) { bubble.destroy() const currentEnemy = enemy as Enemy currentEnemy.hurt(DAMAGE) - currentEnemy.add([ - sprite(Sprite.BubbleGood), - anchor('center'), - scale(0.2), - Tag.EnemyBubble, - ]) - currentEnemy.bubble = true + + if (hasBubble(currentEnemy)) { + const childBubble = currentEnemy.get(Tag.Bubbled)[0] as Bubble + childBubble.scaleTo(childBubble.scale.x * 1.1) + } else { + currentEnemy.add([ + sprite(Sprite.BubbleGood), + anchor('center'), + scale(0.2), + Tag.Bubbled, + ]) + currentEnemy.bubble = true + } }) bubble.onCollide(Tag.Projectile, () => { @@ -38,3 +44,7 @@ export function addBubble(player: Player) { return bubble } + +export function hasBubble(enemy: Enemy) { + return Boolean(enemy.get(Tag.Bubbled).length) +} diff --git a/src/gameobjects/hole.ts b/src/gameobjects/hole.ts index bbc014d..d6a2f35 100644 --- a/src/gameobjects/hole.ts +++ b/src/gameobjects/hole.ts @@ -22,7 +22,7 @@ export function addHole() { hole.onCollide(Tag.Enemy, (enemy) => { const currentEnemy = enemy as Enemy - if (currentEnemy.get(Tag.EnemyBubble).length) { + if (currentEnemy.bubble) { currentEnemy.hurt(100) } }) diff --git a/src/gameobjects/projectile.ts b/src/gameobjects/projectile.ts index eeed22a..d917024 100644 --- a/src/gameobjects/projectile.ts +++ b/src/gameobjects/projectile.ts @@ -29,7 +29,7 @@ export function addProjectile(enemy: Enemy, player: Player) { projectile.onCollide(Tag.Enemy, (enemy) => { play(Sound.Hit) - enemy.removeAll(Tag.EnemyBubble) + enemy.removeAll(Tag.Bubbled) enemy.bubble = false })