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

49 lines
1.3 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"
2022-09-29 14:16:06 +00:00
#include "models/components.h"
#include "models/entity.h"
#include "models/prefabs/vehicle.h"
#include "models/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
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
block_id wall_id = blocks_find(ASSET_WALL);
block_id grnd_id = blocks_find(ASSET_GROUND);
block_id dirt_id = blocks_find(ASSET_DIRT);
block_id watr_id = blocks_find(ASSET_WATER);
block_id lava_id = blocks_find(ASSET_LAVA);
2021-11-03 18:04:34 +00:00
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
2022-09-29 14:41:28 +00:00
world_fill_circle(world->data, grnd_id, world->dim / 2, world->dim / 2, (uint32_t)(radius * 0.7f), NULL);
2022-09-28 20:01:47 +00:00
2021-05-04 17:41:30 +00:00
return WORLD_ERROR_NONE;
}