1
0
forked from noxious/client

Added playSound func, use this on attack

This commit is contained in:
2025-02-06 21:00:32 +01:00
parent 122a178feb
commit c2d41a63a7
9 changed files with 22 additions and 10 deletions

View File

@ -14,6 +14,7 @@ import CharacterHair from '@/components/game/character/partials/CharacterHair.vu
import ChatBubble from '@/components/game/character/partials/ChatBubble.vue'
import HealthBar from '@/components/game/character/partials/HealthBar.vue'
import { useCharacterSpriteComposable } from '@/composables/useCharacterSpriteComposable'
import { useGameComposable } from '@/composables/useGameComposable'
import { useGameStore } from '@/stores/gameStore'
import { useMapStore } from '@/stores/mapStore'
import { Container, Sprite, useScene } from 'phavuer'
@ -29,13 +30,13 @@ const mapStore = useMapStore()
const scene = useScene()
const { characterContainer, characterSprite, currentPositionX, currentPositionY, isometricDepth, isFlippedX, updatePosition, playAnimation, calcDirection, updateSprite, initializeSprite, cleanup } = useCharacterSpriteComposable(scene, props.tileMap, props.mapCharacter)
const { playSound } = useGameComposable()
const handlePositionUpdate = (newValues: any, oldValues: any) => {
if (!newValues) return
if (!oldValues || newValues.positionX !== oldValues.positionX || newValues.positionY !== oldValues.positionY) {
const direction = !oldValues ? Direction.POSITIVE : calcDirection(oldValues.positionX, oldValues.positionY, newValues.positionX, newValues.positionY)
updatePosition(newValues.positionX, newValues.positionY, direction)
updatePosition(newValues.positionX, newValues.positionY)
}
if (newValues.isMoving !== oldValues?.isMoving || newValues.rotation !== oldValues?.rotation) {
@ -57,6 +58,8 @@ watch(
if (props.mapCharacter.isAttacking) {
// Play attack animation
playAnimation('attack')
// Play hit sound
playSound('/assets/sounds/hit.wav')
// Disable attack immediately after playing the animation
mapStore.updateCharacterProperty(props.mapCharacter.character.id, 'isAttacking', false)
}