diff options
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) |