added chunks

This commit is contained in:
2024-07-14 17:22:37 +02:00
parent 5d07477de5
commit 31edd511e0
8 changed files with 213 additions and 124 deletions

View File

@@ -6,6 +6,7 @@ public class Element {
public Color Color = Colors.Black;
public Vector2I Position;
public Chunk Chunk;
public int Density;
public int LastUpdate = -1;
public int LastMove = 0;
@@ -16,20 +17,19 @@ public class Element {
protected const float MAX_COLOR_VARIANCE = 0.1f;
protected static readonly Vector2I VERTICAL_OPPOSITE = new Vector2I(-1, 1);
protected readonly Level Level;
private bool active = true;
private Color originalColor;
public Element(Element e) {
Position = e.Position;
Level = e.Level;
Chunk = e.Chunk;
}
public Element(int x, int y, Level level) {
public Element(int x, int y, Chunk chunk) {
Position.X = x;
Position.Y = y;
Level = level;
Chunk = chunk;
}
public bool Active {
@@ -65,19 +65,19 @@ public class Element {
protected virtual void Tick() {
Vector2I randomDirection = RandomDirectionDown();
if (Level.IsEmpty(Position + Vector2I.Down))
Level.Swap(this, Position + Vector2I.Down);
if (Chunk.IsEmpty(Position + Vector2I.Down))
Chunk.Swap(this, Position + Vector2I.Down);
else if (Level.IsEmpty(Position + randomDirection))
Level.Swap(this, Position + randomDirection);
else if (Chunk.IsEmpty(Position + randomDirection))
Chunk.Swap(this, Position + randomDirection);
else if (Level.IsEmpty(Position + randomDirection * VERTICAL_OPPOSITE))
Level.Swap(this, Position + randomDirection * VERTICAL_OPPOSITE);
else if (Chunk.IsEmpty(Position + randomDirection * VERTICAL_OPPOSITE))
Chunk.Swap(this, Position + randomDirection * VERTICAL_OPPOSITE);
if (GD.Randi() % MAX_DIFFUSE_SPEED > DiffuseSpeed) return; // ascend slower
if (Level.Get(Position + randomDirection)?.Density < Density)
Level.Swap(this, Position + Vector2I.Down);
if (Chunk.Get(Position + randomDirection)?.Density < Density)
Chunk.Swap(this, Position + Vector2I.Down);
}
protected Vector2I RandomDirectionDown() {