From 7faa1cbde913ad8c56bc43bc01512799d4cf6d02 Mon Sep 17 00:00:00 2001 From: nathan Date: Tue, 29 Jul 2025 02:17:10 -0600 Subject: Working hard or hardly working --- src/entity.c | 10 ++++++++++ src/entity.h | 8 +++++--- src/player.c | 28 ++++++++++++++-------------- src/world.c | 60 ++++++++++++++++++++++++++++++++++++++++++++---------------- 4 files changed, 73 insertions(+), 33 deletions(-) diff --git a/src/entity.c b/src/entity.c index 6d1aace..8225e76 100644 --- a/src/entity.c +++ b/src/entity.c @@ -32,6 +32,13 @@ Entity createEntity(EntityId id, Vector3 position) break; case FLOWER: entity.box = entityBoxFromScale(FLOWER_SCALE, 32.0, 54.0); + break; + case POND: + entity.box = (BoundingBox){ + .min = (Vector3){-POND_SIZE, -POND_HEIGHT, -POND_SIZE}, + .max = (Vector3){POND_SIZE, POND_HEIGHT, POND_SIZE} + }; + break; default: break; @@ -66,6 +73,9 @@ void updateEntity(Entity* entity, Game* game) DrawBillboard(game->player.camera, game->assets.textures[FLOWER_TEXTURE], entity->position, FLOWER_SCALE, WHITE); break; + case POND: + DrawBoundingBox(entity->box, YELLOW); + break; default: break; } diff --git a/src/entity.h b/src/entity.h index fdfe55e..cd5659a 100644 --- a/src/entity.h +++ b/src/entity.h @@ -5,12 +5,13 @@ #ifndef ENTITY_H #define ENTITY_H -#define ENTITY_COUNT 5 +#define ENTITY_COUNT 6 -// Entity scales. #define TREE_SCALE 40.0 #define BUSH_SCALE 8.0 #define FLOWER_SCALE 3.0 +#define POND_SIZE 100.0 +#define POND_HEIGHT 10.0 typedef int8_t EntityId; @@ -20,7 +21,8 @@ enum { STICKY_NICKEL, TREE, BUSH, - FLOWER + FLOWER, + POND }; typedef struct { diff --git a/src/player.c b/src/player.c index f32d8bb..eb1f55a 100644 --- a/src/player.c +++ b/src/player.c @@ -83,22 +83,22 @@ void updatePlayer(Player* player, Game* game) camera->position = player->position; camera->target = Vector3Add(player->position, player->direction); -#ifdef FT_DEBUG_MODE - Ray ray = (Ray){ - .position = player->position, - .direction = player->direction - }; +/* #ifdef FT_DEBUG_MODE */ +/* Ray ray = (Ray){ */ +/* .position = player->position, */ +/* .direction = player->direction */ +/* }; */ - DrawRay(ray, YELLOW); +/* DrawRay(ray, YELLOW); */ - int tests; - WorldUID uid = castRayAtWorld(&game->world, ray, &tests); +/* int tests; */ +/* WorldUID uid = castRayAtWorld(&game->world, ray, &tests); */ - //printf("%d\n", tests); +/* //printf("%d\n", tests); */ - if (uid != -1) - { - DrawBoundingBox(game->world.entities[uid].box, RED); - } -#endif +/* if (uid != -1) */ +/* { */ +/* DrawBoundingBox(game->world.entities[uid].box, RED); */ +/* } */ +/* #endif */ } diff --git a/src/world.c b/src/world.c index fd6fc19..5db0130 100644 --- a/src/world.c +++ b/src/world.c @@ -379,49 +379,77 @@ Seed generateWorldItems(World* world, Seed seed, int start, int end) return seed; } -Seed generatePond(World* world, Seed seed) +Seed generatePond(World* world, Color* heightmap, WorldUID id, Seed seed) { // Get position. int distanceRange = PLACE_POND_MAX_DISTANCE * 2; Vector3 position = Vector3Scale(world->size, 0.5); - position.x += FT_RANDOM16(seed) % distanceRange - PLACE_POND_MAX_DISTANCE; - position.z += FT_RANDOM16(seed) % distanceRange - PLACE_POND_MAX_DISTANCE; + position.x += FT_RANDOM16(seed) % distanceRange - PLACE_POND_MAX_DISTANCE; + position.z += FT_RANDOM16(seed) % distanceRange - PLACE_POND_MAX_DISTANCE; + + Entity pond = createEntity(POND, position); + placeEntityOnGround(&pond, world); + world->entities[id] = pond; return seed; } +Texture generateGroundTexture() +{ + Image image = GenImageWhiteNoise(WORLD_IMAGE_WIDTH, WORLD_IMAGE_HEIGHT, + WORLD_GROUND_IMAGE_NOISE); + ImageBlurGaussian(&image, WORLD_GROUND_BLUR); + ImageColorContrast(&image, WORLD_GROUND_CONTRAST); + ImageColorTint(&image, WORLD_GROUND_COLOR); + + Texture texture = LoadTextureFromImage(image); + UnloadImage(image); + + return texture; +} + World createWorld(Seed seed) { World world; world.size = WORLD_SIZE; - // Heightmap. + // Heightmap image. int offsetX = FT_RANDOM16(seed); int offsetY = FT_RANDOM16(seed); Image image = GenImagePerlinNoise(WORLD_IMAGE_WIDTH, WORLD_IMAGE_HEIGHT, offsetX, offsetY, WORLD_IMAGE_SCALE); + Color* colors = LoadImageColors(image); + UnloadImage(image); + // Places. + WorldUID placeId = 0; + seed = generatePond(&world, colors, placeId, seed); + + // Heightmap model. + image = (Image){ + .data = colors, + .width = WORLD_IMAGE_WIDTH, + .height = WORLD_IMAGE_WIDTH, + .format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, + .mipmaps = 1 + }; + Mesh mesh = GenMeshHeightmap(image, world.size); world.heightmap = LoadModelFromMesh(mesh); world.heightmapTexture = LoadTextureFromImage(image); UnloadImage(image); // Model texture. - image = GenImageWhiteNoise(WORLD_IMAGE_WIDTH, WORLD_IMAGE_HEIGHT, - WORLD_GROUND_IMAGE_NOISE); - ImageBlurGaussian(&image, WORLD_GROUND_BLUR); - ImageColorContrast(&image, WORLD_GROUND_CONTRAST); - ImageColorTint(&image, WORLD_GROUND_COLOR); - world.heightmap.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = - LoadTextureFromImage(image); - UnloadImage(image); + generateGroundTexture(); - // Places. - generatePond(&world, seed); + int start = placeId + 1; + int end = WORLD_PLANT_COUNT + start; + seed = generateWorldPlants(&world, seed, start, end); - seed = generateWorldPlants(&world, seed, 0, WORLD_PLANT_COUNT); - seed = generateWorldItems(&world, seed, WORLD_PLANT_COUNT, WORLD_ENTITY_MAX); + start = end; + end = WORLD_ENTITY_MAX; + seed = generateWorldItems(&world, seed, start, end); // Generate BVH. double currentTime = GetTime(); -- cgit v1.2.3