aboutsummaryrefslogtreecommitdiffstats
path: root/src/world.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/world.c')
-rw-r--r--src/world.c32
1 files changed, 24 insertions, 8 deletions
diff --git a/src/world.c b/src/world.c
index 5db0130..87ca0d4 100644
--- a/src/world.c
+++ b/src/world.c
@@ -328,6 +328,20 @@ void buildWorldBVH(World* world)
world->bvhDebugSelect = 0;
}
+// Doesnt set y to a useful value.
+Vector3 getRandomPositionFromCenter(const World* world, Seed* seed,
+ float min, float max)
+{
+ Vector3 position = Vector3Scale(world->size, 0.5);
+ Vector2 direction = randomDirection2(*seed, seed);
+ float distance = Wrap(FT_RANDOM16(*seed), min, max);
+ direction = Vector2Scale(direction, distance);
+ position.x += direction.x;
+ position.z += direction.y;
+
+ return position;
+}
+
Seed generateWorldPlants(World* world, Seed seed, int start, int end)
{
for (int index = start; index < end; ++index)
@@ -381,14 +395,10 @@ Seed generateWorldItems(World* world, Seed seed, int start, int end)
Seed generatePond(World* world, Color* heightmap, WorldUID id, Seed seed)
{
- // Get position.
- int distanceRange = PLACE_POND_MAX_DISTANCE * 2;
- Vector3 position = Vector3Scale(world->size, 0.5);
- position.x += FT_RANDOM16(seed) % distanceRange - PLACE_POND_MAX_DISTANCE;
- position.z += FT_RANDOM16(seed) % distanceRange - PLACE_POND_MAX_DISTANCE;
-
+ Vector3 position = getRandomPositionFromCenter(world, &seed,
+ PLACE_POND_MIN_DISTANCE,
+ PLACE_POND_MAX_DISTANCE);
Entity pond = createEntity(POND, position);
- placeEntityOnGround(&pond, world);
world->entities[id] = pond;
return seed;
@@ -429,7 +439,7 @@ World createWorld(Seed seed)
image = (Image){
.data = colors,
.width = WORLD_IMAGE_WIDTH,
- .height = WORLD_IMAGE_WIDTH,
+ .height = WORLD_IMAGE_HEIGHT,
.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8,
.mipmaps = 1
};
@@ -439,6 +449,12 @@ World createWorld(Seed seed)
world.heightmapTexture = LoadTextureFromImage(image);
UnloadImage(image);
+ // Put places on ground.
+ for (int index = 0; index < WORLD_PLACE_COUNT; ++index)
+ {
+ placeEntityOnGround(&world.entities[index], &world);
+ }
+
// Model texture.
world.heightmap.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture =
generateGroundTexture();