fixed inactive elements when spawning with brush

This commit is contained in:
2024-08-25 19:03:40 +02:00
parent 2d38774341
commit 7388e1a2d7
5 changed files with 16 additions and 17 deletions

View File

@@ -15,7 +15,6 @@ public class Chunk {
private readonly Image image;
private readonly int sizeX;
private readonly int sizeY;
private int frame;
public Chunk(int x, int y, int index) {
Index = index;
@@ -37,10 +36,9 @@ public class Chunk {
for (int x = 0; x < sizeX; x++) {
for (int y = 0; y < sizeY; y++) {
if (Elements[x,y] != null)
Elements[x,y].Update(frame);
Elements[x,y].Update();
}
}
frame++;
// TODO: enable rain again
// MakeItRain(_main.RainAmount);
}
@@ -127,7 +125,5 @@ public class Chunk {
what.Active = true;
swapTo.Active = true;
what.LastMove = frame;
swapTo.LastMove = frame;
}
}

View File

@@ -13,7 +13,7 @@ public class Element {
public int DiffuseSpeed = 10;
public const int MAX_DIFFUSE_SPEED = 100;
public const int STEPS_UNTIL_INACTIVE = 100;
public const int STEPS_UNTIL_INACTIVE = 500;
protected const float MAX_COLOR_VARIANCE = 0.1f;
protected static readonly Vector2I VERTICAL_OPPOSITE = new Vector2I(-1, 1);
@@ -24,12 +24,14 @@ public class Element {
public Element(Element e) {
Position = e.Position;
Chunk = e.Chunk;
LastMove = Engine.GetFramesDrawn();
}
public Element(int x, int y, Chunk chunk) {
Position.X = x;
Position.Y = y;
Chunk = chunk;
LastMove = Engine.GetFramesDrawn();
}
public bool Active {
@@ -49,11 +51,11 @@ public class Element {
/// </summary>
/// <param name="currentFrame"></param>
/// <returns>false if there is nothing to do</returns>
public virtual bool Update(int currentFrame) {
public virtual bool Update() {
if (!Active) return false;
if (LastUpdate == currentFrame) return false; // already updated this frame
LastUpdate = currentFrame;
if (LastUpdate == Engine.GetFramesDrawn()) return false; // already updated this frame
LastUpdate = Engine.GetFramesDrawn();
return true;
}

View File

@@ -7,9 +7,9 @@ public abstract class Liquid : Element {
protected Liquid(int x, int y, ref Chunk chunk) : base(x, y, chunk) { }
public override bool Update(int currentFrame) {
if (!base.Update(currentFrame)) return false;
if (LastMove + STEPS_UNTIL_INACTIVE < currentFrame) Active = false;
public override bool Update() {
if (!base.Update()) return false;
if (LastMove + STEPS_UNTIL_INACTIVE < Engine.GetFramesDrawn()) Active = false;
Tick();

View File

@@ -5,9 +5,9 @@ namespace FOU.Scripts.Elements;
public abstract class Solid : Element {
protected Solid(int x, int y, ref Chunk chunk) : base(x, y, chunk) { }
public override bool Update(int currentFrame) {
if (!base.Update(currentFrame)) return false;
if (LastMove + STEPS_UNTIL_INACTIVE < currentFrame) Active = false;
public override bool Update() {
if (!base.Update()) return false;
if (LastMove + STEPS_UNTIL_INACTIVE < Engine.GetFramesDrawn()) Active = false;
Tick();