aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornathan <nathan@disroot.org>2025-07-29 08:17:10 +0000
committernathan <nathan@disroot.org>2025-07-29 08:17:10 +0000
commit7faa1cbde913ad8c56bc43bc01512799d4cf6d02 (patch)
tree1aa235efd08cc5add125123450d859f3874a4ff7
parent6bcf165f3af3da713953b9b3b80b4f101f7a0f7a (diff)
downloadFindThings-7faa1cbde913ad8c56bc43bc01512799d4cf6d02.tar.gz
FindThings-7faa1cbde913ad8c56bc43bc01512799d4cf6d02.tar.bz2
FindThings-7faa1cbde913ad8c56bc43bc01512799d4cf6d02.zip
Working hard or hardly working
-rw-r--r--src/entity.c10
-rw-r--r--src/entity.h8
-rw-r--r--src/player.c28
-rw-r--r--src/world.c60
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
@@ -33,6 +33,13 @@ Entity createEntity(EntityId id, Vector3 position)
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();