diff options
Diffstat (limited to 'src/world.c')
-rw-r--r-- | src/world.c | 57 |
1 files changed, 53 insertions, 4 deletions
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}; + } } } |