1
0
forked from noxious/client

npm update, player movement logic

This commit is contained in:
2024-05-07 19:41:23 +02:00
parent 7798426e1b
commit f6ea46a3b5
3 changed files with 95 additions and 87 deletions

View File

@ -48,11 +48,21 @@ function onPointerClick(pointer: Phaser.Input.Pointer) {
}
}
/**
* @BUG
* when this component is spawned multiple times, the event listener is also added multiple times
*/
scene.input.on(Phaser.Input.Events.POINTER_UP, onPointerClick);
if (!props.player) {
scene.input.on(Phaser.Input.Events.POINTER_UP, onPointerClick);
}
socket.socket?.on('player_moved', (data) => {
console.log('player_moved', data);
if (data.id !== props.player?.id) {
console.log('not you');
return;
}
position.x = data.coords.x;
position.y = data.coords.y;
})
function getTile (x: number, y: number, layer: Phaser.Tilemaps.TilemapLayer): Phaser.Tilemaps.Tile | undefined {
const tile: Phaser.Tilemaps.Tile = layer.getTileAtWorldXY(x, y);