Work for teleports

This commit is contained in:
2024-08-23 20:15:58 +02:00
parent 43d5e0614e
commit ad096d4ce3
13 changed files with 303 additions and 168 deletions

View File

@ -17,6 +17,7 @@ import { Container, Image, RoundRectangle, Sprite, Text } from 'phavuer'
import { type ExtendedCharacter as CharacterT } from '@/types'
import { tileToWorldX, tileToWorldY } from '@/services/zone'
import { watch, computed, ref, onMounted, onUnmounted } from 'vue'
import config from '@/config'
interface Props {
layer: Phaser.Tilemaps.TilemapLayer
@ -48,19 +49,27 @@ const updatePosition = (x: number, y: number) => {
}
const distance = Math.sqrt(Math.pow(targetX - currentX.value, 2) + Math.pow(targetY - currentY.value, 2))
const duration = distance * 5 // Adjust this multiplier to control overall speed
tween.value = props.layer.scene.tweens.add({
targets: { x: currentX.value, y: currentY.value },
x: targetX,
y: targetY,
duration: duration,
ease: 'Linear',
onUpdate: (tween) => {
currentX.value = tween.targets[0].x ?? 0
currentY.value = tween.targets[0].y ?? 0
}
})
if (distance > config.tile_size.x) {
// Teleport: No animation
currentX.value = targetX
currentY.value = targetY
} else {
// Normal movement: Animate
const duration = distance * 5 // Adjust this multiplier to control overall speed
tween.value = props.layer.scene.tweens.add({
targets: { x: currentX.value, y: currentY.value },
x: targetX,
y: targetY,
duration: duration,
ease: 'Linear',
onUpdate: (tween) => {
currentX.value = tween.targets[0].x ?? 0
currentY.value = tween.targets[0].y ?? 0
}
})
}
}
watch(