From 43d121d4dae83ef507aaeb1a78170cb596ce9af9 Mon Sep 17 00:00:00 2001 From: rogo Date: Tue, 17 Oct 2023 14:33:21 +0200 Subject: [PATCH] added color variance --- Scripts/Elements/Dirt.cs | 5 ++++- Scripts/Elements/Element.cs | 11 ++++++----- Scripts/Elements/Liquid.cs | 8 ++++---- Scripts/Elements/Solid.cs | 8 ++++---- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/Scripts/Elements/Dirt.cs b/Scripts/Elements/Dirt.cs index 050f45a..a2b139e 100644 --- a/Scripts/Elements/Dirt.cs +++ b/Scripts/Elements/Dirt.cs @@ -6,6 +6,9 @@ public class Dirt : Solid { public Dirt(int x, int y, ref Level level) : base(x, y, ref level) { Color = Colors.Brown; + Color.R += (GD.Randf() - 1) * MaxColorVariance; + Color.G += (GD.Randf() - 1) * MaxColorVariance; + Color.B += (GD.Randf() - 1) * MaxColorVariance; } public override bool Update(int currentFrame) { @@ -14,7 +17,7 @@ public class Dirt : Solid { Vector2I freePos = Check(this, Vector2I.Down + Vector2I.Right); if (freePos != Vector2I.Zero) { // diagonally right - _level.Swap(this, freePos); + Level.Swap(this, freePos); return true; } diff --git a/Scripts/Elements/Element.cs b/Scripts/Elements/Element.cs index cde75f1..1a266c0 100644 --- a/Scripts/Elements/Element.cs +++ b/Scripts/Elements/Element.cs @@ -7,14 +7,15 @@ public class Element { public Vector2I Position; - protected Level _level; + protected readonly float MaxColorVariance = 0.1f; + protected readonly Level Level; - private int _lastUpdate = -1; + private int lastUpdate = -1; public Element(int x, int y, ref Level level) { Position.X = x; Position.Y = y; - _level = level; + Level = level; } /// @@ -23,8 +24,8 @@ public class Element { /// /// false if there is nothing to do public virtual bool Update(int currentFrame) { - if (_lastUpdate == currentFrame) return false; // already updated this frame - _lastUpdate = currentFrame; + if (lastUpdate == currentFrame) return false; // already updated this frame + lastUpdate = currentFrame; return true; } diff --git a/Scripts/Elements/Liquid.cs b/Scripts/Elements/Liquid.cs index 9ceaef8..2c18957 100644 --- a/Scripts/Elements/Liquid.cs +++ b/Scripts/Elements/Liquid.cs @@ -11,18 +11,18 @@ public abstract class Liquid : Element { Vector2I freePos = Vector2I.Zero; for (int y = 0; y <= maxDirection.Y; y++) { // height - if (source.Position.Y + y >= _level.SizeY) return freePos; // bounds check + if (source.Position.Y + y >= Level.SizeY) return freePos; // bounds check - if (_level.Get(source.Position.X, source.Position.Y + y).GetType() == typeof(Element)) { + if (Level.Get(source.Position.X, source.Position.Y + y).GetType() == typeof(Element)) { freePos = new Vector2I(source.Position.X, source.Position.Y + y); } for (int x = -maxDirection.X; x <= maxDirection.X; x++) { // width if (freePos != Vector2I.Zero) break; - if (source.Position.X + x >= _level.SizeX || source.Position.X + x < 0) return freePos; // bounds check + if (source.Position.X + x >= Level.SizeX || source.Position.X + x < 0) return freePos; // bounds check - if (_level.Get(source.Position.X + x, source.Position.Y + y).GetType() == typeof(Element)) { + if (Level.Get(source.Position.X + x, source.Position.Y + y).GetType() == typeof(Element)) { freePos = new Vector2I(source.Position.X + x, source.Position.Y + y); break; } diff --git a/Scripts/Elements/Solid.cs b/Scripts/Elements/Solid.cs index 9498d11..343ecfa 100644 --- a/Scripts/Elements/Solid.cs +++ b/Scripts/Elements/Solid.cs @@ -11,9 +11,9 @@ public abstract class Solid : Element { Vector2I freePos = Vector2I.Zero; for (int y = maxDirection.Y; y > 0; y--) { // height - if (source.Position.Y + y >= _level.SizeY) return freePos; // bounds check + if (source.Position.Y + y >= Level.SizeY) return freePos; // bounds check - if (_level.Get(source.Position.X, source.Position.Y + y).GetType() == typeof(Element)) { + if (Level.Get(source.Position.X, source.Position.Y + y).GetType() == typeof(Element)) { freePos = new Vector2I(source.Position.X, source.Position.Y + y); } else { freePos = Vector2I.Zero; @@ -22,9 +22,9 @@ public abstract class Solid : Element { for (int x = -maxDirection.X; x <= maxDirection.X; x++) { // width if (freePos != Vector2I.Zero) break; - if (source.Position.X + x >= _level.SizeX || source.Position.X + x < 0) return freePos; // bounds check + if (source.Position.X + x >= Level.SizeX || source.Position.X + x < 0) return freePos; // bounds check - if (_level.Get(source.Position.X + x, source.Position.Y + y).GetType() == typeof(Element)) { + if (Level.Get(source.Position.X + x, source.Position.Y + y).GetType() == typeof(Element)) { freePos = new Vector2I(source.Position.X + x, source.Position.Y + y); break; }