From bf757814b80f125baeb5c071dea188afb0681df4 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Thu, 17 Sep 2026 01:19:05 +0200 Subject: [PATCH] rogueviz::ru:: basic box physics --- rogueviz/ru/classes.cpp | 18 ++++++++++++++ rogueviz/ru/entity.cpp | 34 +++++++++++++++++++++++-- rogueviz/ru/load-world.cpp | 5 ++++ rogueviz/ru/man.cpp | 9 +------ rogueviz/ru/map.ru | 51 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 107 insertions(+), 10 deletions(-) diff --git a/rogueviz/ru/classes.cpp b/rogueviz/ru/classes.cpp index 5d6d471d..af540d4b 100644 --- a/rogueviz/ru/classes.cpp +++ b/rogueviz/ru/classes.cpp @@ -321,6 +321,8 @@ struct entity { bool destroyed; void kino(); + void apply_walking(ld target_velx); + virtual bool get_jump_control() { return false; } void apply_vel(); void apply_walls(); void apply_walls_reflect(); @@ -483,6 +485,8 @@ struct man : public entity { virtual void hs(stater& s); virtual double grav() { return entity::grav() / current.gravity_value; } + + bool get_jump_control() override { return current.jump_control; } }; extern man m; @@ -506,6 +510,7 @@ struct moving_platform : public entity { string get_help() override { return "Moving platforms move."; } bool nonstatic() override { return false; } virtual void jumped_on() {} + virtual void affected_others_vel(entity *who, xy v) {} }; struct freemoving_platform : public moving_platform { @@ -519,6 +524,19 @@ struct freemoving_platform : public moving_platform { } }; +struct basic_box : public freemoving_platform { + virtual int width() { return 1; } + xy siz() override { return {20, 20}; } + void act() override; + string glyph() override { return "#"; } + color_t color() override { return 0xFFFFC0FF; } + string get_name() override { return "basic box"; } + /* copied from located_entity */ + xy respawn; + xy default_where() override { return respawn; } + void affected_others_vel(entity *who, xy v) override; + }; + struct floating_bubble_platform : public freemoving_platform { virtual int width() { return 1; } xy siz() override { return {6.*width(), 6}; } diff --git a/rogueviz/ru/entity.cpp b/rogueviz/ru/entity.cpp index b598b69b..d121a532 100644 --- a/rogueviz/ru/entity.cpp +++ b/rogueviz/ru/entity.cpp @@ -256,6 +256,7 @@ void entity::apply_walls() { } if(loopcount < 100) for(auto& e: current_room->entities) if(auto p = e->as_platform()) { + if(p == this) continue; auto opw = p->location_at(gframeid-1); auto npw = p->location_at(gframeid); @@ -299,12 +300,15 @@ void entity::apply_walls() { } else { - rvel.x = -rvel.x; + rvel.x = 0; // -rvel.x; reset = true; - zero_vel = zvel; + if(!on_floor) zero_vel = zvel; } + auto vel0 = vel; vel = (rmow + rvel - screen_ctr) * get_scale_at(npw.y) + npw - where; + p->affected_others_vel(this, vel - vel0); + if(reset) goto again; } } @@ -388,6 +392,17 @@ void entity::kino() { gvel = ndelta * gvel + delta * (where - gwhere); } +void entity::apply_walking(ld target_velx) { + if(on_floor || get_jump_control() || wallhug) { + if(on_ice == 0) { + vel.x = target_velx; + } + if(on_ice == 1) { + vel.x = lerp(vel.x, target_velx, 10. / game_fps); + } + } + } + void missile::act() { kino(); if(where.x > screen_x || where.x < 0 || where.y < 0 || where.y > screen_y) destroyed = true; @@ -1241,6 +1256,21 @@ void fight_trader::attacked(int dmg, power *p) { else trader::attacked(dmg, p); } +void basic_box::act() { + if(position_time == gframeid) return; + last_position = where; + position_time = gframeid; + stay_on_screen(); + kino(); + + apply_walking(lerp(vel.x, zero_vel.x, 5. / game_fps)); + } + +void basic_box::affected_others_vel(entity *who, xy v) { + if(who->as_platform()) vel -= v; + else vel -= v * .1; + } + void fight_trader::act() { if(!angered) { trader::act(); return; } if(stay_on_screen()) dir = -dir; diff --git a/rogueviz/ru/load-world.cpp b/rogueviz/ru/load-world.cpp index 9623cc19..f2f0dffc 100644 --- a/rogueviz/ru/load-world.cpp +++ b/rogueviz/ru/load-world.cpp @@ -331,6 +331,11 @@ void load_room(fhstream& f, cell *c) { b->respawn_dir = get_int(); r.entities.emplace_back(std::move(b)); } + else if(cap == "BOX") { + auto b = std::make_unique(); nam(*b); + b->respawn = get_xy(); + r.entities.emplace_back(std::move(b)); + } else if(cap == "NAGA") { auto b = std::make_unique(); nam(*b); b->respawn = get_xy(); diff --git a/rogueviz/ru/man.cpp b/rogueviz/ru/man.cpp index 96ef174f..9f1a2a0b 100644 --- a/rogueviz/ru/man.cpp +++ b/rogueviz/ru/man.cpp @@ -154,14 +154,7 @@ void man::act() { if(next.hallucinating && !current.hallucinating) prepare_hallucination(); - if(on_floor || current.jump_control || wallhug) { - if(on_ice == 0) { - vel.x = zero_vel.x + dat.dx * dat.d * dat.modv * 2.5; - } - if(on_ice == 1) { - vel.x = lerp(vel.x, zero_vel.x + dat.dx * dat.d * dat.modv * 2.5, 10. / game_fps); - } - } + apply_walking(zero_vel.x + dat.dx * dat.d * dat.modv * 2.5); if(on_bounce) { vel.x += dat.dx * dat.d * dat.modv * 0.02; diff --git a/rogueviz/ru/map.ru b/rogueviz/ru/map.ru index d3f45c96..2ccc0750 100644 --- a/rogueviz/ru/map.ru +++ b/rogueviz/ru/map.ru @@ -3716,3 +3716,54 @@ MAP #b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b OK +MOVE 0 Slope Slop Shop +ROOM Ballbox Test +# wall +. air +MAP +################################################################################ +################################################################################ +################################################################################ +################################################################################ +####........................................................................#### +####........................................................................#### +####........................................................................#### +####........................................................................#### +####........................................................................#### +####........................................................................#### +####........................................................................#### +####........................................................................#### +####........................................................................#### +####........................................................................#### +####........................................................................#### +####........................................................................#### +####........................................................................#### +####........................................................................#### +####........................................................................#### +####........................................................................#### +####........................................................................#### +####........................................................................#### +####........................................................................#### +####........................................................................#### +####........................................................................#### +####........................................................................#### +####........................................................................#### +####........................................................................#### +####........................................................................#### +####........................................................................#### +####........................................................................#### +####........................................................................#### +####........................................................................#### +####........................................................................#### +################################################################################ +#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b +################################################################################ +#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b +################################################################################ +#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b +BOX B1 200 100 +BOX B2 210 150 +BOX B3 220 200 +BOX B4 230 250 +OK +