aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/map.c40
-rw-r--r--src/map.h5
-rw-r--r--src/settings.c6
-rw-r--r--src/settings.h4
4 files changed, 30 insertions, 25 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);
}
diff --git a/src/map.h b/src/map.h
index 4a71504..bd581ba 100644
--- a/src/map.h
+++ b/src/map.h
@@ -4,18 +4,17 @@
#ifndef MAP_H
#define MAP_H
-#define MAP_ZOOM_MIN 2.0
+#define MAP_ZOOM_MIN 0.5
#define MAP_ZOOM_MAX 30.0
typedef struct {
Rectangle rect;
RenderTexture render;
Camera2D camera;
+ Texture heightmap;
Vector2 playerPosition;
bool isEnabled;
bool isFullSize;
-
- Texture heightmap;
} Map;
void initMap(Map* map, const World* world, const Settings* settings);
diff --git a/src/settings.c b/src/settings.c
index 3dd1fa5..0d65432 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -22,7 +22,11 @@ Settings defaultSettings()
.mapPreviewWidth = 300.0,
.mapPreviewHeight = 300.0,
.mapAlpha = (unsigned char)255.0 * 0.80,
- .mapPreviewZoomDefault = 10.0,
+ .mapPreviewZoomDefault = 3.0,
+ .mapLowColor = (Color){255, 255, 0, 255},
+ .mapHighColor = (Color){0, 0, 255, 255},
+ .mapColorCount = 7.0,
+ .mapZoomSpeed = 0.2,
.mouseSpeed = 0.1,
.forwardKey = KEY_W,
.backwardKey = KEY_S,
diff --git a/src/settings.h b/src/settings.h
index 94e21ad..d6416ba 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -39,6 +39,10 @@ typedef struct {
float mapPreviewHeight;
unsigned char mapAlpha;
float mapPreviewZoomDefault;
+ Color mapLowColor;
+ Color mapHighColor;
+ float mapColorCount;
+ float mapZoomSpeed;
// Controls.
float mouseSpeed;