@@ -4,6 +4,7 @@ import { PlaceholderAssets } from "../createPlaceholderAssets";
44import { AnalogKey , AnalogReport } from "../../components/ConnectDevice" ;
55import { SpriteAssets } from "../createSpriteAssets" ;
66import { Obstacle } from "../Obstacle" ;
7+ import { InputBar } from "../InputBar" ;
78
89export class GameScene extends Phaser . Scene {
910 private player ! : Player ;
@@ -29,6 +30,10 @@ export class GameScene extends Phaser.Scene {
2930
3031 private gameEnded : boolean = false ;
3132
33+ private inputBar ! : InputBar ;
34+ private analogL : number = 0 ;
35+ private analogR : number = 0 ;
36+
3237 constructor ( ) {
3338 super ( "GameScene" ) ;
3439 }
@@ -42,10 +47,10 @@ export class GameScene extends Phaser.Scene {
4247
4348 onAnalogReport = ( event : AnalogReport ) => {
4449 const { data } = event ;
45- const aKey = data . find ( ( d ) => d . key === AnalogKey . A ) ?. value ?? 0 ;
46- const dKey = data . find ( ( d ) => d . key === AnalogKey . D ) ?. value ?? 0 ;
50+ this . analogL = data . find ( ( d ) => d . key === AnalogKey . A ) ?. value ?? 0 ;
51+ this . analogR = data . find ( ( d ) => d . key === AnalogKey . D ) ?. value ?? 0 ;
4752
48- this . horizontal = dKey - aKey ;
53+ this . horizontal = this . analogR - this . analogL ;
4954 } ;
5055
5156 preload ( ) {
@@ -122,6 +127,8 @@ export class GameScene extends Phaser.Scene {
122127 ) ;
123128 }
124129
130+ this . inputBar = new InputBar ( this ) ;
131+
125132 this . events . on ( "shutdown" , this . cleanup , this ) ;
126133 }
127134
@@ -152,10 +159,7 @@ export class GameScene extends Phaser.Scene {
152159 return o . isAlive ( ) ;
153160 } ) ;
154161
155- // Jump when space is pressed or screen is tapped (handled via pointer events)
156- // if (this.input.keyboard && Phaser.Input.Keyboard.JustDown(this.jumpKey)) {
157- // this.jump();
158- // }
162+ this . inputBar . update ( this . analogL , this . analogR ) ;
159163 }
160164
161165 spawnObstacle ( ) {
@@ -226,6 +230,10 @@ export class GameScene extends Phaser.Scene {
226230 this . player . destroy ( ) ;
227231 }
228232
233+ if ( this . inputBar ) {
234+ this . inputBar . destroy ( ) ;
235+ }
236+
229237 this . obstacles . forEach ( ( o ) => o . destroy ( ) ) ;
230238 this . obstacles = [ ] ;
231239 }
0 commit comments