aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornathan <nathansmith@disroot.org>2025-12-18 10:23:19 +0000
committernathan <nathansmith@disroot.org>2025-12-18 10:23:19 +0000
commitbcdd09d5075c9755538a93db8e3ca2690a803cc1 (patch)
tree25a9e2e307bcc7d0908a81f7de6f365ab9230ff1
parentedaafadf2c5de7f23dfc20d420e973ed9dc92039 (diff)
downloadFindThings-bcdd09d5075c9755538a93db8e3ca2690a803cc1.tar.gz
FindThings-bcdd09d5075c9755538a93db8e3ca2690a803cc1.tar.bz2
FindThings-bcdd09d5075c9755538a93db8e3ca2690a803cc1.zip
Finally getting interaction stuff done
-rw-r--r--design/design.org3
-rw-r--r--src/entities/samantha.c16
-rw-r--r--src/entity.c47
-rw-r--r--src/entity.h7
-rw-r--r--src/game.c2
-rw-r--r--src/player.c78
-rw-r--r--src/player.h3
-rw-r--r--src/settings.c5
-rw-r--r--src/settings.h3
-rw-r--r--src/ui.c44
-rw-r--r--src/ui.h3
11 files changed, 166 insertions, 45 deletions
diff --git a/design/design.org b/design/design.org
index e884d4e..e38a863 100644
--- a/design/design.org
+++ b/design/design.org
@@ -143,13 +143,14 @@ creates is possible to beat. A little wack is fine as long as its
beatable. Since most of the world will just be a height map a image will be
generated first than rest of the world will be based around it.
-* TODO World generation check list [6/8]
+* TODO World generation check list [6/9]
+ [X] Basic terrain
+ [X] Ground texture
+ [X] Trees/plants
+ [X] Sky
+ [X] Pond
+ [X] Power lines
++ [ ] Buildings
+ [ ] Places
+ [ ] Roads
diff --git a/src/entities/samantha.c b/src/entities/samantha.c
index c8f08f6..bc70b7a 100644
--- a/src/entities/samantha.c
+++ b/src/entities/samantha.c
@@ -1,4 +1,5 @@
#include "samantha.h"
+#include "ui.h"
void initSamantha(Entity* entity)
{
@@ -23,6 +24,17 @@ void updateSamantha(Entity* entity, Game* game)
InteractionCommand interactWithSamantha(Entity* entity, Game* game,
Selection selection)
{
- puts("test test");
- return INTERACTION_TALK;
+ InteractionChat* chat = &game->chat;
+
+ switch (selection)
+ {
+ case SELECTION_INTERACT:
+ writeToInteractionChat(chat, "hihi");
+ return INTERACTION_TALK;
+ case SELECTION_NEXT_MESSAGE:
+ case SELECTION_LEAVE:
+ return INTERACTION_END;
+ default:
+ return INTERACTION_END;
+ }
}
diff --git a/src/entity.c b/src/entity.c
index 90ee641..92d4cf2 100644
--- a/src/entity.c
+++ b/src/entity.c
@@ -3,22 +3,27 @@
#include "entitiesInclude.h"
const EntityEntry entityEntries[ENTITY_COUNT] = {
- (EntityEntry){initOldMint, updateOldMint, NULL, NULL, false, true},
- (EntityEntry){initStickyNickel, updateStickyNickel, NULL, NULL, false, true},
- (EntityEntry){initTree, updateTree, NULL, NULL, false, true},
- (EntityEntry){initBush, updateBush, NULL, NULL, false, true},
- (EntityEntry){initFlower, updateFlower, NULL, NULL, false, true},
- (EntityEntry){initPond, updatePond, NULL, NULL, true, true},
- (EntityEntry){initUtilityPole, NULL, NULL, NULL, false, false},
- (EntityEntry){initSamantha, updateSamantha, NULL, interactWithSamantha,
- false, true},
- (EntityEntry){initSamanthasSpot, updateSamanthasSpot, NULL, NULL, true,
+ (EntityEntry){"Old Mint", initOldMint, updateOldMint, NULL, NULL, false,
+ true},
+ (EntityEntry){"Sticky Nickel", initStickyNickel, updateStickyNickel, NULL,
+ NULL, false, true},
+ (EntityEntry){"Tree", initTree, updateTree, NULL, NULL, false, true},
+ (EntityEntry){"Bush", initBush, updateBush, NULL, NULL, false, true},
+ (EntityEntry){"Flower", initFlower, updateFlower, NULL, NULL, false, true},
+ (EntityEntry){"Pond", initPond, updatePond, NULL, NULL, true, true},
+ (EntityEntry){"Utility Pole", initUtilityPole, NULL, NULL, NULL, false,
false},
- (EntityEntry){initTrashcan, updateTrashcan, NULL, NULL, false, true},
- (EntityEntry){initTrash, updateTrash, NULL, NULL, false, true},
- (EntityEntry){initMedicalTrash, updateMedicalTrash, NULL, NULL, false, true},
- (EntityEntry){initJohn, updateJohn, NULL, NULL, false, true},
- (EntityEntry){initRon, updateRon, NULL, NULL, false, true}
+ (EntityEntry){"Samantha", initSamantha, updateSamantha, NULL,
+ interactWithSamantha, false, true},
+ (EntityEntry){"Samantha's Spot", initSamanthasSpot, updateSamanthasSpot,
+ NULL, NULL, true, false},
+ (EntityEntry){"Trashcan", initTrashcan, updateTrashcan, NULL, NULL, false,
+ true},
+ (EntityEntry){"Trash", initTrash, updateTrash, NULL, NULL, false, true},
+ (EntityEntry){"Medical Trash", initMedicalTrash, updateMedicalTrash, NULL,
+ NULL, false, true},
+ (EntityEntry){"John", initJohn, updateJohn, NULL, NULL, false, true},
+ (EntityEntry){"Ron", initRon, updateRon, NULL, NULL, false, true}
};
Entity createEntity(EntityId id, Vector3 position)
@@ -43,8 +48,6 @@ Entity createEntity(EntityId id, Vector3 position)
void updateEntity(Entity* entity, Game* game)
{
- //DrawBoundingBox(entity->box, BLUE);
-
if (entity->id == ENTITY_NONE)
{
return;
@@ -76,6 +79,16 @@ void closeEntity(Entity* entity)
entity->id = ENTITY_NONE;
}
+const char* getEntityName(EntityId id)
+{
+ if (id == ENTITY_NONE)
+ {
+ return NULL;
+ }
+
+ return entityEntries[id].name;
+}
+
void setEntityPosition(Entity* entity, Vector3 position)
{
Vector3 movedBy = Vector3Subtract(position, entity->position);
diff --git a/src/entity.h b/src/entity.h
index 3a707c9..a71b5ff 100644
--- a/src/entity.h
+++ b/src/entity.h
@@ -7,6 +7,8 @@
#define ENTITY_COUNT 14
+#define ENTITY_NAME_MAX 16
+
#define INTERACTION_MENU_MAX 9
#define INTERACTION_LABEL_MAX 6
#define INTERACTION_CHAT_MAX 256
@@ -53,7 +55,7 @@ enum Selection {
SELECTION_INTERACT,
SELECTION_NEXT_MESSAGE,
SELECTION_MENU_ITEM, // +x to select any given menu entry
- SELECTION_LEAVE
+ SELECTION_LEAVE = SELECTION_MENU_ITEM + 16
};
struct Entity {
@@ -65,6 +67,7 @@ struct Entity {
};
typedef struct {
+ char name[ENTITY_NAME_MAX];
InitEntityCallback initCallback;
UpdateEntityCallback updateCallback;
CloseEntityCallback closeCallback;
@@ -81,6 +84,8 @@ Entity createEntity(EntityId id, Vector3 position);
void updateEntity(Entity* entity, Game* game);
void closeEntity(Entity* entity);
+const char* getEntityName(EntityId id);
+
void setEntityPosition(Entity* entity, Vector3 position);
void placeEntityOnGround(Entity* entity, const World* world);
diff --git a/src/game.c b/src/game.c
index a6ed57a..d8823d2 100644
--- a/src/game.c
+++ b/src/game.c
@@ -86,7 +86,7 @@ void initGame(Game* game)
initMap(&game->map, &game->world, &game->settings);
// Interaction chat.
- initInteractionChat(&game->chat);
+ initInteractionChat(&game->chat, &game->settings);
disableGameCursor(game);
}
diff --git a/src/player.c b/src/player.c
index 2d9ec62..715d5ed 100644
--- a/src/player.c
+++ b/src/player.c
@@ -14,7 +14,8 @@ Player createPlayer()
.fovy = 90.0,
.projection = CAMERA_PERSPECTIVE
},
- .cameraAngle = Vector2Zero()
+ .cameraAngle = Vector2Zero(),
+ .interactingWith = ENTITY_NONE
};
}
@@ -100,27 +101,77 @@ bool playerCanEntityBeSelected(Player* player, Entity entity)
<= PLAYER_MAX_SELECT_DISTANCE;
}
-void playerInteractWithEntity(Player* player, Entity* entity, Game* game)
+void playerInteractWithEntity(Player* player, WorldUID uid, Game* game,
+ Selection selection)
{
- printf("%d\n", interactWithEntity(entity, game, SELECTION_INTERACT));
+ InteractionChat* chat = &game->chat;
+ Entity* entity = &game->world.entities[uid];
+ player->interactingWith = uid;
+
+ // Handle selection type.
+ switch (selection)
+ {
+ case SELECTION_INTERACT:
+ clearInteractionChat(chat);
+ chat->entityId = entity->id;
+ break;
+ case SELECTION_LEAVE:
+ player->interactingWith = ENTITY_NONE;
+ chat->entityId = ENTITY_NONE;
+ break;
+ default:
+ break;
+ }
+
+ // Interact with it.
+ switch (interactWithEntity(entity, game, selection))
+ {
+ case INTERACTION_TALK:
+ showInteractionChat(chat);
+ break;
+ case INTERACTION_END:
+ hideInteractionChat(chat);
+ player->interactingWith = ENTITY_NONE;
+ chat->entityId = ENTITY_NONE;
+ break;
+ default:
+ break;
+ }
}
-void playerUpdateSelectedEntity(Player* player, Entity* entity, Game* game)
+void playerUpdateSelectedEntity(Player* player, WorldUID uid, Game* game)
{
+ Entity* entity = &game->world.entities[uid];
+
if (!playerCanEntityBeSelected(player, *entity))
{
+ if (uid == player->interactingWith)
+ {
+ playerInteractWithEntity(player, uid, game, SELECTION_LEAVE);
+ }
+
return;
}
+
+ Color color = PINK;
+
+ if (uid == player->interactingWith)
+ {
+ color = YELLOW;
+ }
- DrawBoundingBox(entity->box, RED);
+ DrawBoundingBox(entity->box, color);
if (IsKeyPressed(game->settings.interactKey))
{
- playerInteractWithEntity(player, entity, game);
+ playerInteractWithEntity(player, uid, game, SELECTION_INTERACT);
+ }
+ else if (IsKeyPressed(game->settings.nextMessageKey))
+ {
+ playerInteractWithEntity(player, uid, game, SELECTION_NEXT_MESSAGE);
}
}
-// TODO: move magic numbers to settings
void updatePlayer(Player* player, Game* game)
{
updatePlayerMovement(player, game);
@@ -135,10 +186,17 @@ void updatePlayer(Player* player, Game* game)
DrawRay(ray, YELLOW);
}
- WorldUID uid = castRayAtWorld(&game->world, ray, false, NULL);
+ if (player->interactingWith == ENTITY_NONE)
+ {
+ WorldUID uid = castRayAtWorld(&game->world, ray, false, NULL);
- if (uid != -1)
+ if (uid != -1)
+ {
+ playerUpdateSelectedEntity(player, uid, game);
+ }
+ }
+ else
{
- playerUpdateSelectedEntity(player, &game->world.entities[uid], game);
+ playerUpdateSelectedEntity(player, player->interactingWith, game);
}
}
diff --git a/src/player.h b/src/player.h
index 71c9993..436f8d0 100644
--- a/src/player.h
+++ b/src/player.h
@@ -1,4 +1,5 @@
#include "utils.h"
+#include "world.h"
#ifndef PLAYER_H
#define PLAYER_H
@@ -14,6 +15,8 @@ typedef struct {
Camera camera;
Vector2 cameraAngle;
+
+ WorldUID interactingWith;
} Player;
Player createPlayer();
diff --git a/src/settings.c b/src/settings.c
index 5f7f823..4b713cd 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,
+ .interactionChatFontSize = 20,
+ .interactionChatHeight = 300.0,
.interactionChatAlpha = (unsigned char)255.0 * 0.9,
.mouseSpeed = 0.1,
.forwardKey = KEY_W,
@@ -37,6 +39,7 @@ Settings defaultSettings()
.toggleCrossHairKey = KEY_C,
.toggleMapPreviewKey = KEY_P,
.defaultMapZoomKey = KEY_Z,
- .interactKey = KEY_E
+ .interactKey = KEY_E,
+ .nextMessageKey = KEY_ENTER
};
}
diff --git a/src/settings.h b/src/settings.h
index 0782fbb..bfeaf50 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -45,6 +45,8 @@ typedef struct {
float mapZoomSpeed;
// Interaction chat.
+ int interactionChatFontSize;
+ float interactionChatHeight;
unsigned char interactionChatAlpha;
// Controls.
@@ -58,6 +60,7 @@ typedef struct {
KeyboardKey toggleMapPreviewKey;
KeyboardKey defaultMapZoomKey;
KeyboardKey interactKey;
+ KeyboardKey nextMessageKey;
} Settings;
Settings defaultSettings();
diff --git a/src/ui.c b/src/ui.c
index a250b01..ae9341f 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -2,13 +2,11 @@
#include "game.h"
#include "settings.h"
-// TODO: byebye magic numbers
-
-void resizeInteractionChat(InteractionChat* chat)
+void resizeInteractionChat(InteractionChat* chat, const Settings* settings)
{
float renderWidth = GetRenderWidth();
float renderHeight = GetRenderHeight();
- float height = 200.0;
+ float height = settings->interactionChatHeight;
chat->rect = (Rectangle){
0.0,
@@ -18,13 +16,13 @@ void resizeInteractionChat(InteractionChat* chat)
};
}
-void initInteractionChat(InteractionChat* chat)
+void initInteractionChat(InteractionChat* chat, const Settings* settings)
{
memset(&chat->text, 0, INTERACTION_CHAT_MAX * sizeof(char));
- chat->visible = true;
+ chat->visible = false;
+ chat->entityId = ENTITY_NONE;
- resizeInteractionChat(chat);
- writeToInteractionChat(chat, "test test test test test\ntest test test test test test test test");
+ resizeInteractionChat(chat, settings);
}
void showInteractionChat(InteractionChat* chat)
@@ -51,7 +49,7 @@ void updateInteractionChat(InteractionChat* chat, Game* game)
{
if (IsWindowResized())
{
- resizeInteractionChat(chat);
+ resizeInteractionChat(chat, &game->settings);
}
if (!chat->visible)
@@ -62,7 +60,31 @@ void updateInteractionChat(InteractionChat* chat, Game* game)
Color background = DARKGRAY;
background.a = game->settings.interactionChatAlpha;
DrawRectangleRec(chat->rect, background);
+
+ float lineThickness = 2.0;
+ float border = 3.0;
+ int fontSize = game->settings.interactionChatFontSize;
- DrawRectangleLinesEx(chat->rect, 2.0, BLACK);
- DrawText(chat->text, chat->rect.x + 3.0, chat->rect.y + 3.0, 20, GREEN);
+ DrawRectangleLinesEx(chat->rect, lineThickness, BLACK);
+
+ if (chat->entityId != ENTITY_NONE)
+ {
+ DrawText(TextFormat("%s says:", getEntityName(chat->entityId)),
+ chat->rect.x + border,
+ chat->rect.y + border,
+ fontSize,
+ WHITE);
+ }
+
+ DrawText(chat->text,
+ chat->rect.x + border,
+ chat->rect.y + (border * 2.0) + fontSize,
+ fontSize,
+ GREEN);
+
+ DrawText("Hit enter to continue...",
+ chat->rect.x + border,
+ chat->rect.y + chat->rect.height - fontSize - border,
+ fontSize,
+ WHITE);
}
diff --git a/src/ui.h b/src/ui.h
index 8de144f..3c3ab47 100644
--- a/src/ui.h
+++ b/src/ui.h
@@ -11,9 +11,10 @@ typedef struct {
char text[INTERACTION_CHAT_MAX];
Rectangle rect;
bool visible;
+ EntityId entityId;
} InteractionChat;
-void initInteractionChat(InteractionChat* chat);
+void initInteractionChat(InteractionChat* chat, const Settings* settings);
void showInteractionChat(InteractionChat* chat);
void hideInteractionChat(InteractionChat* chat);
void writeToInteractionChat(InteractionChat* chat, const char* text);