demo: ice rink test
parent
27bdc1f3a1
commit
44673b5030
Binary file not shown.
Binary file not shown.
|
@ -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;
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
#include "world/blocks.h"
|
||||
#include "world/world.h"
|
|
@ -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;
|
||||
|
|
|
@ -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; i<RAND_RANGE(48, 62); i++) {
|
||||
|
|
|
@ -102,7 +102,7 @@ void RegenerateHP(ecs_iter_t *it) {
|
|||
void SystemsImport(ecs_world_t *ecs) {
|
||||
ECS_MODULE(ecs, Systems);
|
||||
|
||||
ECS_SYSTEM(ecs, MovementImpulse, EcsOnLoad, components.Input, components.Velocity, !components.IsInVehicle);
|
||||
ECS_SYSTEM(ecs, MovementImpulse, EcsOnLoad, components.Input, components.Velocity, components.Position, !components.IsInVehicle);
|
||||
ECS_SYSTEM(ecs, DemoNPCMoveAround, EcsOnLoad, components.Velocity, components.EcsDemoNPC);
|
||||
ECS_SYSTEM(ecs, EnterVehicle, EcsOnLoad, components.Input, components.Position, !components.IsInVehicle);
|
||||
ECS_SYSTEM(ecs, LeaveVehicle, EcsOnLoad, components.Input, components.IsInVehicle);
|
||||
|
|
|
@ -17,12 +17,15 @@ void MoveWalk(ecs_iter_t *it) {
|
|||
void MovementImpulse(ecs_iter_t *it) {
|
||||
Input *in = ecs_column(it, Input, 1);
|
||||
Velocity *v = ecs_column(it, Velocity, 2);
|
||||
Position *p = ecs_term(it, Position, 3);
|
||||
|
||||
for (int i = 0; i < it->count; 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue