From 77760cbcbb219e6f3577cfc92a3e88a837fe4a8b Mon Sep 17 00:00:00 2001 From: outfrost Date: Thu, 31 Jan 2019 03:57:37 +0100 Subject: [PATCH] Flip image Y coordinate to unflip the level Z coordinate --- level.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/level.c b/level.c index 1a1778b..31be493 100644 --- a/level.c +++ b/level.c @@ -95,9 +95,12 @@ void buildLevelFromImage(TgaImage* image) { * sizeof(Block*)) }; playerSpawnPos = (AiVector3D) DEFAULT_PLAYER_SPAWN_POS; - for (int z = 0; z < newGrid.depth; ++z) { + for (int row = 0; row < newGrid.depth; ++row) { for (int x = 0; x < newGrid.width; ++x) { - uint32_t pixelColorARGB = ((uint32_t*) image->bytes)[(z * newGrid.width) + x]; + // Flip the image vertically due to (0, 0) being bottom left + int z = newGrid.depth - row - 1; + + uint32_t pixelColorARGB = ((uint32_t*) image->bytes)[(row * newGrid.width) + x]; Block* block; switch (pixelColorARGB) { case 0xFFFF0000: -- 2.44.0