aboutsummaryrefslogtreecommitdiffstats
path: root/src/player.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/player.c')
-rw-r--r--src/player.c26
1 files changed, 19 insertions, 7 deletions
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]);
+ }
}
}