forked from noxious/client
Added playSound func, use this on attack
This commit is contained in:
parent
122a178feb
commit
c2d41a63a7
6
package-lock.json
generated
6
package-lock.json
generated
@ -2535,9 +2535,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/electron-to-chromium": {
|
||||
"version": "1.5.93",
|
||||
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.93.tgz",
|
||||
"integrity": "sha512-M+29jTcfNNoR9NV7la4SwUqzWAxEwnc7ThA5e1m6LRSotmpfpCpLcIfgtSCVL+MllNLgAyM/5ru86iMRemPzDQ==",
|
||||
"version": "1.5.94",
|
||||
"resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.94.tgz",
|
||||
"integrity": "sha512-v+oaMuy6AgwZ6Hi2u5UgcM3wxzeFscBTsZBQL2FoDTx/T6k1XEQKz++8fe1VlQ3zjXB6hcvy5JPb5ZSkmVtdIQ==",
|
||||
"dev": true,
|
||||
"license": "ISC"
|
||||
},
|
||||
|
BIN
public/assets/sounds/hit.wav
Normal file
BIN
public/assets/sounds/hit.wav
Normal file
Binary file not shown.
@ -47,7 +47,7 @@ addEventListener('click', (event) => {
|
||||
if (!(event.target instanceof HTMLButtonElement)) {
|
||||
return
|
||||
}
|
||||
const audio = new Audio('/assets/music/click-btn.mp3')
|
||||
const audio = new Audio('/assets/sounds/click-btn.mp3')
|
||||
audio.play()
|
||||
})
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -26,11 +26,11 @@
|
||||
</div>
|
||||
<div class="form-field-half">
|
||||
<label for="originX">Origin X</label>
|
||||
<input class="input-field" v-model="mapObjectOriginX" name="originX" id="originX" type="number" />
|
||||
<input class="input-field" v-model="mapObjectOriginX" name="originX" id="originX" type="number" min="0.0" step="0.1" />
|
||||
</div>
|
||||
<div class="form-field-half">
|
||||
<label for="originY">Origin Y</label>
|
||||
<input class="input-field" v-model="mapObjectOriginY" name="originY" id="originY" type="number" />
|
||||
<input class="input-field" v-model="mapObjectOriginY" name="originY" id="originY" type="number" min="0.0" step="0.1" />
|
||||
</div>
|
||||
</div>
|
||||
<button class="btn-cyan px-4 py-1.5 min-w-24" @click="handleUpdate">Save</button>
|
||||
|
@ -77,7 +77,6 @@ const tileCategories = ref<Map<string, string>>(new Map())
|
||||
const selectedGroup = ref<{ parent: Tile; children: Tile[] } | null>(null)
|
||||
const tiles = ref<Tile[]>([])
|
||||
|
||||
|
||||
function startDragging(event: MouseEvent) {
|
||||
isDragging.value = true
|
||||
const startX = event.clientX
|
||||
|
@ -41,7 +41,7 @@ export function useGameControlsComposable(scene: Phaser.Scene, layer: Phaser.Til
|
||||
|
||||
// Start movement loop if not already running
|
||||
if (!moveInterval) {
|
||||
moveInterval = window.setInterval(moveCharacter, 250) // Adjust timing as needed
|
||||
moveInterval = window.setInterval(moveCharacter, 100) // Adjust timing as needed
|
||||
moveCharacter() // Move immediately on first press
|
||||
}
|
||||
}
|
||||
|
10
src/composables/useGameComposable.ts
Normal file
10
src/composables/useGameComposable.ts
Normal file
@ -0,0 +1,10 @@
|
||||
export function useGameComposable() {
|
||||
const playSound = (sound: string) => {
|
||||
const audio = new Audio(sound)
|
||||
audio.play().catch(console.error)
|
||||
}
|
||||
|
||||
return {
|
||||
playSound
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user