@@ -63,18 +63,18 @@ export class GameScene extends Phaser.Scene {
6363 const gameWidth = this . cameras . main . width ;
6464 const gameHeight = this . cameras . main . height ;
6565
66- // Set up background to fill the screen
67- this . background = this . add
68- . tileSprite ( 0 , 0 , gameWidth , gameHeight , "background" )
69- . setOrigin ( 0 , 0 )
70- . setScrollFactor ( 0 ) ;
71-
7266 // Update physics settings for framerate independence
7367 this . physics . world . setFPS ( 60 ) ;
7468
7569 // Load sprites from asset handler
7670 SpriteAssets . createSprites ( this ) ;
7771
72+ // Set up background to fill the screen
73+ this . background = this . add
74+ . tileSprite ( 0 , 0 , gameWidth , gameHeight , "bg" )
75+ . setOrigin ( 0 , 0 )
76+ . setScrollFactor ( 0 ) ;
77+
7878 document . fonts . load ( '24px "Monogram"' ) . then ( ( ) => {
7979 this . scoreText = this . add
8080 . text ( 8 , 0 , `${ this . score } ` , {
@@ -116,14 +116,17 @@ export class GameScene extends Phaser.Scene {
116116 // Convert delta to seconds for easier calculations
117117 const deltaSeconds = delta / 1000 ;
118118
119+ this . background . tilePositionY -= delta * 0.01 ;
120+
119121 // The A key moves from center to the left of the screen
120122 // The D key moves from center to the right of the screen
121123 // Update position according to horizontal
122124 this . player . update ( this . horizontal ) ;
123125
124126 this . obstacleTimer += delta ;
125127
126- if ( this . obstacleTimer > 1000 ) {
128+ // difficulty curve
129+ if ( this . obstacleTimer > Math . max ( 300 , 1000 * Math . pow ( 0.97 , this . score ) ) ) {
127130 this . spawnObstacle ( ) ;
128131 this . obstacleTimer = 0 ;
129132 }
0 commit comments