aboutsummaryrefslogtreecommitdiffstats
path: root/src/player.c
diff options
context:
space:
mode:
authornathan <nathansmith@disroot.org>2025-12-18 11:23:16 +0000
committernathan <nathansmith@disroot.org>2025-12-18 11:23:16 +0000
commit8394a306ed1d8dfdc9ca72e4c2c7888a4b79c576 (patch)
tree8abba02b0218631224b59a8e1165abda64bcf550 /src/player.c
parentbcdd09d5075c9755538a93db8e3ca2690a803cc1 (diff)
downloadFindThings-8394a306ed1d8dfdc9ca72e4c2c7888a4b79c576.tar.gz
FindThings-8394a306ed1d8dfdc9ca72e4c2c7888a4b79c576.tar.bz2
FindThings-8394a306ed1d8dfdc9ca72e4c2c7888a4b79c576.zip
A lot of code for a lot of nothing
Diffstat (limited to 'src/player.c')
-rw-r--r--src/player.c47
1 files changed, 28 insertions, 19 deletions
diff --git a/src/player.c b/src/player.c
index 715d5ed..057eee7 100644
--- a/src/player.c
+++ b/src/player.c
@@ -15,7 +15,8 @@ Player createPlayer()
.projection = CAMERA_PERSPECTIVE
},
.cameraAngle = Vector2Zero(),
- .interactingWith = ENTITY_NONE
+ .selectedEntity = ENTITY_NONE,
+ .isInteracting = false
};
}
@@ -106,7 +107,7 @@ void playerInteractWithEntity(Player* player, WorldUID uid, Game* game,
{
InteractionChat* chat = &game->chat;
Entity* entity = &game->world.entities[uid];
- player->interactingWith = uid;
+
// Handle selection type.
switch (selection)
@@ -114,9 +115,12 @@ void playerInteractWithEntity(Player* player, WorldUID uid, Game* game,
case SELECTION_INTERACT:
clearInteractionChat(chat);
chat->entityId = entity->id;
+ player->selectedEntity = uid;
+ player->isInteracting = true;
break;
case SELECTION_LEAVE:
- player->interactingWith = ENTITY_NONE;
+ player->selectedEntity = ENTITY_NONE;
+ player->isInteracting = false;
chat->entityId = ENTITY_NONE;
break;
default:
@@ -131,7 +135,8 @@ void playerInteractWithEntity(Player* player, WorldUID uid, Game* game,
break;
case INTERACTION_END:
hideInteractionChat(chat);
- player->interactingWith = ENTITY_NONE;
+ player->selectedEntity = ENTITY_NONE;
+ player->isInteracting = false;
chat->entityId = ENTITY_NONE;
break;
default:
@@ -142,10 +147,13 @@ void playerInteractWithEntity(Player* player, WorldUID uid, Game* game,
void playerUpdateSelectedEntity(Player* player, WorldUID uid, Game* game)
{
Entity* entity = &game->world.entities[uid];
-
+
+ // If the entity can be selected.
if (!playerCanEntityBeSelected(player, *entity))
{
- if (uid == player->interactingWith)
+
+ // Leave interaction if far away.
+ if (player->isInteracting)
{
playerInteractWithEntity(player, uid, game, SELECTION_LEAVE);
}
@@ -153,15 +161,12 @@ void playerUpdateSelectedEntity(Player* player, WorldUID uid, Game* game)
return;
}
- Color color = PINK;
+ player->selectedEntity = uid;
- if (uid == player->interactingWith)
- {
- color = YELLOW;
- }
-
- DrawBoundingBox(entity->box, color);
+ // Draw outline.
+ DrawBoundingBox(entity->box, player->isInteracting ? YELLOW : PINK);
+ // Handle key presses.
if (IsKeyPressed(game->settings.interactKey))
{
playerInteractWithEntity(player, uid, game, SELECTION_INTERACT);
@@ -186,17 +191,21 @@ void updatePlayer(Player* player, Game* game)
DrawRay(ray, YELLOW);
}
- if (player->interactingWith == ENTITY_NONE)
+ if (player->isInteracting)
+ {
+ playerUpdateSelectedEntity(player, player->selectedEntity, game);
+ }
+ else
{
WorldUID uid = castRayAtWorld(&game->world, ray, false, NULL);
- if (uid != -1)
+ if (uid == -1)
+ {
+ player->selectedEntity = ENTITY_NONE;
+ }
+ else
{
playerUpdateSelectedEntity(player, uid, game);
}
}
- else
- {
- playerUpdateSelectedEntity(player, player->interactingWith, game);
- }
}