started working on character animations (WIP)

This commit is contained in:
Dennis Postma 2024-06-06 23:12:48 +02:00
parent d70e0c443e
commit b2b4f3c60e
12 changed files with 43 additions and 27 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 372 B

View File

@ -28,7 +28,7 @@ function onPointerMove(pointer: Phaser.Input.Pointer) {
// Convert tile coordinates to world coordinates // Convert tile coordinates to world coordinates
const worldPoint = props.layer.tileToWorldXY(pointer_tile.value.x, pointer_tile.value.y) const worldPoint = props.layer.tileToWorldXY(pointer_tile.value.x, pointer_tile.value.y)
waypoint.value.x = worldPoint.x + config.tile_size.y waypoint.value.x = worldPoint.x + config.tile_size.y
waypoint.value.y = worldPoint.y + config.tile_size.y waypoint.value.y = worldPoint.y + config.tile_size.y + 15
} else { } else {
waypoint.value.visible = false waypoint.value.visible = false
} }

View File

@ -11,7 +11,7 @@
</button> </button>
<div class="sprite-container"> <div class="sprite-container">
<img draggable="false" src="/assets/avatar/default/base_right_down.png" /> <img draggable="false" src="/assets/avatar/default/0.png" />
</div> </div>
<span>Lvl. {{ character.level }}</span> <span>Lvl. {{ character.level }}</span>
</div> </div>

View File

@ -45,36 +45,52 @@ onMounted(() => {
function setupSelf() function setupSelf()
{ {
scene.input.on(Phaser.Input.Events.POINTER_UP, onPointerClick) scene.input.on(Phaser.Input.Events.POINTER_UP, onPointerClick)
function onPointerClick(pointer: Phaser.Input.Pointer) { }
if (!isSelf) return;
const px = scene.cameras.main.worldView.x + pointer.x function onPointerClick(pointer: Phaser.Input.Pointer) {
const py = scene.cameras.main.worldView.y + pointer.y if (!isSelf) return;
pointer_tile.value = getTile(px, py, props.layer) as Phaser.Tilemaps.Tile const px = scene.cameras.main.worldView.x + pointer.x
if (pointer_tile.value) { const py = scene.cameras.main.worldView.y + pointer.y
const worldPoint = props.layer.tileToWorldXY(pointer_tile.value.x, pointer_tile.value.y)
const position_x = worldPoint.x + config.tile_size.y
const position_y = worldPoint.y
socket.getConnection.emit('character:move', { position_x, position_y })
}
//Directions for player sprites + animations pointer_tile.value = getTile(px, py, props.layer) as Phaser.Tilemaps.Tile
if (px < 0 && py > 0) { if (pointer_tile.value) {
console.log('down left') const worldPoint = props.layer.tileToWorldXY(pointer_tile.value.x, pointer_tile.value.y)
} else if (px < 0 && py < 0) { const position_x = worldPoint.x + config.tile_size.y
console.log('top left') const position_y = worldPoint.y
} else if (px > 0 && py > 0) { socket.getConnection.emit('character:move', { position_x, position_y })
console.log('down right')
} else if (px > 0 && py < 0) {
console.log('top right')
}
} }
function getTile(x: number, y: number, layer: Phaser.Tilemaps.TilemapLayer): Phaser.Tilemaps.Tile | undefined { //Directions for player sprites + animations
const tile: Phaser.Tilemaps.Tile = layer.getTileAtWorldXY(x, y) if (px < 0 && py > 0) {
if (!tile) return undefined; console.log('down left')
return tile } else if (px < 0 && py < 0) {
console.log('top left')
} else if (px > 0 && py > 0) {
console.log('down right')
} else if (px > 0 && py < 0) {
console.log('top right')
} }
} }
function getTile(x: number, y: number, layer: Phaser.Tilemaps.TilemapLayer): Phaser.Tilemaps.Tile | undefined {
const tile: Phaser.Tilemaps.Tile = layer.getTileAtWorldXY(x, y)
if (!tile) return undefined;
return tile
}
scene.anims.create({
key: 'walk',
frames: scene.anims.generateFrameNumbers('walk', {
start: 0,
end: 4
}),
});
/**
* Resources:
* https://www.youtube.com/watch?v=9sWrGohw9qo
* https://jsfiddle.net/juwalbose/pu0gt7nc/
*
*/
</script> </script>