Fix worldgen dims bug

isolation_bkp/dynres
Dominik Madarász 2021-01-11 22:50:14 +01:00
parent 6a15cfaa82
commit d10ae63aa7
5 changed files with 12 additions and 8 deletions

View File

@ -6,6 +6,7 @@ typedef enum {
BLOCK_KIND_WATER,
BLOCK_KIND_WALL,
BLOCK_KIND_HILL,
BLOCK_KIND_HILL_SNOW,
BLOCK_KIND_HOLE,
} block_kind;

View File

@ -7,7 +7,7 @@
#define WORLD_ERROR_INVALID_DIMENSIONS -0x0003
#define WORLD_ERROR_INVALID_BUFFER -0x0004
int32_t world_init(int32_t seed, uint8_t width, uint8_t height);
int32_t world_init(int32_t seed, uint32_t width, uint32_t height);
int32_t world_destroy(void);
uint32_t world_buf(uint8_t const **ptr, uint32_t *width);

View File

@ -5,5 +5,6 @@ static block blocks[] = {
{.tex_id = ATLAS_XY(0, 0), .name = "base-ground", .flags = 0, .kind = BLOCK_KIND_GROUND, .biome = 0, .symbol = '.'},
{.tex_id = ATLAS_XY(1, 0), .name = "base-wall", .flags = BLOCK_FLAG_COLLISION, .kind = BLOCK_KIND_WALL, .biome = 0, .symbol = '#'},
{.tex_id = ATLAS_XY(2, 0), .name = "base-hill", .flags = BLOCK_FLAG_COLLISION, .kind = BLOCK_KIND_HILL, .biome = 0, .symbol = '^'},
{.tex_id = ATLAS_XY(3, 0), .name = "base-hill-snow", .flags = BLOCK_FLAG_COLLISION, .kind = BLOCK_KIND_HILL_SNOW, .biome = 0, .symbol = '*'},
{.tex_id = ATLAS_XY(0, 1), .name = "base-water", .flags = BLOCK_FLAG_COLLISION, .kind = BLOCK_KIND_WATER, .biome = 0, .symbol = '~'},
};

View File

@ -9,7 +9,7 @@ static uint32_t world_height = 0;
int32_t world_gen();
int32_t world_init(int32_t seed, uint8_t width, uint8_t height) {
int32_t world_init(int32_t seed, uint32_t width, uint32_t height) {
if (world) {
world_destroy();
}

View File

@ -47,6 +47,9 @@ static WORLD_BLOCK_OBSERVER(shaper) {
if (kind == BLOCK_KIND_WALL && kind == old_kind) {
return blocks_find(biome, BLOCK_KIND_HILL);
}
if (kind == BLOCK_KIND_HILL && kind == old_kind) {
return blocks_find(biome, BLOCK_KIND_HILL_SNOW);
}
}
return id;
@ -89,16 +92,15 @@ int32_t world_gen() {
world_fill_rect(grnd_id, 1, 1, world_width-2, world_height-2, NULL);
// water
for (int i=0; i<RAND_RANGE(0, 8); i++) {
for (int i=0; i<RAND_RANGE(0, 12); i++) {
world_fill_rect_anchor(watr_id, RAND_RANGE(0, world_width), RAND_RANGE(0, world_height), 4+RAND_RANGE(0,3), 4+RAND_RANGE(0,3), 0.5f, 0.5f, shaper_noise33);
}
// hills
world_fill_rect_anchor(wall_id, 14+RAND_RANGE(-10, 10), 21+RAND_RANGE(-10, 10), 8+RAND_RANGE(-2,4), 8+RAND_RANGE(-2,4), 0.5f, 0.5f, shaper_noise80);
world_fill_rect_anchor(wall_id, 14+RAND_RANGE(-10, 10), 21+RAND_RANGE(-10, 10), 4+RAND_RANGE(-2,4), 4+RAND_RANGE(-2,4), 0.5f, 0.5f, shaper_noise50);
const uint32_t HILLS_SIZE = 21;
for (int i=0; i<RAND_RANGE(8, 24); i++) {
world_fill_rect_anchor(wall_id, RAND_RANGE(0, world_width), RAND_RANGE(0, world_height), 4+RAND_RANGE(-2,4), 4+RAND_RANGE(-2,4), 0.5f, 0.5f, shaper_noise50);
// hills
for (int i=0; i<RAND_RANGE(8, 224); i++) {
world_fill_rect_anchor(wall_id, RAND_RANGE(0, world_width), RAND_RANGE(0, world_height), RAND_RANGE(0,HILLS_SIZE), RAND_RANGE(0,HILLS_SIZE), 0.5f, 0.5f, shaper_noise33);
}
return WORLD_ERROR_NONE;