From 63bbb2f09807eedfe50d808287bc7bec415d78ea Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sat, 3 May 2025 00:24:30 +0200 Subject: [PATCH] moving platforms v0 --- rogueviz/ru/classes.cpp | 17 +++++++++ rogueviz/ru/entity.cpp | 37 ++++++++++++++++++++ rogueviz/ru/globals.cpp | 1 + rogueviz/ru/man.cpp | 2 +- rogueviz/ru/map.ru | 76 +++++++++++++++++++++++++++++++++-------- rogueviz/ru/powers.cpp | 2 +- rogueviz/ru/save.cpp | 11 ++++++ 7 files changed, 130 insertions(+), 16 deletions(-) diff --git a/rogueviz/ru/classes.cpp b/rogueviz/ru/classes.cpp index b7695c9e..5295e3ab 100644 --- a/rogueviz/ru/classes.cpp +++ b/rogueviz/ru/classes.cpp @@ -138,6 +138,7 @@ struct entity { xy dsiz() { return get_scale() * siz(); } xy gwhere, gvel; + xy zero_vel; /* relative to the platform */ virtual struct moving_platform* as_platform() { return nullptr; } @@ -227,6 +228,22 @@ struct man : public entity { extern man m; +struct moving_platform : public entity { + xy ctr; + ld radius, shift; + xy siz() override { return {36, 12}; } + string glyph() override { return "#"; } + color_t color() override { return 0xFFFFFFFF; } + virtual xy location_at(ld t) = 0; + void draw() override; + void act() override; + virtual moving_platform* as_platform() { return this; } + }; + +struct ferris_platform : public moving_platform { + xy location_at(ld t) override; + }; + struct npc : public entity { string sglyph, name; color_t col; diff --git a/rogueviz/ru/entity.cpp b/rogueviz/ru/entity.cpp index 9e7fd581..eabbd8e9 100644 --- a/rogueviz/ru/entity.cpp +++ b/rogueviz/ru/entity.cpp @@ -42,6 +42,7 @@ void entity::kino() { on_ice = false; wallhug = false; on_bounce = false; + zero_vel = xy(0, 0); // ld modv = 60. / game_fps; @@ -127,6 +128,22 @@ void entity::kino() { } if((walls[b].flags & W_PAIN) && pain_effect()) goto again; } + + for(auto& e: current_room->entities) if(e->as_platform() && intersect(e->get_pixel_bbox(), get_pixel_bbox())) { + auto p = e->as_platform(); + auto oldpos = p->location_at(gframeid-1); + auto newpos = p->location_at(gframeid-0); + auto oldscale = get_scale_at(oldpos.y); + auto newscale = get_scale_at(newpos.y); + auto new_where = (where - oldpos) / oldscale * newscale + newpos; + zero_vel = new_where - where; + vel.y -= zero_vel.y; + bool err = vel.y == 0; + if(abs(vel.y) < 1e-6) vel.y = 0; else vel.y /= 2; + vel.y += zero_vel.y; + on_floor = true; + if(!err) goto again; + } int bx0 = floor(where.x / block_x); int by0 = floor(where.y / block_y); @@ -243,4 +260,24 @@ void hint::act() { state = cur; } +xy ferris_platform::location_at(ld t) { + return from_hyper(rgpushxto0(to_hyper(ctr)) * xspinpush0(t / game_fps + shift, radius)); + } + +void moving_platform::draw() { + double d = get_scale(); + for(int w=-1; w<=1; w++) { + ld minx = where.x + siz().x * d * (w - 0.5) / 3; + ld miny = where.y - siz().y * d / 2; + ld maxx = where.x + siz().x * d * (w + 0.5) / 3; + ld maxy = where.y + siz().y * d / 2; + asciiletter(minx, miny, maxx, maxy, "#", 0xFFFFFFFF); + } + } + +void moving_platform::act() { + where = location_at(gframeid); + } + + } diff --git a/rogueviz/ru/globals.cpp b/rogueviz/ru/globals.cpp index ed2b999e..22641fca 100644 --- a/rogueviz/ru/globals.cpp +++ b/rogueviz/ru/globals.cpp @@ -140,5 +140,6 @@ void sync_map(); void render_room_objects(room *r); +void asciiletter(ld minx, ld miny, ld maxx, ld maxy, const string& ch, color_t col); } diff --git a/rogueviz/ru/man.cpp b/rogueviz/ru/man.cpp index 9fd47a39..aac443f3 100644 --- a/rogueviz/ru/man.cpp +++ b/rogueviz/ru/man.cpp @@ -17,7 +17,7 @@ void man::act() { handle_powers(dat); if((on_floor || jump_control || wallhug) && !on_ice) { - vel.x = zero_speed + dat.dx * dat.d * dat.modv * 2.5; + vel.x = zero_vel.x + dat.dx * dat.d * dat.modv * 2.5; } if(on_bounce) { diff --git a/rogueviz/ru/map.ru b/rogueviz/ru/map.ru index f9c8581a..cd9a6d53 100644 --- a/rogueviz/ru/map.ru +++ b/rogueviz/ru/map.ru @@ -1015,20 +1015,20 @@ MAP #####################################################################........... #####################################################################........... #####################################################################........... -#####################################################################........... -#####################################################################........... -####################################################################+........... -####################################################################+........... -######################################################################.......... -#############################################################################... -################################################################################ -################################################################################ -################################################################################ -################################################################################ -################################################################################ -################################################################################ -################################################################################ -################################################################################ +.####################################################################........... +.####################################################################........... +....................................................................+........... +....................................................................+........... +..####################################################################.......... +...##########################################################################... +...############################################################################# +...############################################################################# +..############################################################################## +..############################################################################## +..############################################################################## +..############################################################################## +.############################################################################### +.############################################################################### ################################################################################ ################################################################################ ################################################################################ @@ -1043,3 +1043,51 @@ 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 2 Central Cavern Bottom Left +ROOM Ferris Wheel +# 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 +FERRIS 320 140 0.277 8 +OK diff --git a/rogueviz/ru/powers.cpp b/rogueviz/ru/powers.cpp index 37aefa02..b2726c00 100644 --- a/rogueviz/ru/powers.cpp +++ b/rogueviz/ru/powers.cpp @@ -88,7 +88,7 @@ void gen_powers() { if(d.keystate & 1) { bool can_jump = m.on_floor; if(gframeid <= m.on_floor_when + m.coyote_time) can_jump = true; - if(can_jump) m.vel.y = -(non_hyperbolic ? 3 : 5) * d.d * d.modv, m.on_floor_when = -1000; + if(can_jump) m.vel.y = m.zero_vel.y-(non_hyperbolic ? 3 : 5) * d.d * d.modv, m.on_floor_when = -1000; } } ).is_starting(), diff --git a/rogueviz/ru/save.cpp b/rogueviz/ru/save.cpp index 90edb8ac..072f92b5 100644 --- a/rogueviz/ru/save.cpp +++ b/rogueviz/ru/save.cpp @@ -133,6 +133,17 @@ void load_room(fhstream& f, cell *c) { sscanf(param.c_str(), "%lf%lf", &b->where.x, &b->where.y); r.entities.emplace_back(std::move(b)); } + else if(cap == "FERRIS") { + ld cx, cy, radius; int qty; + sscanf(param.c_str(), "%lf%lf%lf%d", &cx, &cy, &radius, &qty); + + for(int i=0; i(); + b->ctr = {cx, cy}; b->radius = radius; + b->shift = i * TAU / qty; + r.entities.emplace_back(std::move(b)); + } + } else if(cap == "HINT") { auto b = std::make_unique(); sscanf(param.c_str(), "%lf%lf%lf%lf", &b->where.x, &b->where.y, &b->size.x, &b->size.y);