From: outfrost Date: Thu, 31 Jan 2019 02:57:37 +0000 (+0100) Subject: Flip image Y coordinate to unflip the level Z coordinate X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=77760cbcbb219e6f3577cfc92a3e88a837fe4a8b;p=shadowclad.git Flip image Y coordinate to unflip the level Z coordinate --- 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: