From 24222a41a5a526dd62ef3ce3dd610f780be19bc5 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sun, 4 May 2025 10:34:02 +0200 Subject: [PATCH] ru:: bats --- rogueviz/ru/classes.cpp | 11 +++++++++++ rogueviz/ru/entity.cpp | 30 ++++++++++++++++++++++++++++++ rogueviz/ru/map.ru | 15 +++++++++++++++ rogueviz/ru/save.cpp | 6 ++++++ 4 files changed, 62 insertions(+) diff --git a/rogueviz/ru/classes.cpp b/rogueviz/ru/classes.cpp index e83825d6..e98b56c3 100644 --- a/rogueviz/ru/classes.cpp +++ b/rogueviz/ru/classes.cpp @@ -325,6 +325,17 @@ struct kestrel : public enemy { string get_help() override { return "A standard dungeon kestrel."; } }; +struct bat : public enemy { + int next_change; + xy siz() override { return {6, 6}; } + string glyph() override { return "B"; } + color_t color() override { return 0xD0A0A0FF; } + void act() override; + void attacked(int s) override; + string get_name() override { return "bat"; } + string get_help() override { return "A cave bat."; } + }; + struct hint : public entity { string hint_text; int state; diff --git a/rogueviz/ru/entity.cpp b/rogueviz/ru/entity.cpp index 1264e773..b3a3a663 100644 --- a/rogueviz/ru/entity.cpp +++ b/rogueviz/ru/entity.cpp @@ -394,6 +394,26 @@ void kestrel::act() { } } +void bat::act() { + if(gframeid >= next_change && gframeid > invinc_end + 300) { + next_change = gframeid + 300 + rand() % 300; + int angle = rand() % 360; + + auto dat = get_dat(); + ld v = dat.d * dat.modv; + + vel.x = v * cos(angle); + vel.y = v * sin(angle); + } + + apply_walls_reflect(); + apply_vel(); + + if(intersect(get_pixel_bbox(), m.get_pixel_bbox())) { + if(m.reduce_hp(15)) addMessage("The bat bites you!"); + } + } + void kestrel::attacked(int dmg) { current_target = this; reduce_hp(dmg); @@ -402,4 +422,14 @@ void kestrel::attacked(int dmg) { if(where.x > m.where.x) vel.x = +abs(vel.x); } +void bat::attacked(int dmg) { + current_target = this; + reduce_hp(dmg); + if(!existing) addMessage("You kill the bat."); else addMessage("You hit the bat."); + if(where.x < m.where.x) vel.x = -abs(vel.x); + if(where.x > m.where.x) vel.x = +abs(vel.x); + if(where.y < m.where.y) vel.y = -abs(vel.y); + if(where.y > m.where.y) vel.y = +abs(vel.y); + } + } diff --git a/rogueviz/ru/map.ru b/rogueviz/ru/map.ru index 1dfc7dc1..f83acd1d 100644 --- a/rogueviz/ru/map.ru +++ b/rogueviz/ru/map.ru @@ -1166,4 +1166,19 @@ 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 +BAT 100 100 +BAT 200 100 +BAT 300 100 +BAT 400 100 +BAT 500 100 +BAT 100 160 +BAT 200 160 +BAT 300 160 +BAT 400 160 +BAT 500 160 +BAT 100 220 +BAT 200 220 +BAT 300 220 +BAT 400 220 +BAT 500 220 OK diff --git a/rogueviz/ru/save.cpp b/rogueviz/ru/save.cpp index 71655785..b9fb9c3f 100644 --- a/rogueviz/ru/save.cpp +++ b/rogueviz/ru/save.cpp @@ -134,6 +134,12 @@ void load_room(fhstream& f, cell *c) { b->respawn = b->where; r.entities.emplace_back(std::move(b)); } + else if(cap == "BAT") { + auto b = std::make_unique(); + sscanf(param.c_str(), "%lf%lf", &b->where.x, &b->where.y); + b->respawn = b->where; + r.entities.emplace_back(std::move(b)); + } else if(cap == "KESTREL") { auto b = std::make_unique(); sscanf(param.c_str(), "%lf%lf%lf%lf", &b->where.x, &b->where.y, &b->vel.x, &b->vel.y);