66 lines
1.9 KiB
C#
66 lines
1.9 KiB
C#
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// base update method, checks if anything is to do at all
|
|
/// </summary>
|
|
/// <param name="currentFrame"></param>
|
|
/// <returns>false if there is nothing to do</returns>
|
|
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;
|
|
// }
|
|
|
|
/// <summary>
|
|
/// Checks from source to maxDirection (also X-mirrored) and returns a free position
|
|
/// </summary>
|
|
/// <param name="source">from where to check</param>
|
|
/// <param name="maxDirection">where to go to (max). X is treated as [-X..X]</param>
|
|
/// <returns>free position or V2.zero if nothing was found</returns>
|
|
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;
|
|
}
|
|
|
|
}
|