added simple sleep state for elements
refactoring
This commit is contained in:
@@ -2,34 +2,11 @@
|
||||
|
||||
namespace FOU.Scripts.Elements;
|
||||
|
||||
public class Water : Solid {
|
||||
public const int MAX_VERTICAL_SPREAD = 3;
|
||||
public class Water : Liquid {
|
||||
|
||||
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() {
|
||||
Vector2I randomDirection = RandomDirectionDown();
|
||||
if (randomDirection.Y != 0)
|
||||
randomDirection *= Vector2I.Left * (int)(GD.Randi() % MAX_VERTICAL_SPREAD);
|
||||
|
||||
if (Level.IsEmpty(Position + Vector2I.Down))
|
||||
Level.Swap(this, Position + Vector2I.Down);
|
||||
|
||||
else if (Level.IsEmpty(Position + randomDirection))
|
||||
Level.Swap(this, Position + Vector2I.Right * randomDirection);
|
||||
|
||||
else if (Level.IsEmpty(Position + randomDirection))
|
||||
Level.Swap(this, Position + Vector2I.Right * randomDirection * VERTICAL_OPPOSITE);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user