diff options
| author | nathan <nathansmith@disroot.org> | 2025-11-25 15:15:02 +0000 |
|---|---|---|
| committer | nathan <nathansmith@disroot.org> | 2025-11-25 15:15:02 +0000 |
| commit | 0e8b4d5e38593cd9299da73ae84b5ca5ca61042f (patch) | |
| tree | bcf848d6f30329ed978a3d0551819ef31d56dd3b /src/map.c | |
| parent | 05624b044e59e70d10b786538f55e77c19cc3c8c (diff) | |
| download | FindThings-0e8b4d5e38593cd9299da73ae84b5ca5ca61042f.tar.gz FindThings-0e8b4d5e38593cd9299da73ae84b5ca5ca61042f.tar.bz2 FindThings-0e8b4d5e38593cd9299da73ae84b5ca5ca61042f.zip | |
Really fancy looking map
Diffstat (limited to 'src/map.c')
| -rw-r--r-- | src/map.c | 48 |
1 files changed, 44 insertions, 4 deletions
@@ -8,7 +8,46 @@ void repositionMap(Map* map) map->rect.x = GetRenderWidth() - map->rect.width; } -void initMap(Map* map, const Settings* settings) +void initMapHeightmap(Map* map, const World* world) +{ + Image image = LoadImageFromTexture(world->heightmapTexture); + Color* colors = LoadImageColors(image); + UnloadImage(image); + + for (int index = 0; index < WORLD_IMAGE_WIDTH * WORLD_IMAGE_HEIGHT; ++index) + { + unsigned char grayValue = GRAY_VALUE(colors[index]); + unsigned char alpha = colors[index].a; + + if (grayValue >= 170) + { + colors[index] = (Color){grayValue, 0, 0, alpha}; + } + else if (grayValue >= 85) + { + colors[index] = (Color){0, grayValue * 2, grayValue, alpha}; + } + else + { + colors[index] = (Color){grayValue, 0, grayValue, alpha}; + } + } + + image = (Image){ + .data = colors, + .width = WORLD_IMAGE_WIDTH, + .height = WORLD_IMAGE_HEIGHT, + .format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, + .mipmaps = 1 + }; + + ImageColorContrast(&image, 25.0); + + map->heightmap = LoadTextureFromImage(image); + UnloadImage(image); +} + +void initMap(Map* map, const World* world, const Settings* settings) { *map = (Map){ .rect = (Rectangle){0.0, 0.0, settings->mapPreviewWidth, @@ -27,6 +66,7 @@ void initMap(Map* map, const Settings* settings) .isFullSize = false }; + initMapHeightmap(map, world); repositionMap(map); } @@ -83,9 +123,8 @@ void updateMapPreview(Map* map, Game* game) ClearBackground(BLANK); // Draw height map. - Color color = GREEN; - color.a = settings->mapAlpha; - DrawTexture(game->world.heightmapTexture, 0.0, 0.0, color); + DrawTexture(map->heightmap, 0.0, 0.0, + (Color){255, 255, 255, settings->mapAlpha}); EndMode2D(); EndTextureMode(); @@ -134,4 +173,5 @@ void updateMap(Map* map, Game* game) void closeMap(Map* map) { UnloadRenderTexture(map->render); + UnloadTexture(map->heightmap); } |
