aboutsummaryrefslogtreecommitdiffstats
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
parent0180e40326f67ef465e1d865a0aed21162e0f5c5 (diff)
downloadFindThings-75338c84cca4f0dad1fb1d79f0db42922a3ea6b5.tar.gz
FindThings-75338c84cca4f0dad1fb1d79f0db42922a3ea6b5.tar.bz2
FindThings-75338c84cca4f0dad1fb1d79f0db42922a3ea6b5.zip
Better place at thingy
-rw-r--r--src/entity.c19
-rw-r--r--src/entity.h2
-rw-r--r--src/player.c45
3 files changed, 55 insertions, 11 deletions
diff --git a/src/entity.c b/src/entity.c
index f094f8d..c295289 100644
--- a/src/entity.c
+++ b/src/entity.c
@@ -61,7 +61,8 @@ const EntityEntry entityEntries[ENTITY_COUNT] = {
.interactionCallback = NULL,
.isPlace = true,
.isBuilding = false,
- .canBeSelected = true
+ .canBeSelected = true,
+ .placeAreaSize = 420.0 // ROFL
},
(EntityEntry){
.name = "Utility Pole",
@@ -91,7 +92,8 @@ const EntityEntry entityEntries[ENTITY_COUNT] = {
.interactionCallback = NULL,
.isPlace = true,
.isBuilding = false,
- .canBeSelected = false
+ .canBeSelected = false,
+ .placeAreaSize = 20.0
},
(EntityEntry){
.name = "Trashcan",
@@ -141,7 +143,8 @@ const EntityEntry entityEntries[ENTITY_COUNT] = {
.interactionCallback = NULL,
.isPlace = true,
.isBuilding = true,
- .canBeSelected = false
+ .canBeSelected = false,
+ .placeAreaSize = 35.0
},
(EntityEntry){
.name = "Ron",
@@ -279,6 +282,16 @@ bool entityCanBeSelected(EntityId id)
return entityEntries[id].canBeSelected;
}
+float getEntityPlaceAreaSize(EntityId id)
+{
+ if (id == ENTITY_NONE)
+ {
+ return 0.0;
+ }
+
+ return entityEntries[id].placeAreaSize;
+}
+
float getEntityDistance(Entity entity, Vector3 position)
{
return Vector3Distance(entity.position, position)
diff --git a/src/entity.h b/src/entity.h
index 8cfcad6..d0e9f9f 100644
--- a/src/entity.h
+++ b/src/entity.h
@@ -91,6 +91,7 @@ typedef struct {
bool isPlace;
bool isBuilding;
bool canBeSelected;
+ float placeAreaSize; // If <= 0.0 use collision instead.
} EntityEntry;
// Am I still insane if I am aware of my insanity?
@@ -109,6 +110,7 @@ void placeEntityOnGround(Entity* entity, const World* world);
bool entityIsPlace(EntityId id);
bool entityIsBuilding(EntityId id);
bool entityCanBeSelected(EntityId id);
+float getEntityPlaceAreaSize(EntityId id);
float getEntityDistance(Entity entity, Vector3 position);
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);