Skip to content

Commit

Permalink
refactor(helpers): move bubble state from player to gameState
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed Jan 30, 2025
1 parent 8a298ad commit d11bf1d
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/gameobjects/bubble.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { GameObj } from 'kaplay'

import { Sound, Sprite, Tag } from '../constants'
import { getDirection } from '../helpers'
import { gameState, getDirection } from '../helpers'
import type { Bubble, ChildBubble, Enemy, Player } from '../types'
import { game } from '.'

Expand All @@ -14,14 +14,14 @@ export function addBubble(player: Player) {
pos(player.pos),
move(
getDirection(player.screenPos()!, mousePos()),
player.attack.bubbleSpeed,
gameState.player.bubble.speed,
),
area({ scale: 0.7 }),
offscreen({ destroy: true }),
anchor('center'),
scale(SCALE_MIN * player.attack.bubbleSize),
scale(SCALE_MIN * gameState.player.bubble.size),
Tag.Bubble,
{ damage: player.attack.bubbleDamage },
{ damage: gameState.player.bubble.damage },
])

bubble.onCollide(Tag.Enemy, (enemy) => {
Expand Down Expand Up @@ -56,7 +56,7 @@ export function addBubble(player: Player) {
bubble.destroy()
}

if (currentBubble.scale.x > SCALE_MAX * player.attack.bubbleSize) {
if (currentBubble.scale.x > SCALE_MAX * gameState.player.bubble.size) {
currentBubble.destroy()
} else {
currentBubble.scaleBy(1.1)
Expand Down
3 changes: 0 additions & 3 deletions src/gameobjects/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ export function addPlayer(x = center().x, y = center().y) {
Tag.Player,
{
attack: {
bubbleDamage: 20,
bubbleSpeed: 200,
bubbleSize: 1,
delay: 1,
lastFired: -1,
},
Expand Down
8 changes: 8 additions & 0 deletions src/helpers/gameState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ class GameState {
sprites: [] as Sprite[],
}

player = {
bubble: {
damage: 20,
speed: 200,
size: 1,
},
}

reward = {
score: 5,
increment: 5,
Expand Down
7 changes: 3 additions & 4 deletions src/helpers/rewards.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getPlayer } from '../gameobjects'
import { gameState } from '../helpers'

const rewards = [
// heal hp
Expand Down Expand Up @@ -75,8 +76,7 @@ const rewards = [
return `Bubble Damage +${this.percentage}%`
},
action() {
const player = getPlayer()!
player.attack.bubbleDamage *= (100 + this.percentage) / 100
gameState.player.bubble.damage *= (100 + this.percentage) / 100
},
},

Expand All @@ -90,8 +90,7 @@ const rewards = [
return `Bubble Size +${this.percentage}%`
},
action() {
const player = getPlayer()!
player.attack.bubbleSize *= (100 + this.percentage) / 100
gameState.player.bubble.size *= (100 + this.percentage) / 100
},
},
]
Expand Down

0 comments on commit d11bf1d

Please sign in to comment.