aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/player.c32
-rw-r--r--src/player.h1
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;