aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/game.c2
-rw-r--r--src/map.c48
-rw-r--r--src/map.h4
-rw-r--r--src/settings.c2
-rw-r--r--src/utils.h2
5 files changed, 51 insertions, 7 deletions
diff --git a/src/game.c b/src/game.c
index 5f7565f..9d7686f 100644
--- a/src/game.c
+++ b/src/game.c
@@ -83,7 +83,7 @@ void initGame(Game* game)
game->player.position = Vector3Scale(game->world.size, 0.5);
// Map.
- initMap(&game->map, &game->settings);
+ initMap(&game->map, &game->world, &game->settings);
disableGameCursor(game);
}
diff --git a/src/map.c b/src/map.c
index 81839b5..33e57bc 100644
--- a/src/map.c
+++ b/src/map.c
@@ -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);
}
diff --git a/src/map.h b/src/map.h
index 9a1d41e..4a71504 100644
--- a/src/map.h
+++ b/src/map.h
@@ -14,9 +14,11 @@ typedef struct {
Vector2 playerPosition;
bool isEnabled;
bool isFullSize;
+
+ Texture heightmap;
} Map;
-void initMap(Map* map, const Settings* settings);
+void initMap(Map* map, const World* world, const Settings* settings);
void updateMap(Map* map, Game* game);
void closeMap(Map* map);
diff --git a/src/settings.c b/src/settings.c
index 4ca38c4..3dd1fa5 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -21,7 +21,7 @@ Settings defaultSettings()
.isMapPreviewEnabledDefault = true,
.mapPreviewWidth = 300.0,
.mapPreviewHeight = 300.0,
- .mapAlpha = (unsigned char)255.0 * 0.85,
+ .mapAlpha = (unsigned char)255.0 * 0.80,
.mapPreviewZoomDefault = 10.0,
.mouseSpeed = 0.1,
.forwardKey = KEY_W,
diff --git a/src/utils.h b/src/utils.h
index 75e27fd..fddfa9d 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -54,6 +54,8 @@
#define PRINT_VECTOR2(v) printf("%f %f\n", v.x, v.y)
#define PRINT_VECTOR3(v) printf("%f %f %f\n", v.x, v.y, v.z)
+#define GRAY_VALUE(color) ((float)(color.r + color.g + color.b) / 3.0)
+
#define RANDOM_DIRECTION_UNITS 4096
// Typedef hackery.