added a way do speed up the camera movement

This commit is contained in:
kharhamel 2020-04-06 16:59:14 +02:00
parent 7146decb5b
commit d0c09ecd4f

View File

@ -8,6 +8,7 @@ export class GameScene extends Phaser.Scene {
private keyLeft: Phaser.Input.Keyboard.Key; private keyLeft: Phaser.Input.Keyboard.Key;
private keyUp: Phaser.Input.Keyboard.Key; private keyUp: Phaser.Input.Keyboard.Key;
private keyDown: Phaser.Input.Keyboard.Key; private keyDown: Phaser.Input.Keyboard.Key;
private keyShift: Phaser.Input.Keyboard.Key;
constructor() { constructor() {
super({ super({
@ -21,6 +22,8 @@ export class GameScene extends Phaser.Scene {
} }
init(): void { init(): void {
this.keyShift = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.SHIFT);
this.keyZ = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.Z); this.keyZ = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.Z);
this.keyQ = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.Q); this.keyQ = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.Q);
this.keyS = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.S); this.keyS = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.S);
@ -32,9 +35,9 @@ export class GameScene extends Phaser.Scene {
this.keyRight = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.RIGHT); this.keyRight = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.RIGHT);
} }
private moveCamera(x:number, y:number): void { private moveCamera(x:number, y:number, speedMultiplier: number): void {
this.cameras.main.scrollX += 2 * x; this.cameras.main.scrollX += speedMultiplier * 2 * x;
this.cameras.main.scrollY += 2 * y; this.cameras.main.scrollY += speedMultiplier * 2 * y;
} }
create(): void { create(): void {
@ -49,18 +52,20 @@ export class GameScene extends Phaser.Scene {
private angle: number = 0; private angle: number = 0;
update(dt: number): void { update(dt: number): void {
let speedMultiplier = this.keyShift.isDown ? 5 : 1;
if (this.keyZ.isDown || this.keyUp.isDown) { if (this.keyZ.isDown || this.keyUp.isDown) {
this.moveCamera(0, -1); this.moveCamera(0, -1, speedMultiplier);
} }
if (this.keyQ.isDown || this.keyLeft.isDown) { if (this.keyQ.isDown || this.keyLeft.isDown) {
this.moveCamera(-1, 0); this.moveCamera(-1, 0, speedMultiplier);
} }
if (this.keyS.isDown || this.keyDown.isDown) { if (this.keyS.isDown || this.keyDown.isDown) {
this.moveCamera(0, 1); this.moveCamera(0, 1, speedMultiplier);
} }
if (this.keyD.isDown || this.keyRight.isDown) { if (this.keyD.isDown || this.keyRight.isDown) {
this.moveCamera(1, 0); this.moveCamera(1, 0, speedMultiplier);
} }
/*this.cameras.main.scrollX = Math.floor(300 + 300 * Math.cos(this.angle)); /*this.cameras.main.scrollX = Math.floor(300 + 300 * Math.cos(this.angle));