From 38c64002ddef5012aa919bfe6f537568d00deee8 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Mon, 5 May 2025 18:05:32 +0200 Subject: [PATCH] ru:: enemies stay on screen --- rogueviz/ru/classes.cpp | 1 + rogueviz/ru/entity.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/rogueviz/ru/classes.cpp b/rogueviz/ru/classes.cpp index 8777ea0b..0efaa9a8 100644 --- a/rogueviz/ru/classes.cpp +++ b/rogueviz/ru/classes.cpp @@ -202,6 +202,7 @@ struct entity { void apply_walls_reflect(); void apply_grav(); void apply_portal_grav(); + void stay_on_screen(); virtual void act() { kino(); } double get_scale() { return get_scale_at(where.y); } diff --git a/rogueviz/ru/entity.cpp b/rogueviz/ru/entity.cpp index d1d7dffc..9471d8d6 100644 --- a/rogueviz/ru/entity.cpp +++ b/rogueviz/ru/entity.cpp @@ -206,6 +206,13 @@ void entity::apply_walls() { } } +void entity::stay_on_screen() { + if(where.x < l_margin_at && vel.x < 0) vel.x = -vel.x; + if(where.x > r_margin_at && vel.x > 0) vel.x = -vel.x; + if(where.y < t_margin_at && vel.y < 0) vel.y = -vel.y; + if(where.y > b_margin_at && vel.y > 0) vel.y = -vel.y; + } + void entity::kino() { on_floor = false; on_ice = false; @@ -251,6 +258,7 @@ void npc::act() { } void boar::act() { + stay_on_screen(); kino(); if(intersect(get_pixel_bbox(), m.get_pixel_bbox())) { int s = where.x < m.where.x ? -1 : 1; @@ -281,6 +289,7 @@ void boar::attacked(int dmg) { } void snake::act() { + stay_on_screen(); kino(); if(abs(vel.x) < 1e-6) { auto dat = get_dat(); @@ -378,6 +387,7 @@ void entity::apply_walls_reflect() { } void kestrel::act() { + stay_on_screen(); apply_walls_reflect(); apply_vel(); @@ -398,6 +408,7 @@ void bat::act() { vel.y = v * sin(angle); } + stay_on_screen(); apply_walls_reflect(); apply_vel();