code: changed zoom behavior
parent
3fd5e282cf
commit
645111b53c
|
@ -21,7 +21,7 @@
|
|||
|
||||
#define DEFAULT_WORLD_SEED 302097
|
||||
#define DEFAULT_CHUNK_SIZE 16 /* amount of blocks within a chunk (single axis) */
|
||||
#define DEFAULT_WORLD_SIZE 32 /* amount of chunks within a world (single axis) */
|
||||
#define DEFAULT_WORLD_SIZE 5 /* amount of chunks within a world (single axis) */
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
zpl_opts opts={0};
|
||||
|
|
|
@ -79,11 +79,13 @@ void platform_input_update_input_frame(game_keystate_data data) {
|
|||
|
||||
void platform_input() {
|
||||
float mouse_z = (GetMouseWheelMove()*0.5f);
|
||||
float mouse_modified = target_zoom < 4 ? mouse_z / (zpl_exp(4 - (target_zoom))) : mouse_z;
|
||||
|
||||
if (mouse_z != 0.0f) {
|
||||
target_zoom = zpl_clamp(target_zoom+mouse_z, 0.1f, 11.0f);
|
||||
target_zoom = zpl_clamp(target_zoom + mouse_modified, 0.1f, 11.0f);
|
||||
}
|
||||
|
||||
|
||||
// NOTE(zaklaus): keystate handling
|
||||
{
|
||||
float x=0.0f, y=0.0f;
|
||||
|
|
|
@ -21,6 +21,10 @@ typedef WORLD_BLOCK_OBSERVER(world_block_observer_proc);
|
|||
|
||||
#define BLOCK_INVALID 0xF
|
||||
|
||||
int eco_incircle(int x, int y, int radius) {
|
||||
return (zpl_pow(x, 2) + zpl_pow(y, 2)) < zpl_pow(radius, 2);
|
||||
}
|
||||
|
||||
block_id worldgen_biome_find(uint32_t biome, uint32_t kind) {
|
||||
asset_id asset = ASSET_INVALID;
|
||||
switch (biome) {
|
||||
|
@ -62,12 +66,14 @@ static void world_fill_rect(block_id *data, block_id id, uint32_t x, uint32_t y,
|
|||
}
|
||||
}
|
||||
|
||||
static void world_fill_circle(block_id *data, block_id id, uint32_t x, uint32_t y, uint32_t w, uint32_t h, world_block_observer_proc *proc) {
|
||||
for (uint32_t cy=y; cy<y+h; cy++) {
|
||||
for (uint32_t cx=x; cx<x+w; cx++) {
|
||||
if (cx < 0 || cx >= world->dim) continue;
|
||||
if (cy < 0 || cy >= world->dim) continue;
|
||||
uint32_t i = (cy*world->dim) + cx;
|
||||
static void world_fill_circle(block_id *data, block_id id, uint32_t cx, uint32_t cy, uint32_t radius, world_block_observer_proc *proc) {
|
||||
for (int x = -(int32_t)(radius); x < (int32_t)radius; ++x) {
|
||||
for (int y = -(int32_t)(radius); y < (int32_t)radius; ++y) {
|
||||
if (eco_incircle(x, y, radius)) {
|
||||
int fx = x + cx;
|
||||
int fy = y + cy;
|
||||
|
||||
uint32_t i = (fy*world->dim) + fx;
|
||||
|
||||
if (proc) {
|
||||
block_id new_id = (*proc)(data, id, i);
|
||||
|
@ -81,6 +87,7 @@ static void world_fill_circle(block_id *data, block_id id, uint32_t x, uint32_t
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void world_fill_rect_anchor(block_id *data, block_id id, uint32_t x, uint32_t y, uint32_t w, uint32_t h, float ax, float ay, world_block_observer_proc *proc) {
|
||||
uint32_t w2 = (uint32_t)floorf(w*ax);
|
||||
|
@ -179,98 +186,16 @@ int32_t worldgen_build(world_data *wld) {
|
|||
world_fill_rect(world->data, wall_id, 0, 0, world->dim, world->dim, NULL);
|
||||
|
||||
// ground
|
||||
world_fill_rect(world->data, grnd_id, 1, 1, world->dim-2, world->dim-2, NULL);
|
||||
world_fill_rect(world->data, dirt_id, 1, 1, world->dim-2, world->dim-2, shaper_noise05);
|
||||
world_fill_rect(world->outer_data, tree_id, 1, 1, world->dim-2, world->dim-2, shaper_noise01b);
|
||||
world_fill_rect(world->data, watr_id, 1, 1, world->dim-2, world->dim-2, NULL);
|
||||
|
||||
// water
|
||||
#if 1
|
||||
for (int i=0; i<RAND_RANGE(58, 92); i++) {
|
||||
world_fill_rect_anchor(world->data, watr_id, RAND_RANGE(0, world->dim), RAND_RANGE(0, world->dim), 4+RAND_RANGE(0,3), 4+RAND_RANGE(0,3), 0.5f, 0.5f, shaper_noise80);
|
||||
}
|
||||
#endif
|
||||
int radius = 25;
|
||||
|
||||
// ice rink
|
||||
#if 0
|
||||
world_fill_rect_anchor(world->data, watr_id, 450, 125, 10, 10, 0.0f, 0.0f, NULL);
|
||||
#endif
|
||||
// wide boy circle
|
||||
world_fill_circle(world->data, dirt_id, world->dim / 2, world->dim / 2, radius, NULL);
|
||||
|
||||
// lava
|
||||
#if 1
|
||||
for (int i=0; i<RAND_RANGE(48, 62); i++) {
|
||||
world_fill_rect_anchor(world->data, lava_id, RAND_RANGE(0, world->dim), RAND_RANGE(0, world->dim), 4+RAND_RANGE(0,3), 4+RAND_RANGE(0,3), 0.5f, 0.5f, shaper_noise80);
|
||||
}
|
||||
#endif
|
||||
// narrow boy cirlce
|
||||
world_fill_circle(world->data, grnd_id, world->dim / 2, world->dim / 2, radius * 0.7f, NULL);
|
||||
|
||||
|
||||
// hills
|
||||
#if 1
|
||||
const uint32_t HILLS_SIZE = 21;
|
||||
for (int i=0; i<RAND_RANGE(8, 124); i++) {
|
||||
world_fill_rect_anchor(world->data, wall_id, RAND_RANGE(0, world->dim), RAND_RANGE(0, world->dim), RAND_RANGE(0,HILLS_SIZE), RAND_RANGE(0,HILLS_SIZE), 0.5f, 0.5f, shaper_noise50);
|
||||
}
|
||||
#endif
|
||||
|
||||
// vehicles
|
||||
#if 1
|
||||
for (int i=0; i<RAND_RANGE(258, 1124); i++) {
|
||||
uint64_t e = vehicle_spawn();
|
||||
|
||||
Position *dest = ecs_get_mut(world_ecs(), e, Position);
|
||||
dest->x = RAND_RANGEF(0, world->dim*WORLD_BLOCK_SIZE);
|
||||
dest->y = RAND_RANGEF(0, world->dim*WORLD_BLOCK_SIZE);
|
||||
entity_set_position(e, dest->x, dest->y);
|
||||
}
|
||||
#endif
|
||||
|
||||
// items
|
||||
#if 1
|
||||
for (int i=0; i<RAND_RANGE(328, 164); i++) {
|
||||
uint64_t e = item_spawn(ASSET_DEMO_ICEMAKER, 32);
|
||||
|
||||
Position *dest = ecs_get_mut(world_ecs(), e, Position);
|
||||
dest->x = RAND_RANGEF(0, world->dim*WORLD_BLOCK_SIZE);
|
||||
dest->y = RAND_RANGEF(0, world->dim*WORLD_BLOCK_SIZE);
|
||||
entity_set_position(e, dest->x, dest->y);
|
||||
}
|
||||
|
||||
for (int i=0; i<RAND_RANGE(328, 164); i++) {
|
||||
uint64_t e = item_spawn(ASSET_FENCE, 64);
|
||||
|
||||
Position *dest = ecs_get_mut(world_ecs(), e, Position);
|
||||
dest->x = RAND_RANGEF(0, world->dim*WORLD_BLOCK_SIZE);
|
||||
dest->y = RAND_RANGEF(0, world->dim*WORLD_BLOCK_SIZE);
|
||||
entity_set_position(e, dest->x, dest->y);
|
||||
}
|
||||
|
||||
for (int i=0; i<RAND_RANGE(328, 164); i++) {
|
||||
uint64_t e = item_spawn(ASSET_WOOD, 64);
|
||||
|
||||
Position *dest = ecs_get_mut(world_ecs(), e, Position);
|
||||
dest->x = RAND_RANGEF(0, world->dim*WORLD_BLOCK_SIZE);
|
||||
dest->y = RAND_RANGEF(0, world->dim*WORLD_BLOCK_SIZE);
|
||||
entity_set_position(e, dest->x, dest->y);
|
||||
}
|
||||
|
||||
for (int i=0; i<RAND_RANGE(128, 564); i++) {
|
||||
uint64_t e = item_spawn(ASSET_BELT, 999);
|
||||
|
||||
Position *dest = ecs_get_mut(world_ecs(), e, Position);
|
||||
dest->x = RAND_RANGEF(0, world->dim*WORLD_BLOCK_SIZE);
|
||||
dest->y = RAND_RANGEF(0, world->dim*WORLD_BLOCK_SIZE);
|
||||
entity_set_position(e, dest->x, dest->y);
|
||||
}
|
||||
|
||||
for (int i=0; i<RAND_RANGE(128, 964); i++) {
|
||||
uint64_t e = item_spawn(ASSET_CHEST, 4);
|
||||
|
||||
Position *dest = ecs_get_mut(world_ecs(), e, Position);
|
||||
dest->x = RAND_RANGEF(0, world->dim*WORLD_BLOCK_SIZE);
|
||||
dest->y = RAND_RANGEF(0, world->dim*WORLD_BLOCK_SIZE);
|
||||
entity_set_position(e, dest->x, dest->y);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return WORLD_ERROR_NONE;
|
||||
}
|
||||
|
|
|
@ -79,9 +79,10 @@ void platform_input_update_input_frame(game_keystate_data data) {
|
|||
|
||||
void platform_input() {
|
||||
float mouse_z = (GetMouseWheelMove()*0.5f);
|
||||
float mouse_modified = target_zoom < 4 ? mouse_z / (zpl_exp(4 - (target_zoom))) : mouse_z;
|
||||
|
||||
if (mouse_z != 0.0f) {
|
||||
target_zoom = zpl_clamp(target_zoom+mouse_z, 0.1f, 11.0f);
|
||||
target_zoom = zpl_clamp(target_zoom + mouse_modified, 0.1f, 11.0f);
|
||||
}
|
||||
|
||||
// NOTE(zaklaus): keystate handling
|
||||
|
|
|
@ -136,9 +136,10 @@ void platform_input_update_input_frame(game_keystate_data data) {
|
|||
|
||||
void platform_input() {
|
||||
float mouse_z = (GetMouseWheelMove()*0.5f);
|
||||
float mouse_modified = target_zoom < 4 ? mouse_z / (zpl_exp(4 - (target_zoom))) : mouse_z;
|
||||
|
||||
if (mouse_z != 0.0f) {
|
||||
target_zoom = zpl_clamp(target_zoom+mouse_z, 0.1f, 11.0f);
|
||||
target_zoom = zpl_clamp(target_zoom + mouse_modified, 0.1f, 11.0f);
|
||||
}
|
||||
|
||||
// NOTE(zaklaus): keystate handling
|
||||
|
|
Loading…
Reference in New Issue