eco2d/code/games/minimal/src/worldgen.c

69 lines
2.1 KiB
C
Raw Normal View History

2021-05-04 17:41:30 +00:00
#include "zpl.h"
#include <math.h>
#include <stdlib.h>
#include "world/world.h"
#include "world/blocks.h"
#include "world/perlin.h"
#include "ecs/components.h"
#include "ents/entity.h"
2022-09-29 14:05:07 +00:00
#include "ents/prefabs/vehicle.h"
#include "ents/items.h"
2021-11-02 11:49:03 +00:00
#include "world/blocks_info.h"
2021-09-08 14:12:38 +00:00
2022-09-29 11:59:51 +00:00
#include "world/worldgen_utils.h"
2022-09-28 20:01:47 +00:00
2021-11-03 18:04:34 +00:00
block_id worldgen_biome_find(uint32_t biome, uint32_t kind) {
2021-11-02 11:49:03 +00:00
asset_id asset = ASSET_INVALID;
switch (biome) {
case BLOCK_BIOME_DEV: {
switch (kind) {
case BLOCK_KIND_GROUND: asset = ASSET_GROUND; break;
case BLOCK_KIND_DIRT: asset = ASSET_DIRT; break;
case BLOCK_KIND_WALL: asset = ASSET_WALL; break;
case BLOCK_KIND_HILL_SNOW:
case BLOCK_KIND_HILL: asset = ASSET_HILL; break;
case BLOCK_KIND_WATER: asset = ASSET_WATER; break;
case BLOCK_KIND_LAVA: asset = ASSET_LAVA; break;
}
}
}
2022-09-28 20:01:47 +00:00
2021-11-02 11:49:03 +00:00
return blocks_find(asset);
}
2022-09-28 05:29:32 +00:00
int32_t worldgen_build(world_data *wld) {
2021-05-12 14:02:12 +00:00
// TODO(zaklaus): pass world as an arg instead
world = wld;
2022-09-28 20:01:47 +00:00
2021-05-04 17:41:30 +00:00
// TODO: perform world gen
// atm, we will fill the world with ground and surround it by walls
2021-11-03 18:04:34 +00:00
block_id wall_id = worldgen_biome_find(BLOCK_BIOME_DEV, BLOCK_KIND_WALL);
block_id grnd_id = worldgen_biome_find(BLOCK_BIOME_DEV, BLOCK_KIND_GROUND);
block_id dirt_id = worldgen_biome_find(BLOCK_BIOME_DEV, BLOCK_KIND_DIRT);
block_id watr_id = worldgen_biome_find(BLOCK_BIOME_DEV, BLOCK_KIND_WATER);
block_id lava_id = worldgen_biome_find(BLOCK_BIOME_DEV, BLOCK_KIND_LAVA);
block_id tree_id = blocks_find(ASSET_TREE);
2022-09-28 20:01:47 +00:00
2021-05-12 14:02:12 +00:00
srand(world->seed);
2022-09-28 20:01:47 +00:00
2021-05-04 17:41:30 +00:00
// walls
2021-11-02 17:09:54 +00:00
world_fill_rect(world->data, wall_id, 0, 0, world->dim, world->dim, NULL);
2022-09-28 20:01:47 +00:00
2021-05-04 17:41:30 +00:00
// ground
2022-09-28 20:01:47 +00:00
world_fill_rect(world->data, watr_id, 1, 1, world->dim-2, world->dim-2, NULL);
int radius = 25;
// wide boy circle
world_fill_circle(world->data, dirt_id, world->dim / 2, world->dim / 2, radius, NULL);
// narrow boy cirlce
world_fill_circle(world->data, grnd_id, world->dim / 2, world->dim / 2, radius * 0.7f, NULL);
2021-05-04 17:41:30 +00:00
return WORLD_ERROR_NONE;
}