Skip to content

Commit 7db4d4a

Browse files
committed
- touch input test
1 parent 06c80b0 commit 7db4d4a

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/game-objects/hero.game-object.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ export class Hero extends Sprite {
2424
public get offset(): { x: number; y: number } {
2525
return this._offset;
2626
}
27+
public get heroState(): HeroState {
28+
return this._state;
29+
}
2730

2831
private _speed = 160;
2932
private _jumpSpeed = 360;

src/scenes/game.scene.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,28 @@ export class Game extends Scene {
2828
this._keyboard = this.input.keyboard;
2929
this.createDebug();
3030

31+
this.input.on(Phaser.Input.Events.POINTER_DOWN, (pointer: Phaser.Input.Pointer) => {
32+
if (!this._hero) {
33+
return;
34+
}
35+
36+
const xIsLeft = pointer.x < this.cameras.main.width / 2;
37+
const yIsTop = pointer.y < this.cameras.main.height / 2;
38+
39+
if (xIsLeft && yIsTop) {
40+
this._hero.heroState.set({ action: "JUMPING" });
41+
}
42+
if (!xIsLeft && yIsTop) {
43+
this._hero.heroState.set({ action: "SHOOTING" });
44+
}
45+
if (xIsLeft && !yIsTop) {
46+
this._hero.heroState.set({ action: "MOVING-LEFT" });
47+
}
48+
if (!xIsLeft && !yIsTop) {
49+
this._hero.heroState.set({ action: "MOVING-RIGHT" });
50+
}
51+
});
52+
3153
this._hero = new Hero(this);
3254
this._currentLevel = new ForestLevel(this._hero, this);
3355
}

0 commit comments

Comments
 (0)