Files
FOU/Scripts/Elements/Water.cs
rogo eb94c3bef9 added density
code improvements
2023-12-02 00:45:09 +01:00

38 lines
1.1 KiB
C#

using Godot;
namespace FOU.Scripts.Elements;
public class Water : Solid {
public Water(int x, int y, ref Level level) : base(x, y, ref level) {
Color = AddColorVariance(Colors.Blue);
Density = 1;
}
public override bool Update(int currentFrame) {
if (!base.Update(currentFrame)) return false;
Tick();
return true; // not necessarily end, subclasses could do some more things
}
protected override void Tick() {
int randomDirection = GD.Randi() % 2 != 0 ? 1 : -1;
randomDirection *= GD.Randi() % 2 != 0 ? 1 : 2;
if (Level.IsEmpty(Position + Vector2I.Down)) {
Level.Swap(this, Position + Vector2I.Down);
return;
} else if (Level.IsEmpty(Position + Vector2I.Right * randomDirection)) {
Level.Swap(this, Position + Vector2I.Right * randomDirection);
return;
} else if (Level.IsEmpty(Position + Vector2I.Right * randomDirection * -1)) {
Level.Swap(this, Position + Vector2I.Right*randomDirection);
return;
}
}
}