From 5f2c7a09b124d057a6ecc22e26f128727878e565 Mon Sep 17 00:00:00 2001 From: Dennis Postma Date: Mon, 10 Feb 2025 18:32:35 +0100 Subject: [PATCH] Slightly improved logic --- .../controls/useGameControlsComposable.ts | 39 ++++++++----------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/src/composables/controls/useGameControlsComposable.ts b/src/composables/controls/useGameControlsComposable.ts index 6f4ef6b..3325997 100644 --- a/src/composables/controls/useGameControlsComposable.ts +++ b/src/composables/controls/useGameControlsComposable.ts @@ -65,30 +65,25 @@ export function useGameControlsComposable(scene: Phaser.Scene, layer: Phaser.Til function moveCharacter() { if (!gameStore.character) return - const { positionX, positionY } = gameStore.character + + // Don't allow movement while attacking + if (gameStore.character.isAttacking) return - if (pressedKeys.has('ArrowLeft')) { + const { positionX, positionY } = gameStore.character + let newX = positionX + let newY = positionY + + // Calculate new position based on pressed keys + if (pressedKeys.has('ArrowLeft')) newX-- + if (pressedKeys.has('ArrowRight')) newX++ + if (pressedKeys.has('ArrowUp')) newY-- + if (pressedKeys.has('ArrowDown')) newY++ + + // Only emit if position changed + if (newX !== positionX || newY !== positionY) { gameStore.connection?.emit('map:character:move', { - positionX: positionX - 1, - positionY: positionY - }) - } - if (pressedKeys.has('ArrowRight')) { - gameStore.connection?.emit('map:character:move', { - positionX: positionX + 1, - positionY: positionY - }) - } - if (pressedKeys.has('ArrowUp')) { - gameStore.connection?.emit('map:character:move', { - positionX: positionX, - positionY: positionY - 1 - }) - } - if (pressedKeys.has('ArrowDown')) { - gameStore.connection?.emit('map:character:move', { - positionX: positionX, - positionY: positionY + 1 + positionX: newX, + positionY: newY }) } }