aboutsummaryrefslogtreecommitdiffstats
path: root/src/world.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/world.c')
-rw-r--r--src/world.c71
1 files changed, 51 insertions, 20 deletions
diff --git a/src/world.c b/src/world.c
index a6fdf24..deb3b97 100644
--- a/src/world.c
+++ b/src/world.c
@@ -412,14 +412,19 @@ void averageOutAreaWorld(const World* world, Color* heightmap, Rectangle area)
setWorldAreaToHeight(heightmap, area, height);
}
-Seed generatePond(World* world, Color* heightmap, WorldUID id, Seed seed)
+Seed generatePond(World* world, Color* heightmap, WorldUID* placeId,
+ 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;
+ world->entities[*id] = pond;
+ world->places[*placeId] = *id;
+
+ *id = *id + 1;
+ *placeId = *placeId + 1;
// Get lowest height.
int height = 255;
@@ -488,7 +493,8 @@ Seed generatePond(World* world, Color* heightmap, WorldUID id, Seed seed)
}
void generateWorldSamanthasPlace(World* world, const Assets* assets,
- Color* heightmap, WorldUID* placeId)
+ Color* heightmap, WorldUID* placeId,
+ WorldUID* id)
{
// Make area flat.
float width = SAMANTHAS_SPOT_SIZE * (WORLD_IMAGE_WIDTH / world->size.x)
@@ -508,15 +514,17 @@ void generateWorldSamanthasPlace(World* world, const Assets* assets,
// Samanthas spot.
Vector3 center = Vector3Scale(world->size, 0.5);
Entity spot = createEntity(SAMANTHAS_SPOT, center);
- world->entities[*placeId] = spot;
- world->places[*placeId] = *placeId;
+ world->entities[*id] = spot;
+ world->places[*placeId] = *id;
+
+ *id = *id + 1;
*placeId = *placeId + 1;
// Samantha.
Entity samantha = createEntity(SAMANTHA, Vector3Add(center,
SAMANTHA_OFFSET));
- world->entities[*placeId] = samantha;
- *placeId = *placeId + 1;
+ world->entities[*id] = samantha;
+ *id = *id + 1;
// Trashcans yippee!
Vector3 trashPosition = (Vector3){-SAMANTHAS_SPOT,
@@ -527,8 +535,8 @@ void generateWorldSamanthasPlace(World* world, const Assets* assets,
{
Entity trashcan = createEntity(TRASHCAN,
Vector3Add(trashPosition, center));
- world->entities[*placeId] = trashcan;
- *placeId = *placeId + 1;
+ world->entities[*id] = trashcan;
+ *id = *id + 1;
trashPosition.x += (float)(SAMANTHAS_SPOT_SIZE * 2.0)
/ SAMANTHAS_SPOT_TRASHCAN_COUNT;
}
@@ -542,8 +550,8 @@ void generateWorldSamanthasPlace(World* world, const Assets* assets,
{
Entity trash = createEntity(index % 2 == 0 ? TRASH : MEDICAL_TRASH,
Vector3Add(trashPosition, center));
- world->entities[*placeId] = trash;
- *placeId = *placeId + 1;
+ world->entities[*id] = trash;
+ *id = *id + 1;
trashPosition.x += (float)(SAMANTHAS_SPOT_SIZE * 2.0)
/ SAMANTHAS_SPOT_TRASH_COUNT;
}
@@ -557,6 +565,13 @@ void generateWorldSamanthasPlace(World* world, const Assets* assets,
.texture = assets->textures[SAMANTHA_FLOOR_TEXTURE];
}
+void generateJohnsShop(World* world, Color* colors, WorldUID* placeId)
+{
+ Vector3 position = Vector3Scale(world->size, 0.5);
+ Entity johnsShop = createEntity(JOHNS_STORE, position);
+ world->entities[*placeId] = johnsShop;
+}
+
Seed generateWorldPlants(World* world, Seed seed, int start, int end)
{
for (int index = start; index < end; ++index)
@@ -730,6 +745,27 @@ Seed generateWorldCharacters(World* world, Seed seed, WorldUID start)
return seed;
}
+Seed generateWorldPlaces(World* world, const Assets* assets, Color* colors,
+ Seed seed, WorldUID* id)
+{
+ WorldUID placeId = 0;
+
+ // Pond.
+ seed = generatePond(world, colors, &placeId, id, seed);
+
+ // Samantha's place.
+ generateWorldSamanthasPlace(world, assets, colors, &placeId, id);
+
+ // Sanity check (something I should do more often...)
+ if (placeId != WORLD_PLACE_COUNT)
+ {
+ TraceLog(LOG_WARNING, "placeId is %d when it should be %d", placeId,
+ WORLD_PLACE_COUNT);
+ }
+
+ return seed;
+}
+
World createWorld(Seed seed, const Assets* assets)
{
World world;
@@ -744,14 +780,9 @@ World createWorld(Seed seed, const Assets* assets)
UnloadImage(image);
// Places.
- WorldUID placeId = 0;
-
- // Pond.
- seed = generatePond(&world, colors, placeId, seed);
- world.places[0] = placeId;
+ WorldUID id = 0;
- ++placeId;
- generateWorldSamanthasPlace(&world, assets, colors, &placeId);
+ seed = generateWorldPlaces(&world, assets, colors, seed, &id);
// Heightmap model.
image = (Image){
@@ -768,7 +799,7 @@ World createWorld(Seed seed, const Assets* assets)
UnloadImage(image);
// Put places on ground.
- for (int index = 0; index < placeId; ++index)
+ for (int index = 0; index < id; ++index)
{
placeEntityOnGround(&world.entities[index], &world);
}
@@ -778,7 +809,7 @@ World createWorld(Seed seed, const Assets* assets)
generateGroundTexture();
// Plants
- int start = placeId + 1;
+ int start = id;
int end = WORLD_PLANT_COUNT + start;
seed = generateWorldPlants(&world, seed, start, end);