aboutsummaryrefslogtreecommitdiffstats
path: root/src/player.c
diff options
context:
space:
mode:
authornathan <nathansmith@disroot.org>2026-01-08 02:07:35 +0000
committernathan <nathansmith@disroot.org>2026-01-08 02:07:35 +0000
commit75338c84cca4f0dad1fb1d79f0db42922a3ea6b5 (patch)
tree7f9240685c7cf73388069f544e79e590bd6e0cb9 /src/player.c
parent0180e40326f67ef465e1d865a0aed21162e0f5c5 (diff)
downloadFindThings-75338c84cca4f0dad1fb1d79f0db42922a3ea6b5.tar.gz
FindThings-75338c84cca4f0dad1fb1d79f0db42922a3ea6b5.tar.bz2
FindThings-75338c84cca4f0dad1fb1d79f0db42922a3ea6b5.zip
Better place at thingy
Diffstat (limited to 'src/player.c')
-rw-r--r--src/player.c45
1 files changed, 37 insertions, 8 deletions
diff --git a/src/player.c b/src/player.c
index fd33524..ed3fd10 100644
--- a/src/player.c
+++ b/src/player.c
@@ -60,14 +60,15 @@ void updatePlayerLookingAround(Player* player, Game* game)
player->direction = (Vector3){matrix.m2, matrix.m6, matrix.m10};
}
-WorldUID playerCheckCollisionWithPlace(Player* player, Game* game)
+WorldUID playerCheckCollisionWithBuildings(Player* player, Game* game)
{
for (int index = 0; index < WORLD_PLACE_COUNT; ++index)
{
WorldUID uid = game->world.places[index];
Entity* place = &game->world.entities[uid];
- if (CheckCollisionBoxes(place->box, player->box))
+ if (entityIsBuilding(place->id)
+ && CheckCollisionBoxes(place->box, player->box))
{
return uid;
}
@@ -76,6 +77,33 @@ WorldUID playerCheckCollisionWithPlace(Player* player, Game* game)
return ENTITY_NONE;
}
+WorldUID findPlacePlayerIsAt(Player* player, Game* game)
+{
+ for (int index = 0; index < WORLD_PLACE_COUNT; ++index)
+ {
+ WorldUID uid = game->world.places[index];
+ Entity* place = &game->world.entities[uid];
+ float placeAreaSize = getEntityPlaceAreaSize(place->id);
+
+ if (placeAreaSize <= 0.0) // Collision based.
+ {
+ if (CheckCollisionBoxes(player->box, place->box))
+ {
+ return uid;
+ }
+ }
+ else // Area based.
+ {
+ if (Vector3Distance(player->position, place->position) <= placeAreaSize)
+ {
+ return uid;
+ }
+ }
+ }
+
+ return ENTITY_NONE;
+}
+
void playerHandleCollisionWithBuildingBlock(Player* player,
EntityBuilding* building,
BoundingBox block,
@@ -449,15 +477,16 @@ void updatePlayer(Player* player, Game* game)
updatePlayerMovement(player, game);
- WorldUID placeUID = playerCheckCollisionWithPlace(player, game);
- player->place = placeUID;
-
// Collision with buildings.
- if (placeUID != ENTITY_NONE &&
- entityIsBuilding(game->world.entities[placeUID].id))
+ WorldUID buildingUID = playerCheckCollisionWithBuildings(player, game);
+
+ if (buildingUID != ENTITY_NONE)
{
- playerHandleCollisionWithBuilding(player, game, placeUID);
+ playerHandleCollisionWithBuilding(player, game, buildingUID);
}
+
+ // Place player is at.
+ player->place = findPlacePlayerIsAt(player, game);
playerApplyVelocity(player);
updatePlayerHeight(player, game);