From a938280334f69df66842393109af4af1b00fba65 Mon Sep 17 00:00:00 2001 From: Mark Date: Tue, 28 Jan 2025 19:49:26 -0500 Subject: [PATCH] refactor(gameobjects): remove player arg and use getPlayer in health --- src/gameobjects/health.ts | 6 ++++-- src/scenes/game.ts | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/gameobjects/health.ts b/src/gameobjects/health.ts index 3d12421..f3b4593 100644 --- a/src/gameobjects/health.ts +++ b/src/gameobjects/health.ts @@ -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), @@ -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 } diff --git a/src/scenes/game.ts b/src/scenes/game.ts index 4295ff4..5ca85f2 100644 --- a/src/scenes/game.ts +++ b/src/scenes/game.ts @@ -33,8 +33,8 @@ scene(Scene.Game, () => { addGame() addPause() - const player = addPlayer() - addHealth(player) + addPlayer() + addHealth() addAvatar() levels.forEach((level) => {