From 29185791d97f771fa97ffadb457248deafb6713b Mon Sep 17 00:00:00 2001 From: rogo Date: Sun, 14 Jul 2024 18:15:14 +0200 Subject: [PATCH] fixed chunk neighbor orientation --- Scripts/Chunk.cs | 25 ++++++++++++++----------- Scripts/Level.cs | 11 +++++++---- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/Scripts/Chunk.cs b/Scripts/Chunk.cs index 06c814f..793b441 100644 --- a/Scripts/Chunk.cs +++ b/Scripts/Chunk.cs @@ -77,21 +77,20 @@ public class Chunk { } public Element Get(Vector2I pos) { - // North - if (pos.X < 0) - if (NeighborN != null) return NeighborN.Get(NeighborN.sizeX + pos.X, pos.Y); + if (pos.Y == 54) + GD.Print("magic number"); - // South - if (pos.X >= sizeX) - if (NeighborS != null) return NeighborS.Get(sizeX - pos.X, pos.Y); - - // West if (pos.Y < 0) - if (NeighborW != null) return NeighborW.Get(pos.X, NeighborW.sizeY + pos.Y); + if (NeighborN != null) return NeighborN.Get(pos.X, NeighborN.sizeY + pos.Y); - // East if (pos.Y >= sizeY) - if (NeighborE != null) return NeighborE.Get(pos.X, sizeY - pos.Y); + if (NeighborS != null) return NeighborS.Get(pos.X, sizeY - pos.Y); + + if (pos.X < 0) + if (NeighborE != null) return NeighborE.Get(NeighborE.sizeX + pos.X, pos.Y); + + if (pos.X >= sizeX) + if (NeighborW != null) return NeighborW.Get(sizeX - pos.X, pos.Y); return Get(pos.X, pos.Y); } @@ -110,6 +109,9 @@ public class Chunk { private void Swap(Element what, Element swapTo) { Element swap = new Element(what); + GD.Print($"Swap: {what} -> {swapTo}"); + if (swapTo.Position.Y == 0) GD.Print($""); + if (what == null || swapTo == null) return; what.Position = swapTo.Position; @@ -120,6 +122,7 @@ public class Chunk { swapTo.Chunk = swap.Chunk; Elements[swap.Position.X, swap.Position.Y] = swapTo; + what.Active = true; swapTo.Active = true; what.LastMove = frame; diff --git a/Scripts/Level.cs b/Scripts/Level.cs index a1aaef0..f524990 100644 --- a/Scripts/Level.cs +++ b/Scripts/Level.cs @@ -26,6 +26,8 @@ public class Level { chunkResX = sizeX / chunksX; chunkResY = sizeY / chunksY; + GD.Print($"{chunksX}x{chunksY} chunks. {chunkResX}:{chunkResY} res each."); + image = Image.Create(sizeX, sizeY, false, Image.Format.Rgb8); chunks = new Chunk[chunksX, chunksY]; @@ -40,11 +42,12 @@ public class Level { for (int x = 0; x < chunksX; x++) { for (int y = 0; y < chunksY; y++) { - if (x > 0) chunks[x, y].NeighborN = chunks[x-1, y]; - if (x < chunksX-1) chunks[x, y].NeighborS = chunks[x+1, y]; + if (y > 0) chunks[x, y].NeighborN = chunks[x, y-1]; + if (y < chunksY-1) chunks[x, y].NeighborS = chunks[x, y+1]; + + if (x > 0) chunks[x, y].NeighborE = chunks[x-1, y]; + if (x < chunksX-1) chunks[x, y].NeighborW = chunks[x+1, y]; - if (y > 0) chunks[x, y].NeighborW = chunks[x, y-1]; - if (y < chunksY-1) chunks[x, y].NeighborE = chunks[x, y+1]; } } }