added falling sand - dirt actually
This commit is contained in:
@@ -3,7 +3,18 @@
|
||||
namespace FOU.Scripts.Elements;
|
||||
|
||||
public class Dirt : Solid {
|
||||
public Dirt() {
|
||||
|
||||
public Dirt(int x, int y, ref Level level) : base(x, y, ref level) {
|
||||
Color = Colors.Brown;
|
||||
}
|
||||
|
||||
public override bool Update(int currentFrame) {
|
||||
if (!base.Update(currentFrame)) return false;
|
||||
|
||||
if (CheckBelow(X, Y)) {
|
||||
_level.Swap(this, X, Y+1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,44 @@
|
||||
|
||||
namespace FOU.Scripts.Elements;
|
||||
|
||||
public abstract class Element {
|
||||
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 $"{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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
namespace FOU.Scripts.Elements;
|
||||
|
||||
public abstract class Solid : Element {
|
||||
|
||||
protected Solid(int x, int y, ref Level level) : base(x, y, ref level) { }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user