aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornathan <nathansmith@disroot.org>2025-10-24 10:24:35 +0000
committernathan <nathansmith@disroot.org>2025-10-24 10:24:35 +0000
commit8874e4a585d66c16299ad45e79ea6c55960dee02 (patch)
tree728de2a02a5b61e0ecb57d35f653c7f280a97e0d
parent5f402fc99a19d7d73ba75f632aed5cbef7e3920a (diff)
downloadFindThings-8874e4a585d66c16299ad45e79ea6c55960dee02.tar.gz
FindThings-8874e4a585d66c16299ad45e79ea6c55960dee02.tar.bz2
FindThings-8874e4a585d66c16299ad45e79ea6c55960dee02.zip
Working on interaction system (finally)
-rw-r--r--src/entity.c30
-rw-r--r--src/entity.h29
2 files changed, 59 insertions, 0 deletions
diff --git a/src/entity.c b/src/entity.c
index 919da95..70a7db5 100644
--- a/src/entity.c
+++ b/src/entity.c
@@ -16,6 +16,7 @@ Entity createEntity(EntityId id, Vector3 position)
{
Entity entity;
entity.id = id;
+ entity.state = ENTITY_DEFAULT_STATE;
// Bounding boxes.
switch (id)
@@ -213,3 +214,32 @@ void placeEntityOnGround(Entity* entity, const World* world)
setEntityPosition(entity, position);
}
+
+
+InteractionCommand interactWithOldMint(Entity* entity, Game* game,
+ Selection selection)
+{
+ if (selection == SELECTION_INTERACT)
+ {
+ // Run display message code.
+ return INTERACTION_TALK;
+ }
+ else
+ {
+ return INTERACTION_END;
+ }
+}
+
+InteractionCommand interactWithEntity(Entity* entity, Game* game,
+ Selection selection)
+{
+ switch (entity->id)
+ {
+ case OLD_MINT: // For testing.
+ return interactWithOldMint(entity, game, selection);
+ default:
+ break;
+ }
+
+ return INTERACTION_END;
+}
diff --git a/src/entity.h b/src/entity.h
index 9c842d3..72fadb4 100644
--- a/src/entity.h
+++ b/src/entity.h
@@ -40,7 +40,12 @@
#define SHOPKEEPER_HEIGHT (2.59521 / 2.0)
#define SHOPKEEPER_THICKNESS (0.493349 / 2.0)
+#define INTERACTION_MENU_MAX 9
+#define INTERACTION_LABEL_MAX 64
+#define ENTITY_DEFAULT_STATE -1
+
typedef int8_t EntityId;
+typedef int8_t EntityState;
enum {
ENTITY_NONE = -1,
@@ -60,15 +65,39 @@ enum {
RON
};
+typedef enum {
+ INTERACTION_TALK,
+ INTERACTION_SHOW_MENU,
+ INTERACTION_END
+} InteractionCommand;
+
+typedef enum {
+ SELECTION_INTERACT,
+ SELECTION_NEXT_MESSAGE,
+ SELECTION_MENU_ITEM, // +x to select any given menu entry
+ SELECTION_LEAVE
+} Selection;
+
typedef struct {
EntityId id;
Vector3 position; // Shouldnt be changed directly.
BoundingBox box;
+ EntityState state;
} Entity;
+typedef void (*InteractionCallback)(Entity* entity, Game* game);
+
+typedef struct {
+ char label[INTERACTION_LABEL_MAX];
+ InteractionCallback callback;
+} InteractionMenuEntry;
+
Entity createEntity(EntityId id, Vector3 position);
void updateEntity(Entity* entity, Game* game);
void setEntityPosition(Entity* entity, Vector3 position);
void placeEntityOnGround(Entity* entity, const World* world);
+InteractionCommand interactWithEntity(Entity* entity, Game* game,
+ Selection selection);
+
#endif