Provided WASD movement
This commit is contained in:
@@ -20,11 +20,18 @@ export interface GameInputEvents {
|
|||||||
export class GameInput extends Phaser.Events.EventEmitter {
|
export class GameInput extends Phaser.Events.EventEmitter {
|
||||||
private scene: Phaser.Scene;
|
private scene: Phaser.Scene;
|
||||||
private cursors: Phaser.Types.Input.Keyboard.CursorKeys;
|
private cursors: Phaser.Types.Input.Keyboard.CursorKeys;
|
||||||
|
private wasd: {
|
||||||
|
W: Phaser.Input.Keyboard.Key;
|
||||||
|
A: Phaser.Input.Keyboard.Key;
|
||||||
|
S: Phaser.Input.Keyboard.Key;
|
||||||
|
D: Phaser.Input.Keyboard.Key;
|
||||||
|
};
|
||||||
|
|
||||||
constructor(scene: Phaser.Scene) {
|
constructor(scene: Phaser.Scene) {
|
||||||
super();
|
super();
|
||||||
this.scene = scene;
|
this.scene = scene;
|
||||||
this.cursors = this.scene.input.keyboard!.createCursorKeys();
|
this.cursors = this.scene.input.keyboard!.createCursorKeys();
|
||||||
|
this.wasd = this.scene.input.keyboard!.addKeys("W,A,S,D") as any;
|
||||||
|
|
||||||
this.setupKeyboard();
|
this.setupKeyboard();
|
||||||
this.setupMouse();
|
this.setupMouse();
|
||||||
@@ -96,10 +103,10 @@ export class GameInput extends Phaser.Events.EventEmitter {
|
|||||||
let dx = 0;
|
let dx = 0;
|
||||||
let dy = 0;
|
let dy = 0;
|
||||||
|
|
||||||
const left = this.cursors.left?.isDown;
|
const left = this.cursors.left?.isDown || this.wasd.A.isDown;
|
||||||
const right = this.cursors.right?.isDown;
|
const right = this.cursors.right?.isDown || this.wasd.D.isDown;
|
||||||
const up = this.cursors.up?.isDown;
|
const up = this.cursors.up?.isDown || this.wasd.W.isDown;
|
||||||
const down = this.cursors.down?.isDown;
|
const down = this.cursors.down?.isDown || this.wasd.S.isDown;
|
||||||
|
|
||||||
if (left) dx -= 1;
|
if (left) dx -= 1;
|
||||||
if (right) dx += 1;
|
if (right) dx += 1;
|
||||||
@@ -109,7 +116,11 @@ export class GameInput extends Phaser.Events.EventEmitter {
|
|||||||
const anyJustDown = Phaser.Input.Keyboard.JustDown(this.cursors.left!) ||
|
const anyJustDown = Phaser.Input.Keyboard.JustDown(this.cursors.left!) ||
|
||||||
Phaser.Input.Keyboard.JustDown(this.cursors.right!) ||
|
Phaser.Input.Keyboard.JustDown(this.cursors.right!) ||
|
||||||
Phaser.Input.Keyboard.JustDown(this.cursors.up!) ||
|
Phaser.Input.Keyboard.JustDown(this.cursors.up!) ||
|
||||||
Phaser.Input.Keyboard.JustDown(this.cursors.down!);
|
Phaser.Input.Keyboard.JustDown(this.cursors.down!) ||
|
||||||
|
Phaser.Input.Keyboard.JustDown(this.wasd.W) ||
|
||||||
|
Phaser.Input.Keyboard.JustDown(this.wasd.A) ||
|
||||||
|
Phaser.Input.Keyboard.JustDown(this.wasd.S) ||
|
||||||
|
Phaser.Input.Keyboard.JustDown(this.wasd.D);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
dx, dy, anyJustDown,
|
dx, dy, anyJustDown,
|
||||||
|
|||||||
Reference in New Issue
Block a user