fixed chunk neighbor orientation
This commit is contained in:
@@ -77,21 +77,20 @@ public class Chunk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Element Get(Vector2I pos) {
|
public Element Get(Vector2I pos) {
|
||||||
// North
|
if (pos.Y == 54)
|
||||||
if (pos.X < 0)
|
GD.Print("magic number");
|
||||||
if (NeighborN != null) return NeighborN.Get(NeighborN.sizeX + pos.X, pos.Y);
|
|
||||||
|
|
||||||
// South
|
|
||||||
if (pos.X >= sizeX)
|
|
||||||
if (NeighborS != null) return NeighborS.Get(sizeX - pos.X, pos.Y);
|
|
||||||
|
|
||||||
// West
|
|
||||||
if (pos.Y < 0)
|
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 (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);
|
return Get(pos.X, pos.Y);
|
||||||
}
|
}
|
||||||
@@ -110,6 +109,9 @@ public class Chunk {
|
|||||||
private void Swap(Element what, Element swapTo) {
|
private void Swap(Element what, Element swapTo) {
|
||||||
Element swap = new Element(what);
|
Element swap = new Element(what);
|
||||||
|
|
||||||
|
GD.Print($"Swap: {what} -> {swapTo}");
|
||||||
|
if (swapTo.Position.Y == 0) GD.Print($"");
|
||||||
|
|
||||||
if (what == null || swapTo == null) return;
|
if (what == null || swapTo == null) return;
|
||||||
|
|
||||||
what.Position = swapTo.Position;
|
what.Position = swapTo.Position;
|
||||||
@@ -120,6 +122,7 @@ public class Chunk {
|
|||||||
swapTo.Chunk = swap.Chunk;
|
swapTo.Chunk = swap.Chunk;
|
||||||
Elements[swap.Position.X, swap.Position.Y] = swapTo;
|
Elements[swap.Position.X, swap.Position.Y] = swapTo;
|
||||||
|
|
||||||
|
|
||||||
what.Active = true;
|
what.Active = true;
|
||||||
swapTo.Active = true;
|
swapTo.Active = true;
|
||||||
what.LastMove = frame;
|
what.LastMove = frame;
|
||||||
|
|||||||
@@ -26,6 +26,8 @@ public class Level {
|
|||||||
chunkResX = sizeX / chunksX;
|
chunkResX = sizeX / chunksX;
|
||||||
chunkResY = sizeY / chunksY;
|
chunkResY = sizeY / chunksY;
|
||||||
|
|
||||||
|
GD.Print($"{chunksX}x{chunksY} chunks. {chunkResX}:{chunkResY} res each.");
|
||||||
|
|
||||||
image = Image.Create(sizeX, sizeY, false, Image.Format.Rgb8);
|
image = Image.Create(sizeX, sizeY, false, Image.Format.Rgb8);
|
||||||
|
|
||||||
chunks = new Chunk[chunksX, chunksY];
|
chunks = new Chunk[chunksX, chunksY];
|
||||||
@@ -40,11 +42,12 @@ public class Level {
|
|||||||
for (int x = 0; x < chunksX; x++) {
|
for (int x = 0; x < chunksX; x++) {
|
||||||
for (int y = 0; y < chunksY; y++) {
|
for (int y = 0; y < chunksY; y++) {
|
||||||
|
|
||||||
if (x > 0) chunks[x, y].NeighborN = chunks[x-1, y];
|
if (y > 0) chunks[x, y].NeighborN = chunks[x, y-1];
|
||||||
if (x < chunksX-1) chunks[x, y].NeighborS = chunks[x+1, y];
|
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];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user