aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authornathan <nathansmith@disroot.org>2025-10-27 12:58:37 +0000
committernathan <nathansmith@disroot.org>2025-10-27 12:58:37 +0000
commit95af9c76abef62466dc99cd48fe60d5c8c0677aa (patch)
tree016e9b8ca2681603512980bb32b571db6b530e10 /src
parent5925230971875ba3e6e591f0655cf84b739b50fc (diff)
downloadFindThings-95af9c76abef62466dc99cd48fe60d5c8c0677aa.tar.gz
FindThings-95af9c76abef62466dc99cd48fe60d5c8c0677aa.tar.bz2
FindThings-95af9c76abef62466dc99cd48fe60d5c8c0677aa.zip
Working on interaction stuff
Diffstat (limited to 'src')
-rw-r--r--src/entities/samantha.c7
-rw-r--r--src/entities/samantha.h2
-rw-r--r--src/entity.c69
-rw-r--r--src/entity.h22
-rw-r--r--src/player.c26
-rw-r--r--src/settings.c3
-rw-r--r--src/settings.h1
7 files changed, 81 insertions, 49 deletions
diff --git a/src/entities/samantha.c b/src/entities/samantha.c
index a78b075..c8f08f6 100644
--- a/src/entities/samantha.c
+++ b/src/entities/samantha.c
@@ -19,3 +19,10 @@ void updateSamantha(Entity* entity, Game* game)
DrawModel(game->assets.models[SAMANTHA_MODEL], entity->position, 1.0, WHITE);
}
+
+InteractionCommand interactWithSamantha(Entity* entity, Game* game,
+ Selection selection)
+{
+ puts("test test");
+ return INTERACTION_TALK;
+}
diff --git a/src/entities/samantha.h b/src/entities/samantha.h
index 360c9f0..57587ff 100644
--- a/src/entities/samantha.h
+++ b/src/entities/samantha.h
@@ -12,5 +12,7 @@
void initSamantha(Entity* entity);
void updateSamantha(Entity* entity, Game* game);
+InteractionCommand interactWithSamantha(Entity* entity, Game* game,
+ Selection selection);
#endif
diff --git a/src/entity.c b/src/entity.c
index aff0295..2242878 100644
--- a/src/entity.c
+++ b/src/entity.c
@@ -3,20 +3,22 @@
#include "entitiesInclude.h"
const EntityEntry entityEntries[ENTITY_COUNT] = {
- (EntityEntry){initOldMint, updateOldMint, NULL, false, true},
- (EntityEntry){initStickyNickel, updateStickyNickel, NULL, false, true},
- (EntityEntry){initTree, updateTree, NULL, false, true},
- (EntityEntry){initBush, updateBush, NULL, false, true},
- (EntityEntry){initFlower, updateFlower, NULL, false, true},
- (EntityEntry){initPond, updatePond, NULL, true, true},
- (EntityEntry){initUtilityPole, NULL, NULL, false, false},
- (EntityEntry){initSamantha, updateSamantha, NULL, false, true},
- (EntityEntry){initSamanthasSpot, updateSamanthasSpot, NULL, true, false},
- (EntityEntry){initTrashcan, updateTrashcan, NULL, false, true},
- (EntityEntry){initTrash, updateTrash, NULL, false, true},
- (EntityEntry){initMedicalTrash, updateMedicalTrash, NULL, false, true},
- (EntityEntry){initJohn, updateJohn, NULL, false, true},
- (EntityEntry){initRon, updateRon, NULL, false, true}
+ (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,
+ 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}
};
Entity createEntity(EntityId id, Vector3 position)
@@ -43,6 +45,11 @@ void updateEntity(Entity* entity, Game* game)
{
//DrawBoundingBox(entity->box, BLUE);
+ if (entity->id == ENTITY_NONE)
+ {
+ return;
+ }
+
UpdateEntityCallback updateCallback =
entityEntries[entity->id].updateCallback;
@@ -90,37 +97,37 @@ void placeEntityOnGround(Entity* entity, const World* world)
bool entityIsPlace(EntityId id)
{
+ if (id == ENTITY_NONE)
+ {
+ return false;
+ }
+
return entityEntries[id].isPlace;
}
bool entityCanBeSelected(EntityId id)
{
+ if (id == ENTITY_NONE)
+ {
+ return false;
+ }
+
return entityEntries[id].canBeSelected;
}
-InteractionCommand interactWithOldMint(Entity* entity, Game* game,
- Selection selection)
+InteractionCommand interactWithEntity(Entity* entity, Game* game,
+ Selection selection)
{
- if (selection == SELECTION_INTERACT)
- {
- // Run display message code.
- return INTERACTION_TALK;
- }
- else
+ if (entity->id == ENTITY_NONE)
{
return INTERACTION_END;
}
-}
+
+ InteractionCallback callback = entityEntries[entity->id].interactionCallback;
-InteractionCommand interactWithEntity(Entity* entity, Game* game,
- Selection selection)
-{
- switch (entity->id)
+ if (callback != NULL)
{
- case OLD_MINT: // For testing.
- return interactWithOldMint(entity, game, selection);
- default:
- break;
+ return callback(entity, game, selection);
}
return INTERACTION_END;
diff --git a/src/entity.h b/src/entity.h
index a394d7a..d791c51 100644
--- a/src/entity.h
+++ b/src/entity.h
@@ -13,9 +13,13 @@
typedef int8_t EntityId;
typedef int16_t EntityState;
+typedef enum InteractionCommand InteractionCommand;
+typedef enum Selection Selection;
typedef struct Entity Entity;
-typedef void (*InteractionCallback)(Entity* entity, Game* game);
+
+typedef InteractionCommand (*InteractionCallback)(Entity* entity, Game* game,
+ Selection selection);
typedef void (*InitEntityCallback)(Entity* entity);
typedef void (*UpdateEntityCallback)(Entity* entity, Game* game);
typedef void (*CloseEntityCallback)(Entity* entity);
@@ -38,18 +42,18 @@ enum {
RON
};
-typedef enum {
+enum InteractionCommand {
+ INTERACTION_END,
INTERACTION_TALK,
INTERACTION_SHOW_MENU,
- INTERACTION_END
-} InteractionCommand;
+};
-typedef enum {
+enum Selection {
SELECTION_INTERACT,
SELECTION_NEXT_MESSAGE,
SELECTION_MENU_ITEM, // +x to select any given menu entry
SELECTION_LEAVE
-} Selection;
+};
struct Entity {
EntityId id;
@@ -63,14 +67,12 @@ typedef struct {
InitEntityCallback initCallback;
UpdateEntityCallback updateCallback;
CloseEntityCallback closeCallback;
+ InteractionCallback interactionCallback;
bool isPlace;
bool canBeSelected;
} EntityEntry;
-typedef struct {
- char label[INTERACTION_LABEL_MAX];
- InteractionCallback callback;
-} InteractionMenuEntry;
+// Am I still insane if I am aware of my insanity?
extern const EntityEntry entityEntries[ENTITY_COUNT];
diff --git a/src/player.c b/src/player.c
index 4fe468e..f0928e9 100644
--- a/src/player.c
+++ b/src/player.c
@@ -26,8 +26,7 @@ void updatePlayerHeight(Player* player, Game* game)
player->position.y = height;
}
-// TODO: move magic numbers to settings
-void updatePlayer(Player* player, Game* game)
+void updatePlayerMovement(Player* player, Game* game)
{
Camera* camera = &player->camera;
Vector2* cameraAngle = &player->cameraAngle;
@@ -47,7 +46,7 @@ void updatePlayer(Player* player, Game* game)
(Vector3){-cameraAngle->y, cameraAngle->x, 0.0});
player->direction = (Vector3){matrix.m2, matrix.m6, matrix.m10};
- // Player movement.
+ // Walking around.
player->velocity = Vector3Zero();
if (IsKeyDown(settings->forwardKey))
@@ -82,6 +81,17 @@ void updatePlayer(Player* player, Game* game)
// Apply camera.
camera->position = player->position;
camera->target = Vector3Add(player->position, player->direction);
+}
+
+void playerInteractWithEntity(Player* player, Game* game, Entity* entity)
+{
+ printf("%d\n", interactWithEntity(entity, game, SELECTION_INTERACT));
+}
+
+// TODO: move magic numbers to settings
+void updatePlayer(Player* player, Game* game)
+{
+ updatePlayerMovement(player, game);
Ray ray = (Ray){
.position = player->position,
@@ -90,13 +100,15 @@ void updatePlayer(Player* player, Game* game)
DrawRay(ray, YELLOW);
- int tests;
- WorldUID uid = castRayAtWorld(&game->world, ray, false, &tests);
-
- //printf("%d\n", tests);
+ WorldUID uid = castRayAtWorld(&game->world, ray, false, NULL);
if (uid != -1)
{
DrawBoundingBox(game->world.entities[uid].box, RED);
+
+ if (IsKeyPressed(game->settings.interactKey))
+ {
+ playerInteractWithEntity(player, game, &game->world.entities[uid]);
+ }
}
}
diff --git a/src/settings.c b/src/settings.c
index b88ac83..5356ffc 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -18,6 +18,7 @@ Settings defaultSettings()
.backwardKey = KEY_S,
.rightKey = KEY_D,
.leftKey = KEY_A,
- .toggleCursorKey = KEY_LEFT_ALT
+ .toggleCursorKey = KEY_LEFT_ALT,
+ .interactKey = KEY_E
};
}
diff --git a/src/settings.h b/src/settings.h
index 68cdca7..c399fcc 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -31,6 +31,7 @@ typedef struct {
KeyboardKey rightKey;
KeyboardKey leftKey;
KeyboardKey toggleCursorKey;
+ KeyboardKey interactKey;
} Settings;
Settings defaultSettings();