added color variance

This commit is contained in:
2023-10-17 14:33:21 +02:00
parent 31dbbbf070
commit 43d121d4da
4 changed files with 18 additions and 14 deletions

View File

@@ -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;
}

View File

@@ -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;
}
/// <summary>
@@ -23,8 +24,8 @@ public class Element {
/// <param name="currentFrame"></param>
/// <returns>false if there is nothing to do</returns>
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;
}

View File

@@ -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;
}

View File

@@ -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;
}