forked from noxious/client
Added container for character for easier X and Y coord handling
This commit is contained in:
parent
e4b9bb4d61
commit
af26ca5e89
@ -1,8 +1,10 @@
|
|||||||
<template>
|
<template>
|
||||||
<ChatBubble :mapCharacter="props.mapCharacter" :currentX="currentPositionX" :currentY="currentPositionY" />
|
<Container ref="characterContainer" :x="currentPositionX" :y="currentPositionY">
|
||||||
<HealthBar :mapCharacter="props.mapCharacter" :currentX="currentPositionX" :currentY="currentPositionY" />
|
<ChatBubble :mapCharacter="props.mapCharacter" />
|
||||||
<CharacterHair :mapCharacter="props.mapCharacter" :currentX="currentPositionX" :currentY="currentPositionY" />
|
<HealthBar :mapCharacter="props.mapCharacter" />
|
||||||
<Sprite ref="charSprite" :depth="isometricDepth" :x="currentPositionX" :y="currentPositionY" :origin-y="1" :flipX="isFlippedX" />
|
<CharacterHair :mapCharacter="props.mapCharacter" />
|
||||||
|
<Sprite ref="characterSprite" :depth="isometricDepth" :origin-y="1" :flipX="isFlippedX" />
|
||||||
|
</Container>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
@ -13,7 +15,7 @@ import HealthBar from '@/components/game/character/partials/HealthBar.vue'
|
|||||||
import { useCharacterSprite } from '@/composables/useCharacterSpriteComposable'
|
import { useCharacterSprite } from '@/composables/useCharacterSpriteComposable'
|
||||||
import { useGameStore } from '@/stores/gameStore'
|
import { useGameStore } from '@/stores/gameStore'
|
||||||
import { useMapStore } from '@/stores/mapStore'
|
import { useMapStore } from '@/stores/mapStore'
|
||||||
import { Sprite, useScene } from 'phavuer'
|
import { Container, Sprite, useScene } from 'phavuer'
|
||||||
import { onMounted, onUnmounted, watch } from 'vue'
|
import { onMounted, onUnmounted, watch } from 'vue'
|
||||||
import { Direction } from '@/application/enums'
|
import { Direction } from '@/application/enums'
|
||||||
|
|
||||||
@ -27,7 +29,8 @@ const mapStore = useMapStore()
|
|||||||
const scene = useScene()
|
const scene = useScene()
|
||||||
|
|
||||||
const {
|
const {
|
||||||
charSprite,
|
characterContainer,
|
||||||
|
characterSprite,
|
||||||
currentPositionX,
|
currentPositionX,
|
||||||
currentPositionY,
|
currentPositionY,
|
||||||
isometricDepth,
|
isometricDepth,
|
||||||
@ -68,7 +71,7 @@ onMounted(async () => {
|
|||||||
|
|
||||||
if (props.mapCharacter.character.id === gameStore.character!.id) {
|
if (props.mapCharacter.character.id === gameStore.character!.id) {
|
||||||
mapStore.setCharacterLoaded(true)
|
mapStore.setCharacterLoaded(true)
|
||||||
scene.cameras.main.startFollow(charSprite.value as Phaser.GameObjects.Sprite)
|
scene.cameras.main.startFollow(characterContainer.value as Phaser.GameObjects.Container)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -12,8 +12,6 @@ import { computed, onMounted, ref } from 'vue'
|
|||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
mapCharacter: MapCharacter
|
mapCharacter: MapCharacter
|
||||||
currentX: number
|
|
||||||
currentY: number
|
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const gameStore = useGameStore()
|
const gameStore = useGameStore()
|
||||||
@ -39,9 +37,7 @@ const imageProps = computed(() => {
|
|||||||
originX: Number(spriteAction?.originX) ?? 0,
|
originX: Number(spriteAction?.originX) ?? 0,
|
||||||
originY: Number(spriteAction?.originY) ?? 0,
|
originY: Number(spriteAction?.originY) ?? 0,
|
||||||
flipX: isFlippedX.value,
|
flipX: isFlippedX.value,
|
||||||
texture: texture.value,
|
texture: texture.value
|
||||||
y: props.currentY,
|
|
||||||
x: props.currentX
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<Container ref="charChatContainer" :depth="999" :x="currentX" :y="currentY">
|
<Container ref="charChatContainer" :depth="999">
|
||||||
<RoundRectangle @create="createChatBubble" :origin-x="0.5" :origin-y="7.5" :fillColor="0xffffff" :width="194" :height="21" :radius="20" />
|
<RoundRectangle @create="createChatBubble" :origin-x="0.5" :origin-y="7.5" :fillColor="0xffffff" :width="194" :height="21" :radius="20" />
|
||||||
<Text @create="createChatText" :style="{ fontSize: 13, fontFamily: 'Arial', color: '#000' }" />
|
<Text @create="createChatText" :style="{ fontSize: 13, fontFamily: 'Arial', color: '#000' }" />
|
||||||
</Container>
|
</Container>
|
||||||
@ -12,8 +12,6 @@ import { onMounted } from 'vue'
|
|||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
mapCharacter: MapCharacter
|
mapCharacter: MapCharacter
|
||||||
currentX: number
|
|
||||||
currentY: number
|
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const game = useGame()
|
const game = useGame()
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<Container :depth="999" :x="currentX" :y="currentY">
|
<Container :depth="999">
|
||||||
<Text @create="createNicknameText" :text="props.mapCharacter.character.name" />
|
<Text @create="createNicknameText" :text="props.mapCharacter.character.name" />
|
||||||
<RoundRectangle :origin-x="0.5" :origin-y="18.5" :fillColor="0xffffff" :width="74" :height="6" :radius="5" />
|
<RoundRectangle :origin-x="0.5" :origin-y="18.5" :fillColor="0xffffff" :width="74" :height="6" :radius="5" />
|
||||||
<RoundRectangle :origin-x="0.5" :origin-y="36.4" :fillColor="0x00b3b3" :width="70" :height="3" :radius="5" />
|
<RoundRectangle :origin-x="0.5" :origin-y="36.4" :fillColor="0x00b3b3" :width="70" :height="3" :radius="5" />
|
||||||
@ -12,8 +12,6 @@ import { Container, RoundRectangle, Text, useGame } from 'phavuer'
|
|||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
mapCharacter: MapCharacter
|
mapCharacter: MapCharacter
|
||||||
currentX: number
|
|
||||||
currentY: number
|
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const game = useGame()
|
const game = useGame()
|
||||||
|
@ -7,8 +7,9 @@ import { computed, ref } from 'vue'
|
|||||||
import { Direction } from '@/application/enums'
|
import { Direction } from '@/application/enums'
|
||||||
|
|
||||||
export function useCharacterSprite(scene: Phaser.Scene, tilemap: Phaser.Tilemaps.Tilemap, mapCharacter: MapCharacter) {
|
export function useCharacterSprite(scene: Phaser.Scene, tilemap: Phaser.Tilemaps.Tilemap, mapCharacter: MapCharacter) {
|
||||||
const charSprite = refObj<Phaser.GameObjects.Sprite>()
|
const characterContainer = refObj<Phaser.GameObjects.Container>()
|
||||||
const charSpriteId = ref('')
|
const characterSpriteId = ref('')
|
||||||
|
const characterSprite = refObj<Phaser.GameObjects.Sprite>()
|
||||||
const currentPositionX = ref(0)
|
const currentPositionX = ref(0)
|
||||||
const currentPositionY = ref(0)
|
const currentPositionY = ref(0)
|
||||||
const isometricDepth = ref(1)
|
const isometricDepth = ref(1)
|
||||||
@ -39,7 +40,7 @@ export function useCharacterSprite(scene: Phaser.Scene, tilemap: Phaser.Tilemaps
|
|||||||
const duration = (distance / baseSpeed) * 1000 // Convert to milliseconds
|
const duration = (distance / baseSpeed) * 1000 // Convert to milliseconds
|
||||||
|
|
||||||
tween.value = tilemap.scene.tweens.add({
|
tween.value = tilemap.scene.tweens.add({
|
||||||
targets: charSprite.value,
|
targets: characterContainer.value,
|
||||||
x: newPositionX,
|
x: newPositionX,
|
||||||
y: newPositionY,
|
y: newPositionY,
|
||||||
duration,
|
duration,
|
||||||
@ -50,8 +51,8 @@ export function useCharacterSprite(scene: Phaser.Scene, tilemap: Phaser.Tilemaps
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
onUpdate: () => {
|
onUpdate: () => {
|
||||||
currentPositionX.value = charSprite.value?.x ?? currentPositionX.value
|
currentPositionX.value = characterContainer.value?.x ?? currentPositionX.value
|
||||||
currentPositionY.value = charSprite.value?.y ?? currentPositionY.value
|
currentPositionY.value = characterContainer.value?.y ?? currentPositionY.value
|
||||||
},
|
},
|
||||||
onComplete: () => {
|
onComplete: () => {
|
||||||
if (direction === Direction.NEGATIVE) {
|
if (direction === Direction.NEGATIVE) {
|
||||||
@ -78,19 +79,19 @@ export function useCharacterSprite(scene: Phaser.Scene, tilemap: Phaser.Tilemaps
|
|||||||
})
|
})
|
||||||
|
|
||||||
const charTexture = computed(() => {
|
const charTexture = computed(() => {
|
||||||
const spriteId = charSpriteId.value ?? 'idle_right_down'
|
const spriteId = characterSpriteId.value ?? 'idle_right_down'
|
||||||
return `${spriteId}-${currentAction.value}_${currentDirection.value}`
|
return `${spriteId}-${currentAction.value}_${currentDirection.value}`
|
||||||
})
|
})
|
||||||
|
|
||||||
const updateSprite = () => {
|
const updateSprite = () => {
|
||||||
if (!charSprite.value) return
|
if (!characterSprite.value) return
|
||||||
|
|
||||||
if (mapCharacter.isMoving) {
|
if (mapCharacter.isMoving) {
|
||||||
charSprite.value.anims.play(charTexture.value, true)
|
characterSprite.value.anims.play(charTexture.value, true)
|
||||||
} else {
|
} else {
|
||||||
charSprite.value.anims.stop()
|
characterSprite.value.anims.stop()
|
||||||
charSprite.value.setFrame(0)
|
characterSprite.value.setFrame(0)
|
||||||
charSprite.value.setTexture(charTexture.value)
|
characterSprite.value.setTexture(charTexture.value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,13 +100,13 @@ export function useCharacterSprite(scene: Phaser.Scene, tilemap: Phaser.Tilemaps
|
|||||||
const spriteId = await characterTypeStorage.getSpriteId(mapCharacter.character.characterType!)
|
const spriteId = await characterTypeStorage.getSpriteId(mapCharacter.character.characterType!)
|
||||||
if (!spriteId) return
|
if (!spriteId) return
|
||||||
|
|
||||||
charSpriteId.value = spriteId
|
characterSpriteId.value = spriteId
|
||||||
await loadSpriteTextures(scene, spriteId)
|
await loadSpriteTextures(scene, spriteId)
|
||||||
|
|
||||||
if (charSprite.value) {
|
if (characterSprite.value) {
|
||||||
charSprite.value.setTexture(charTexture.value)
|
characterSprite.value.setTexture(charTexture.value)
|
||||||
charSprite.value.setFlipX(isFlippedX.value)
|
characterSprite.value.setFlipX(isFlippedX.value)
|
||||||
charSprite.value.setName(mapCharacter.character.name)
|
characterSprite.value.setName(mapCharacter.character.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
updatePosition(mapCharacter.character.positionX, mapCharacter.character.positionY, mapCharacter.character.rotation)
|
updatePosition(mapCharacter.character.positionX, mapCharacter.character.positionY, mapCharacter.character.rotation)
|
||||||
@ -116,8 +117,9 @@ export function useCharacterSprite(scene: Phaser.Scene, tilemap: Phaser.Tilemaps
|
|||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
charSprite,
|
characterContainer,
|
||||||
charSpriteId,
|
characterSpriteId,
|
||||||
|
characterSprite,
|
||||||
currentPositionX,
|
currentPositionX,
|
||||||
currentPositionY,
|
currentPositionY,
|
||||||
isometricDepth,
|
isometricDepth,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user