aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornathan <nathansmith@disroot.org>2025-08-04 07:30:27 +0000
committernathan <nathansmith@disroot.org>2025-08-04 07:30:27 +0000
commit6c6b8982ca4f1b29ecd0fd37beb6238315e36f10 (patch)
tree1180d3a731bbe5fb2b4926a90dbdfdf0334595a3
parent5a689b3db1e84cc8a6aac337ec5d8544c7e9c40e (diff)
downloadFindThings-6c6b8982ca4f1b29ecd0fd37beb6238315e36f10.tar.gz
FindThings-6c6b8982ca4f1b29ecd0fd37beb6238315e36f10.tar.bz2
FindThings-6c6b8982ca4f1b29ecd0fd37beb6238315e36f10.zip
Even better pond (:
-rw-r--r--src/entity.c3
-rw-r--r--src/entity.h2
-rw-r--r--src/game.c2
-rw-r--r--src/world.c72
-rw-r--r--src/world.h4
5 files changed, 46 insertions, 37 deletions
diff --git a/src/entity.c b/src/entity.c
index 164d9f4..97af95e 100644
--- a/src/entity.c
+++ b/src/entity.c
@@ -74,9 +74,8 @@ void updateEntity(Entity* entity, Game* game)
entity->position, FLOWER_SCALE, WHITE);
break;
case POND:
- DrawBoundingBox(entity->box, YELLOW);
DrawPlane(
- Vector3Add(entity->position, (Vector3){0.0, POND_HEIGHT / 2.0, 0.0}),
+ Vector3Add(entity->position, (Vector3){0.0, POND_HEIGHT * 2.0, 0.0}),
(Vector2){POND_SIZE * 2.5, POND_SIZE * 2.5}, BLUE);
break;
default:
diff --git a/src/entity.h b/src/entity.h
index 2c5c51e..231304f 100644
--- a/src/entity.h
+++ b/src/entity.h
@@ -10,7 +10,7 @@
#define TREE_SCALE 40.0
#define BUSH_SCALE 8.0
#define FLOWER_SCALE 3.0
-#define POND_SIZE 100.0
+#define POND_SIZE 250.0
#define POND_HEIGHT 10.0
typedef int8_t EntityId;
diff --git a/src/game.c b/src/game.c
index fb88f7b..e4d74ff 100644
--- a/src/game.c
+++ b/src/game.c
@@ -30,7 +30,7 @@ void initGame(Game* game)
CUBEMAP_LAYOUT_AUTO_DETECT);
// World.
- game->world = createWorld(3458);
+ game->world = createWorld(345893);
// Player.
game->player = createPlayer();
diff --git a/src/world.c b/src/world.c
index 82d0d5a..8547eef 100644
--- a/src/world.c
+++ b/src/world.c
@@ -342,6 +342,41 @@ Vector3 getRandomPositionFromCenter(const World* world, Seed* seed,
return position;
}
+bool checkForPlaceOverlap(const World* world, BoundingBox box)
+{
+ for (int index = 0; index < WORLD_PLACE_COUNT; ++index)
+ {
+ if (CheckCollisionBoxes(world->entities[world->places[index]].box, box))
+ {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+// Ensures entity will not overlap with a place.
+Seed putEntityInRandomPlace(const World* world, Seed seed, Entity* entity)
+{
+ while (true)
+ {
+ Vector3 position;
+ position.x = FT_RANDOM16(seed) % (int)world->size.x;
+ position.y = 0.0;
+ position.z = FT_RANDOM16(seed) % (int)world->size.z;
+
+ setEntityPosition(entity, position);
+ placeEntityOnGround(entity, world);
+
+ if (!checkForPlaceOverlap(world, entity->box))
+ {
+ break;
+ }
+ }
+
+ return seed;
+}
+
Seed generateWorldPlants(World* world, Seed seed, int start, int end)
{
for (int index = start; index < end; ++index)
@@ -353,15 +388,9 @@ Seed generateWorldPlants(World* world, Seed seed, int start, int end)
size_t plantsSize = 3;
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;
-
// Create entity.
- Entity entity = createEntity(id, position);
- placeEntityOnGround(&entity, world);
+ Entity entity = createEntity(id, Vector3Zero());
+ seed = putEntityInRandomPlace(world, seed, &entity);
world->entities[index] = entity;
}
@@ -379,13 +408,8 @@ Seed generateWorldItems(World* world, Seed seed, int start, int end)
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;
-
- Entity entity = createEntity(id, position);
- placeEntityOnGround(&entity, world);
+ Entity entity = createEntity(id, Vector3Zero());
+ seed = putEntityInRandomPlace(world, seed, &entity);
world->entities[index] = entity;
}
@@ -393,21 +417,6 @@ Seed generateWorldItems(World* world, Seed seed, int start, int end)
return seed;
}
-bool isValidPlaceForItem(const World* world, BoundingBox box)
-{
- for (int index = 0; index < WORLD_PLACE_COUNT; ++index)
- {
- if (CheckCollisionBoxes(world->entities[world->places[index]].box, box))
- {
- return false;
- }
- }
-
- return true;
-}
-
-//Vector2 generateRandomItemPosition(const World* world,
-
Seed generatePond(World* world, Color* heightmap, WorldUID id, Seed seed)
{
// Create pond entity.
@@ -440,7 +449,7 @@ Seed generatePond(World* world, Color* heightmap, WorldUID id, Seed seed)
// Set new height.
int area = PLACE_POND_OUTER_AREA;
- int edge = PLACE_POND_DEPTH * (world->size.y / 255.0 * 2.0) / 2.0 + height;
+ int edge = PLACE_POND_DEPTH * (world->size.y / 255.0 * 2.0) / 4.0 + height;
for (int y = start.y - area; y < end.y + area; ++y)
{
@@ -513,6 +522,7 @@ World createWorld(Seed seed)
// Places.
WorldUID placeId = 0;
seed = generatePond(&world, colors, placeId, seed);
+ world.places[0] = placeId;
// Heightmap model.
image = (Image){
diff --git a/src/world.h b/src/world.h
index a837dae..8135a57 100644
--- a/src/world.h
+++ b/src/world.h
@@ -5,8 +5,8 @@
#ifndef WORLD_H
#define WORLD_H
-#define WORLD_ENTITY_MAX 3000
-#define WORLD_PLANT_COUNT 1000
+#define WORLD_ENTITY_MAX 4500
+#define WORLD_PLANT_COUNT 2500
#define WORLD_PLACE_COUNT 1
#define WORLD_SIZE (Vector3){4096.0, 256.0, 4096.0}