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