diff options
Diffstat (limited to 'src/map.c')
| -rw-r--r-- | src/map.c | 59 |
1 files changed, 52 insertions, 7 deletions
@@ -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); |
