File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed
Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff 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 ;
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments