Compare commits
2 Commits
abf948a310
...
a119e92bf6
| Author | SHA1 | Date | |
|---|---|---|---|
| a119e92bf6 | |||
| da3afd22fc |
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
[node name="Main" type="Node2D"]
|
[node name="Main" type="Node2D"]
|
||||||
script = ExtResource("1_k1i8e")
|
script = ExtResource("1_k1i8e")
|
||||||
|
DebugMode = true
|
||||||
BrushSize = 2
|
BrushSize = 2
|
||||||
RainAmount = 1.0
|
RainAmount = 1.0
|
||||||
|
|
||||||
|
|||||||
@@ -15,12 +15,12 @@ public class Element {
|
|||||||
|
|
||||||
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);
|
||||||
protected int lastMove = 0;
|
|
||||||
|
|
||||||
private bool active = false;
|
private bool active = false;
|
||||||
private bool wasMovedThisTick = false;
|
|
||||||
private int lastUpdate = -1;
|
private int lastUpdate = -1;
|
||||||
|
private int lastMove = 0;
|
||||||
private Color originalColor;
|
private Color originalColor;
|
||||||
|
private bool markedForUpdate = false;
|
||||||
|
|
||||||
public Element(Element e) {
|
public Element(Element e) {
|
||||||
Position = e.Position;
|
Position = e.Position;
|
||||||
@@ -34,7 +34,6 @@ public class Element {
|
|||||||
Chunk = chunk;
|
Chunk = chunk;
|
||||||
lastMove = Engine.GetFramesDrawn();
|
lastMove = Engine.GetFramesDrawn();
|
||||||
Active = false;
|
Active = false;
|
||||||
wasMovedThisTick = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Active {
|
public bool Active {
|
||||||
@@ -44,6 +43,9 @@ public class Element {
|
|||||||
|
|
||||||
active = value;
|
active = value;
|
||||||
Chunk.SetElementActive(this, value);
|
Chunk.SetElementActive(this, value);
|
||||||
|
if (!active)
|
||||||
|
ResetColor();
|
||||||
|
else
|
||||||
Moved();
|
Moved();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -58,8 +60,13 @@ public class Element {
|
|||||||
public virtual bool Update() {
|
public virtual bool Update() {
|
||||||
if (!Active) return false;
|
if (!Active) return false;
|
||||||
|
|
||||||
if (lastUpdate == Engine.GetFramesDrawn()) return false; // already updated this frame
|
int frame = Engine.GetFramesDrawn();
|
||||||
lastUpdate = Engine.GetFramesDrawn();
|
if (lastMove + STEPS_UNTIL_INACTIVE < frame)
|
||||||
|
Active = false;
|
||||||
|
if (lastUpdate == frame)
|
||||||
|
return false; // already updated this frame
|
||||||
|
|
||||||
|
lastUpdate = frame;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -70,7 +77,6 @@ public class Element {
|
|||||||
|
|
||||||
protected virtual void Tick() {
|
protected virtual void Tick() {
|
||||||
Vector2I randomDirection = RandomDirectionDown();
|
Vector2I randomDirection = RandomDirectionDown();
|
||||||
wasMovedThisTick = false;
|
|
||||||
|
|
||||||
if (Chunk.IsEmpty(Position + Vector2I.Down))
|
if (Chunk.IsEmpty(Position + Vector2I.Down))
|
||||||
Chunk.Swap(this, Position + Vector2I.Down);
|
Chunk.Swap(this, Position + Vector2I.Down);
|
||||||
@@ -106,21 +112,25 @@ public class Element {
|
|||||||
|
|
||||||
public void ResetColor() {
|
public void ResetColor() {
|
||||||
color = originalColor;
|
color = originalColor;
|
||||||
|
MarkForUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetDebugColor(Color color) {
|
public void SetDebugColor(Color color) {
|
||||||
if (!Main.Instance.DebugMode) return;
|
if (!Main.Instance.DebugMode) return;
|
||||||
|
|
||||||
this.color = color;
|
this.color = color;
|
||||||
wasMovedThisTick = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Moved() {
|
public void Moved() {
|
||||||
lastMove = Engine.GetFramesDrawn();
|
lastMove = Engine.GetFramesDrawn();
|
||||||
wasMovedThisTick = true;
|
MarkForUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool WasMoved() {
|
public bool MarkedForUpdate() {
|
||||||
return wasMovedThisTick;
|
return markedForUpdate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void MarkForUpdate(bool mark = true) {
|
||||||
|
markedForUpdate = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,11 +5,12 @@ namespace FOU.Scripts.Elements;
|
|||||||
public abstract class Liquid : Element {
|
public abstract class Liquid : Element {
|
||||||
public const int MAX_VERTICAL_SPREAD = 3;
|
public const int MAX_VERTICAL_SPREAD = 3;
|
||||||
|
|
||||||
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) {
|
||||||
|
MarkForUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
public override bool Update() {
|
public override bool Update() {
|
||||||
if (!base.Update()) return false;
|
if (!base.Update()) return false;
|
||||||
if (lastMove + STEPS_UNTIL_INACTIVE < Engine.GetFramesDrawn()) Active = false;
|
|
||||||
|
|
||||||
Tick();
|
Tick();
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,12 @@
|
|||||||
namespace FOU.Scripts.Elements;
|
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) {
|
||||||
|
MarkForUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
public override bool Update() {
|
public override bool Update() {
|
||||||
if (!base.Update()) return false;
|
if (!base.Update()) return false;
|
||||||
if (lastMove + STEPS_UNTIL_INACTIVE < Engine.GetFramesDrawn()) Active = false;
|
|
||||||
|
|
||||||
Tick();
|
Tick();
|
||||||
|
|
||||||
|
|||||||
@@ -113,28 +113,26 @@ public class Level {
|
|||||||
iteratorX = chunkResX + startPtX + iteratorX;
|
iteratorX = chunkResX + startPtX + iteratorX;
|
||||||
ptX = startPtX + iteratorX;
|
ptX = startPtX + iteratorX;
|
||||||
|
|
||||||
// right of chunk
|
|
||||||
} else if (startPtX + iteratorX >= chunkResX) {
|
|
||||||
chunkX++;
|
|
||||||
ptX = startPtX + iteratorX - chunkResX;
|
|
||||||
} else {
|
} else {
|
||||||
ptX = startPtX + iteratorX;
|
ptX = startPtX + iteratorX;
|
||||||
}
|
}
|
||||||
|
if (startPtX + iteratorX >= chunkResX) {
|
||||||
|
chunkX++;
|
||||||
|
ptX = startPtX + iteratorX - chunkResX;
|
||||||
|
}
|
||||||
int chunkY = y/chunkResY;
|
int chunkY = y/chunkResY;
|
||||||
|
|
||||||
// above chunk
|
// above chunk
|
||||||
if (startPtY + iteratorY < 0) {
|
if (startPtY + iteratorY < 0) {
|
||||||
chunkY--;
|
chunkY--;
|
||||||
ptY = chunkResY + (startPtY + iteratorY);
|
ptY = chunkResY + (startPtY + iteratorY);
|
||||||
|
|
||||||
// left of chunk
|
|
||||||
} else if (startPtY + iteratorY >= chunkResY) {
|
|
||||||
chunkY++;
|
|
||||||
ptY = iteratorY % chunkResY;
|
|
||||||
} else {
|
} else {
|
||||||
ptY = startPtY + iteratorY;
|
ptY = startPtY + iteratorY;
|
||||||
}
|
}
|
||||||
|
if (startPtY + iteratorY >= chunkResY) {
|
||||||
|
chunkY++;
|
||||||
|
ptY = startPtY + iteratorY - chunkResY;
|
||||||
|
}
|
||||||
|
|
||||||
// ignore everything outside
|
// ignore everything outside
|
||||||
if (chunkX < 0) continue;
|
if (chunkX < 0) continue;
|
||||||
@@ -157,8 +155,10 @@ public class Level {
|
|||||||
for (int y = 0; y < chunkResY; y++) {
|
for (int y = 0; y < chunkResY; y++) {
|
||||||
// TODO: multithreading here! use Chunk.DrawLevel() and stitch images together
|
// TODO: multithreading here! use Chunk.DrawLevel() and stitch images together
|
||||||
|
|
||||||
if (chunks[cx, cy].Elements[x, y].WasMoved())
|
if (chunks[cx, cy].Elements[x, y].MarkedForUpdate()) {
|
||||||
image.SetPixel(cx * chunkResX + x, cy * chunkResY + y, chunks[cx, cy].Elements[x, y].Color);
|
image.SetPixel(cx * chunkResX + x, cy * chunkResY + y, chunks[cx, cy].Elements[x, y].Color);
|
||||||
|
chunks[cx, cy].Elements[x, y].MarkForUpdate(false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user