finalized dirt

added base for liquids
This commit is contained in:
2023-10-17 14:29:42 +02:00
parent 9145a6a3f9
commit 31dbbbf070
6 changed files with 113 additions and 29 deletions

View File

@@ -1,5 +1,36 @@
namespace FOU.Scripts.Elements;
using Godot;
namespace FOU.Scripts.Elements;
public abstract class Solid : Element {
protected Solid(int x, int y, ref Level level) : base(x, y, ref level) { }
protected Vector2I Check(Element source, Vector2I maxDirection) {
if (GD.Randi() % 2 != 0)
maxDirection.X *= -1;
Vector2I freePos = Vector2I.Zero;
for (int y = maxDirection.Y; y > 0; y--) { // height
if (source.Position.Y + y >= _level.SizeY) return freePos; // bounds check
if (_level.Get(source.Position.X, source.Position.Y + y).GetType() == typeof(Element)) {
freePos = new Vector2I(source.Position.X, source.Position.Y + y);
} else {
freePos = Vector2I.Zero;
}
for (int x = -maxDirection.X; x <= maxDirection.X; x++) { // width
if (freePos != Vector2I.Zero) break;
if (source.Position.X + x >= _level.SizeX || source.Position.X + x < 0) return freePos; // bounds check
if (_level.Get(source.Position.X + x, source.Position.Y + y).GetType() == typeof(Element)) {
freePos = new Vector2I(source.Position.X + x, source.Position.Y + y);
break;
}
}
}
return freePos;
}
}