Compare commits

2 Commits

Author SHA1 Message Date
28ada065a6 fixed stuck pixels 2025-05-01 22:50:35 +02:00
ea34b8ecc0 moved tick to process from physics process
fixed fall speed
improved naming
2025-05-01 22:46:51 +02:00
3 changed files with 15 additions and 8 deletions

View File

@@ -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 + randomDirection);
}
/// <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;
}

View File

@@ -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);
}

View File

@@ -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());
}