diff --git a/src/components/player/Player.vue b/src/components/player/Player.vue index cfd550c..f92d42a 100644 --- a/src/components/player/Player.vue +++ b/src/components/player/Player.vue @@ -7,11 +7,16 @@ import { Sprite, useScene } from 'phavuer' import { ref } from 'vue' import config from '@/config.js' -const scene = useScene() +/** + * 1 tile is 64x32 + * the map is 10x10 + * so the map is 640x320 + */ +const scene = useScene() const player = ref(); -let playerX = ref(0) -let playerY = ref(0) +const playerX = ref(0) +const playerY = ref(0) // W,S,A,D // Listen for keydown events @@ -51,16 +56,10 @@ scene.input.on('pointerdown', function (pointer) { playerY.value = gridToScreen(tileX, tileY, config.tile_size).screenY; }); -/** - * 1 tile is 64x32 - * the map is 10x10 - * so the map is 640x320 - */ - function gridToScreen(x, y, tileSize) { - // Convert grid coordinates to screen coordinates - const screenX = x * tileSize.x + tileSize.x / 2; - const screenY = y * tileSize.y + tileSize.y / 2; + // Convert grid coordinates to isometric screen coordinates + const screenX = (x - y) * tileSize.x / 2; + const screenY = (x + y) * tileSize.y / 2; return { screenX, screenY }; }