diff options
Diffstat (limited to 'src/player.c')
| -rw-r--r-- | src/player.c | 47 |
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); - } } |
