fixed wrong opposite random direction

This commit is contained in:
2023-12-02 01:43:09 +01:00
parent f0a6396073
commit 7db4ba3c2a
2 changed files with 20 additions and 20 deletions

View File

@@ -3,6 +3,8 @@
namespace FOU.Scripts.Elements;
public class Water : Solid {
public const int MAX_VERTICAL_SPREAD = 3;
public Water(int x, int y, ref Level level) : base(x, y, ref level) {
Color = AddColorVariance(Colors.Blue);
Density = 1;
@@ -17,21 +19,19 @@ public class Water : Solid {
}
protected override void Tick() {
int randomDirection = GD.Randi() % 2 != 0 ? 1 : -1;
randomDirection *= GD.Randi() % 2 != 0 ? 1 : 2;
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);
return;
} else if (Level.IsEmpty(Position + Vector2I.Right * randomDirection)) {
} else if (Level.IsEmpty(Position + 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;
} else if (Level.IsEmpty(Position + randomDirection)) {
Level.Swap(this, Position + Vector2I.Right * randomDirection * VERTICAL_OPPOSITE);
}
}
}