aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authornathan <nathansmith@disroot.org>2025-11-24 12:59:01 +0000
committernathan <nathansmith@disroot.org>2025-11-24 12:59:01 +0000
commit6db246171bcc0a7472624b2bf6c74898c43b9248 (patch)
tree76a152bd23b48e56b2acfdeae7953be870c7a7e9 /src
parent9d363e00bc33df2821e008d03794675c09c413ec (diff)
downloadFindThings-6db246171bcc0a7472624b2bf6c74898c43b9248.tar.gz
FindThings-6db246171bcc0a7472624b2bf6c74898c43b9248.tar.bz2
FindThings-6db246171bcc0a7472624b2bf6c74898c43b9248.zip
Working map preview
Diffstat (limited to 'src')
-rw-r--r--src/map.c63
-rw-r--r--src/map.h4
-rw-r--r--src/player.c5
-rw-r--r--src/settings.c6
-rw-r--r--src/settings.h6
5 files changed, 77 insertions, 7 deletions
diff --git a/src/map.c b/src/map.c
index ebcb077..9d91202 100644
--- a/src/map.c
+++ b/src/map.c
@@ -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);
}
diff --git a/src/map.h b/src/map.h
index ce4e71e..9e94190 100644
--- a/src/map.h
+++ b/src/map.h
@@ -6,6 +6,10 @@
typedef struct {
Rectangle rect;
+ Rectangle heightmapRect;
+ float zoom;
+ Vector2 playerPosition;
+ float playerRotation;
bool isEnabled;
bool isFullSize;
} Map;
diff --git a/src/player.c b/src/player.c
index 9a08204..2d9ec62 100644
--- a/src/player.c
+++ b/src/player.c
@@ -130,7 +130,10 @@ void updatePlayer(Player* player, Game* game)
.direction = player->direction
};
- DrawRay(ray, YELLOW);
+ if (game->isCrossHairEnabled)
+ {
+ DrawRay(ray, YELLOW);
+ }
WorldUID uid = castRayAtWorld(&game->world, ray, false, NULL);
diff --git a/src/settings.c b/src/settings.c
index 26caa73..8396fba 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -19,7 +19,10 @@ Settings defaultSettings()
.crossHairThickness = 3.0,
.crossHairColor = BLUE,
.isMapPreviewEnabledDefault = true,
- .mapPreviewSize = 300.0,
+ .mapPreviewWidth = 300.0,
+ .mapPreviewHeight = 300.0,
+ .mapColor = (Color){255, 0.0, 0.0, (unsigned char)255.0 * 0.80},
+ .mapPreviewZoomDefault = 1.0,
.mouseSpeed = 0.1,
.forwardKey = KEY_W,
.backwardKey = KEY_S,
@@ -27,6 +30,7 @@ Settings defaultSettings()
.leftKey = KEY_A,
.toggleCursorKey = KEY_LEFT_ALT,
.toggleCrossHairKey = KEY_C,
+ .toggleMapPreviewKey = KEY_P,
.interactKey = KEY_E
};
}
diff --git a/src/settings.h b/src/settings.h
index 118bf84..a76b0ab 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -35,7 +35,10 @@ typedef struct {
// Map.
bool isMapPreviewEnabledDefault;
- float mapPreviewSize;
+ float mapPreviewWidth;
+ float mapPreviewHeight;
+ Color mapColor;
+ float mapPreviewZoomDefault;
// Controls.
float mouseSpeed;
@@ -45,6 +48,7 @@ typedef struct {
KeyboardKey leftKey;
KeyboardKey toggleCursorKey;
KeyboardKey toggleCrossHairKey;
+ KeyboardKey toggleMapPreviewKey;
KeyboardKey interactKey;
} Settings;