Skip to content

Commit

Permalink
feat(gameobjects): add tween to reward menu
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed Jan 28, 2025
1 parent 261db76 commit 31b4cad
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
10 changes: 1 addition & 9 deletions src/gameobjects/modal.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
interface Options {
hidden?: boolean
}

export function addModal(options?: Options) {
export function addModal() {
const modal = add([
rect(width(), height()),
color(0, 0, 0),
opacity(0.5),
fixed(),
])

if (typeof options?.hidden === 'boolean') {
modal.hidden = options.hidden
}

return modal
}
9 changes: 3 additions & 6 deletions src/gameobjects/pause.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export function addPause() {
}
})

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

const pauseMenu = modal.add([
rect(340, 300),
Expand Down Expand Up @@ -63,10 +64,6 @@ export function addPause() {
easings.easeOutElastic,
)

if (game.paused) {
modal.hidden = false
} else {
modal.hidden = true
}
modal.hidden = !game.paused
}
}
28 changes: 20 additions & 8 deletions src/gameobjects/reward.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,26 @@ export function addReward() {
game.paused = true

const modal = addModal()
const container = modal.add([pos(center())])
const { x, y } = center()

const rewardMenu = modal.add([
rect(500, 400),
color(255, 255, 255),
outline(4),
anchor('center'),
pos(x, y + 700),
])

rewardMenu.hidden = true

addText({
width: 550,
height: 80,
width: 0,
height: 0,
x: 0,
y: -120,
text: 'Choose a reward',
fontSize: 48,
parent: container,
parent: rewardMenu,
})

getRewards().forEach((reward, index) => {
Expand All @@ -84,17 +94,19 @@ export function addReward() {
game.reward = false
game.paused = false
},
parent: container,
parent: rewardMenu,
})
})

tween(
container.pos,
center(),
rewardMenu.pos,
game.paused ? center() : center().add(0, 700),
1,
(position) => (container.pos = position),
(position) => (rewardMenu.pos = position),
easings.easeOutElastic,
)

rewardMenu.hidden = false
}

function getRewards(total = 2) {
Expand Down

0 comments on commit 31b4cad

Please sign in to comment.