re-enabled rain
This commit is contained in:
@@ -39,8 +39,6 @@ public class Chunk {
|
||||
Elements[x,y].Update();
|
||||
}
|
||||
}
|
||||
// TODO: enable rain again
|
||||
// MakeItRain(_main.RainAmount);
|
||||
}
|
||||
|
||||
public void WritePixel<T>(int x, int y, int size) {
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using FOU.Scripts.Elements;
|
||||
using Godot;
|
||||
|
||||
namespace FOU.Scripts;
|
||||
|
||||
@@ -16,6 +18,9 @@ public class Level {
|
||||
private int chunkResX;
|
||||
private int chunkResY;
|
||||
|
||||
private bool enableRain = false;
|
||||
private float rainAmount = 0;
|
||||
|
||||
public Level(Main main, int sizeX, int sizeY) {
|
||||
GD.Print($"Generating level ({sizeX}:{sizeY}) with {chunksX*chunksY} chunks ({chunkResX} * {chunkResY})");
|
||||
|
||||
@@ -51,18 +56,25 @@ public class Level {
|
||||
}
|
||||
|
||||
public void Update() {
|
||||
MakeItRain();
|
||||
|
||||
foreach (Chunk c in chunks)
|
||||
c.Update();
|
||||
}
|
||||
|
||||
// TODO!
|
||||
private void MakeItRain(float rainAmount) {
|
||||
// int rainDrops = (int)Math.Round(rainAmount);
|
||||
//
|
||||
// for (int i = 0; i <= rainDrops; i++) {
|
||||
// if (GD.Randf() < rainAmount)
|
||||
// WritePixel<Water>((int)(GD.Randi() % SizeX), 0, 1);
|
||||
// }
|
||||
public void SetRainAmount(float amount) {
|
||||
rainAmount = amount;
|
||||
}
|
||||
|
||||
private void MakeItRain() {
|
||||
if (rainAmount < .1f) return;
|
||||
|
||||
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) {
|
||||
|
||||
@@ -9,16 +9,27 @@ public partial class Main : Node2D {
|
||||
[Export] public int BrushSize = 5;
|
||||
[Export] public float TextureResolution = 0.5f;
|
||||
[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;
|
||||
|
||||
private TextureRect mLevelDrawer;
|
||||
private Level mLevel;
|
||||
private bool enableRain;
|
||||
private float rainAmount;
|
||||
|
||||
public override void _Ready() {
|
||||
mLevel = new Level(this, (int)(GetViewportRect().Size.X * TextureResolution),
|
||||
(int)(GetViewportRect().Size.Y * TextureResolution));
|
||||
mLevel.SetRainAmount(rainAmount);
|
||||
mLevelDrawer = GetNode<TextureRect>("CanvasLayer/LevelDrawer");
|
||||
|
||||
Instance = this;
|
||||
|
||||
Reference in New Issue
Block a user