@@ -8,6 +8,7 @@ import {TitleScreen} from "../../classes/gui/window/title";
88import { initializeSounds } from "../../classes/audio/audio" ;
99import { Mobile } from "../../classes/gui/window/mobile" ;
1010import { PotionEffectType } from "../../classes/collectibles/potion/potioneffect" ;
11+ import { LeaderboardService } from "../../services/leaderboard.service" ;
1112
1213@Component ( {
1314 selector : 'app-game' ,
@@ -24,7 +25,9 @@ export class GameComponent implements AfterViewInit {
2425 public static isTitleScreen : boolean = true ;
2526 public static hasInteracted : boolean = false ;
2627 public static isFlashLightShaderOn : boolean = true ;
27- private static currentLevel = level1 ;
28+ public static levels = [ level4 ] ;
29+
30+ private static currentLevel = level1 ?? GameComponent . levels [ 0 ] ;
2831 @ViewChild ( 'canvas' , { static : true } )
2932 public canvas : ElementRef < HTMLCanvasElement > | undefined ;
3033 @ViewChild ( 'cameraCanvas' , { static : true } )
@@ -35,8 +38,10 @@ export class GameComponent implements AfterViewInit {
3538 public volume : number = localStorage . getItem ( 'volume' ) ? parseFloat ( localStorage . getItem ( 'volume' ) ! ) : 1.0 ;
3639 private oldFrameTime : number = 1 ;
3740
41+ public static isFinished : boolean = false ;
42+
3843
39- constructor ( ) {
44+ constructor ( public readonly leaderboard : LeaderboardService ) {
4045 GameComponent . player = new Player ( ) ;
4146 initializeSounds ( ) ;
4247 this . registerGuiListener ( ) ;
@@ -62,9 +67,9 @@ export class GameComponent implements AfterViewInit {
6267 }
6368
6469 public static levelChange ( ) : void {
65- const levels = [ level4 ] ;
66- const index = levels . indexOf ( GameComponent . getCurrentLevel ( ) ) ;
67- GameComponent . setCurrentLevel ( levels [ ( index + 1 ) % levels . length ] ) ;
70+
71+ const index = this . levels . indexOf ( GameComponent . getCurrentLevel ( ) ) ;
72+ GameComponent . setCurrentLevel ( this . levels [ ( index + 1 ) % this . levels . length ] ) ;
6873
6974
7075 }
@@ -197,6 +202,8 @@ export class GameComponent implements AfterViewInit {
197202 this . oldFrameTime = performance . now ( ) ;
198203
199204
205+
206+
200207 GameComponent . getCurrentLevel ( ) . draw ( this . context ! , delta ) ;
201208 GameComponent . player . update ( this . context ! , delta ) ;
202209 GameComponent . player . drawSprite ( this . context ! , delta ) ;
@@ -231,6 +238,8 @@ export class GameComponent implements AfterViewInit {
231238 return ;
232239 }
233240
241+ if ( ! GameComponent . isFinished )
242+ this . leaderboard . time += delta ;
234243
235244 }
236245
@@ -263,30 +272,35 @@ export class GameComponent implements AfterViewInit {
263272 0 , 0 , cameraWidth , cameraHeight
264273 ) ;
265274
275+ //Draw Name onto Camera Canvas
276+ this . cameraContext ! . fillStyle = 'white' ;
277+ this . cameraContext ! . font = '20px Arial' ;
278+ this . cameraContext ! . fillText ( `Name: ${ this . leaderboard . name } Time: ${ Math . round ( this . leaderboard . time * 100 ) / 100 } ` , 10 , 30 ) ;
279+
266280 //Draw Coin Counter onto Camera Canvas
267281 this . cameraContext ! . fillStyle = 'white' ;
268282 this . cameraContext ! . font = '20px Arial' ;
269- this . cameraContext ! . fillText ( `Coins: ${ GameComponent . player . collectedCoins } ` , 10 , 30 ) ;
283+ this . cameraContext ! . fillText ( `Coins: ${ GameComponent . player . collectedCoins } ` , 10 , 60 ) ;
270284
271285 //Draw Shine Counter onto Camera Canvas
272286 this . cameraContext ! . fillStyle = 'white' ;
273287 this . cameraContext ! . font = '20px Arial' ;
274- this . cameraContext ! . fillText ( `Shines: ${ GameComponent . player . collectedShines } ` , 10 , 60 ) ;
288+ this . cameraContext ! . fillText ( `Shines: ${ GameComponent . player . collectedShines } ` , 10 , 90 ) ;
275289
276290 //Draw Key Counter onto Camera Canvas
277291 this . cameraContext ! . fillStyle = 'white' ;
278292 this . cameraContext ! . font = '20px Arial' ;
279- this . cameraContext ! . fillText ( `Keys: ${ GameComponent . player . collectedKeys } ` , 10 , 90 ) ;
293+ this . cameraContext ! . fillText ( `Keys: ${ GameComponent . player . collectedKeys } ` , 10 , 120 ) ;
280294
281295 //Draw Active Potion Effects
282296 this . cameraContext ! . fillStyle = 'white' ;
283297 this . cameraContext ! . font = '20px Arial' ;
284298
285- for ( let i = 0 ; i < GameComponent . player . getPotionEffects ( ) . length ; i ++ ) {
299+ for ( let i = 0 ; i < GameComponent . player . getPotionEffects ( ) . length ; i ++ ) {
286300 let duration = GameComponent . player . getPotionEffects ( ) [ i ] . duration ;
287301 //Round to 2 decimal places
288302 duration = Math . round ( duration * 100 ) / 100 ;
289- this . cameraContext ! . fillText ( PotionEffectType [ GameComponent . player . getPotionEffects ( ) [ i ] . type ] + ": " + duration , 10 , 120 + i * 30 ) ;
303+ this . cameraContext ! . fillText ( PotionEffectType [ GameComponent . player . getPotionEffects ( ) [ i ] . type ] + ": " + duration , 10 , 150 + i * 30 ) ;
290304 }
291305
292306 }
0 commit comments