added simple sleep state for elements
refactoring
This commit is contained in:
@@ -7,15 +7,19 @@ public class Element {
|
||||
|
||||
public Vector2I Position;
|
||||
public int Density;
|
||||
public int LastUpdate = -1;
|
||||
public int LastMove = 0;
|
||||
|
||||
public int DiffuseSpeed = 10;
|
||||
public const int MAX_DIFFUSE_SPEED = 100;
|
||||
public const int STEPS_UNTIL_INACTIVE = 100;
|
||||
|
||||
protected const float MAX_COLOR_VARIANCE = 0.1f;
|
||||
protected static readonly Vector2I VERTICAL_OPPOSITE = new Vector2I(-1, 1);
|
||||
protected readonly Level Level;
|
||||
|
||||
private int lastUpdate = -1;
|
||||
private bool active = true;
|
||||
private Color originalColor;
|
||||
|
||||
public Element(Element e) {
|
||||
Position = e.Position;
|
||||
@@ -28,14 +32,28 @@ public class Element {
|
||||
Level = level;
|
||||
}
|
||||
|
||||
public bool Active {
|
||||
get => active;
|
||||
set {
|
||||
active = value;
|
||||
|
||||
if (active)
|
||||
Color = originalColor;
|
||||
else if (Main.Instance.DebugVisualization)
|
||||
Color = new Color(0.2f, 0.2f, 0.2f);
|
||||
}
|
||||
}
|
||||
|
||||
/// <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;
|
||||
if (!Active) return false;
|
||||
|
||||
if (LastUpdate == currentFrame) return false; // already updated this frame
|
||||
LastUpdate = currentFrame;
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -74,6 +92,8 @@ public class Element {
|
||||
c.R += (GD.Randf() - 1) * MAX_COLOR_VARIANCE;
|
||||
c.G += (GD.Randf() - 1) * MAX_COLOR_VARIANCE;
|
||||
c.B += (GD.Randf() - 1) * MAX_COLOR_VARIANCE;
|
||||
|
||||
originalColor = c;
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user