Skip to content

Commit

Permalink
chore(cursors): move with WASD
Browse files Browse the repository at this point in the history
  • Loading branch information
remarkablemark committed Jan 21, 2025
1 parent 5c90818 commit be25094
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions src/events/cursors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,27 @@ import type { Player } from '../types'
const SPEED = 320

export function addCursorKeys(player: Player) {
onKeyDown('left', () => {
player.move(-SPEED, 0)
})
onKeyDown((key) => {
switch (key) {
case 'left':
case 'a':
player.move(-SPEED, 0)
break

onKeyDown('right', () => {
player.move(SPEED, 0)
})
case 'right':
case 'd':
player.move(SPEED, 0)
break

onKeyDown('up', () => {
player.move(0, -SPEED)
})
case 'up':
case 'w':
player.move(0, -SPEED)
break

onKeyDown('down', () => {
player.move(0, SPEED)
case 'down':
case 's':
player.move(0, SPEED)
break
}
})
}

0 comments on commit be25094

Please sign in to comment.