added density
code improvements
This commit is contained in:
@@ -6,6 +6,7 @@ public class Element {
|
||||
public Color Color = Colors.Black;
|
||||
|
||||
public Vector2I Position;
|
||||
public int Density;
|
||||
|
||||
protected readonly float MaxColorVariance = 0.1f;
|
||||
protected readonly Level Level;
|
||||
@@ -40,9 +41,7 @@ public class Element {
|
||||
}
|
||||
|
||||
protected virtual void Tick() {
|
||||
int randomDirection = 1;
|
||||
if (GD.Randi() % 2 != 0)
|
||||
randomDirection *= -1;
|
||||
int randomDirection = GD.Randi() % 2 != 0 ? 1 : -1;
|
||||
|
||||
if (Level.IsEmpty(Position + Vector2I.Down)) {
|
||||
Level.Swap(this, Position + Vector2I.Down);
|
||||
@@ -53,6 +52,15 @@ public class Element {
|
||||
} else if (Level.IsEmpty(Position + Vector2I.Down + Vector2I.Right * randomDirection * -1)) {
|
||||
Level.Swap(this, Position + Vector2I.Right*randomDirection);
|
||||
}
|
||||
|
||||
if (GD.Randi() % 10 > 1) return; // ascend slower
|
||||
|
||||
if (Level.Get(Position + Vector2I.Down
|
||||
// maybe also side
|
||||
+ (GD.Randi() % 2 != 0 ?
|
||||
Vector2I.Zero : Vector2I.Right * randomDirection)
|
||||
)?.Density < Density)
|
||||
Level.Swap(this, Position + Vector2I.Down);
|
||||
}
|
||||
|
||||
protected Color AddColorVariance(Color baseColor) {
|
||||
|
||||
Reference in New Issue
Block a user