File tree Expand file tree Collapse file tree 1 file changed +23
-6
lines changed
Expand file tree Collapse file tree 1 file changed +23
-6
lines changed Original file line number Diff line number Diff line change @@ -42,12 +42,6 @@ export class Game extends Scene {
4242 if ( ! xIsLeft && yIsTop ) {
4343 this . _hero . heroState . set ( { action : "SHOOTING" } ) ;
4444 }
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- }
5145 } ) ;
5246
5347 this . _hero = new Hero ( this ) ;
@@ -69,11 +63,34 @@ export class Game extends Scene {
6963 }
7064 }
7165
66+ const pointer = this . input . activePointer ;
67+
68+ if ( pointer . isDown ) {
69+ this . handlePointer ( pointer ) ;
70+ }
71+
7272 this . _hero ?. update ( time , delta ) ;
7373 this . _currentLevel ?. update ( ) ;
7474 }
7575
7676 private createDebug ( ) : void {
7777 this . _toggleDebugKey = this . _keyboard ?. addKey ( Phaser . Input . Keyboard . KeyCodes . D ) ;
7878 }
79+
80+ private handlePointer ( pointer : Phaser . Input . Pointer ) {
81+ if ( ! this . _hero ) {
82+ return ;
83+ }
84+
85+ const xIsLeft = pointer . x < this . cameras . main . width / 2 ;
86+ const yIsTop = pointer . y < this . cameras . main . height / 2 ;
87+
88+ if ( xIsLeft && ! yIsTop ) {
89+ this . _hero . heroState . set ( { action : "MOVING-LEFT" } ) ;
90+ console . log ( "should move left" ) ;
91+ }
92+ if ( ! xIsLeft && ! yIsTop ) {
93+ this . _hero . heroState . set ( { action : "MOVING-RIGHT" } ) ;
94+ }
95+ }
7996}
You can’t perform that action at this time.
0 commit comments