diff options
Diffstat (limited to 'src/map.c')
| -rw-r--r-- | src/map.c | 63 |
1 files changed, 59 insertions, 4 deletions
@@ -1,35 +1,90 @@ #include "map.h" #include "game.h" +#include "world.h" void repositionMap(Map* map) { map->rect.x = GetRenderWidth() - map->rect.width; } +void zoomMap(Map* map, float zoom) +{ + map->zoom = zoom; + map->heightmapRect.width = WORLD_IMAGE_WIDTH / zoom; + map->heightmapRect.height = WORLD_IMAGE_HEIGHT / zoom; +} + void initMap(Map* map, const Settings* settings) { *map = (Map){ - .rect = (Rectangle){0.0, 0.0, settings->mapPreviewSize, - settings->mapPreviewSize}, + .rect = (Rectangle){0.0, 0.0, settings->mapPreviewWidth, + settings->mapPreviewHeight}, .isEnabled = settings->isMapPreviewEnabledDefault, - .isFullSize = false + .isFullSize = false, + .zoom = settings->mapPreviewZoomDefault, + .playerPosition = Vector2Zero(), + .playerRotation = 0.0 }; + zoomMap(map, 10.0); repositionMap(map); } +void updateMapPreview(Map* map, Game* game) +{ + const Settings* settings = &game->settings; + const World* world = &game->world; + + // 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 + }; + + map->heightmapRect.x = map->playerPosition.x - + (map->heightmapRect.width / 2.0); + map->heightmapRect.y = map->playerPosition.y - + (map->heightmapRect.height / 2.0); + + // Draw map. + DrawTexturePro(world->heightmapTexture, + map->heightmapRect, + map->rect, + (Vector2){0.0, 0.0}, + 0.0, + 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); + + // Outline. + DrawRectangleLinesEx(map->rect, 3.0, BLUE); +} + void updateMap(Map* map, Game* game) { + const Settings* settings = &game->settings; + // Handle window resize. if (IsWindowResized()) { repositionMap(map); } + + // Toggle preview. + if (IsKeyPressed(settings->toggleMapPreviewKey)) + { + map->isEnabled = !map->isEnabled; + } if (!map->isEnabled) { return; } - DrawRectangleLinesEx(map->rect, 3.0, BLUE); + updateMapPreview(map, game); } |
