diff options
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); } |
