added diffuse speed and refactoring
This commit is contained in:
@@ -7,6 +7,7 @@ public class Dirt : Solid {
|
|||||||
public Dirt(int x, int y, ref Level level) : base(x, y, ref level) {
|
public Dirt(int x, int y, ref Level level) : base(x, y, ref level) {
|
||||||
Color = AddColorVariance(Colors.Brown);
|
Color = AddColorVariance(Colors.Brown);
|
||||||
Density = 10;
|
Density = 10;
|
||||||
|
DiffuseSpeed = 50;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool Update(int currentFrame) {
|
public override bool Update(int currentFrame) {
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ public class Element {
|
|||||||
public Vector2I Position;
|
public Vector2I Position;
|
||||||
public int Density;
|
public int Density;
|
||||||
|
|
||||||
|
public int DiffuseSpeed = 10;
|
||||||
|
public const int MAX_DIFFUSE_SPEED = 100;
|
||||||
|
|
||||||
protected readonly float MaxColorVariance = 0.1f;
|
protected readonly float MaxColorVariance = 0.1f;
|
||||||
protected readonly Level Level;
|
protected readonly Level Level;
|
||||||
|
|
||||||
@@ -41,28 +44,32 @@ public class Element {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void Tick() {
|
protected virtual void Tick() {
|
||||||
int randomDirection = GD.Randi() % 2 != 0 ? 1 : -1;
|
Vector2I randomDirection = RandomDirectionDown();
|
||||||
|
|
||||||
if (Level.IsEmpty(Position + Vector2I.Down)) {
|
if (Level.IsEmpty(Position + Vector2I.Down)) {
|
||||||
Level.Swap(this, Position + Vector2I.Down);
|
Level.Swap(this, Position + Vector2I.Down);
|
||||||
|
|
||||||
} else if (Level.IsEmpty(Position + Vector2I.Down + Vector2I.Right * randomDirection)) {
|
} else if (Level.IsEmpty(Position + randomDirection)) {
|
||||||
Level.Swap(this, Position + Vector2I.Right * randomDirection);
|
Level.Swap(this, Position + randomDirection);
|
||||||
|
|
||||||
} else if (Level.IsEmpty(Position + Vector2I.Down + Vector2I.Right * randomDirection * -1)) {
|
} else if (Level.IsEmpty(Position + randomDirection * -Vector2I.Left)) {
|
||||||
Level.Swap(this, Position + Vector2I.Right*randomDirection);
|
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
|
if (Level.Get(Position + randomDirection)?.Density < Density)
|
||||||
// maybe also side
|
|
||||||
+ (GD.Randi() % 2 != 0 ?
|
|
||||||
Vector2I.Zero : Vector2I.Right * randomDirection)
|
|
||||||
)?.Density < Density)
|
|
||||||
Level.Swap(this, Position + Vector2I.Down);
|
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) {
|
protected Color AddColorVariance(Color baseColor) {
|
||||||
Color c = baseColor;
|
Color c = baseColor;
|
||||||
c.R += (GD.Randf() - 1) * MaxColorVariance;
|
c.R += (GD.Randf() - 1) * MaxColorVariance;
|
||||||
|
|||||||
Reference in New Issue
Block a user