activated activateneighbors experiment

This commit is contained in:
2025-05-01 23:46:18 +02:00
parent f932ae1bcd
commit 9a36418d23
3 changed files with 53 additions and 11 deletions

View File

@@ -131,4 +131,23 @@ public class Element{
public bool IsEmpty() {
return GetType() == typeof(Element);
}
public virtual void ActivateNeighbors() {
Element n = Chunk.Get(Position + Vector2I.Up);
if (n != null && !n.IsEmpty())
n.Active = true;
//
// Element e = Chunk.Get(Position + Vector2I.Right);
// if (e != null && !e.IsEmpty())
// e.Active = true;
//
// Element s = Chunk.Get(Position + Vector2I.Down);
// if (null != s && !s.IsEmpty())
// s.Active = true;
//
// Element w = Chunk.Get(Position + Vector2I.Left);
// if (null != w && !w.IsEmpty())
// w.Active = true;
}
}

View File

@@ -24,11 +24,30 @@ public abstract class Liquid : Element {
if (Chunk.IsEmpty(Position + Vector2I.Down))
Chunk.Swap(this, Position + Vector2I.Down);
else if (Chunk.IsEmpty(Position + randomDirection))
Chunk.Swap(this, Position + randomDirection);
else if (Chunk.IsEmpty(Position + randomDirection * VERTICAL_OPPOSITE))
Chunk.Swap(this, Position + randomDirection * VERTICAL_OPPOSITE);
else if (Chunk.IsEmpty(Position + randomDirection))
Chunk.Swap(this, Position + Vector2I.Right * randomDirection);
Chunk.Swap(this, Position + Vector2I.Right + randomDirection);
else if (Chunk.IsEmpty(Position - randomDirection))
Chunk.Swap(this, Position + Vector2I.Right + randomDirection * VERTICAL_OPPOSITE);
}
else if (Chunk.IsEmpty(Position + randomDirection))
Chunk.Swap(this, Position + Vector2I.Right * randomDirection * VERTICAL_OPPOSITE);
public override void ActivateNeighbors() {
Element n = Chunk.Get(Position + Vector2I.Up);
if (n != null && !n.IsEmpty())
n.Active = true;
// only activate liquids left or right
Element e = Chunk.Get(Position + Vector2I.Right);
if (e != null && e.GetType() == typeof(Liquid))
e.Active = true;
Element s = Chunk.Get(Position + Vector2I.Down);
if (null != s && s.GetType() == typeof(Liquid))
s.Active = true;
}
}