diff --git a/src/components/sprites/Character.vue b/src/components/sprites/Character.vue
index 6ecfe0d..b3ea906 100644
--- a/src/components/sprites/Character.vue
+++ b/src/components/sprites/Character.vue
@@ -8,7 +8,8 @@
-
+
+
@@ -21,6 +22,12 @@ import { calculateIsometricDepth, tileToWorldX, tileToWorldY } from '@/services/
import { watch, computed, ref, onMounted, onUnmounted } from 'vue'
import config from '@/config'
+enum Direction {
+ POSITIVE,
+ NEGATIVE,
+ NOCHANGE
+}
+
interface Props {
layer: Phaser.Tilemaps.TilemapLayer
character?: CharacterT
@@ -30,12 +37,18 @@ const props = withDefaults(defineProps(), {
character: undefined
})
+const isometricDepth = ref(calculateIsometricDepth(props.character.positionX, props.character.positionY, 28, 94, true));
const currentX = ref(0)
const currentY = ref(0)
const tween = ref(null)
const isInitialPosition = ref(true)
-const updatePosition = (x: number, y: number) => {
+const calculateLocalDepth = (x: number, y: number, width: number, height: number, isCharacter: boolean) => {
+ isometricDepth.value = calculateIsometricDepth(x, y, width, height, isCharacter);
+ console.log(isometricDepth.value);
+}
+
+const updatePosition = (x: number, y: number, direction: Direction) => {
const targetX = tileToWorldX(props.layer, x, y)
const targetY = tileToWorldY(props.layer, x, y)
@@ -77,9 +90,19 @@ const updatePosition = (x: number, y: number) => {
y: targetY,
duration: duration,
ease: 'Linear',
+ onStart: () => {
+ if(direction === Direction.POSITIVE) {
+ calculateLocalDepth(x, y, 28, 94, true)
+ }
+ },
onUpdate: (tween) => {
currentX.value = tween.targets[0].x ?? 0
currentY.value = tween.targets[0].y ?? 0
+ },
+ onComplete: () => {
+ if(direction === Direction.NEGATIVE) {
+ calculateLocalDepth(x, y, 28, 94, true)
+ }
}
})
}
@@ -90,12 +113,27 @@ watch(
(newChar, oldChar) => {
if (!newChar) return
if (!oldChar || newChar.positionX !== oldChar.positionX || newChar.positionY !== oldChar.positionY) {
- updatePosition(newChar.positionX, newChar.positionY)
+ if(!oldChar) {
+ updatePosition(newChar.positionX, newChar.positionY, Direction.POSITIVE);
+ } else {
+ const direction = calcDirection(oldChar.positionX, oldChar.positionY, newChar.positionX, newChar.positionY);
+ updatePosition(newChar.positionX, newChar.positionY, direction);
+ }
}
},
{ immediate: true, deep: true }
)
+const calcDirection = (oldX, oldY, newX, newY) => {
+ if(newY < oldY || newX < oldX) {
+ return Direction.NEGATIVE;
+ }
+ if(newX > oldX || newY > oldY) {
+ return Direction.POSITIVE;
+ }
+ return Direction.NOCHANGE;
+}
+
const charTexture = computed(() => {
if (!props.character?.characterType?.sprite) {
return 'idle_right_down'
@@ -121,7 +159,7 @@ const createText = (text: Phaser.GameObjects.Text) => {
onMounted(() => {
if (props.character) {
- updatePosition(props.character.positionX, props.character.positionY)
+ updatePosition(props.character.positionX, props.character.positionY, Direction.Positive)
}
})
diff --git a/src/components/zone/Objects.vue b/src/components/zone/Objects.vue
index ddf6658..f681b28 100644
--- a/src/components/zone/Objects.vue
+++ b/src/components/zone/Objects.vue
@@ -1,10 +1,11 @@
-
+
+