diff options
| author | nathan <nathansmith@disroot.org> | 2025-12-29 12:42:08 +0000 |
|---|---|---|
| committer | nathan <nathansmith@disroot.org> | 2025-12-29 12:42:08 +0000 |
| commit | 91b1c45da05c892a04b6a1daa99b1de89fa1f363 (patch) | |
| tree | 5eeb0e8f7c5a4f0382b69780a4a14f69f971d9a2 | |
| parent | 8f2d85aa019f089b6946f3b9e0355ce59b12b67a (diff) | |
| download | FindThings-91b1c45da05c892a04b6a1daa99b1de89fa1f363.tar.gz FindThings-91b1c45da05c892a04b6a1daa99b1de89fa1f363.tar.bz2 FindThings-91b1c45da05c892a04b6a1daa99b1de89fa1f363.zip | |
working on building roofs
| -rw-r--r-- | src/entities/johnsStore.c | 3 | ||||
| -rw-r--r-- | src/entities/samanthasSpot.c | 8 | ||||
| -rw-r--r-- | src/entity.c | 24 | ||||
| -rw-r--r-- | src/entity.h | 10 | ||||
| -rw-r--r-- | src/utils.h | 1 |
5 files changed, 38 insertions, 8 deletions
diff --git a/src/entities/johnsStore.c b/src/entities/johnsStore.c index e3f4908..41217ed 100644 --- a/src/entities/johnsStore.c +++ b/src/entities/johnsStore.c @@ -27,8 +27,7 @@ void updateJohnsStore(Entity* entity, Game* game) building->model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = game->assets.textures[JOHNS_SHOP_TEXTURE]; DrawModel(building->model, entity->position, 1.0, WHITE); - - DrawBoundingBox(entity->box, RED); + drawBuildingRoof(building, entity->position, BROWN); } void closeJohnsStore(Entity* entity) diff --git a/src/entities/samanthasSpot.c b/src/entities/samanthasSpot.c index 0205e46..2022f37 100644 --- a/src/entities/samanthasSpot.c +++ b/src/entities/samanthasSpot.c @@ -13,7 +13,9 @@ void initSamanthasSpot(Entity* entity) void updateSamanthasSpot(Entity* entity, Game* game) { DrawModel(game->world.samanthasSpotFloor, - Vector3Add(entity->position, - (Vector3){0.0, -SAMANTHAS_SPOT_HEIGHT + 0.01, 0.0}), - 1.0, WHITE); + Vector3Add( + entity->position, + (Vector3){0.0, -SAMANTHAS_SPOT_HEIGHT + TOUCHING_OFFSET, 0.0}), + 1.0, + WHITE); } diff --git a/src/entity.c b/src/entity.c index fa3a414..1d10e4f 100644 --- a/src/entity.c +++ b/src/entity.c @@ -239,7 +239,7 @@ void placeEntityOnGround(Entity* entity, const World* world) if (entityIsBuilding(entity->id)) { - position.y += ENTITY_BUILDING_GROUND_OFFSET; + position.y += TOUCHING_OFFSET; } else { @@ -335,10 +335,22 @@ EntityBuilding* createEntityBuilding(Image heightmap) return NULL; } + float widthInWorld = heightmap.width * ENTITY_BUILDING_CUBE_SIZE.x; + float heightInWorld = heightmap.height * ENTITY_BUILDING_CUBE_SIZE.z; + *entityBuilding = (EntityBuilding){ .model = LoadModelFromMesh(GenMeshCubicmap(heightmap, ENTITY_BUILDING_CUBE_SIZE)), - .pixelMap = LoadImageColors(heightmap) + .pixelMap = LoadImageColors(heightmap), + .width = heightmap.width, + .height = heightmap.height, + .roofSize = (hypotf(widthInWorld, heightInWorld) + + ENTITY_BUILDING_CUBE_SIZE.x) / 2.0, + .roofHeight = BUILDING_DEFAULT_ROOF_HEIGHT, + .roofOffset = (Vector3){ + widthInWorld / 2.0 - ENTITY_BUILDING_CUBE_SIZE.x / 2.0, + ENTITY_BUILDING_CUBE_SIZE.y + TOUCHING_OFFSET, + heightInWorld / 2.0 - ENTITY_BUILDING_CUBE_SIZE.z / 2.0} }; return entityBuilding; @@ -353,3 +365,11 @@ void freeEntityBuilding(EntityBuilding* entityBuilding) FT_FREE(entityBuilding); } } + +void drawBuildingRoof(const EntityBuilding* building, Vector3 position, + Color color) +{ + DrawCylinder(Vector3Add(position, building->roofOffset), 1.0, + building->roofSize, building->roofHeight, BUILDING_ROOF_SLICES, + color); +} diff --git a/src/entity.h b/src/entity.h index 5f03e52..0469476 100644 --- a/src/entity.h +++ b/src/entity.h @@ -14,7 +14,8 @@ #define INTERACTION_CHAT_MAX 256 #define ENTITY_BUILDING_CUBE_SIZE (Vector3){4.0, 4.0, 4.0} -#define ENTITY_BUILDING_GROUND_OFFSET 0.03 +#define BUILDING_DEFAULT_ROOF_HEIGHT 10.0 +#define BUILDING_ROOF_SLICES 9 // Yes 9 (: typedef int8_t EntityId; typedef enum InteractionCommand InteractionCommand; @@ -74,6 +75,11 @@ struct Entity { typedef struct { Model model; Color* pixelMap; + float width; + float height; + float roofSize; + float roofHeight; + Vector3 roofOffset; } EntityBuilding; typedef struct { @@ -114,5 +120,7 @@ BoundingBox entityBoxFromScale(float scale, float width, float height); EntityBuilding* createEntityBuilding(Image heightmap); void freeEntityBuilding(EntityBuilding* entityBuilding); +void drawBuildingRoof(const EntityBuilding* building, Vector3 position, + Color color); #endif diff --git a/src/utils.h b/src/utils.h index cccec85..7b43dba 100644 --- a/src/utils.h +++ b/src/utils.h @@ -17,6 +17,7 @@ //#define FT_DEBUG_MODE #define FT_NAMEMAX 256 +#define TOUCHING_OFFSET 0.03 // Memory management. #define FT_MALLOC(size) malloc(size) |
