fixed stuck rain

refactoring
This commit is contained in:
2025-04-30 23:13:53 +02:00
parent d9bde10c3c
commit 0b97027e00
4 changed files with 21 additions and 6 deletions

View File

@@ -84,8 +84,11 @@ public class Level {
int rainDrops = (int)Math.Round(rainAmount);
for (int i = 0; i <= rainDrops; i++) {
if (GD.Randf() < rainAmount)
WritePixel<Water>((int)(GD.Randi() % (chunkResX * chunksPerX)), 0, 1);
if (GD.Randf() < rainAmount) {
int d = (int)(GD.Randi() % (chunkResX * chunksPerX));
if (GetElement(d, 0).IsEmpty())
WritePixel<Water>(d, 0, 1);
}
}
}
@@ -145,6 +148,13 @@ public class Level {
}
}
public Element GetElement(int x, int y) {
if (x < 0 || x > chunkResX * chunkResX) return null;
if (y < 0 || y > chunkResY * chunkResY) return null;
return chunks[x / chunkResX, y / chunkResY].Elements[x % chunkResX, y % chunkResY];
}
public Image DrawLevel() {
// chunk
for (int cx = 0; cx < chunksPerX; cx++) {