using Godot;
namespace FOU.Scripts.Elements;
public class Element {
public Color Color = Colors.Black;
public Vector2I Position;
protected readonly float MaxColorVariance = 0.1f;
protected readonly Level Level;
private int lastUpdate = -1;
public Element(int x, int y, Level level) {
Position.X = x;
Position.Y = y;
Level = level;
}
///
/// base update method, checks if anything is to do at all
///
///
/// false if there is nothing to do
public virtual bool Update(int currentFrame) {
if (lastUpdate == currentFrame) return false; // already updated this frame
lastUpdate = currentFrame;
return true;
}
public override string ToString() {
return $"{GetType()} {Position}";
}
// OBSOLETE:
// protected bool CheckBelow(int sourceX, int sourceY) {
// if (sourceY+1 >= _level.SizeY) return false;
//
// if (_level.Get(sourceX, sourceY+1).GetType() == GetType())
// return false;
//
// return true;
// }
///
/// Checks from source to maxDirection (also X-mirrored) and returns a free position
///
/// from where to check
/// where to go to (max). X is treated as [-X..X]
/// free position or V2.zero if nothing was found
protected virtual Vector2I Check(Element source, Vector2I maxDirection) {
return Vector2I.Zero;
}
protected Color AddColorVariance(Color baseColor) {
Color c = baseColor;
c.R += (GD.Randf() - 1) * MaxColorVariance;
c.G += (GD.Randf() - 1) * MaxColorVariance;
c.B += (GD.Randf() - 1) * MaxColorVariance;
return c;
}
}