moved tick to process from physics process
fixed fall speed improved naming
This commit is contained in:
@@ -88,13 +88,13 @@ public class Element{
|
||||
else if (Chunk.IsEmpty(Position + randomDirection * VERTICAL_OPPOSITE))
|
||||
Chunk.Swap(this, Position + randomDirection * VERTICAL_OPPOSITE);
|
||||
|
||||
if (GD.Randi() % MAX_DIFFUSE_SPEED > DiffuseSpeed) return; // descend slower
|
||||
|
||||
if (Chunk.Get(Position + randomDirection)?.Density < Density)
|
||||
// density check
|
||||
if (Chunk.Get(Position + Vector2I.Down)?.Density < Density)
|
||||
Chunk.Swap(this, Position + Vector2I.Down);
|
||||
else if (Chunk.Get(Position + Vector2I.Down + randomDirection)?.Density < Density)
|
||||
Chunk.Swap(this, Position + Vector2I.Down);
|
||||
}
|
||||
|
||||
/// <returns>-1, 0 or 1</returns>
|
||||
protected Vector2I RandomDirectionDown() {
|
||||
int randomDirection = GD.Randi() % 2 != 0 ? 1 : -1;
|
||||
|
||||
@@ -102,6 +102,13 @@ public class Element{
|
||||
+ (GD.Randi() % 2 != 0 ? Vector2I.Zero : Vector2I.Right * randomDirection);
|
||||
}
|
||||
|
||||
/// <returns>-1, 0 or 1</returns>
|
||||
protected Vector2I RandomDirection() {
|
||||
int randomDirection = GD.Randi() % 2 != 0 ? 1 : -1;
|
||||
|
||||
return (GD.Randi() % 2 != 0 ? Vector2I.Zero : Vector2I.Right * randomDirection);
|
||||
}
|
||||
|
||||
protected Color AddColorVariance(Color baseColor) {
|
||||
Color c = baseColor;
|
||||
c.R += (GD.Randf() - 1) * MAX_COLOR_VARIANCE;
|
||||
@@ -128,7 +135,7 @@ public class Element{
|
||||
MarkForUpdate();
|
||||
}
|
||||
|
||||
public bool MarkedForUpdate() {
|
||||
public bool IsMarkedForUpdate() {
|
||||
return markedForUpdate;
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ public class Level {
|
||||
|
||||
GD.Print($"Generating level ({sizeX}:{sizeY}) with {chunksPerX*chunksPerY} chunks ({chunkResX} * {chunkResY})");
|
||||
|
||||
image = Image.Create(sizeX, sizeY, false, Image.Format.Rgb8);
|
||||
image = Image.CreateEmpty(sizeX, sizeY, false, Image.Format.Rgb8);
|
||||
|
||||
chunks = new Chunk[chunksPerX, chunksPerY];
|
||||
int index = 0;
|
||||
@@ -165,7 +165,7 @@ public class Level {
|
||||
for (int y = 0; y < chunkResY; y++) {
|
||||
// TODO: multithreading here! use Chunk.DrawLevel() and stitch images together
|
||||
|
||||
if (chunks[cx, cy].Elements[x, y].MarkedForUpdate()) {
|
||||
if (chunks[cx, cy].Elements[x, y].IsMarkedForUpdate()) {
|
||||
image.SetPixel(cx * chunkResX + x, cy * chunkResY + y, chunks[cx, cy].Elements[x, y].Color);
|
||||
chunks[cx, cy].Elements[x, y].MarkForUpdate(false);
|
||||
}
|
||||
|
||||
@@ -36,10 +36,10 @@ public partial class Main : Node2D {
|
||||
|
||||
public override void _PhysicsProcess(double delta) {
|
||||
base._PhysicsProcess(delta);
|
||||
Level.Update();
|
||||
}
|
||||
|
||||
public override void _Process(double delta) {
|
||||
Level.Update();
|
||||
mLevelDrawer.Texture?.Dispose();
|
||||
mLevelDrawer.Texture = ImageTexture.CreateFromImage(Level.DrawLevel());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user