aboutsummaryrefslogtreecommitdiffstats
path: root/src/world.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/world.c')
-rw-r--r--src/world.c38
1 files changed, 25 insertions, 13 deletions
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();