From eff6d7308d69ece8b89fe22e529b815f67a893e2 Mon Sep 17 00:00:00 2001 From: nathan Date: Mon, 24 Nov 2025 06:47:58 -0700 Subject: Map zoom working --- src/map.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++------- src/map.h | 4 ++++ src/player.h | 2 +- src/settings.c | 6 +++--- 4 files changed, 60 insertions(+), 11 deletions(-) (limited to 'src') 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); diff --git a/src/map.h b/src/map.h index 9e94190..23faebe 100644 --- a/src/map.h +++ b/src/map.h @@ -4,12 +4,16 @@ #ifndef MAP_H #define MAP_H +#define MAP_ZOOM_MIN 1.0 +#define MAP_ZOOM_MAX 30.0 + typedef struct { Rectangle rect; Rectangle heightmapRect; float zoom; Vector2 playerPosition; float playerRotation; + bool isEnabled; bool isFullSize; } Map; diff --git a/src/player.h b/src/player.h index 71c9993..acd9d7d 100644 --- a/src/player.h +++ b/src/player.h @@ -4,7 +4,7 @@ #define PLAYER_H #define PLAYER_HEIGHT 2.0 -#define PLAYER_SPEED 8.0 +#define PLAYER_SPEED 80.0 #define PLAYER_MAX_SELECT_DISTANCE 10.0 typedef struct { diff --git a/src/settings.c b/src/settings.c index 8396fba..8baaa80 100644 --- a/src/settings.c +++ b/src/settings.c @@ -19,10 +19,10 @@ Settings defaultSettings() .crossHairThickness = 3.0, .crossHairColor = BLUE, .isMapPreviewEnabledDefault = true, - .mapPreviewWidth = 300.0, - .mapPreviewHeight = 300.0, + .mapPreviewWidth = 700.0, + .mapPreviewHeight = 700.0, .mapColor = (Color){255, 0.0, 0.0, (unsigned char)255.0 * 0.80}, - .mapPreviewZoomDefault = 1.0, + .mapPreviewZoomDefault = 10.0, .mouseSpeed = 0.1, .forwardKey = KEY_W, .backwardKey = KEY_S, -- cgit v1.2.3