@@ -24,15 +24,12 @@ public class BirdFormationManager {
2424 private Texture birdTexture1 ;
2525 private Texture birdTexture2 ;
2626 private Sound birdSound ;
27- private long birdSoundId = -1 ;
28- private boolean isFadingOut = false ;
29- private float currentVolume = 1.0f ;
30- private float fadeOutTimer = 0f ;
27+
28+ private static final float BIRD_VOLUME = 0.7f ; // 70% volume (reduced by 30%)
3129
3230 private static final float MIN_SPAWN_INTERVAL = 60f ; // 1 minute
3331 private static final float MAX_SPAWN_INTERVAL = 180f ; // 3 minutes
3432 private static final float BIRD_SPEED = 100f ; // pixels per second
35- private static final float FADE_OUT_DURATION = 1.0f ; // 1 second fade out
3633
3734 public BirdFormationManager (OrthographicCamera camera , Viewport viewport ) {
3835 this .camera = camera ;
@@ -93,35 +90,6 @@ public void update(float deltaTime, float playerX, float playerY) {
9390 return ; // Bird system disabled if textures failed to load
9491 }
9592
96- // Update fade-out if in progress
97- if (isFadingOut && birdSound != null && birdSoundId != -1 ) {
98- fadeOutTimer += deltaTime ;
99- float fadeProgress = fadeOutTimer / FADE_OUT_DURATION ;
100-
101- if (fadeProgress >= 1.0f ) {
102- // Fade complete, stop sound
103- try {
104- birdSound .stop (birdSoundId );
105- System .out .println ("[BIRDS] Bird sound stopped (fade complete)" );
106- } catch (Exception e ) {
107- System .err .println ("[BIRDS] Error stopping bird sound: " + e .getMessage ());
108- } finally {
109- birdSoundId = -1 ;
110- isFadingOut = false ;
111- currentVolume = 1.0f ;
112- fadeOutTimer = 0f ;
113- }
114- } else {
115- // Update volume during fade
116- currentVolume = 1.0f - fadeProgress ;
117- try {
118- birdSound .setVolume (birdSoundId , currentVolume );
119- } catch (Exception e ) {
120- System .err .println ("[BIRDS] Error setting bird sound volume: " + e .getMessage ());
121- }
122- }
123- }
124-
12593 // Update active formation
12694 if (activeFormation != null ) {
12795 activeFormation .update (deltaTime );
@@ -137,7 +105,7 @@ public void update(float deltaTime, float playerX, float playerY) {
137105 }
138106
139107 // Update spawn timer
140- if (activeFormation == null && ! isFadingOut ) {
108+ if (activeFormation == null ) {
141109 spawnTimer -= deltaTime ;
142110
143111 if (spawnTimer <= 0 ) {
@@ -153,17 +121,6 @@ public void render(SpriteBatch batch) {
153121 }
154122
155123 public void dispose () {
156- // Stop sound if playing
157- if (birdSound != null && birdSoundId != -1 ) {
158- try {
159- birdSound .stop (birdSoundId );
160- } catch (Exception e ) {
161- System .err .println ("[BIRDS] Error stopping bird sound during dispose: " + e .getMessage ());
162- } finally {
163- birdSoundId = -1 ;
164- }
165- }
166-
167124 // Dispose sound resource
168125 if (birdSound != null ) {
169126 try {
@@ -193,18 +150,13 @@ private void spawnFormation() {
193150 activeFormation = new BirdFormation (spawnPoint , velocity , birdTexture1 , birdTexture2 );
194151 lastSpawnBoundary = spawnPoint .boundary ;
195152
196- // Start bird sound
197- if (birdSound != null && birdSoundId == - 1 ) {
153+ // Play bird sound once
154+ if (birdSound != null ) {
198155 try {
199- birdSoundId = birdSound .loop ();
200- birdSound .setVolume (birdSoundId , 1.0f );
201- currentVolume = 1.0f ;
202- isFadingOut = false ;
203- fadeOutTimer = 0f ;
204- System .out .println ("[BIRDS] Bird sound started" );
156+ birdSound .play (BIRD_VOLUME );
157+ System .out .println ("[BIRDS] Bird sound played once" );
205158 } catch (Exception e ) {
206- System .err .println ("[BIRDS] Error starting bird sound: " + e .getMessage ());
207- birdSoundId = -1 ; // Ensure sound ID remains in stopped state
159+ System .err .println ("[BIRDS] Error playing bird sound: " + e .getMessage ());
208160 }
209161 }
210162
@@ -226,13 +178,6 @@ private void spawnFormation() {
226178 }
227179
228180 private void despawnFormation () {
229- // Start fade-out for bird sound
230- if (birdSound != null && birdSoundId != -1 && !isFadingOut ) {
231- isFadingOut = true ;
232- fadeOutTimer = 0f ;
233- System .out .println ("[BIRDS] Bird sound fading out" );
234- }
235-
236181 if (activeFormation != null ) {
237182 activeFormation .dispose ();
238183 activeFormation = null ;
0 commit comments