diff options
| author | nathan <nathansmith@disroot.org> | 2025-10-27 14:30:15 +0000 |
|---|---|---|
| committer | nathan <nathansmith@disroot.org> | 2025-10-27 14:30:15 +0000 |
| commit | 5a1c6f8d8db8311d8be286c40792227549594693 (patch) | |
| tree | 8453f917c21cc1ea2eef2520606d0d42dfed4a14 | |
| parent | 95af9c76abef62466dc99cd48fe60d5c8c0677aa (diff) | |
| download | FindThings-5a1c6f8d8db8311d8be286c40792227549594693.tar.gz FindThings-5a1c6f8d8db8311d8be286c40792227549594693.tar.bz2 FindThings-5a1c6f8d8db8311d8be286c40792227549594693.zip | |
Added max select distance
| -rw-r--r-- | src/player.c | 32 | ||||
| -rw-r--r-- | src/player.h | 1 |
2 files changed, 26 insertions, 7 deletions
diff --git a/src/player.c b/src/player.c index f0928e9..36f5efe 100644 --- a/src/player.c +++ b/src/player.c @@ -83,11 +83,34 @@ void updatePlayerMovement(Player* player, Game* game) camera->target = Vector3Add(player->position, player->direction); } -void playerInteractWithEntity(Player* player, Game* game, Entity* entity) +bool playerCanEntityBeSelected(Player* player, Entity* entity) +{ + float maxDistance = PLAYER_MAX_SELECT_DISTANCE; + maxDistance += Vector3Distance(entity->box.min, entity->box.max) / 2.0; + + return Vector3Distance(player->position, entity->position) <= maxDistance; +} + +void playerInteractWithEntity(Player* player, Entity* entity, Game* game) { printf("%d\n", interactWithEntity(entity, game, SELECTION_INTERACT)); } +void playerUpdateSelectedEntity(Player* player, Entity* entity, Game* game) +{ + if (!playerCanEntityBeSelected(player, entity)) + { + return; + } + + DrawBoundingBox(entity->box, RED); + + if (IsKeyPressed(game->settings.interactKey)) + { + playerInteractWithEntity(player, entity, game); + } +} + // TODO: move magic numbers to settings void updatePlayer(Player* player, Game* game) { @@ -104,11 +127,6 @@ void updatePlayer(Player* player, Game* game) if (uid != -1) { - DrawBoundingBox(game->world.entities[uid].box, RED); - - if (IsKeyPressed(game->settings.interactKey)) - { - playerInteractWithEntity(player, game, &game->world.entities[uid]); - } + playerUpdateSelectedEntity(player, &game->world.entities[uid], game); } } diff --git a/src/player.h b/src/player.h index d66b9dd..71c9993 100644 --- a/src/player.h +++ b/src/player.h @@ -5,6 +5,7 @@ #define PLAYER_HEIGHT 2.0 #define PLAYER_SPEED 8.0 +#define PLAYER_MAX_SELECT_DISTANCE 10.0 typedef struct { Vector3 position; |
