diff options
author | nathan <nathansmith@disroot.org> | 2025-07-06 17:11:56 +0000 |
---|---|---|
committer | nathan <nathansmith@disroot.org> | 2025-07-06 17:11:56 +0000 |
commit | 255c938a77f8a73229b1867aadd10f3bf9c44f2e (patch) | |
tree | 7972e9a81d5e1a221bb160c7d82397c80b07fac7 /src/world.c | |
parent | b00544e8f0e77c149d44dca3ab81d97a07fcea3f (diff) | |
download | FindThings-255c938a77f8a73229b1867aadd10f3bf9c44f2e.tar.gz FindThings-255c938a77f8a73229b1867aadd10f3bf9c44f2e.tar.bz2 FindThings-255c938a77f8a73229b1867aadd10f3bf9c44f2e.zip |
Playing around with world generating a bit
Diffstat (limited to 'src/world.c')
-rw-r--r-- | src/world.c | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/src/world.c b/src/world.c index db6e55d..3513042 100644 --- a/src/world.c +++ b/src/world.c @@ -4,15 +4,32 @@ World createWorld(const Assets* assets) { World world; - world.size = (Vector3){1000.0, 30.0, 1000.0}; + world.size = (Vector3){1000.0, 20.0, 1000.0}; world.image = &assets->images[HEIGHT_MAP_IMAGE]; - + + // Heightmap. Mesh mesh = GenMeshHeightmap(*world.image, world.size); world.heightmap = LoadModelFromMesh(mesh); world.heightmap.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = assets->textures[HEIGHT_MAP_TEXTURE]; - world.heightmapColors = LoadImageColors(assets->images[HEIGHT_MAP_IMAGE]); + uint32_t seed = 57; + + // Entities. + for (int index = 0; index < WORLD_ENTITY_MAX; ++index) + { + FT_RANDOM16(seed); + + Entity entity = createEntity(seed % ENTITY_COUNT, Vector3Zero()); + FT_RANDOM16(seed); + // It be funky and give negative numbers. + entity.position.x = seed % (int)world.size.x; + FT_RANDOM16(seed); + entity.position.z = seed % (int)world.size.z; + entity.position.y = getWorldHeightAtLocation(world, entity.position.x, + entity.position.z) + 1.0; + world.entities[index] = entity; + } return world; } @@ -20,12 +37,16 @@ World createWorld(const Assets* assets) void updateWorld(World* world, Game* game) { DrawModel(world->heightmap, Vector3Zero(), 1.0, WHITE); + + for (int index = 0; index < WORLD_ENTITY_MAX; ++index) + { + updateEntity(&world->entities[index], game); + } } void freeWorld(World world) { UnloadModel(world.heightmap); - UnloadImageColors(world.heightmapColors); } float getWorldPixelHeight(World world, int x, int y) |