]> git.lizzy.rs Git - shadowclad.git/commitdiff
Flip image Y coordinate to unflip the level Z coordinate
authoroutfrost <kotlet.bahn@gmail.com>
Thu, 31 Jan 2019 02:57:37 +0000 (03:57 +0100)
committeroutfrost <kotlet.bahn@gmail.com>
Thu, 31 Jan 2019 02:57:37 +0000 (03:57 +0100)
level.c

diff --git a/level.c b/level.c
index 1a1778b29c0c170b5fc8b5b39357e0c759153b92..31be493b2bd979f8d668f306a0499aa62b9fbef2 100644 (file)
--- 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: