hierarchy rework
fixed swap
This commit is contained in:
@@ -12,6 +12,11 @@ public class Element {
|
||||
|
||||
private int lastUpdate = -1;
|
||||
|
||||
public Element(Element e) {
|
||||
Position = e.Position;
|
||||
Level = e.Level;
|
||||
}
|
||||
|
||||
public Element(int x, int y, Level level) {
|
||||
Position.X = x;
|
||||
Position.Y = y;
|
||||
@@ -34,24 +39,20 @@ public class Element {
|
||||
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;
|
||||
// }
|
||||
protected virtual void Tick() {
|
||||
int randomDirection = 1;
|
||||
if (GD.Randi() % 2 != 0)
|
||||
randomDirection *= -1;
|
||||
|
||||
/// <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;
|
||||
if (Level.IsEmpty(Position + Vector2I.Down)) {
|
||||
Level.Swap(this, Position + Vector2I.Down);
|
||||
|
||||
} else if (Level.IsEmpty(Position + Vector2I.Down + Vector2I.Right * randomDirection)) {
|
||||
Level.Swap(this, Position + Vector2I.Right * randomDirection);
|
||||
|
||||
} else if (Level.IsEmpty(Position + Vector2I.Down + Vector2I.Right * randomDirection * -1)) {
|
||||
Level.Swap(this, Position + Vector2I.Right*randomDirection);
|
||||
}
|
||||
}
|
||||
|
||||
protected Color AddColorVariance(Color baseColor) {
|
||||
|
||||
Reference in New Issue
Block a user