Skip to content

Commit

Permalink
chore(gameobjects): increase bubble size on hit
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed Jan 25, 2025
1 parent c2fece5 commit a2fbfd9
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/constants/tags.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export enum Tag {
Bubble = 'Bubble',
Bubbled = 'Bubbled',
Enemy = 'Enemy',
EnemyBubble = 'EnemyBubble',
Hole = 'Hole',
Player = 'Player',
Projectile = 'Projectile',
Expand Down
26 changes: 18 additions & 8 deletions src/gameobjects/bubble.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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, () => {
Expand All @@ -38,3 +44,7 @@ export function addBubble(player: Player) {

return bubble
}

export function hasBubble(enemy: Enemy) {
return Boolean(enemy.get(Tag.Bubbled).length)
}
2 changes: 1 addition & 1 deletion src/gameobjects/hole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
Expand Down
2 changes: 1 addition & 1 deletion src/gameobjects/projectile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})

Expand Down

0 comments on commit a2fbfd9

Please sign in to comment.