Skip to content

Commit 2cccb27

Browse files
committed
few tweaks on puddle, water and birds sound
1 parent 2bae125 commit 2cccb27

5 files changed

Lines changed: 35 additions & 74 deletions

File tree

screenshots/first-water-sign.png

435 KB
Loading

screenshots/fully-loaded.png

493 KB
Loading

src/main/java/wagemaker/uk/biome/BiomeManager.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ private boolean isInSandPatch(float worldX, float worldY) {
188188
/**
189189
* Checks if a position is within a water patch.
190190
* Uses multi-octave noise to create organic lake shapes.
191-
* Target distribution: ~15% water coverage
191+
* Target distribution: ~15% water coverage with smaller, more varied shapes
192192
*
193193
* @param worldX The x-coordinate in world space
194194
* @param worldY The y-coordinate in world space
@@ -205,23 +205,23 @@ private boolean isInWaterPatch(float worldX, float worldY) {
205205
}
206206

207207
// Use multi-octave noise for organic lake shapes
208-
// Using smaller scale values (lower frequency) to create larger, more contiguous lakes
209-
float noiseScale1 = 0.00005f; // Large features (lake locations) - very low frequency for large lakes
210-
float noiseScale2 = 0.0002f; // Medium features (lake shapes) - reduced for more contiguity
211-
float noiseScale3 = 0.0008f; // Small features (shoreline detail) - reduced for smoother edges
208+
// Higher frequency values create smaller, more varied water bodies
209+
float noiseScale1 = 0.0003f; // Large features (lake locations) - increased for smaller lakes
210+
float noiseScale2 = 0.0012f; // Medium features (lake shapes) - increased for more variation
211+
float noiseScale3 = 0.0025f; // Small features (shoreline detail) - increased for irregular edges
212212

213213
// Sample noise at different scales
214214
float noise1 = simplexNoise(worldX * noiseScale1, worldY * noiseScale1);
215215
float noise2 = simplexNoise(worldX * noiseScale2, worldY * noiseScale2);
216216
float noise3 = simplexNoise(worldX * noiseScale3, worldY * noiseScale3);
217217

218-
// Combine noise octaves with heavy weight on large features for maximum contiguity
219-
float combinedNoise = noise1 * 0.7f + noise2 * 0.2f + noise3 * 0.1f;
218+
// Combine noise octaves with more balanced weights for varied shapes
219+
float combinedNoise = noise1 * 0.4f + noise2 * 0.35f + noise3 * 0.25f;
220220

221221
// Normalize to 0-1 range
222222
float waterProbability = combinedNoise * 0.5f + 0.5f;
223223

224-
// Threshold for water (0.75 = ~15% coverage)
224+
// Threshold for water - adjusted to maintain ~15% coverage with new noise scales
225225
return waterProbability > BiomeConfig.WATER_NOISE_THRESHOLD;
226226
}
227227

src/main/java/wagemaker/uk/birds/BirdFormationManager.java

Lines changed: 8 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

src/main/java/wagemaker/uk/weather/PuddleRenderer.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,12 +312,28 @@ public void setBiomeManager(BiomeManager biomeManager) {
312312
* @return true if the position has adequate spacing, false otherwise
313313
*/
314314
private boolean hasMinimumSpacing(float x, float y, WaterPuddle excludePuddle) {
315-
// Check if location is in water biome
315+
// Check if location is in or near water biome (minimum 128px distance)
316316
if (biomeManager != null && biomeManager.isInitialized()) {
317-
BiomeType biomeType = biomeManager.getBiomeAtPosition(x, y);
318-
if (biomeType == BiomeType.WATER) {
317+
float waterCheckRadius = 128f;
318+
int checkPoints = 8; // Check 8 points around the puddle location
319+
320+
// Check center point
321+
BiomeType centerBiome = biomeManager.getBiomeAtPosition(x, y);
322+
if (centerBiome == BiomeType.WATER) {
319323
return false; // Don't create puddles in water
320324
}
325+
326+
// Check points in a circle around the puddle location
327+
for (int i = 0; i < checkPoints; i++) {
328+
float angle = (float) (2 * Math.PI * i / checkPoints);
329+
float checkX = x + (float) Math.cos(angle) * waterCheckRadius;
330+
float checkY = y + (float) Math.sin(angle) * waterCheckRadius;
331+
332+
BiomeType biomeType = biomeManager.getBiomeAtPosition(checkX, checkY);
333+
if (biomeType == BiomeType.WATER) {
334+
return false; // Too close to water
335+
}
336+
}
321337
}
322338

323339
float minSpacingSquared = PuddleConfig.MIN_PUDDLE_SPACING * PuddleConfig.MIN_PUDDLE_SPACING;

0 commit comments

Comments
 (0)