fixed stuck rain
refactoring
This commit is contained in:
@@ -9,7 +9,6 @@
|
|||||||
script = ExtResource("1_k1i8e")
|
script = ExtResource("1_k1i8e")
|
||||||
DebugMode = true
|
DebugMode = true
|
||||||
BrushSize = 4
|
BrushSize = 4
|
||||||
RainAmount = 1.0
|
|
||||||
|
|
||||||
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
||||||
|
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ public class Chunk {
|
|||||||
object o = Activator.CreateInstance(type, x, y, this);
|
object o = Activator.CreateInstance(type, x, y, this);
|
||||||
|
|
||||||
// check if not empty and overwrite not allowed:
|
// check if not empty and overwrite not allowed:
|
||||||
if (Elements[x,y].GetType() != typeof(Element) && !Main.Instance.AllowOverwrite) {
|
if (!Elements[x,y].IsEmpty() && !Main.Instance.AllowOverwrite) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,8 +32,7 @@ public class Element{
|
|||||||
Position.X = x;
|
Position.X = x;
|
||||||
Position.Y = y;
|
Position.Y = y;
|
||||||
Chunk = chunk;
|
Chunk = chunk;
|
||||||
lastMove = Engine.GetFramesDrawn();
|
Active = true;
|
||||||
Active = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Active {
|
public bool Active {
|
||||||
@@ -43,6 +42,8 @@ public class Element{
|
|||||||
|
|
||||||
active = value;
|
active = value;
|
||||||
Chunk.SetElementActive(this, value);
|
Chunk.SetElementActive(this, value);
|
||||||
|
lastMove = Engine.GetFramesDrawn();
|
||||||
|
|
||||||
if (!active)
|
if (!active)
|
||||||
ResetColor();
|
ResetColor();
|
||||||
else
|
else
|
||||||
@@ -93,6 +94,7 @@ public class Element{
|
|||||||
Chunk.Swap(this, Position + Vector2I.Down);
|
Chunk.Swap(this, Position + Vector2I.Down);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <returns>-1, 0 or 1</returns>
|
||||||
protected Vector2I RandomDirectionDown() {
|
protected Vector2I RandomDirectionDown() {
|
||||||
int randomDirection = GD.Randi() % 2 != 0 ? 1 : -1;
|
int randomDirection = GD.Randi() % 2 != 0 ? 1 : -1;
|
||||||
|
|
||||||
@@ -133,4 +135,8 @@ public class Element{
|
|||||||
public void MarkForUpdate(bool mark = true) {
|
public void MarkForUpdate(bool mark = true) {
|
||||||
markedForUpdate = true;
|
markedForUpdate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool IsEmpty() {
|
||||||
|
return GetType() == typeof(Element);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,8 +84,11 @@ public class Level {
|
|||||||
int rainDrops = (int)Math.Round(rainAmount);
|
int rainDrops = (int)Math.Round(rainAmount);
|
||||||
|
|
||||||
for (int i = 0; i <= rainDrops; i++) {
|
for (int i = 0; i <= rainDrops; i++) {
|
||||||
if (GD.Randf() < rainAmount)
|
if (GD.Randf() < rainAmount) {
|
||||||
WritePixel<Water>((int)(GD.Randi() % (chunkResX * chunksPerX)), 0, 1);
|
int d = (int)(GD.Randi() % (chunkResX * chunksPerX));
|
||||||
|
if (GetElement(d, 0).IsEmpty())
|
||||||
|
WritePixel<Water>(d, 0, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,6 +148,13 @@ public class Level {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Element GetElement(int x, int y) {
|
||||||
|
if (x < 0 || x > chunkResX * chunkResX) return null;
|
||||||
|
if (y < 0 || y > chunkResY * chunkResY) return null;
|
||||||
|
|
||||||
|
return chunks[x / chunkResX, y / chunkResY].Elements[x % chunkResX, y % chunkResY];
|
||||||
|
}
|
||||||
|
|
||||||
public Image DrawLevel() {
|
public Image DrawLevel() {
|
||||||
// chunk
|
// chunk
|
||||||
for (int cx = 0; cx < chunksPerX; cx++) {
|
for (int cx = 0; cx < chunksPerX; cx++) {
|
||||||
|
|||||||
Reference in New Issue
Block a user