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

@@ -6,8 +6,9 @@
[node name="Main" type="Node2D"] [node name="Main" type="Node2D"]
script = ExtResource("1_k1i8e") script = ExtResource("1_k1i8e")
BrushSize = 0 DebugVisualization = true
TextureResolution = 0.25 BrushSize = 2
TextureResolution = 0.35
RainAmount = 5.0 RainAmount = 5.0
[node name="CanvasLayer" type="CanvasLayer" parent="."] [node name="CanvasLayer" type="CanvasLayer" parent="."]

View File

@@ -15,7 +15,6 @@ public class Chunk {
private readonly Image image; private readonly Image image;
private readonly int sizeX; private readonly int sizeX;
private readonly int sizeY; private readonly int sizeY;
private int frame;
public Chunk(int x, int y, int index) { public Chunk(int x, int y, int index) {
Index = index; Index = index;
@@ -37,10 +36,9 @@ public class Chunk {
for (int x = 0; x < sizeX; x++) { for (int x = 0; x < sizeX; x++) {
for (int y = 0; y < sizeY; y++) { for (int y = 0; y < sizeY; y++) {
if (Elements[x,y] != null) if (Elements[x,y] != null)
Elements[x,y].Update(frame); Elements[x,y].Update();
} }
} }
frame++;
// TODO: enable rain again // TODO: enable rain again
// MakeItRain(_main.RainAmount); // MakeItRain(_main.RainAmount);
} }
@@ -127,7 +125,5 @@ public class Chunk {
what.Active = true; what.Active = true;
swapTo.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 int DiffuseSpeed = 10;
public const int MAX_DIFFUSE_SPEED = 100; 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 const float MAX_COLOR_VARIANCE = 0.1f;
protected static readonly Vector2I VERTICAL_OPPOSITE = new Vector2I(-1, 1); protected static readonly Vector2I VERTICAL_OPPOSITE = new Vector2I(-1, 1);
@@ -24,12 +24,14 @@ public class Element {
public Element(Element e) { public Element(Element e) {
Position = e.Position; Position = e.Position;
Chunk = e.Chunk; Chunk = e.Chunk;
LastMove = Engine.GetFramesDrawn();
} }
public Element(int x, int y, Chunk chunk) { public Element(int x, int y, Chunk chunk) {
Position.X = x; Position.X = x;
Position.Y = y; Position.Y = y;
Chunk = chunk; Chunk = chunk;
LastMove = Engine.GetFramesDrawn();
} }
public bool Active { public bool Active {
@@ -49,11 +51,11 @@ public class Element {
/// </summary> /// </summary>
/// <param name="currentFrame"></param> /// <param name="currentFrame"></param>
/// <returns>false if there is nothing to do</returns> /// <returns>false if there is nothing to do</returns>
public virtual bool Update(int currentFrame) { public virtual bool Update() {
if (!Active) return false; if (!Active) return false;
if (LastUpdate == currentFrame) return false; // already updated this frame if (LastUpdate == Engine.GetFramesDrawn()) return false; // already updated this frame
LastUpdate = currentFrame; LastUpdate = Engine.GetFramesDrawn();
return true; 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) { } protected Liquid(int x, int y, ref Chunk chunk) : base(x, y, chunk) { }
public override bool Update(int currentFrame) { public override bool Update() {
if (!base.Update(currentFrame)) return false; if (!base.Update()) return false;
if (LastMove + STEPS_UNTIL_INACTIVE < currentFrame) Active = false; if (LastMove + STEPS_UNTIL_INACTIVE < Engine.GetFramesDrawn()) Active = false;
Tick(); Tick();

View File

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