aboutsummaryrefslogtreecommitdiffstats
path: root/src/map.c
diff options
context:
space:
mode:
authornathan <nathansmith@disroot.org>2025-11-24 13:47:58 +0000
committernathan <nathansmith@disroot.org>2025-11-24 13:47:58 +0000
commiteff6d7308d69ece8b89fe22e529b815f67a893e2 (patch)
treecd996e8d664d69580a9c126657612a6cb1384110 /src/map.c
parent6db246171bcc0a7472624b2bf6c74898c43b9248 (diff)
downloadFindThings-eff6d7308d69ece8b89fe22e529b815f67a893e2.tar.gz
FindThings-eff6d7308d69ece8b89fe22e529b815f67a893e2.tar.bz2
FindThings-eff6d7308d69ece8b89fe22e529b815f67a893e2.zip
Map zoom working
Diffstat (limited to 'src/map.c')
-rw-r--r--src/map.c59
1 files changed, 52 insertions, 7 deletions
diff --git a/src/map.c b/src/map.c
index 9d91202..3b763f0 100644
--- a/src/map.c
+++ b/src/map.c
@@ -21,12 +21,11 @@ void initMap(Map* map, const Settings* settings)
settings->mapPreviewHeight},
.isEnabled = settings->isMapPreviewEnabledDefault,
.isFullSize = false,
- .zoom = settings->mapPreviewZoomDefault,
.playerPosition = Vector2Zero(),
.playerRotation = 0.0
};
- zoomMap(map, 10.0);
+ zoomMap(map, settings->mapPreviewZoomDefault);
repositionMap(map);
}
@@ -35,17 +34,67 @@ void updateMapPreview(Map* map, Game* game)
const Settings* settings = &game->settings;
const World* world = &game->world;
+ float mouseWheel = GetMouseWheelMove();
+
+ if (mouseWheel != 0.0)
+ {
+ zoomMap(map, Clamp(map->zoom + mouseWheel, MAP_ZOOM_MIN, MAP_ZOOM_MAX));
+ }
+
// Player position.
map->playerPosition = (Vector2){
WORLD_IMAGE_WIDTH / world->size.x * game->player.position.x,
WORLD_IMAGE_HEIGHT / world->size.z * game->player.position.z
};
+ Vector2 playerPreviewPosition = Vector2Add(
+ (Vector2){map->rect.x, map->rect.y},
+ (Vector2){map->rect.width / 2.0, map->rect.height / 2.0});
+
map->heightmapRect.x = map->playerPosition.x -
(map->heightmapRect.width / 2.0);
map->heightmapRect.y = map->playerPosition.y -
(map->heightmapRect.height / 2.0);
+ // Preview out of bounds.
+ bool outOfX = false;
+ bool outOfY = false;
+ float oldX = map->heightmapRect.x;
+ float oldY = map->heightmapRect.y;
+
+ if (map->heightmapRect.x + map->heightmapRect.width > WORLD_IMAGE_WIDTH)
+ {
+ map->heightmapRect.x = WORLD_IMAGE_WIDTH - map->heightmapRect.width;
+ outOfX = true;
+ }
+ else if (map->heightmapRect.x < 0.0)
+ {
+ map->heightmapRect.x = 0.0;
+ outOfX = true;
+ }
+
+ if (map->heightmapRect.y + map->heightmapRect.height > WORLD_IMAGE_HEIGHT)
+ {
+ map->heightmapRect.y = WORLD_IMAGE_HEIGHT - map->heightmapRect.height;
+ outOfY = true;
+ }
+ else if (map->heightmapRect.y < 0.0)
+ {
+ map->heightmapRect.y = 0.0;
+ outOfY = true;
+ }
+
+ if (outOfX)
+ {
+ playerPreviewPosition.x += (oldX - map->heightmapRect.x) *
+ (map->rect.width / map->heightmapRect.width);
+ }
+ if (outOfY)
+ {
+ playerPreviewPosition.y += (oldY - map->heightmapRect.y) *
+ (map->rect.height / map->heightmapRect.height);
+ }
+
// Draw map.
DrawTexturePro(world->heightmapTexture,
map->heightmapRect,
@@ -55,11 +104,7 @@ void updateMapPreview(Map* map, Game* game)
settings->mapColor);
// Draw player.
- DrawCircleV(Vector2Add((Vector2){map->rect.x, map->rect.y},
- (Vector2){map->rect.width / 2.0,
- map->rect.height / 2.0}),
- 3.0,
- BLUE);
+ DrawCircleV(playerPreviewPosition, 3.0, BLUE);
// Outline.
DrawRectangleLinesEx(map->rect, 3.0, BLUE);