re-enabled rain

This commit is contained in:
2024-10-27 13:53:49 +01:00
parent 7388e1a2d7
commit bb2f498ac5
4 changed files with 33 additions and 13 deletions

View File

@@ -9,7 +9,6 @@ script = ExtResource("1_k1i8e")
DebugVisualization = true DebugVisualization = true
BrushSize = 2 BrushSize = 2
TextureResolution = 0.35 TextureResolution = 0.35
RainAmount = 5.0
[node name="CanvasLayer" type="CanvasLayer" parent="."] [node name="CanvasLayer" type="CanvasLayer" parent="."]

View File

@@ -39,8 +39,6 @@ public class Chunk {
Elements[x,y].Update(); Elements[x,y].Update();
} }
} }
// TODO: enable rain again
// MakeItRain(_main.RainAmount);
} }
public void WritePixel<T>(int x, int y, int size) { public void WritePixel<T>(int x, int y, int size) {

View File

@@ -1,4 +1,6 @@
using Godot; using System;
using FOU.Scripts.Elements;
using Godot;
namespace FOU.Scripts; namespace FOU.Scripts;
@@ -16,6 +18,9 @@ public class Level {
private int chunkResX; private int chunkResX;
private int chunkResY; private int chunkResY;
private bool enableRain = false;
private float rainAmount = 0;
public Level(Main main, int sizeX, int sizeY) { public Level(Main main, int sizeX, int sizeY) {
GD.Print($"Generating level ({sizeX}:{sizeY}) with {chunksX*chunksY} chunks ({chunkResX} * {chunkResY})"); GD.Print($"Generating level ({sizeX}:{sizeY}) with {chunksX*chunksY} chunks ({chunkResX} * {chunkResY})");
@@ -51,18 +56,25 @@ public class Level {
} }
public void Update() { public void Update() {
MakeItRain();
foreach (Chunk c in chunks) foreach (Chunk c in chunks)
c.Update(); c.Update();
} }
// TODO! public void SetRainAmount(float amount) {
private void MakeItRain(float rainAmount) { rainAmount = amount;
// int rainDrops = (int)Math.Round(rainAmount); }
//
// for (int i = 0; i <= rainDrops; i++) { private void MakeItRain() {
// if (GD.Randf() < rainAmount) if (rainAmount < .1f) return;
// WritePixel<Water>((int)(GD.Randi() % SizeX), 0, 1);
// } int rainDrops = (int)Math.Round(rainAmount);
for (int i = 0; i <= rainDrops; i++) {
if (GD.Randf() < rainAmount)
WritePixel<Water>((int)(GD.Randi() % (chunkResX * chunksX)), 0, 1);
}
} }
public void WritePixel<T>(int x, int y, int size) { public void WritePixel<T>(int x, int y, int size) {

View File

@@ -9,16 +9,27 @@ public partial class Main : Node2D {
[Export] public int BrushSize = 5; [Export] public int BrushSize = 5;
[Export] public float TextureResolution = 0.5f; [Export] public float TextureResolution = 0.5f;
[Export] public int ChunksPerAxis = 2; [Export] public int ChunksPerAxis = 2;
[Export] public float RainAmount = 0.01f;
[Export]
public float RainAmount {
get => rainAmount;
set {
rainAmount = value;
mLevel.SetRainAmount(rainAmount);
}
}
public static Main Instance; public static Main Instance;
private TextureRect mLevelDrawer; private TextureRect mLevelDrawer;
private Level mLevel; private Level mLevel;
private bool enableRain;
private float rainAmount;
public override void _Ready() { public override void _Ready() {
mLevel = new Level(this, (int)(GetViewportRect().Size.X * TextureResolution), mLevel = new Level(this, (int)(GetViewportRect().Size.X * TextureResolution),
(int)(GetViewportRect().Size.Y * TextureResolution)); (int)(GetViewportRect().Size.Y * TextureResolution));
mLevel.SetRainAmount(rainAmount);
mLevelDrawer = GetNode<TextureRect>("CanvasLayer/LevelDrawer"); mLevelDrawer = GetNode<TextureRect>("CanvasLayer/LevelDrawer");
Instance = this; Instance = this;