Files
FOU/Scripts/Elements/Element.cs
2023-10-17 12:48:49 +02:00

46 lines
1022 B
C#

using Godot;
namespace FOU.Scripts.Elements;
public class Element {
public Color Color = Colors.Black;
public int X;
public int Y;
protected Level _level;
private int _lastUpdate = -1;
public Element(int x, int y, ref Level level) {
X = x;
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()} {X}:{Y}";
}
protected bool CheckBelow(int x, int y) {
if (y+1 >= _level.SizeY) return false;
if (_level.Get(x, y+1).GetType() == GetType())
return false;
return true;
}
}