@@ -13,6 +13,7 @@ export enum Layer {
1313const layers : Layer [ ] = [ Layer . FRONT , Layer . MIDDLE , /*Layer.BACK*/ ] ;
1414
1515// Config
16+ const backgroundImage : string = "gameBackground3" ;
1617const backgroundSpeed : number = 1 ;
1718const houseKeys : string [ ] = [ "house1" , "house2" , "house3" , "house4" , "church" ] ;
1819const layerPropertiesMap : Record < Layer , LayerProperties > = {
@@ -43,7 +44,7 @@ const layerPropertiesMap: Record<Layer, LayerProperties> = {
4344 scale: () => 4 + Math.random() * 0.2,
4445 depth: -3,
4546 y: () => globalConsts.gameHeight - 55,
46- speed: () => 1.2 * globalConsts.houseSpeed
47+ speed: () => 1.2 * globalConsts.houseSpeed
4748 speed: () => 0.6,
4849 opacity: 0.6,
4950 // Data
@@ -92,12 +93,12 @@ export function spawnHouses(scene: Scene): void {
9293// Create Background
9394function createBackground ( ) : void {
9495 // Background A
95- backgroundA = currentScene . add . image ( globalConsts . gameWidth / 2 , globalConsts . gameHeight / 2.2 , "gameBackground3" ) ;
96+ backgroundA = currentScene . add . image ( globalConsts . gameWidth / 2 , globalConsts . gameHeight / 2.2 , backgroundImage ) ;
9697 backgroundA . setScale ( 4.5 ) ;
9798 backgroundA . setDepth ( - 4 ) ;
9899
99100 // Background B
100- backgroundB = currentScene . add . image ( globalConsts . gameWidth / 2 + backgroundA . displayWidth , globalConsts . gameHeight / 2.2 , "gameBackground3" ) ;
101+ backgroundB = currentScene . add . image ( globalConsts . gameWidth / 2 + backgroundA . displayWidth , globalConsts . gameHeight / 2.2 , backgroundImage ) ;
101102 backgroundB . setScale ( 4.5 ) ;
102103 backgroundB . setDepth ( - 4 ) ;
103104}
@@ -129,26 +130,27 @@ function spawnHouse(layer: Layer): void {
129130// Moves every house on every layer
130131export function updateMovement ( ) : void {
131132 for ( let layer of layers ) moveHouses ( getLayerDetails ( layer ) . houses , getLayerDetails ( layer ) . speed ( ) ) ; // Moves houses
132- moveBackground ( ) ; // ️ Moves Background
133+ moveBackground ( ) ; // ️ Moves Backgrounds
133134}
134135
135136// Moves background
136137function moveBackground ( ) : void {
137138 backgroundA . x -= backgroundSpeed * globalConsts . backgroundSpeed ;
138139 backgroundB . x -= backgroundSpeed * globalConsts . backgroundSpeed ;
139140
140-
141141 if ( backgroundA . x <= - backgroundA . displayWidth / 2 ) backgroundA . x = backgroundB . x + backgroundB . displayWidth ;
142142 if ( backgroundB . x <= - backgroundB . displayWidth / 2 ) backgroundB . x = backgroundA . x + backgroundA . displayWidth ;
143143}
144144
145145
146146// Moves every house on specified layer
147147function moveHouses ( houses : Phaser . GameObjects . Image [ ] , speed : number ) : void {
148+ // Moves houses
148149 houses . forEach ( house => {
149150 house . x -= speed ;
150151 } ) ;
151152
153+ // Destroys houses when out of bounds
152154 for ( let i = houses . length - 3 ; i >= 0 ; i -- ) {
153155 if ( houses [ i ] . x < - houses [ i ] . width * 4 - 50 ) {
154156 houses [ i ] . destroy ( ) ;
0 commit comments