diff --git a/src/components/game/character/Character.vue b/src/components/game/character/Character.vue
index 795e0c5..c38f109 100644
--- a/src/components/game/character/Character.vue
+++ b/src/components/game/character/Character.vue
@@ -28,7 +28,7 @@ const gameStore = useGameStore()
const mapStore = useMapStore()
const scene = useScene()
-const { characterContainer, characterSprite, currentPositionX, currentPositionY, isometricDepth, isFlippedX, updatePosition, calcDirection, updateSprite, initializeSprite, cleanup } = useCharacterSpriteComposable(scene, props.tileMap, props.mapCharacter)
+const { characterContainer, characterSprite, currentPositionX, currentPositionY, isometricDepth, isFlippedX, updatePosition, playAnimation, calcDirection, updateSprite, initializeSprite, cleanup } = useCharacterSpriteComposable(scene, props.tileMap, props.mapCharacter)
const handlePositionUpdate = (newValues: any, oldValues: any) => {
if (!newValues) return
@@ -51,7 +51,16 @@ watch(
rotation: props.mapCharacter.character.rotation,
isAttacking: props.mapCharacter.isAttacking
}),
- handlePositionUpdate
+ (oldValues, newValues) => {
+ handlePositionUpdate(oldValues, newValues)
+
+ if (props.mapCharacter.isAttacking) {
+ // Play attack animation
+ playAnimation('attack')
+ // Disable attack immediately after playing the animation
+ mapStore.updateCharacterProperty(props.mapCharacter.character.id, 'isAttacking', false)
+ }
+ }
)
onMounted(async () => {
diff --git a/src/components/game/map/Characters.vue b/src/components/game/map/Characters.vue
index 3f9172c..611cc88 100644
--- a/src/components/game/map/Characters.vue
+++ b/src/components/game/map/Characters.vue
@@ -3,12 +3,44 @@
diff --git a/src/components/game/map/Map.vue b/src/components/game/map/Map.vue
index 752ad90..832c49e 100644
--- a/src/components/game/map/Map.vue
+++ b/src/components/game/map/Map.vue
@@ -5,7 +5,7 @@
diff --git a/src/composables/useCharacterSpriteComposable.ts b/src/composables/useCharacterSpriteComposable.ts
index fe583f9..ae93e98 100644
--- a/src/composables/useCharacterSpriteComposable.ts
+++ b/src/composables/useCharacterSpriteComposable.ts
@@ -59,6 +59,26 @@ export function useCharacterSpriteComposable(scene: Phaser.Scene, tilemap: Phase
})
}
+ const playAnimation = (animation: string, loop = false) => {
+ if (!characterSprite.value || !characterSpriteId.value) return
+
+ const fullAnimationName = `${characterSpriteId.value}-${animation}_${currentDirection.value}`
+
+ // Remove any existing animation complete listeners
+ characterSprite.value.off(Phaser.Animations.Events.ANIMATION_COMPLETE)
+
+ // Add new listener
+ characterSprite.value.on(Phaser.Animations.Events.ANIMATION_COMPLETE, () => {
+ characterSprite.value!.setFrame(0)
+ characterSprite.value!.setTexture(charTexture.value)
+ })
+
+ characterSprite.value.anims.play({
+ key: fullAnimationName,
+ repeat: loop ? -1 : 0
+ })
+ }
+
const calcDirection = (oldPositionX: number, oldPositionY: number, newPositionX: number, newPositionY: number): Direction => {
if (newPositionY < oldPositionY || newPositionX < oldPositionX) return Direction.NEGATIVE
if (newPositionX > oldPositionX || newPositionY > oldPositionY) return Direction.POSITIVE
@@ -125,6 +145,7 @@ export function useCharacterSpriteComposable(scene: Phaser.Scene, tilemap: Phase
isometricDepth,
isFlippedX,
updatePosition,
+ playAnimation,
calcDirection,
updateSprite,
initializeSprite,
diff --git a/src/stores/mapStore.ts b/src/stores/mapStore.ts
index da2a01f..8537f9a 100644
--- a/src/stores/mapStore.ts
+++ b/src/stores/mapStore.ts
@@ -27,7 +27,7 @@ export const useMapStore = defineStore('map', {
addCharacter(character: MapCharacter) {
this.characters.push(character)
},
- updateCharacterProperty(characterId: UUID, property: K, value: MapCharacter[K]) {
+ updateCharacterProperty(characterId: string, property: K, value: MapCharacter[K]) {
const character = this.characters.find((char) => char.character.id === characterId)
if (character) {
character[property] = value