diff --git a/Scripts/Elements/Element.cs b/Scripts/Elements/Element.cs
index f272ed7..8ce8b33 100644
--- a/Scripts/Elements/Element.cs
+++ b/Scripts/Elements/Element.cs
@@ -88,13 +88,13 @@ public class Element{
else if (Chunk.IsEmpty(Position + randomDirection * VERTICAL_OPPOSITE))
Chunk.Swap(this, Position + randomDirection * VERTICAL_OPPOSITE);
- if (GD.Randi() % MAX_DIFFUSE_SPEED > DiffuseSpeed) return; // descend slower
-
- if (Chunk.Get(Position + randomDirection)?.Density < Density)
+ // density check
+ if (Chunk.Get(Position + Vector2I.Down)?.Density < Density)
+ Chunk.Swap(this, Position + Vector2I.Down);
+ else if (Chunk.Get(Position + Vector2I.Down + randomDirection)?.Density < Density)
Chunk.Swap(this, Position + Vector2I.Down);
}
- /// -1, 0 or 1
protected Vector2I RandomDirectionDown() {
int randomDirection = GD.Randi() % 2 != 0 ? 1 : -1;
@@ -102,6 +102,13 @@ public class Element{
+ (GD.Randi() % 2 != 0 ? Vector2I.Zero : Vector2I.Right * randomDirection);
}
+ /// -1, 0 or 1
+ protected Vector2I RandomDirection() {
+ int randomDirection = GD.Randi() % 2 != 0 ? 1 : -1;
+
+ return (GD.Randi() % 2 != 0 ? Vector2I.Zero : Vector2I.Right * randomDirection);
+ }
+
protected Color AddColorVariance(Color baseColor) {
Color c = baseColor;
c.R += (GD.Randf() - 1) * MAX_COLOR_VARIANCE;
@@ -128,7 +135,7 @@ public class Element{
MarkForUpdate();
}
- public bool MarkedForUpdate() {
+ public bool IsMarkedForUpdate() {
return markedForUpdate;
}
diff --git a/Scripts/Level.cs b/Scripts/Level.cs
index c14b7d8..d7156d2 100644
--- a/Scripts/Level.cs
+++ b/Scripts/Level.cs
@@ -30,7 +30,7 @@ public class Level {
GD.Print($"Generating level ({sizeX}:{sizeY}) with {chunksPerX*chunksPerY} chunks ({chunkResX} * {chunkResY})");
- image = Image.Create(sizeX, sizeY, false, Image.Format.Rgb8);
+ image = Image.CreateEmpty(sizeX, sizeY, false, Image.Format.Rgb8);
chunks = new Chunk[chunksPerX, chunksPerY];
int index = 0;
@@ -165,7 +165,7 @@ public class Level {
for (int y = 0; y < chunkResY; y++) {
// TODO: multithreading here! use Chunk.DrawLevel() and stitch images together
- if (chunks[cx, cy].Elements[x, y].MarkedForUpdate()) {
+ if (chunks[cx, cy].Elements[x, y].IsMarkedForUpdate()) {
image.SetPixel(cx * chunkResX + x, cy * chunkResY + y, chunks[cx, cy].Elements[x, y].Color);
chunks[cx, cy].Elements[x, y].MarkForUpdate(false);
}
diff --git a/Scripts/Main.cs b/Scripts/Main.cs
index b671b99..c5bbff1 100644
--- a/Scripts/Main.cs
+++ b/Scripts/Main.cs
@@ -36,10 +36,10 @@ public partial class Main : Node2D {
public override void _PhysicsProcess(double delta) {
base._PhysicsProcess(delta);
- Level.Update();
}
public override void _Process(double delta) {
+ Level.Update();
mLevelDrawer.Texture?.Dispose();
mLevelDrawer.Texture = ImageTexture.CreateFromImage(Level.DrawLevel());
}