aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornathan <nathansmith@disroot.org>2025-07-27 10:29:07 +0000
committernathan <nathansmith@disroot.org>2025-07-27 10:29:07 +0000
commit49a0487a9c02a4bcd9da965400e393820ba6372f (patch)
tree877fc60f249119704b60800e2b3d94895ee5a9f6
parent68a46c5d8e92218622c93bd3b5356c25c079fef4 (diff)
downloadFindThings-49a0487a9c02a4bcd9da965400e393820ba6372f.tar.gz
FindThings-49a0487a9c02a4bcd9da965400e393820ba6372f.tar.bz2
FindThings-49a0487a9c02a4bcd9da965400e393820ba6372f.zip
Bush
-rw-r--r--assets/bush.pngbin0 -> 46102 bytes
-rw-r--r--design.org3
-rw-r--r--src/assets.c3
-rw-r--r--src/assets.h5
-rw-r--r--src/entity.c55
-rw-r--r--src/entity.h11
-rw-r--r--src/player.c28
-rw-r--r--src/utils.h2
-rw-r--r--src/world.c38
-rw-r--r--src/world.h6
10 files changed, 94 insertions, 57 deletions
diff --git a/assets/bush.png b/assets/bush.png
new file mode 100644
index 0000000..07256a4
--- /dev/null
+++ b/assets/bush.png
Binary files differ
diff --git a/design.org b/design.org
index 293018e..1cf2a9e 100644
--- a/design.org
+++ b/design.org
@@ -94,10 +94,11 @@ creates is possible to beat. A little wack is fine as long as its
beatable. Since most of the world will just be a height map a image will be
generated first than rest of the world will be based around it.
-* TODO World generation check list [2/7]
+* TODO World generation check list [2/8]
+ [X] Basic terrain
+ [X] Ground texture
+ [ ] Trees/plants
++ [ ] Sky
+ [ ] Pond
+ [ ] Power lines
+ [ ] Buildings
diff --git a/src/assets.c b/src/assets.c
index 6f2ac0c..1a7113a 100644
--- a/src/assets.c
+++ b/src/assets.c
@@ -3,7 +3,8 @@
const char textureAssetPaths[TEXTURE_ASSET_COUNT][FT_NAMEMAX] = {
"mint.png",
"nickel.png",
- "tree.png"
+ "tree.png",
+ "bush.png"
};
void initAssets(Assets* assets)
diff --git a/src/assets.h b/src/assets.h
index 88345b1..f5ef97f 100644
--- a/src/assets.h
+++ b/src/assets.h
@@ -3,7 +3,7 @@
#ifndef ASSETS_H
#define ASSETS_H
-#define TEXTURE_ASSET_COUNT 3
+#define TEXTURE_ASSET_COUNT 4
extern const char textureAssetPaths[TEXTURE_ASSET_COUNT][FT_NAMEMAX];
@@ -13,7 +13,8 @@ typedef int8_t AssetId;
enum {
MINT_TEXTURE,
NICKEL_TEXTURE,
- TREE_TEXTURE
+ TREE_TEXTURE,
+ BUSH_TEXTURE
};
typedef struct {
diff --git a/src/entity.c b/src/entity.c
index 23844bf..de5f7f3 100644
--- a/src/entity.c
+++ b/src/entity.c
@@ -1,6 +1,17 @@
#include "entity.h"
#include "game.h"
+BoundingBox entityBoxFromScale(float scale, float width, float height)
+{
+ Vector2 size = (Vector2){width / height * scale, scale};
+ size = Vector2Scale(size, 0.5);
+
+ return (BoundingBox){
+ .min = (Vector3){-size.x, -size.y, -size.x},
+ .max = (Vector3){size.x, size.y, size.x}
+ };
+}
+
// TODO: Entity creation system
Entity createEntity(EntityId id, Vector3 position)
{
@@ -11,29 +22,19 @@ Entity createEntity(EntityId id, Vector3 position)
{
case OLD_MINT:
case STICKY_NICKEL:
- entity.box = (BoundingBox){
- .min = (Vector3){-0.4, -0.4, -0.4},
- .max = (Vector3){0.4, 0.4, 0.4}
- };
-
+ entity.box = entityBoxFromScale(1.0, 32.0, 32.0);
break;
case TREE:
-
- {
- Vector2 size = (Vector2){225.0 / 500.0 * TREE_SCALE, TREE_SCALE};
- size = Vector2Scale(size, 0.5);
-
- entity.box = (BoundingBox){
- .min = (Vector3){-size.x, -size.y, -size.x},
- .max = (Vector3){size.x, size.y, size.x}
- };
- }
-
+ entity.box = entityBoxFromScale(TREE_SCALE, 225.0, 500.0);
+ break;
+ case BUSH:
+ entity.box = entityBoxFromScale(BUSH_SCALE, 174.0, 124.0);
break;
default:
break;
}
-
+
+ entity.position = Vector3Zero();
setEntityPosition(&entity, position);
return entity;
}
@@ -54,6 +55,10 @@ void updateEntity(Entity* entity, Game* game)
DrawBillboard(game->player.camera, game->assets.textures[TREE_TEXTURE],
entity->position, TREE_SCALE, WHITE);
break;
+ case BUSH:
+ DrawBillboard(game->player.camera, game->assets.textures[BUSH_TEXTURE],
+ entity->position, BUSH_SCALE, WHITE);
+ break;
default:
break;
}
@@ -61,7 +66,19 @@ void updateEntity(Entity* entity, Game* game)
void setEntityPosition(Entity* entity, Vector3 position)
{
+ Vector3 movedBy = Vector3Subtract(position, entity->position);
entity->position = position;
- entity->box.min = Vector3Add(entity->box.min, position);
- entity->box.max = Vector3Add(entity->box.max, position);
+ entity->box.min = Vector3Add(entity->box.min, movedBy);
+ entity->box.max = Vector3Add(entity->box.max, movedBy);
+}
+
+void placeEntityOnGround(Entity* entity, const World* world)
+{
+ Vector3 position = entity->position;
+
+ position.y = getWorldHeightAtLocation(
+ world, entity->position.x, entity->position.z);
+ position.y += (entity->box.max.y - entity->box.min.y) / 2.0;
+
+ setEntityPosition(entity, position);
}
diff --git a/src/entity.h b/src/entity.h
index 38f4092..915c562 100644
--- a/src/entity.h
+++ b/src/entity.h
@@ -7,26 +7,29 @@
typedef int8_t EntityId;
-#define ENTITY_COUNT 3
+#define ENTITY_COUNT 4
-// Constants for entities.
+// Entity scales.
#define TREE_SCALE 32.0
+#define BUSH_SCALE 6.0
enum {
ENTITY_NONE = -1,
OLD_MINT,
STICKY_NICKEL,
- TREE
+ TREE,
+ BUSH
};
typedef struct {
EntityId id;
- Vector3 position;
+ Vector3 position; // Shouldnt be accessed directly.
BoundingBox box;
} Entity;
Entity createEntity(EntityId id, Vector3 position);
void updateEntity(Entity* entity, Game* game);
void setEntityPosition(Entity* entity, Vector3 position);
+void placeEntityOnGround(Entity* entity, const World* world);
#endif
diff --git a/src/player.c b/src/player.c
index fbf404d..f32d8bb 100644
--- a/src/player.c
+++ b/src/player.c
@@ -83,22 +83,22 @@ void updatePlayer(Player* player, Game* game)
camera->position = player->position;
camera->target = Vector3Add(player->position, player->direction);
-/* #ifdef FT_DEBUG_MODE */
-/* Ray ray = (Ray){ */
-/* .position = player->position, */
-/* .direction = player->direction */
-/* }; */
+#ifdef FT_DEBUG_MODE
+ Ray ray = (Ray){
+ .position = player->position,
+ .direction = player->direction
+ };
-/* DrawRay(ray, YELLOW); */
+ DrawRay(ray, YELLOW);
-/* int tests; */
-/* WorldUID uid = castRayAtWorld(&game->world, ray, &tests); */
+ int tests;
+ WorldUID uid = castRayAtWorld(&game->world, ray, &tests);
-/* printf("%d\n", tests); */
+ //printf("%d\n", tests);
-/* if (uid != -1) */
-/* { */
-/* DrawBoundingBox(game->world.entities[uid].box, RED); */
-/* } */
-/* #endif */
+ if (uid != -1)
+ {
+ DrawBoundingBox(game->world.entities[uid].box, RED);
+ }
+#endif
}
diff --git a/src/utils.h b/src/utils.h
index 1c78b45..08239b8 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -29,7 +29,9 @@
#define ALLOCATION_ERROR TraceLog(LOG_ERROR, "Allocation error in %s:%d", \
__FILE__, __LINE__)
+// Typedef hackery.
typedef struct Game Game;
+typedef struct World World;
typedef enum FTError {
FTERROR = -1,
diff --git a/src/world.c b/src/world.c
index 38ae7af..a576e24 100644
--- a/src/world.c
+++ b/src/world.c
@@ -328,17 +328,26 @@ void buildWorldBVH(World* world)
world->bvhDebugSelect = 0;
}
-Seed generateWorldTrees(World* world, Seed seed)
+Seed generateWorldPlants(World* world, Seed seed)
{
- for (int index = 0; index < WORLD_TREE_COUNT; ++index)
+ for (int index = 0; index < WORLD_PLANT_COUNT; ++index)
{
+ FT_RANDOM16(seed);
+
+ // Get id for plant.
+ EntityId plants[] = {TREE, BUSH};
+ size_t plantsSize = 2;
+ EntityId id = plants[seed % plantsSize];
+
+ // Get position.
Vector3 position;
position.x = FT_RANDOM16(seed) % (int)world->size.x;
+ position.y = 0.0;
position.z = FT_RANDOM16(seed) % (int)world->size.z;
- position.y = getWorldHeightAtLocation(
- world,
- position.x, position.z) + (TREE_SCALE / 2.0);
- Entity entity = createEntity(TREE, position);
+
+ // Create entity.
+ Entity entity = createEntity(id, position);
+ placeEntityOnGround(&entity, world);
world->entities[index] = entity;
}
@@ -348,18 +357,21 @@ Seed generateWorldTrees(World* world, Seed seed)
Seed generateWorldItems(World* world, Seed seed)
{
- for (int index = WORLD_TREE_COUNT; index < WORLD_ENTITY_MAX; ++index)
+ for (int index = WORLD_PLANT_COUNT; index < WORLD_ENTITY_MAX; ++index)
{
FT_RANDOM16(seed);
+ EntityId items[] = {OLD_MINT, STICKY_NICKEL};
+ size_t itemsSize = 2;
+ EntityId id = items[seed % itemsSize];
+
Vector3 position;
position.x = FT_RANDOM16(seed) % (int)world->size.x;
+ position.y = 0.0;
position.z = FT_RANDOM16(seed) % (int)world->size.z;
- position.y = getWorldHeightAtLocation(world,
- position.x, position.z) + 1.0;
- EntityId items[] = {OLD_MINT, STICKY_NICKEL};
- size_t itemsSize = 2;
- Entity entity = createEntity(items[seed % itemsSize], position);
+
+ Entity entity = createEntity(id, position);
+ placeEntityOnGround(&entity, world);
world->entities[index] = entity;
}
@@ -391,7 +403,7 @@ World createWorld(Seed seed)
UnloadImage(image);
- seed = generateWorldTrees(&world, seed);
+ seed = generateWorldPlants(&world, seed);
seed = generateWorldItems(&world, seed);
double currentTime = GetTime();
diff --git a/src/world.h b/src/world.h
index 0a90ec4..606ae46 100644
--- a/src/world.h
+++ b/src/world.h
@@ -14,7 +14,7 @@
#define WORLD_IMAGE_WIDTH 100
#define WORLD_IMAGE_HEIGHT 100
#define WORLD_IMAGE_SCALE 5.0
-#define WORLD_TREE_COUNT 500
+#define WORLD_PLANT_COUNT 500
#define WORLD_GROUND_COLOR GREEN
#define WORLD_GROUND_BLUR 4
@@ -31,7 +31,7 @@ typedef struct BVHNode {
int8_t branchCount;
} BVHNode;
-typedef struct {
+struct World {
Vector3 size;
Texture texture;
Model heightmap;
@@ -39,7 +39,7 @@ typedef struct {
BVHNode bvh;
int bvhDebugSelect;
-} World;
+};
World createWorld(Seed seed);
void updateWorld(World* world, Game* game);