@@ -11,21 +11,34 @@ class PatternFormation {
1111 this . virtualWidth = options . virtualWidth || 1080 ;
1212 this . virtualHeight = options . virtualHeight || 1080 ;
1313
14- // Initialize config first
14+ // Initialize config with new starting values
1515 this . config = {
1616 speed : 0.3 ,
1717 radius : 80 ,
1818 patternType : 'infinity' ,
1919 loopDuration : 10 ,
20- alienCount : 5 ,
21- showPath : false , // Changed from true to false
20+ alienCount : 10 , // Increased from 5 to 10
21+ showPath : false ,
2222 pathPoints : 100 , // number of points to draw on path
2323 formationRadius : 150 , // New separate radius for formation
2424 pulseIntensity : 0 , // Add pulse intensity control
2525 pulseSpeed : 1 , // Add pulse speed control
2626 shootingEnabled : true // Add shooting enabled control
2727 } ;
2828
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+
2942 this . aliens = [ ] ;
3043 this . pattern = patterns [ options . pattern || 'circle' ] ;
3144 this . time = 0 ;
@@ -64,9 +77,6 @@ class PatternFormation {
6477 this . shootTimer = 0 ;
6578 this . shootInterval = 1.0 ; // Time between shots
6679
67- // Delay GUI setup to ensure dat.GUI is loaded
68- setTimeout ( ( ) => this . setupGUI ( ) , 100 ) ;
69-
7080 this . difficulty = options . difficulty || 1 ;
7181 this . shootInterval = Math . max ( 0.3 , 1.0 - ( this . difficulty * 0.1 ) ) ; // Shoot faster with higher difficulty
7282 this . config . speed = Math . min ( 2.0 , 0.3 + ( this . difficulty * 0.1 ) ) ; // Move faster with higher difficulty
@@ -76,77 +86,31 @@ class PatternFormation {
7686 this . explosionEffect = new ExplosionEffect ( ctx ) ;
7787 }
7888
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 ) ) ;
85109
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 } ` ) ;
150114 }
151115
152116 calculateFormationParameters ( ) {
@@ -158,7 +122,11 @@ class PatternFormation {
158122 this . formationSpacing = Math . max ( minSpacing , this . config . formationRadius * 0.8 ) ;
159123 }
160124
125+ // Modify createFormation to apply current difficulty settings
161126 createFormation ( ) {
127+ // Apply new difficulty modifiers before creating formation
128+ this . applyDifficultyModifiers ( ) ;
129+
162130 this . aliens = [ ] ;
163131 this . alienSlots = [ ] ; // Reset slots
164132 const count = Math . floor ( this . config . alienCount ) ;
@@ -303,6 +271,9 @@ class PatternFormation {
303271 shooter . y + shooter . height
304272 ) ;
305273 this . lasers . push ( laser ) ;
274+
275+ // Play shoot sound with position
276+ AlienLaser . playShootSound ( shooter . x + shooter . width / 2 , this . virtualWidth ) ;
306277 }
307278
308279 getPatternPosition ( angle , centerX , centerY , radiusX , radiusY ) {
0 commit comments