36 lines
1.1 KiB
C#
36 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 = Colors.Blue;
|
|
Color = AddColorVariance(Color);
|
|
}
|
|
|
|
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 = 1;
|
|
if (GD.Randi() % 2 != 0)
|
|
randomDirection *= -1;
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|