forked from noxious/client
walk anims
This commit is contained in:
parent
336f90128d
commit
471f84904f
@ -1,8 +1,9 @@
|
|||||||
<template>
|
<template>
|
||||||
<Container v-if="props.character">
|
<Container v-if="props.character">
|
||||||
<RoundRectangle :x="tileToWorldX(props.layer, props.character.position_x, props.character.position_y)" :y="tileToWorldY(props.layer, props.character.position_x, props.character.position_y)" :origin-x="0.5" :origin-y="16" :fillColor="0xffffff" :width="74" :height="8" :radius="4" />
|
<RoundRectangle :tween="tween" :x="tileToWorldX(props.layer, props.character.position_x, props.character.position_y)" :y="tileToWorldY(props.layer, props.character.position_x, props.character.position_y)" :origin-x="0.5" :origin-y="16" :fillColor="0xffffff" :width="74" :height="8" :radius="4" />
|
||||||
<RoundRectangle :x="tileToWorldX(props.layer, props.character.position_x, props.character.position_y)" :y="tileToWorldY(props.layer, props.character.position_x, props.character.position_y)" :origin-x="0.5" :origin-y="31.5" :fillColor="0x09ad19" :width="70" :height="4" :radius="4" />
|
<RoundRectangle :tween="tween" :x="tileToWorldX(props.layer, props.character.position_x, props.character.position_y)" :y="tileToWorldY(props.layer, props.character.position_x, props.character.position_y)" :origin-x="0.5" :origin-y="31.5" :fillColor="0x09ad19" :width="70" :height="4" :radius="4" />
|
||||||
<Text
|
<Text
|
||||||
|
:tween="tween"
|
||||||
@create="createText"
|
@create="createText"
|
||||||
:text="props.character.name"
|
:text="props.character.name"
|
||||||
:x="tileToWorldX(props.layer, props.character.position_x, props.character.position_y)"
|
:x="tileToWorldX(props.layer, props.character.position_x, props.character.position_y)"
|
||||||
@ -19,16 +20,10 @@
|
|||||||
<Image texture="character" :x="tileToWorldX(props.layer, props.character.position_x, props.character.position_y)" :y="tileToWorldY(props.layer, props.character.position_x, props.character.position_y)" :origin-y="1" />
|
<Image texture="character" :x="tileToWorldX(props.layer, props.character.position_x, props.character.position_y)" :y="tileToWorldY(props.layer, props.character.position_x, props.character.position_y)" :origin-y="1" />
|
||||||
</Container>
|
</Container>
|
||||||
<Container v-else>
|
<Container v-else>
|
||||||
<Image v-if="!props.character.isMoving"
|
<Sprite
|
||||||
|
:tween="tween"
|
||||||
:texture="charTexture"
|
:texture="charTexture"
|
||||||
:x="tileToWorldX(props.layer, props.character.position_x, props.character.position_y)"
|
:play="props.character.isMoving ? charTexture : undefined"
|
||||||
:y="tileToWorldY(props.layer, props.character.position_x, props.character.position_y)"
|
|
||||||
:origin-y="1"
|
|
||||||
:flipX="props.character.rotation === 6 || props.character.rotation === 4"
|
|
||||||
:flipY="false"
|
|
||||||
/>
|
|
||||||
<Sprite v-else
|
|
||||||
:play="charTexture + '-anim'"
|
|
||||||
:x="tileToWorldX(props.layer, props.character.position_x, props.character.position_y)"
|
:x="tileToWorldX(props.layer, props.character.position_x, props.character.position_y)"
|
||||||
:y="tileToWorldY(props.layer, props.character.position_x, props.character.position_y)"
|
:y="tileToWorldY(props.layer, props.character.position_x, props.character.position_y)"
|
||||||
:origin-y="1"
|
:origin-y="1"
|
||||||
@ -41,10 +36,11 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
|
import config from '@/config'
|
||||||
import { Container, Image, RoundRectangle, Sprite, Text } from 'phavuer'
|
import { Container, Image, RoundRectangle, Sprite, Text } from 'phavuer'
|
||||||
import { type ExtendedCharacter as CharacterT } from '@/types'
|
import { type ExtendedCharacter as CharacterT } from '@/types'
|
||||||
import { tileToWorldX, tileToWorldY } from '@/services/zone'
|
import { tileToWorldX, tileToWorldY } from '@/services/zone'
|
||||||
import { watch, computed } from 'vue'
|
import { watch, computed, ref } from 'vue'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
layer: Phaser.Tilemaps.TilemapLayer
|
layer: Phaser.Tilemaps.TilemapLayer
|
||||||
@ -55,6 +51,39 @@ const props = withDefaults(defineProps<Props>(), {
|
|||||||
character: undefined
|
character: undefined
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const currentVisualPosition = ref({ x: 0, y: 0 })
|
||||||
|
|
||||||
|
const tween = computed(() => {
|
||||||
|
if (!props.character || !props.layer) return null
|
||||||
|
|
||||||
|
const { position_x, position_y, isMoving } = props.character
|
||||||
|
|
||||||
|
if (!isMoving) return null
|
||||||
|
|
||||||
|
const targetX = tileToWorldX(props.layer, position_x, position_y)
|
||||||
|
const targetY = tileToWorldY(props.layer, position_x, position_y)
|
||||||
|
|
||||||
|
// Use the current visual position for the starting point
|
||||||
|
const { x: currentX, y: currentY } = currentVisualPosition.value
|
||||||
|
|
||||||
|
const tweenConfig = {
|
||||||
|
x: targetX,
|
||||||
|
y: targetY,
|
||||||
|
duration: 750,
|
||||||
|
ease: 'Power2',
|
||||||
|
repeat: 0,
|
||||||
|
yoyo: false,
|
||||||
|
from: { x: currentX, y: currentY },
|
||||||
|
to: { x: targetX, y: targetY },
|
||||||
|
onComplete: () => {
|
||||||
|
// Update the current visual position when the tween completes
|
||||||
|
currentVisualPosition.value = { x: targetX, y: targetY }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return tweenConfig
|
||||||
|
})
|
||||||
|
|
||||||
const charTexture = computed(() => {
|
const charTexture = computed(() => {
|
||||||
console.log('Character texture:', props.character)
|
console.log('Character texture:', props.character)
|
||||||
if (!props.character?.characterType?.sprite) {
|
if (!props.character?.characterType?.sprite) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<Teleport to="body">
|
<Teleport to="body">
|
||||||
<div v-if="isModalOpenRef" class="fixed bg-gray-300/80 border-solid border-2 border-cyan-200 z-50 flex flex-col backdrop-blur-sm shadow-lg" :style="modalStyle">
|
<div v-if="isModalOpenRef" class="fixed bg-gray-300/80 border-solid border-2 border-cyan-200 z-50 flex flex-col backdrop-blur-sm shadow-lg" :style="modalStyle">
|
||||||
<div @mousedown="startDrag" class="cursor-move p-2.5 flex justify-between items-center">
|
<div @mousedown="startDrag" class="cursor-move p-2.5 flex justify-between items-center border-solid border-0 border-b border-cyan-200">
|
||||||
<slot name="modalHeader" />
|
<slot name="modalHeader" />
|
||||||
<div class="flex gap-2.5">
|
<div class="flex gap-2.5">
|
||||||
<button @click="toggleFullScreen" class="w-5 h-5 m-0 p-0 relative hover:scale-110 transition-transform duration-300 ease-in-out" v-if="canFullScreen">
|
<button @click="toggleFullScreen" class="w-5 h-5 m-0 p-0 relative hover:scale-110 transition-transform duration-300 ease-in-out" v-if="canFullScreen">
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
const dev: boolean = true
|
const dev: boolean = false
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'New Quest',
|
name: 'New Quest',
|
||||||
|
@ -112,7 +112,7 @@ const preloadScene = (scene: Phaser.Scene) => {
|
|||||||
* Load the assets into the Phaser scene
|
* Load the assets into the Phaser scene
|
||||||
*/
|
*/
|
||||||
assets.value.forEach((asset) => {
|
assets.value.forEach((asset) => {
|
||||||
if (asset.group === 'sprites') {
|
if (asset.group === 'sprite_animations') {
|
||||||
if (!asset.frameWidth || !asset.frameHeight) {
|
if (!asset.frameWidth || !asset.frameHeight) {
|
||||||
console.error('Frame width and height must be defined for spritesheets', asset)
|
console.error('Frame width and height must be defined for spritesheets', asset)
|
||||||
}
|
}
|
||||||
@ -139,7 +139,7 @@ const createScene = (scene: Phaser.Scene) => {
|
|||||||
scene.anims.create({
|
scene.anims.create({
|
||||||
key: asset.key,
|
key: asset.key,
|
||||||
frameRate: 7,
|
frameRate: 7,
|
||||||
frames: scene.anims.generateFrameNumbers(asset.key, { start: 0, end: 3 }),
|
frames: scene.anims.generateFrameNumbers(asset.key, { start: 0, end: 4 }),
|
||||||
repeat: -1
|
repeat: -1
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user