summaryrefslogtreecommitdiff
path: root/client/src/akkamon/render/GridControls.ts
blob: d7feef297a56f0bfebbc1d0c7a3a58f08d83f7e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { Direction } from './Direction';
import type { GridPhysics } from './GridPhysics';

export class GridControls {
    private cursors: Phaser.Types.Input.Keyboard.CursorKeys;

    constructor(
        private input: Phaser.Input.InputPlugin,
        private gridPhysics: GridPhysics,
    ) {
        this.cursors = this.input.keyboard.createCursorKeys();
    }

    update() {
        if (this.cursors.left.isDown) {
            this.gridPhysics.movePlayerSprite(Direction.LEFT);
        } else if (this.cursors.right.isDown) {
            this.gridPhysics.movePlayerSprite(Direction.RIGHT);
        } else if (this.cursors.up.isDown) {
            this.gridPhysics.movePlayerSprite(Direction.UP);
        } else if (this.cursors.down.isDown) {
            this.gridPhysics.movePlayerSprite(Direction.DOWN);
        }
    }


}