Skip to content

Commit

Permalink
refactor(gameobjects): remove player arg and use getPlayer in health
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed Jan 29, 2025
1 parent e79b522 commit a938280
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/gameobjects/health.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Layer } from '../constants'
import type { Player } from '../types'
import { getPlayer } from '.'

const WIDTH = 300
const HEIGHT = 30

export function addHealth(player: Player) {
export function addHealth() {
const background = add([
rect(WIDTH, HEIGHT),
pos(30, height() - 60),
Expand All @@ -19,6 +19,8 @@ export function addHealth(player: Player) {
color(255, 0, 0),
])

const player = getPlayer()!

function updateHealth() {
health.width = (player.hp() / player.maxHP()!) * WIDTH
}
Expand Down
4 changes: 2 additions & 2 deletions src/scenes/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ scene(Scene.Game, () => {
addGame()
addPause()

const player = addPlayer()
addHealth(player)
addPlayer()
addHealth()
addAvatar()

levels.forEach((level) => {
Expand Down

0 comments on commit a938280

Please sign in to comment.