aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/entity.h2
-rw-r--r--src/game.c2
-rw-r--r--src/world.c38
-rw-r--r--src/world.h2
4 files changed, 42 insertions, 2 deletions
diff --git a/src/entity.h b/src/entity.h
index cd5659a..2c5c51e 100644
--- a/src/entity.h
+++ b/src/entity.h
@@ -27,7 +27,7 @@ enum {
typedef struct {
EntityId id;
- Vector3 position; // Shouldnt be accessed directly.
+ Vector3 position; // Shouldnt be changed accessed directly.
BoundingBox box;
} Entity;
diff --git a/src/game.c b/src/game.c
index 7f61ddb..aee498c 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(103489);
+ game->world = createWorld(1234);
// Player.
game->player = createPlayer();
diff --git a/src/world.c b/src/world.c
index 87ca0d4..7b9abe4 100644
--- a/src/world.c
+++ b/src/world.c
@@ -395,11 +395,41 @@ Seed generateWorldItems(World* world, Seed seed, int start, int end)
Seed generatePond(World* world, Color* heightmap, WorldUID id, Seed seed)
{
+ // Create pond entity.
Vector3 position = getRandomPositionFromCenter(world, &seed,
PLACE_POND_MIN_DISTANCE,
PLACE_POND_MAX_DISTANCE);
Entity pond = createEntity(POND, position);
world->entities[id] = pond;
+
+ // Get lowest height.
+ int height = 255;
+
+ Vector2 start = worldPositionToPixel(world, pond.box.min.x, pond.box.min.z);
+ Vector2 end = worldPositionToPixel(world, pond.box.max.x, pond.box.max.z);
+
+ for (int y = start.y; y < end.y; ++y)
+ {
+ for (int x = start.x; x < end.x; ++x)
+ {
+ int pixelHeight = heightmap[y * WORLD_IMAGE_WIDTH + x].r;
+
+ if (pixelHeight < height)
+ {
+ height = pixelHeight;
+ }
+ }
+ }
+
+ // Set new height.
+ for (int y = start.y; y < end.y; ++y)
+ {
+ for (int x = start.x; x < end.x; ++x)
+ {
+ heightmap[y * WORLD_IMAGE_WIDTH + x] =
+ (Color){height, height, height, 255};
+ }
+ }
return seed;
}
@@ -540,6 +570,14 @@ void freeWorld(World world)
freeWorldBVH(world.bvh);
}
+Vector2 worldPositionToPixel(const World* world, float x, float y)
+{
+ return (Vector2){
+ roundf((float)WORLD_IMAGE_WIDTH / world->size.x * x),
+ roundf((float)WORLD_IMAGE_HEIGHT / world->size.z * y)
+ };
+}
+
float getWorldHeightAtLocation(const World* world, float x, float y)
{
float mapX = (float)WORLD_IMAGE_WIDTH / world->size.x * x;
diff --git a/src/world.h b/src/world.h
index 6060b90..149e7dd 100644
--- a/src/world.h
+++ b/src/world.h
@@ -60,7 +60,9 @@ void updateWorld(World* world, Game* game);
void freeWorld(World world);
// Dam, I wanta live in a free world ):
+// When dealing with the world in 2d use y in place of z.
float getWorldHeightAtLocation(const World* world, float x, float y);
+Vector2 worldPositionToPixel(const World* world, float x, float y);
WorldUID castRayAtWorld(const World* world, Ray ray, int* tests);
#endif