fixed brush Y dimension
This commit is contained in:
@@ -92,52 +92,57 @@ public class Level {
|
||||
public void WritePixel<T>(int x, int y, int size) {
|
||||
int halfsize = size/2;
|
||||
|
||||
int startPtX = x % chunkResX;
|
||||
int startPtY = y % chunkResY;
|
||||
|
||||
for (int i = -halfsize; i <= halfsize; i++) {
|
||||
for (int j = 0; j < 1; j++) {
|
||||
// for (int j = -halfsize; j <= halfsize; j++) {
|
||||
for (int j = -halfsize; j <= halfsize; j++) {
|
||||
|
||||
// calculate in-chunk coordinates
|
||||
int inChunkX = x % chunkResX;
|
||||
int inChunkY = y % chunkResY;
|
||||
int brushX = i;
|
||||
int brushY = j;
|
||||
int iteratorX = i;
|
||||
int iteratorY = j;
|
||||
int ptX = startPtX;
|
||||
int ptY = startPtY;
|
||||
|
||||
// calculate chunk to write to
|
||||
int chunkX = x/chunkResX;
|
||||
if (inChunkX + i < 0) {
|
||||
chunkX--;
|
||||
// 320 -22
|
||||
brushX = chunkResX + inChunkX + i;
|
||||
inChunkX = chunkResX - inChunkX;
|
||||
} else if (inChunkX + i >= chunkResX) {
|
||||
chunkX++;
|
||||
inChunkX = 0;
|
||||
brushX = i % chunkResX;
|
||||
}
|
||||
inChunkX += brushX;
|
||||
|
||||
if (chunkX < 0 || chunkX >= chunksPerX) {
|
||||
GD.PrintErr($"Trying to write out of bounds: {x}:{y}");
|
||||
return;
|
||||
// left of chunk
|
||||
if (startPtX + iteratorX < 0) {
|
||||
chunkX--;
|
||||
iteratorX = chunkResX + startPtX + iteratorX;
|
||||
ptX = startPtX + iteratorX;
|
||||
|
||||
// right of chunk
|
||||
} else if (startPtX + iteratorX >= chunkResX) {
|
||||
chunkX++;
|
||||
ptX = startPtX + iteratorX - chunkResX;
|
||||
} else {
|
||||
ptX = startPtX + iteratorX;
|
||||
}
|
||||
|
||||
int chunkY = y/chunkResY;
|
||||
if (inChunkY + j < 0) {
|
||||
|
||||
// above chunk
|
||||
if (startPtY + iteratorY < 0) {
|
||||
chunkY--;
|
||||
brushY = chunkResY - (inChunkY + j);
|
||||
inChunkY = chunkResY - inChunkY;
|
||||
} else if (inChunkY + j >= chunkResY) {
|
||||
ptY = chunkResY + (startPtY + iteratorY);
|
||||
|
||||
// left of chunk
|
||||
} else if (startPtY + iteratorY >= chunkResY) {
|
||||
chunkY++;
|
||||
inChunkY = 0;
|
||||
brushY = j % chunkResY;
|
||||
}
|
||||
inChunkY += brushY;
|
||||
|
||||
if (chunkY < 0 || chunkY >= chunksPerY) {
|
||||
GD.PrintErr($"Trying to write out of bounds: {x}:{y}");
|
||||
return;
|
||||
ptY = iteratorY % chunkResY;
|
||||
} else {
|
||||
ptY = startPtY + iteratorY;
|
||||
}
|
||||
|
||||
chunks[chunkX, chunkY].WritePixel<T>(inChunkX, inChunkY);
|
||||
// ignore everything outside
|
||||
if (chunkX < 0) continue;
|
||||
if (chunkX > chunksPerX) continue;
|
||||
if (chunkY < 0) continue;
|
||||
if (chunkY > chunksPerY) continue;
|
||||
|
||||
chunks[chunkX, chunkY].WritePixel<T>(ptX, ptY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user