aboutsummaryrefslogtreecommitdiffstats
path: root/src/map.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/map.c')
-rw-r--r--src/map.c40
1 files changed, 19 insertions, 21 deletions
diff --git a/src/map.c b/src/map.c
index 33e57bc..0ff87ea 100644
--- a/src/map.c
+++ b/src/map.c
@@ -8,7 +8,7 @@ void repositionMap(Map* map)
map->rect.x = GetRenderWidth() - map->rect.width;
}
-void initMapHeightmap(Map* map, const World* world)
+void initMapHeightmap(Map* map, const World* world, const Settings* settings)
{
Image image = LoadImageFromTexture(world->heightmapTexture);
Color* colors = LoadImageColors(image);
@@ -16,21 +16,20 @@ void initMapHeightmap(Map* map, const World* world)
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};
- }
+ float height = (float)GRAY_VALUE(colors[index]) / 255.0;
+
+ // Limit color acount.
+ height *= settings->mapColorCount;
+ height = floorf(height);
+ height /= settings->mapColorCount;
+
+ Color lowColor = settings->mapLowColor;
+ Color highColor = settings->mapHighColor;
+
+ // Lerp between low and high colors.
+ colors[index].r = Lerp(lowColor.r, highColor.r, height);
+ colors[index].g = Lerp(lowColor.g, highColor.g, height);
+ colors[index].b = Lerp(lowColor.b, highColor.b, height);
}
image = (Image){
@@ -40,8 +39,6 @@ void initMapHeightmap(Map* map, const World* world)
.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8,
.mipmaps = 1
};
-
- ImageColorContrast(&image, 25.0);
map->heightmap = LoadTextureFromImage(image);
UnloadImage(image);
@@ -66,7 +63,7 @@ void initMap(Map* map, const World* world, const Settings* settings)
.isFullSize = false
};
- initMapHeightmap(map, world);
+ initMapHeightmap(map, world, settings);
repositionMap(map);
}
@@ -109,8 +106,9 @@ void updateMapPreview(Map* map, Game* game)
if (mouseScroll != 0.0)
{
- map->camera.zoom = expf(logf(map->camera.zoom) +
- ((float)GetMouseWheelMove() * 0.1f));
+ map->camera.zoom = expf(
+ logf(map->camera.zoom) +
+ ((float)GetMouseWheelMove() * settings->mapZoomSpeed));
map->camera.zoom = Clamp(map->camera.zoom, MAP_ZOOM_MIN, MAP_ZOOM_MAX);
}