From 0929058933096a5844b710e0a7440277342dd0b8 Mon Sep 17 00:00:00 2001 From: Mark Date: Wed, 22 Jan 2025 20:28:39 -0500 Subject: [PATCH] chore(gameobjects): add body to player --- src/events/cursors.ts | 8 -------- src/gameobjects/enemy.ts | 1 + src/gameobjects/player.ts | 5 +++++ 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/events/cursors.ts b/src/events/cursors.ts index 3732c0f..836f58b 100644 --- a/src/events/cursors.ts +++ b/src/events/cursors.ts @@ -9,30 +9,22 @@ export function addCursorKeys(player: Player) { case 'left': case 'a': player.move(-SPEED, 0) - setCameraPosition(player) break case 'right': case 'd': player.move(SPEED, 0) - setCameraPosition(player) break case 'up': case 'w': player.move(0, -SPEED) - setCameraPosition(player) break case 'down': case 's': player.move(0, SPEED) - setCameraPosition(player) break } }) } - -function setCameraPosition(player: Player) { - setCamPos(player.worldPos()!) -} diff --git a/src/gameobjects/enemy.ts b/src/gameobjects/enemy.ts index 415d4fb..7376241 100644 --- a/src/gameobjects/enemy.ts +++ b/src/gameobjects/enemy.ts @@ -19,6 +19,7 @@ export function addEnemy(x: number, y: number, player: Player) { health(hp, hp), opacity(1), area(), + body(), scale(0.75), Tag.Enemy, { damage, speed }, diff --git a/src/gameobjects/player.ts b/src/gameobjects/player.ts index 322ca10..8c48c03 100644 --- a/src/gameobjects/player.ts +++ b/src/gameobjects/player.ts @@ -11,6 +11,7 @@ export function addPlayer(x = center().x, y = center().y) { rotate(0), anchor('center'), area(), + body(), health(HEALTH, HEALTH), Tag.Player, ]) @@ -18,6 +19,10 @@ export function addPlayer(x = center().x, y = center().y) { addCursorKeys(player) addAttack(player) + player.onUpdate(() => { + setCamPos(player.worldPos()!) + }) + player.onCollide(Tag.Enemy, (enemy) => { const currentEnemy = enemy as Enemy player.hurt(currentEnemy.damage)