diff options
author | nathan <nathansmith@disroot.org> | 2025-08-04 06:35:17 +0000 |
---|---|---|
committer | nathan <nathansmith@disroot.org> | 2025-08-04 06:35:17 +0000 |
commit | 5a689b3db1e84cc8a6aac337ec5d8544c7e9c40e (patch) | |
tree | cdd88dded10260b970c0946dde8d0f93f71b6516 | |
parent | 1163519c148d0cc7d885630995874af2747419d0 (diff) | |
download | FindThings-5a689b3db1e84cc8a6aac337ec5d8544c7e9c40e.tar.gz FindThings-5a689b3db1e84cc8a6aac337ec5d8544c7e9c40e.tar.bz2 FindThings-5a689b3db1e84cc8a6aac337ec5d8544c7e9c40e.zip |
Better area clearing for pond
-rw-r--r-- | src/entity.c | 3 | ||||
-rw-r--r-- | src/game.c | 2 | ||||
-rw-r--r-- | src/player.c | 2 | ||||
-rw-r--r-- | src/world.c | 57 | ||||
-rw-r--r-- | src/world.h | 3 |
5 files changed, 61 insertions, 6 deletions
diff --git a/src/entity.c b/src/entity.c index 8225e76..164d9f4 100644 --- a/src/entity.c +++ b/src/entity.c @@ -75,6 +75,9 @@ void updateEntity(Entity* entity, Game* game) break; case POND: DrawBoundingBox(entity->box, YELLOW); + DrawPlane( + Vector3Add(entity->position, (Vector3){0.0, POND_HEIGHT / 2.0, 0.0}), + (Vector2){POND_SIZE * 2.5, POND_SIZE * 2.5}, BLUE); break; default: break; @@ -30,7 +30,7 @@ void initGame(Game* game) CUBEMAP_LAYOUT_AUTO_DETECT); // World. - game->world = createWorld(1234); + game->world = createWorld(3458); // Player. game->player = createPlayer(); diff --git a/src/player.c b/src/player.c index eb1f55a..64bdce6 100644 --- a/src/player.c +++ b/src/player.c @@ -71,7 +71,7 @@ void updatePlayer(Player* player, Game* game) player->velocity.x += -sinf(cameraAngle->x + (PI / 2.0)); } - player->velocity = Vector3Scale(player->velocity, 20.0); + player->velocity = Vector3Scale(player->velocity, 60.0); // Apply velocity. player->position = Vector3Add( diff --git a/src/world.c b/src/world.c index 7b9abe4..82d0d5a 100644 --- a/src/world.c +++ b/src/world.c @@ -393,6 +393,21 @@ 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. @@ -421,13 +436,47 @@ Seed generatePond(World* world, Color* heightmap, WorldUID id, Seed seed) } } + height -= PLACE_POND_DEPTH * (world->size.y / 255.0 * 2.0); + // Set new height. - for (int y = start.y; y < end.y; ++y) + int area = PLACE_POND_OUTER_AREA; + int edge = PLACE_POND_DEPTH * (world->size.y / 255.0 * 2.0) / 2.0 + height; + + for (int y = start.y - area; y < end.y + area; ++y) { - for (int x = start.x; x < end.x; ++x) + for (int x = start.x - area; x < end.x + area; ++x) { - heightmap[y * WORLD_IMAGE_WIDTH + x] = - (Color){height, height, height, 255}; + if ((x == start.x || x == end.x || // Closest edge. + y == start.y || y == end.y) && + (x >= start.x && x <= end.x && + y >= start.y && y <= end.y)) + { + heightmap[y * WORLD_IMAGE_WIDTH + x] = (Color){edge, edge, edge, 255}; + } + else if (x < start.x || x > end.x || // Smooth out rest of the edge. + y < start.y || y > end.y) + { + int distance = Vector2Distance( + (Vector2){x, y}, + Vector2Scale(Vector2Add(start, end), 0.5)); + int edgeHeight = distance + edge; + + // Average out the heights. + if (distance > Vector2Distance(start, end) / 2.0 + + PLACE_POND_WALKING_AREA) + { + edgeHeight += heightmap[y * WORLD_IMAGE_WIDTH + x].r; + edgeHeight /= 2; + } + + heightmap[y * WORLD_IMAGE_WIDTH + x] = + (Color){edgeHeight, edgeHeight, edgeHeight, 255}; + } + else + { + heightmap[y * WORLD_IMAGE_WIDTH + x] = + (Color){height, height, height, 255}; + } } } diff --git a/src/world.h b/src/world.h index 149e7dd..a837dae 100644 --- a/src/world.h +++ b/src/world.h @@ -26,6 +26,9 @@ // Places. #define PLACE_POND_MIN_DISTANCE 400 // Pond distance from center. #define PLACE_POND_MAX_DISTANCE 600 +#define PLACE_POND_DEPTH 10 +#define PLACE_POND_OUTER_AREA 25 +#define PLACE_POND_WALKING_AREA 7 // UID for anything in the world. typedef int16_t WorldUID; |