1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2025-06-26 15:12:48 +00:00

ru:: enemies stay on screen

This commit is contained in:
Zeno Rogue 2025-05-05 18:05:32 +02:00
parent 3790269e79
commit 38c64002dd
2 changed files with 12 additions and 0 deletions

View File

@ -202,6 +202,7 @@ struct entity {
void apply_walls_reflect(); void apply_walls_reflect();
void apply_grav(); void apply_grav();
void apply_portal_grav(); void apply_portal_grav();
void stay_on_screen();
virtual void act() { kino(); } virtual void act() { kino(); }
double get_scale() { return get_scale_at(where.y); } double get_scale() { return get_scale_at(where.y); }

View File

@ -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() { void entity::kino() {
on_floor = false; on_floor = false;
on_ice = false; on_ice = false;
@ -251,6 +258,7 @@ void npc::act() {
} }
void boar::act() { void boar::act() {
stay_on_screen();
kino(); kino();
if(intersect(get_pixel_bbox(), m.get_pixel_bbox())) { if(intersect(get_pixel_bbox(), m.get_pixel_bbox())) {
int s = where.x < m.where.x ? -1 : 1; int s = where.x < m.where.x ? -1 : 1;
@ -281,6 +289,7 @@ void boar::attacked(int dmg) {
} }
void snake::act() { void snake::act() {
stay_on_screen();
kino(); kino();
if(abs(vel.x) < 1e-6) { if(abs(vel.x) < 1e-6) {
auto dat = get_dat(); auto dat = get_dat();
@ -378,6 +387,7 @@ void entity::apply_walls_reflect() {
} }
void kestrel::act() { void kestrel::act() {
stay_on_screen();
apply_walls_reflect(); apply_walls_reflect();
apply_vel(); apply_vel();
@ -398,6 +408,7 @@ void bat::act() {
vel.y = v * sin(angle); vel.y = v * sin(angle);
} }
stay_on_screen();
apply_walls_reflect(); apply_walls_reflect();
apply_vel(); apply_vel();