Skip to content

Commit

Permalink
refactor(gameobjects): modularize modal from pause
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed Jan 28, 2025
1 parent 67f9cfe commit f874cd8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/gameobjects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export * from './drain'
export * from './enemy'
export * from './game'
export * from './health'
export * from './modal'
export * from './music'
export * from './pause'
export * from './player'
Expand Down
12 changes: 12 additions & 0 deletions src/gameobjects/modal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export function addModal({ hidden = false }) {
const modal = add([
rect(width(), height()),
color(0, 0, 0),
opacity(0.5),
fixed(),
])

modal.hidden = hidden

return modal
}
11 changes: 2 additions & 9 deletions src/gameobjects/pause.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { TweenController } from 'kaplay'

import { Scene } from '../constants'
import { addButton, game, music } from '.'
import { addButton, addModal, game, music } from '.'

export function addPause() {
let currentTween: TweenController
Expand All @@ -13,14 +13,7 @@ export function addPause() {
}
})

const modal = add([
rect(width(), height()),
color(0, 0, 0),
opacity(0.5),
fixed(),
])

modal.hidden = true
const modal = addModal({ hidden: true })

const pauseMenu = modal.add([
rect(340, 300),
Expand Down

0 comments on commit f874cd8

Please sign in to comment.