@@ -5,6 +5,7 @@ import { AnalogKey, AnalogReport } from "../../components/ConnectDevice";
55import { SpriteAssets } from "../createSpriteAssets" ;
66import { Obstacle } from "../Obstacle" ;
77import { InputBar } from "../InputBar" ;
8+ import { LivesDisplay } from "../LivesDisplay" ;
89
910export class GameScene extends Phaser . Scene {
1011 private player ! : Player ;
@@ -16,8 +17,6 @@ export class GameScene extends Phaser.Scene {
1617 private scoreText ! : Phaser . GameObjects . Text ;
1718 private scoreTimer ! : Phaser . Time . TimerEvent ;
1819
19- private livesText ! : Phaser . GameObjects . Text ;
20-
2120 private switchy ! : Phaser . GameObjects . Sprite ;
2221
2322 private background ! : Phaser . GameObjects . TileSprite ;
@@ -34,6 +33,8 @@ export class GameScene extends Phaser.Scene {
3433 private analogL : number = 0 ;
3534 private analogR : number = 0 ;
3635
36+ private livesDisplay ! : LivesDisplay ;
37+
3738 constructor ( ) {
3839 super ( "GameScene" ) ;
3940 }
@@ -87,24 +88,13 @@ export class GameScene extends Phaser.Scene {
8788
8889 document . fonts . load ( '24px "Monogram"' ) . then ( ( ) => {
8990 this . scoreText = this . add
90- . text ( 8 , 0 , `SCORE: ${ this . score } ` , {
91+ . text ( 4 , 18 , `SCORE: ${ this . score } ` , {
9192 fontFamily : "Monogram" ,
9293 fontSize : "16px" ,
9394 color : "#0f380f" ,
9495 } )
9596 . setOrigin ( 0 , 0 )
9697 . setDepth ( 1000 ) ;
97-
98- this . livesText = this . add . text (
99- 8 ,
100- 12 ,
101- `LIVES: ${ this . player . getLives ( ) } ` ,
102- {
103- fontFamily : "Monogram" ,
104- fontSize : "16px" ,
105- color : "#0f380f" ,
106- }
107- ) ;
10898 } ) ;
10999
110100 this . scoreTimer = this . time . addEvent ( {
@@ -129,6 +119,9 @@ export class GameScene extends Phaser.Scene {
129119
130120 this . inputBar = new InputBar ( this ) ;
131121
122+ this . livesDisplay = new LivesDisplay ( this ) ;
123+ this . livesDisplay . updateLivesRemaining ( this . player . getLives ( ) ) ;
124+
132125 this . events . on ( "shutdown" , this . cleanup , this ) ;
133126 }
134127
@@ -204,7 +197,7 @@ export class GameScene extends Phaser.Scene {
204197 ) ;
205198 } else {
206199 this . player . depleteLives ( ) ;
207- this . livesText . setText ( `LIVES: ${ this . player . getLives ( ) } ` ) ;
200+ this . livesDisplay . updateLivesRemaining ( this . player . getLives ( ) ) ;
208201 this . player . startInvincibility ( ) ;
209202 }
210203 }
@@ -234,6 +227,10 @@ export class GameScene extends Phaser.Scene {
234227 this . inputBar . destroy ( ) ;
235228 }
236229
230+ if ( this . livesDisplay ) {
231+ this . livesDisplay . destroy ( ) ;
232+ }
233+
237234 this . obstacles . forEach ( ( o ) => o . destroy ( ) ) ;
238235 this . obstacles = [ ] ;
239236 }
0 commit comments