diff options
| author | nathan <nathansmith@disroot.org> | 2025-12-18 11:23:16 +0000 |
|---|---|---|
| committer | nathan <nathansmith@disroot.org> | 2025-12-18 11:23:16 +0000 |
| commit | 8394a306ed1d8dfdc9ca72e4c2c7888a4b79c576 (patch) | |
| tree | 8abba02b0218631224b59a8e1165abda64bcf550 | |
| parent | bcdd09d5075c9755538a93db8e3ca2690a803cc1 (diff) | |
| download | FindThings-8394a306ed1d8dfdc9ca72e4c2c7888a4b79c576.tar.gz FindThings-8394a306ed1d8dfdc9ca72e4c2c7888a4b79c576.tar.bz2 FindThings-8394a306ed1d8dfdc9ca72e4c2c7888a4b79c576.zip | |
A lot of code for a lot of nothing
| -rw-r--r-- | src/game.c | 33 | ||||
| -rw-r--r-- | src/player.c | 47 | ||||
| -rw-r--r-- | src/player.h | 3 | ||||
| -rw-r--r-- | src/settings.c | 2 | ||||
| -rw-r--r-- | src/settings.h | 4 |
5 files changed, 69 insertions, 20 deletions
@@ -152,6 +152,38 @@ void drawCrosshair(float crossHairSize, float crossHairThickness, Color color) crossHairThickness, color); } +void updateGameEntityInfo(Game* game) +{ + // Get size. + float screenWidth = GetRenderWidth(); + float screenHeight = GetRenderWidth(); + float x = game->map.rect.x + (game->map.rect.width * 0.25); + float y = game->map.rect.y + game->map.rect.height; + + int lines = 1; + int fontSize = game->settings.entityInfoFontSize; + + if (!game->map.isEnabled) + { + y = 0.0; + } + + WorldUID selected = game->player.selectedEntity; + + if (selected == ENTITY_NONE) + { + return; + } + + Color backgroundColor = PINK; + backgroundColor.a = game->settings.entityInfoAlpha; + DrawRectangle(x, y, screenWidth - x, lines * fontSize, backgroundColor); + + // Draw name. + Entity* selectedEntity = &game->world.entities[selected]; + DrawText(getEntityName(selectedEntity->id), x, y, fontSize, BLACK); +} + void updateGameScene(Game* game) { // Handle toggle cursor. @@ -189,6 +221,7 @@ void updateGameScene(Game* game) drawGameScreen(game); updateMap(&game->map, game); + updateGameEntityInfo(game); updateInteractionChat(&game->chat, game); // Cross hair. 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); - } } diff --git a/src/player.h b/src/player.h index 436f8d0..6be9258 100644 --- a/src/player.h +++ b/src/player.h @@ -16,7 +16,8 @@ typedef struct { Camera camera; Vector2 cameraAngle; - WorldUID interactingWith; + WorldUID selectedEntity; + bool isInteracting; } Player; Player createPlayer(); diff --git a/src/settings.c b/src/settings.c index 4b713cd..600431b 100644 --- a/src/settings.c +++ b/src/settings.c @@ -27,6 +27,8 @@ Settings defaultSettings() .mapHighColor = (Color){0, 0, 255, 255}, .mapColorCount = 7.0, .mapZoomSpeed = 0.2, + .entityInfoFontSize = 20, + .entityInfoAlpha = (unsigned char)255.0 * 0.8, .interactionChatFontSize = 20, .interactionChatHeight = 300.0, .interactionChatAlpha = (unsigned char)255.0 * 0.9, diff --git a/src/settings.h b/src/settings.h index bfeaf50..dd079a7 100644 --- a/src/settings.h +++ b/src/settings.h @@ -44,6 +44,10 @@ typedef struct { float mapColorCount; float mapZoomSpeed; + // Side info. + int entityInfoFontSize; + unsigned char entityInfoAlpha; + // Interaction chat. int interactionChatFontSize; float interactionChatHeight; |
