eco2d/code/apps/server/source/world_gen.c

40 lines
1.1 KiB
C
Raw Normal View History

2021-01-11 16:20:12 +00:00
#include "world.h"
#include "blocks.h"
#include "zpl.h"
2021-01-11 16:49:00 +00:00
#include <math.h>
static void world_fill_rect(uint32_t id, uint32_t x, uint32_t y, uint32_t w, uint32_t h) {
2021-01-11 16:20:12 +00:00
for (uint32_t cy=y; cy<y+h; cy++) {
for (uint32_t cx=x; cx<x+w; cx++) {
2021-01-11 16:49:00 +00:00
uint32_t i = (cy*world_width) + cx;
2021-01-11 16:20:12 +00:00
world[i] = id;
}
}
}
2021-01-11 16:49:00 +00:00
static void world_fill_dot(uint32_t id, uint32_t x, uint32_t y, uint32_t w, uint32_t h) {
uint32_t w2 = (uint32_t)floor(w/2.0);
uint32_t h2 = (uint32_t)floor(h/2.0);
world_fill_rect(id, x-w2, y-h2, w, h);
}
int32_t world_gen(int32_t seed) {
2021-01-11 16:20:12 +00:00
// TODO: perform world gen
// atm, we will fill the world with ground and surround it by walls
uint32_t wall_id = blocks_find(BLOCK_BIOME_DEV, BLOCK_KIND_WALL);
uint32_t grnd_id = blocks_find(BLOCK_BIOME_DEV, BLOCK_KIND_GROUND);
uint32_t watr_id = blocks_find(BLOCK_BIOME_DEV, BLOCK_KIND_WATER);
// walls
2021-01-11 16:49:00 +00:00
world_fill_rect(wall_id, 0, 0, world_width, world_height);
2021-01-11 16:20:12 +00:00
// ground
2021-01-11 16:49:00 +00:00
world_fill_rect(grnd_id, 1, 1, world_width-2, world_height-2);
2021-01-11 16:20:12 +00:00
// water
2021-01-11 16:49:00 +00:00
world_fill_dot(watr_id, 8, 8, 4, 4);
2021-01-11 16:20:12 +00:00
return WORLD_ERROR_NONE;
}