@@ -11,21 +11,34 @@ class PatternFormation {
11
11
this . virtualWidth = options . virtualWidth || 1080 ;
12
12
this . virtualHeight = options . virtualHeight || 1080 ;
13
13
14
- // Initialize config first
14
+ // Initialize config with new starting values
15
15
this . config = {
16
16
speed : 0.3 ,
17
17
radius : 80 ,
18
18
patternType : 'infinity' ,
19
19
loopDuration : 10 ,
20
- alienCount : 5 ,
21
- showPath : false , // Changed from true to false
20
+ alienCount : 10 , // Increased from 5 to 10
21
+ showPath : false ,
22
22
pathPoints : 100 , // number of points to draw on path
23
23
formationRadius : 150 , // New separate radius for formation
24
24
pulseIntensity : 0 , // Add pulse intensity control
25
25
pulseSpeed : 1 , // Add pulse speed control
26
26
shootingEnabled : true // Add shooting enabled control
27
27
} ;
28
28
29
+ // Add difficulty progression parameters
30
+ this . difficulty = options . difficulty || 1 ;
31
+ this . maxDifficulty = 10 ; // After this, reset and speed up
32
+ this . baseFormationRadius = 150 ;
33
+ this . radiusIncrease = 20 ; // Amount to increase per level
34
+ this . basePulseIntensity = 0 ;
35
+ this . pulseIntensityIncrease = 0.5 ;
36
+ this . basePulseSpeed = 1 ;
37
+ this . pulseSpeedIncrease = 0.2 ;
38
+
39
+ // Apply difficulty modifiers
40
+ this . applyDifficultyModifiers ( ) ;
41
+
29
42
this . aliens = [ ] ;
30
43
this . pattern = patterns [ options . pattern || 'circle' ] ;
31
44
this . time = 0 ;
@@ -64,9 +77,6 @@ class PatternFormation {
64
77
this . shootTimer = 0 ;
65
78
this . shootInterval = 1.0 ; // Time between shots
66
79
67
- // Delay GUI setup to ensure dat.GUI is loaded
68
- setTimeout ( ( ) => this . setupGUI ( ) , 100 ) ;
69
-
70
80
this . difficulty = options . difficulty || 1 ;
71
81
this . shootInterval = Math . max ( 0.3 , 1.0 - ( this . difficulty * 0.1 ) ) ; // Shoot faster with higher difficulty
72
82
this . config . speed = Math . min ( 2.0 , 0.3 + ( this . difficulty * 0.1 ) ) ; // Move faster with higher difficulty
@@ -76,77 +86,31 @@ class PatternFormation {
76
86
this . explosionEffect = new ExplosionEffect ( ctx ) ;
77
87
}
78
88
79
- setupGUI ( ) {
80
- if ( ! window . dat || ! window . dat . GUI ) {
81
- console . error ( 'dat.GUI not loaded, retrying...' ) ;
82
- setTimeout ( ( ) => this . setupGUI ( ) , 100 ) ;
83
- return ;
84
- }
89
+ applyDifficultyModifiers ( ) {
90
+ // Calculate actual difficulty level (cycles through 1-10)
91
+ const cycleDifficulty = ( ( this . difficulty - 1 ) % this . maxDifficulty ) + 1 ;
92
+
93
+ // Increase formation radius with difficulty
94
+ this . config . formationRadius = this . baseFormationRadius +
95
+ ( cycleDifficulty - 1 ) * this . radiusIncrease ;
96
+
97
+ // Increase pulse intensity and speed
98
+ this . config . pulseIntensity = this . basePulseIntensity +
99
+ ( cycleDifficulty - 1 ) * this . pulseIntensityIncrease ;
100
+ this . config . pulseSpeed = this . basePulseSpeed +
101
+ ( cycleDifficulty - 1 ) * this . pulseSpeedIncrease ;
102
+
103
+ // Adjust base shooting speed based on cycle count
104
+ const cycleCount = Math . floor ( ( this . difficulty - 1 ) / this . maxDifficulty ) ;
105
+ this . shootInterval = Math . max ( 0.3 , 1.0 - ( cycleCount * 0.1 ) - ( cycleDifficulty * 0.05 ) ) ;
106
+
107
+ // Adjust movement speed
108
+ this . config . speed = Math . min ( 2.0 , 0.3 + ( cycleCount * 0.1 ) + ( cycleDifficulty * 0.05 ) ) ;
85
109
86
- try {
87
- this . gui = new dat . GUI ( {
88
- width : 300 ,
89
- autoPlace : true ,
90
- closed : false
91
- } ) ;
92
-
93
- // Add controls to the GUI
94
- const folder = this . gui . addFolder ( 'Formation Controls' ) ;
95
-
96
- // Update speed control to affect loopDuration
97
- folder . add ( this . config , 'speed' , 0.1 , 2.0 )
98
- . name ( 'Speed' )
99
- . onChange ( value => {
100
- this . loopDuration = 10 / value ; // Adjust base duration by speed
101
- } ) ;
102
-
103
- // Formation radius control
104
- folder . add ( this . config , 'formationRadius' , 50 , 300 )
105
- . name ( 'Formation Radius' )
106
- . onChange ( value => {
107
- this . calculateFormationParameters ( ) ;
108
- } ) ;
109
-
110
- folder . add ( this . config , 'alienCount' , 3 , 10 )
111
- . step ( 1 )
112
- . name ( 'Alien Count' )
113
- . onChange ( value => {
114
- // Recreate formation with new count
115
- this . createFormation ( ) ;
116
- } ) ;
117
- folder . add ( this . config , 'loopDuration' , 5 , 20 ) . name ( 'Loop Duration' ) ;
118
- folder . add ( this . config , 'showPath' ) . name ( 'Show Path' ) . onChange ( ( value ) => {
119
- this . config . showPath = value ;
120
- } ) ;
121
-
122
- folder . add ( this . path , 'smoothingFactor' , 0.8 , 0.99 )
123
- . name ( 'Path Smoothing' )
124
- . onChange ( value => {
125
- this . path . smoothingFactor = value ;
126
- } ) ;
127
-
128
- // Add pulse controls
129
- folder . add ( this . config , 'pulseIntensity' , 0 , 10 )
130
- . name ( 'Pulse Intensity' )
131
- . onChange ( ( ) => this . calculateFormationParameters ( ) ) ;
132
-
133
- folder . add ( this . config , 'pulseSpeed' , 0.1 , 2 )
134
- . name ( 'Pulse Speed' ) ;
135
-
136
- folder . add ( this . config , 'shootingEnabled' )
137
- . name ( 'Alien Shooting' ) ;
138
-
139
- // Force the folder to be open
140
- folder . open ( ) ;
141
-
142
- // Ensure GUI is visible
143
- this . gui . domElement . style . zIndex = '10000' ;
144
- document . body . appendChild ( this . gui . domElement ) ;
145
-
146
- console . log ( 'GUI setup complete' ) ;
147
- } catch ( error ) {
148
- console . error ( 'Error setting up GUI:' , error ) ;
149
- }
110
+ console . log ( `Level ${ this . difficulty } (Cycle ${ cycleCount + 1 } , Difficulty ${ cycleDifficulty } )` ) ;
111
+ console . log ( `Formation Radius: ${ this . config . formationRadius } ` ) ;
112
+ console . log ( `Pulse Intensity: ${ this . config . pulseIntensity } ` ) ;
113
+ console . log ( `Pulse Speed: ${ this . config . pulseSpeed } ` ) ;
150
114
}
151
115
152
116
calculateFormationParameters ( ) {
@@ -158,7 +122,11 @@ class PatternFormation {
158
122
this . formationSpacing = Math . max ( minSpacing , this . config . formationRadius * 0.8 ) ;
159
123
}
160
124
125
+ // Modify createFormation to apply current difficulty settings
161
126
createFormation ( ) {
127
+ // Apply new difficulty modifiers before creating formation
128
+ this . applyDifficultyModifiers ( ) ;
129
+
162
130
this . aliens = [ ] ;
163
131
this . alienSlots = [ ] ; // Reset slots
164
132
const count = Math . floor ( this . config . alienCount ) ;
@@ -303,6 +271,9 @@ class PatternFormation {
303
271
shooter . y + shooter . height
304
272
) ;
305
273
this . lasers . push ( laser ) ;
274
+
275
+ // Play shoot sound with position
276
+ AlienLaser . playShootSound ( shooter . x + shooter . width / 2 , this . virtualWidth ) ;
306
277
}
307
278
308
279
getPatternPosition ( angle , centerX , centerY , radiusX , radiusY ) {
0 commit comments