diff --git a/Scripts/Elements/Dirt.cs b/Scripts/Elements/Dirt.cs index 680bf0a..6900d64 100644 --- a/Scripts/Elements/Dirt.cs +++ b/Scripts/Elements/Dirt.cs @@ -7,6 +7,7 @@ public class Dirt : Solid { public Dirt(int x, int y, ref Level level) : base(x, y, ref level) { Color = AddColorVariance(Colors.Brown); Density = 10; + DiffuseSpeed = 50; } public override bool Update(int currentFrame) { diff --git a/Scripts/Elements/Element.cs b/Scripts/Elements/Element.cs index 36e0a32..b7f26da 100644 --- a/Scripts/Elements/Element.cs +++ b/Scripts/Elements/Element.cs @@ -8,6 +8,9 @@ public class Element { public Vector2I Position; public int Density; + public int DiffuseSpeed = 10; + public const int MAX_DIFFUSE_SPEED = 100; + protected readonly float MaxColorVariance = 0.1f; protected readonly Level Level; @@ -41,28 +44,32 @@ public class Element { } protected virtual void Tick() { - int randomDirection = GD.Randi() % 2 != 0 ? 1 : -1; + Vector2I randomDirection = RandomDirectionDown(); if (Level.IsEmpty(Position + Vector2I.Down)) { Level.Swap(this, Position + Vector2I.Down); - } else if (Level.IsEmpty(Position + Vector2I.Down + Vector2I.Right * randomDirection)) { - Level.Swap(this, Position + Vector2I.Right * randomDirection); + } else if (Level.IsEmpty(Position + randomDirection)) { + Level.Swap(this, Position + randomDirection); - } else if (Level.IsEmpty(Position + Vector2I.Down + Vector2I.Right * randomDirection * -1)) { - Level.Swap(this, Position + Vector2I.Right*randomDirection); + } else if (Level.IsEmpty(Position + randomDirection * -Vector2I.Left)) { + Level.Swap(this, Position + randomDirection * -1); } - if (GD.Randi() % 10 > 1) return; // ascend slower + if (GD.Randi() % 100 > DiffuseSpeed) return; // ascend slower - if (Level.Get(Position + Vector2I.Down - // maybe also side - + (GD.Randi() % 2 != 0 ? - Vector2I.Zero : Vector2I.Right * randomDirection) - )?.Density < Density) + if (Level.Get(Position + randomDirection)?.Density < Density) Level.Swap(this, Position + Vector2I.Down); } + protected Vector2I RandomDirectionDown() { + int randomDirection = GD.Randi() % 2 != 0 ? 1 : -1; + + return Vector2I.Down + // maybe also side + + (GD.Randi() % 2 != 0 ? Vector2I.Zero : Vector2I.Right * randomDirection); + } + protected Color AddColorVariance(Color baseColor) { Color c = baseColor; c.R += (GD.Randf() - 1) * MaxColorVariance;