From b9230bd662b3aeda60ef5fb038bbbea6471dc30d Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sat, 3 May 2025 22:09:30 +0200 Subject: [PATCH] ru:: pendulum platforms --- rogueviz/ru/classes.cpp | 10 +++++ rogueviz/ru/entity.cpp | 8 ++++ rogueviz/ru/map.ru | 95 ++++++++++++++++++++++++++++++++--------- rogueviz/ru/save.cpp | 5 +++ 4 files changed, 98 insertions(+), 20 deletions(-) diff --git a/rogueviz/ru/classes.cpp b/rogueviz/ru/classes.cpp index 780ce3ed..f350281b 100644 --- a/rogueviz/ru/classes.cpp +++ b/rogueviz/ru/classes.cpp @@ -257,6 +257,16 @@ struct moving_platform : public entity { struct ferris_platform : public moving_platform { xy location_at(ld t) override; + string get_name() override { return "Ferris platform"; } + string get_help() override { return "Ferris wheel platforms, powered by some ancient mechanism. They always go in perfect circles, with constant velocity."; } + }; + +struct pendulum_platform : public moving_platform { + xy a, b; + ld period, shift; + xy location_at(ld t) override; + string get_name() override { return "pendulum platform"; } + string get_help() override { return "These pendulum platforms go back and forth between two locations, taking the shortest path possible."; } }; struct npc : public entity { diff --git a/rogueviz/ru/entity.cpp b/rogueviz/ru/entity.cpp index 3960b115..8b4a458b 100644 --- a/rogueviz/ru/entity.cpp +++ b/rogueviz/ru/entity.cpp @@ -296,6 +296,14 @@ xy ferris_platform::location_at(ld t) { return from_hyper(rgpushxto0(to_hyper(ctr)) * xspinpush0(t / game_fps + shift, radius)); } +xy pendulum_platform::location_at(ld t) { + auto h1 = to_hyper(a); + auto h2 = to_hyper(b); + auto d = hdist(h1, h2); + auto x = (1 - cos(t / game_fps * TAU / period)) / 2 * d; + return from_hyper(rgpushxto0(h1) * rspintox(gpushxto0(h1) * h2) * xpush0(x)); + } + void moving_platform::draw() { double d = get_scale(); for(int w=-1; w<=1; w++) { diff --git a/rogueviz/ru/map.ru b/rogueviz/ru/map.ru index 75490f1c..48e6c5cc 100644 --- a/rogueviz/ru/map.ru +++ b/rogueviz/ru/map.ru @@ -1048,6 +1048,7 @@ MOVE 2 Central Cavern Bottom Left ROOM Ferris Wheel # wall . air +- staircase ^ spike MAP ################################################################################ @@ -1058,30 +1059,30 @@ MAP #########.#b#b......................................................###b#b###### ########....####..................................................######...##### #######.....#b#b#####.............................................#b#b.....##### -######.......................................................######........##### -#####......................................................................##### -####........................................................................#### -####........................................................................#### -###.........................................................................#### -###..........................................................................### -##...........................................................................### -##.............................................................................. +.#####.......................................................######........##### +.####......................................................................##### +.###........................................................................#### +.##.........................................................................#### +.#..........................................................................#### +.............................................................................### +.............................................................................### ................................................................................ ................................................................................ ................................................................................ ................................................................................ -####################^......................................^#################### -####################........................................#################### -####################........................................#################### -####################........................................#################### -####################........................................#################### -###########...........................................................########## -###########...........................................................########## -###########...........................................................########## -###########...........................................................########## -####################........................................#################### -####################........................................#################### -####################........................................#################### +................................................................................ +...........-########^......................................^#################### +..........-#########........................................#################### +.........-##########........................................#################### +........-###########........................................#################### +.......-############........................................#################### +......-####...........................................................########## +.....-#####...........................................................########## +....-######...........................................................########## +...-#######...........................................................########## +..-#################........................................#################### +.-##################........................................#################### +-###################........................................#################### ####################........................................#################### ####################........................................#################### ####################........................................#################### @@ -1104,3 +1105,57 @@ ITEM 542 211 8 gold You find some more gold. OK + +MOVE 2 Ferris Wheel +ROOM Platform Fest +# wall +- staircase +. air +^ spike +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 +PENDULUM 63 264 90 200 5 0 +PENDULUM 200 208 303 235 6 0 +PENDULUM 344 229 513 231 5 0 +PENDULUM 551 215 554 70 6 0 +PENDULUM 510 60 60 60 5 0 +OK diff --git a/rogueviz/ru/save.cpp b/rogueviz/ru/save.cpp index f3b674ef..3f735e8a 100644 --- a/rogueviz/ru/save.cpp +++ b/rogueviz/ru/save.cpp @@ -145,6 +145,11 @@ void load_room(fhstream& f, cell *c) { r.entities.emplace_back(std::move(b)); } } + else if(cap == "PENDULUM") { + auto b = std::make_unique(); + sscanf(param.c_str(), "%lf%lf%lf%lf%lf%lf", &b->a.x, &b->a.y, &b->b.x, &b->b.y, &b->period, &b->shift); + 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);