Compare commits
2 Commits
4462573267
...
28ada065a6
| Author | SHA1 | Date | |
|---|---|---|---|
| 28ada065a6 | |||
| ea34b8ecc0 |
@@ -88,13 +88,13 @@ public class Element{
|
|||||||
else if (Chunk.IsEmpty(Position + randomDirection * VERTICAL_OPPOSITE))
|
else if (Chunk.IsEmpty(Position + randomDirection * VERTICAL_OPPOSITE))
|
||||||
Chunk.Swap(this, Position + randomDirection * VERTICAL_OPPOSITE);
|
Chunk.Swap(this, Position + randomDirection * VERTICAL_OPPOSITE);
|
||||||
|
|
||||||
if (GD.Randi() % MAX_DIFFUSE_SPEED > DiffuseSpeed) return; // descend slower
|
// density check
|
||||||
|
if (Chunk.Get(Position + Vector2I.Down)?.Density < Density)
|
||||||
if (Chunk.Get(Position + randomDirection)?.Density < Density)
|
|
||||||
Chunk.Swap(this, Position + Vector2I.Down);
|
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() {
|
protected Vector2I RandomDirectionDown() {
|
||||||
int randomDirection = GD.Randi() % 2 != 0 ? 1 : -1;
|
int randomDirection = GD.Randi() % 2 != 0 ? 1 : -1;
|
||||||
|
|
||||||
@@ -102,6 +102,13 @@ public class Element{
|
|||||||
+ (GD.Randi() % 2 != 0 ? Vector2I.Zero : Vector2I.Right * randomDirection);
|
+ (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) {
|
protected Color AddColorVariance(Color baseColor) {
|
||||||
Color c = baseColor;
|
Color c = baseColor;
|
||||||
c.R += (GD.Randf() - 1) * MAX_COLOR_VARIANCE;
|
c.R += (GD.Randf() - 1) * MAX_COLOR_VARIANCE;
|
||||||
@@ -128,7 +135,7 @@ public class Element{
|
|||||||
MarkForUpdate();
|
MarkForUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool MarkedForUpdate() {
|
public bool IsMarkedForUpdate() {
|
||||||
return markedForUpdate;
|
return markedForUpdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public class Level {
|
|||||||
|
|
||||||
GD.Print($"Generating level ({sizeX}:{sizeY}) with {chunksPerX*chunksPerY} chunks ({chunkResX} * {chunkResY})");
|
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];
|
chunks = new Chunk[chunksPerX, chunksPerY];
|
||||||
int index = 0;
|
int index = 0;
|
||||||
@@ -165,7 +165,7 @@ 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].MarkedForUpdate()) {
|
if (chunks[cx, cy].Elements[x, y].IsMarkedForUpdate()) {
|
||||||
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);
|
chunks[cx, cy].Elements[x, y].MarkForUpdate(false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,10 +36,10 @@ public partial class Main : Node2D {
|
|||||||
|
|
||||||
public override void _PhysicsProcess(double delta) {
|
public override void _PhysicsProcess(double delta) {
|
||||||
base._PhysicsProcess(delta);
|
base._PhysicsProcess(delta);
|
||||||
Level.Update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _Process(double delta) {
|
public override void _Process(double delta) {
|
||||||
|
Level.Update();
|
||||||
mLevelDrawer.Texture?.Dispose();
|
mLevelDrawer.Texture?.Dispose();
|
||||||
mLevelDrawer.Texture = ImageTexture.CreateFromImage(Level.DrawLevel());
|
mLevelDrawer.Texture = ImageTexture.CreateFromImage(Level.DrawLevel());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user