added debug logic
This commit is contained in:
parent
29923b57df
commit
745e4be984
@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<Login />
|
||||
<Game />
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
|
@ -26,6 +26,11 @@ const gameConfig = {
|
||||
}
|
||||
|
||||
const preload = (scene) => {
|
||||
/**
|
||||
* @TODO
|
||||
* Write logic that downloads all assets from out websocket server in base64 format
|
||||
* Don't forget to check how intensive that operation is for performance
|
||||
*/
|
||||
scene.load.image('tiles', '/assets/tiles/default.png');
|
||||
scene.textures.addBase64('player', 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABwAAABeCAYAAAAwnXTzAAAHWUlEQVR4nLVaQUhcRxj+DCuILruHXdbnYkBimkdFdouwFBdWKCWHHkoChragmAo9pKG3ltQGWrGHkEpzS0t7Mgn2EiIYcvQiLurBIF0RYYtbFiK6Lhqyiy4BBXt4+8/OzHvz3ryN/eCx782bN9/8//z/P//MbMvHP/wJXXTMTJ45lR+PT7XothHwQzQ8OIBUpt/2fmLaeq9D7EnYMTN5Njw4ALM3iFC8B0Y6ifZYWKjzKJ1EaSWHienJMy/SCzpkqUy/QNZqJISrPRaGkU7i/p0xpdq1CAHA7A0CAIx0UlnHD6mSkKQLxXu8+iTArWOuhCrUyhWclDZc67hJqWWlTqTt2LCV6aApQj8EMjxVWt0tAgBOD8tNEcjwlDBfOAIKm/jE7NJq8Mvr374b4affjwAAXvzyF7uXG300/4Ddz++8wkj3RRwr2vNUaWklBwBIZfqZWud3XmF+5xU66vd+oCQ8Hp9qmVtdx1p2k5Ee5PdweljGm5dPWb2R7ovCd29ePsWPd8aUhFpWupbdZLH0IL+HqGk1/BunSjm+quCqUpISqBtPHQf5PUZCF8HLXTzHkCddy26y8tPDMmrliu06PSxjYvqJcqrSDm0yKY2nfJH0KmhHmuHBAUZKSDnUc5POFyGRAg1p5Q4A3rO+L0JKL1KZflR3i8gXjpj1eklGaHFLovhchhpWobpbxL3ZJfasIneUkCciE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Q3NrC8YciKd0HAMuHDFgBViYLbm2BjFx2D75D5Ao3w22Yc9FOALB85dJhWbnTezPcBoDzP0UdszfoGfgDx+NTLXMzk2epTD9C77+nrGj2BvEw3jizoJyVUslGYrzquBAlMKORM2uZLBTvQdTsYhd/YEI5rQ4uAA3zdUsZqMFAJIZAJCYQ+Nn5F9xClSoQKOMOJzIIRGKOK1xtwuPxqRbV5g4vQauRUBqXnIi5EhKpfl/9k9kIdeB1SHLuhEDzZxZNEXqReTm+L0J5g6EZ+D4KciNqj4VtsViGloRyiuhkkfyK2A2+JSTnr0Ecr3/nl2CkvY3JFyG/tpe3wKq7RVSfFT3b8GU0tL1FC1GnTQfPTvshBKzEFnA2f6fNPBm+/VCWxG8A9yWhMOdJO06+5kMv0OTLuwMvmfzODdoS8u4ANLdsA5oM3u+CcyM8l/PD/wPnRqi7R+CL0K1R3Uzg3CTUzQLOhZCOGXR2ObT+wENwU5vuloq2hHTI7JVa3B0dQsfM5JlqQav9jyEi9UIo3oO7o0PKVbRWaNMJzHydqNmFUHwPZm8Q96QzRF+zhXz0I4PPCAKRrLXInRXnx6anJ1re5QtHMFGsvwdqANph7VrQ3oxvQuv/F43zishHwzBvAak/HmJi+kl9Aeo807seyTqBl8BIW3PeSWlDiDrn9ldBWo4PYwAmrKyskWIsue4Eq+B6jk9w2yTyu8T7D0vv92u9uVoPAAAAAElFTkSuQmCC')
|
||||
}
|
||||
@ -40,7 +45,9 @@ const create = (scene) => {
|
||||
});
|
||||
|
||||
// set camera to center
|
||||
// cam.centerOn(0, 0);
|
||||
cam.centerOn(0, 0);
|
||||
|
||||
scene.add.grid(0, 0, 800, 600, 64, 32, 0, 0, 0xff00ff, 0.5).setOrigin(0, 0);
|
||||
}
|
||||
</script>
|
||||
|
||||
|
@ -24,6 +24,10 @@ const map = new Phaser.Tilemaps.Tilemap(scene, mapData);
|
||||
const tileset = map.addTilesetImage('default', 'tiles');
|
||||
const layer = map.createBlankLayer('layer', tileset, -config.tile_size.x + width / 2, height / 2 - (config.tile_size.x * tileSizeWidth * 0.25));
|
||||
|
||||
const tilemapLayer = t => {
|
||||
|
||||
}
|
||||
|
||||
const game = useGame();
|
||||
|
||||
const data = [
|
||||
|
@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<Sprite ref="player" texture="player" :x="playerX" :y="playerY" />
|
||||
<Sprite ref="sprite" texture="player" :x :y />
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
@ -13,54 +13,35 @@ import config from '@/config.js'
|
||||
* so the map is 640x320
|
||||
*/
|
||||
|
||||
// const props = defineProps({
|
||||
// x: Number,
|
||||
// y: Number
|
||||
// })
|
||||
const scene = useScene()
|
||||
const player = ref();
|
||||
const playerX = ref(0)
|
||||
const playerY = ref(0)
|
||||
|
||||
// W,S,A,D
|
||||
// Listen for keydown events
|
||||
scene.input.keyboard.on('keydown', function (event) {
|
||||
// Check which key was pressed
|
||||
switch (event.code) {
|
||||
case 'KeyW': // Move up and to the left
|
||||
playerX.value -= config.tile_size.x / 2;
|
||||
playerY.value -= config.tile_size.y / 2;
|
||||
break;
|
||||
case 'KeyS': // Move down and to the right
|
||||
playerX.value += config.tile_size.x / 2;
|
||||
playerY.value += config.tile_size.y / 2;
|
||||
break;
|
||||
case 'KeyA': // Move down and to the left
|
||||
playerX.value -= config.tile_size.x / 2;
|
||||
playerY.value += config.tile_size.y / 2;
|
||||
break;
|
||||
case 'KeyD': // Move up and to the right
|
||||
playerX.value += config.tile_size.x / 2;
|
||||
playerY.value -= config.tile_size.y / 2;
|
||||
break;
|
||||
}
|
||||
});
|
||||
const x = ref(0);
|
||||
const y = ref(0);
|
||||
|
||||
const sprite = v => {
|
||||
v.object.add.graphics({ lineStyle: { color: 0xffff00, width: 2, alpha: 0.5 } });
|
||||
}
|
||||
|
||||
scene.input.on('pointerdown', function (pointer) {
|
||||
// Convert pointer coordinates to tile coordinates
|
||||
const tileX = Math.floor(pointer.x / config.tile_size.x);
|
||||
const tileY = Math.floor(pointer.y / config.tile_size.y);
|
||||
|
||||
// Convert tile coordinates to world coordinates (center of the tile)
|
||||
const worldX = tileX * config.tile_size.x + config.tile_size.x / 2;
|
||||
const worldY = tileY * config.tile_size.y + config.tile_size.y / 2;
|
||||
|
||||
// Update the sprite's position
|
||||
playerX.value = gridToScreen(tileX, tileY, config.tile_size).screenX;
|
||||
playerY.value = gridToScreen(tileX, tileY, config.tile_size).screenY;
|
||||
const { x: mapX, y: mapY } = getTileCoordinates(pointer.x, pointer.y);
|
||||
x.value = mapX * config.tile_size.x;
|
||||
y.value = mapY * config.tile_size.y;
|
||||
sprite.value.x = x.value;
|
||||
sprite.value.y = y.value;
|
||||
});
|
||||
|
||||
function gridToScreen(x, y, tileSize) {
|
||||
// Convert grid coordinates to isometric screen coordinates
|
||||
const screenX = (x - y) * tileSize.x / 2;
|
||||
const screenY = (x + y) * tileSize.y / 2;
|
||||
|
||||
return { screenX, screenY };
|
||||
// a function that translates click coordinates to map tile coordinates
|
||||
function getTileCoordinates(x, y) {
|
||||
const tileWidth = config.tile_size.x;
|
||||
const tileHeight = config.tile_size.y;
|
||||
const mapWidth = 10;
|
||||
const mapHeight = 10;
|
||||
const mapX = Math.floor((x - tileWidth / 2) / tileWidth);
|
||||
const mapY = Math.floor((y - tileHeight / 2) / tileHeight);
|
||||
return { x: mapX, y: mapY };
|
||||
}
|
||||
</script>
|
Loading…
x
Reference in New Issue
Block a user