diff --git a/art/ice_rink.dem b/art/ice_rink.dem new file mode 100644 index 0000000..b8adceb Binary files /dev/null and b/art/ice_rink.dem differ diff --git a/art/vehicle_unset.dem b/art/vehicle_unset.dem new file mode 100644 index 0000000..1c36fb1 Binary files /dev/null and b/art/vehicle_unset.dem differ diff --git a/code/game/src/debug_replay.c b/code/game/src/debug_replay.c index fac3593..88a7950 100644 --- a/code/game/src/debug_replay.c +++ b/code/game/src/debug_replay.c @@ -9,6 +9,7 @@ typedef enum { // NOTE(zaklaus): Special actions RPKIND_SPAWN_CAR, + RPKIND_PLACE_ICE_RINK, } replay_kind; typedef struct { @@ -146,6 +147,8 @@ void debug_replay_run(void) { camera_set_follow(mime); } +void ActPlaceIceRink(); + void debug_replay_update(void) { if (!is_playing) return; if (playback_time >= zpl_time_rel_ms()) return; @@ -170,6 +173,9 @@ void debug_replay_update(void) { zpl_array_append(temp_actors, e); }break; + case RPKIND_PLACE_ICE_RINK: { + ActPlaceIceRink(); + }break; default: { ZPL_PANIC("unreachable"); }break; diff --git a/code/game/src/debug_ui.c b/code/game/src/debug_ui.c index 2082e75..5f84cca 100644 --- a/code/game/src/debug_ui.c +++ b/code/game/src/debug_ui.c @@ -98,7 +98,7 @@ static debug_item items[] = { .list = { .items = (debug_item[]) { { .kind = DITEM_TEXT, .name = "delta time", .proc = DrawDeltaTime }, - { .kind = DITEM_TEXT, .name = "random literal", .text = "hello", .proc = DrawLiteral }, + { .kind = DITEM_TEXT, .name = "pos", .proc = DrawCameraPos }, { .kind = DITEM_TEXT, .name = "zoom", .proc = DrawZoom }, { .kind = DITEM_SLIDER, .name = "slider", .slider = { .min = 0.0f, .max = 1.0f, .val = 0.5f } }, { .kind = DITEM_END }, @@ -111,6 +111,7 @@ static debug_item items[] = { .list = { .items = (debug_item[]) { { .kind = DITEM_BUTTON, .name = "spawn car", .on_click = ActSpawnCar }, + { .kind = DITEM_BUTTON, .name = "place ice rink", .on_click = ActPlaceIceRink }, { .kind = DITEM_LIST, .name = "demo npcs", diff --git a/code/game/src/debug_ui_actions.c b/code/game/src/debug_ui_actions.c index dd41767..94277c9 100644 --- a/code/game/src/debug_ui_actions.c +++ b/code/game/src/debug_ui_actions.c @@ -1,4 +1,5 @@ #include "debug_ui.h" +#include "world/blocks.h" static inline void ActExitGame(void) { @@ -17,6 +18,23 @@ ActSpawnCar(void) { debug_replay_special_action(RPKIND_SPAWN_CAR); } +static inline void +ActPlaceIceRink(void) { + ecs_entity_t plr = camera_get().ent_id; + uint8_t watr_id = blocks_find(BLOCK_BIOME_DEV, BLOCK_KIND_WATER); + Position const *p = ecs_get(world_ecs(), plr, Position); + float const bs = WORLD_BLOCK_SIZE; + + for (int y = 0; y < 100; y++) { + for (int x = 0; x < 100; x++) { + world_block_lookup l = world_block_from_realpos((p->x - (x*bs)/2.0f), p->y - (y*bs)/2.0f); + world_chunk_replace_block(world_ecs(), l.chunk_id, l.id, watr_id); + } + } + + debug_replay_special_action(RPKIND_PLACE_ICE_RINK); +} + // NOTE(zaklaus): Replay system static inline uint8_t diff --git a/code/game/src/debug_ui_helpers.c b/code/game/src/debug_ui_helpers.c new file mode 100644 index 0000000..5964c6a --- /dev/null +++ b/code/game/src/debug_ui_helpers.c @@ -0,0 +1,2 @@ +#include "world/blocks.h" +#include "world/world.h" diff --git a/code/game/src/debug_ui_widgets.c b/code/game/src/debug_ui_widgets.c index 85c86fd..8c4be0b 100644 --- a/code/game/src/debug_ui_widgets.c +++ b/code/game/src/debug_ui_widgets.c @@ -26,6 +26,13 @@ DrawFormattedText(float xpos, float ypos, char const *text) { //~ NOTE(zaklaus): widgets +static inline debug_draw_result +DrawCameraPos(debug_item *it, float xpos, float ypos) { + (void)it; + camera cam = camera_get(); + return DrawFormattedText(xpos, ypos, TextFormat("%d %d", (int)(cam.x/WORLD_BLOCK_SIZE), (int)(cam.y/WORLD_BLOCK_SIZE))); +} + static inline debug_draw_result DrawUnmeasuredTime(debug_item *it, float xpos, float ypos) { (void)it; diff --git a/code/game/src/world/worldgen/worldgen_test.c b/code/game/src/world/worldgen/worldgen_test.c index d7e8167..85dbf68 100644 --- a/code/game/src/world/worldgen/worldgen_test.c +++ b/code/game/src/world/worldgen/worldgen_test.c @@ -152,6 +152,11 @@ int32_t worldgen_test(world_data *wld) { } #endif + // ice rink +#if 0 + world_fill_rect_anchor(watr_id, 450, 125, 10, 10, 0.0f, 0.0f, NULL); +#endif + // lava #if 1 for (int i=0; icount; i++) { + world_block_lookup lookup = world_block_from_realpos(p[i].x, p[i].y); + float drag = blocks_get_drag(lookup.block_id); double speed = PLR_MOVE_SPEED * (in[i].sprint ? PLR_MOVE_SPEED_MULT : 1.0); if (zpl_abs(v[i].x) < speed && in[i].x) - v[i].x = in[i].x*speed; + v[i].x += in[i].x*speed*drag; if (zpl_abs(v[i].y) < speed && in[i].y) - v[i].y = in[i].y*speed; + v[i].y += in[i].y*speed*drag; } } diff --git a/code/modules/source/system_vehicle.c b/code/modules/source/system_vehicle.c index 32bb610..437a037 100644 --- a/code/modules/source/system_vehicle.c +++ b/code/modules/source/system_vehicle.c @@ -100,8 +100,9 @@ void VehicleHandling(ecs_iter_t *it) { // NOTE(zaklaus): Handle driver input if (j == 0) { Input const* in = ecs_get(it->world, pe, Input); + world_block_lookup lookup = world_block_from_realpos(p[i].x, p[i].y); - car->force += zpl_lerp(0.0f, in->y * VEHICLE_FORCE, VEHICLE_ACCEL); + car->force += zpl_lerp(0.0f, in->y * VEHICLE_FORCE, VEHICLE_ACCEL) * blocks_get_drag(lookup.block_id); car->steer += in->x * -VEHICLE_STEER; car->steer = zpl_clamp(car->steer, -40.0f, 40.0f); } @@ -130,7 +131,7 @@ void ClearVehicle(ecs_iter_t *it) { for (int i = 0; i < it->count; i++) { for (int k = 0; k < 4; k++) { - if (veh[i].seats[k] != 0) { + if (world_entity_valid(veh[i].seats[k])) { ecs_remove(it->world, veh[i].seats[k], IsInVehicle); } }