1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2025-06-25 06:32:52 +00:00

ru:: existing flag for entities, to handle magic fountains in the future

This commit is contained in:
Zeno Rogue 2025-05-03 17:31:52 +02:00
parent 877660deb8
commit 7867902f82
4 changed files with 15 additions and 5 deletions

View File

@ -134,6 +134,7 @@ struct xy {
struct entity {
virtual xy siz() = 0;
xy where, vel;
bool existing;
xy dsiz() { return get_scale() * siz(); }
@ -157,6 +158,7 @@ struct entity {
entity() {
where = xy(screen_x / 2., screen_y / 2.);
vel = xy(0, 0);
existing = true;
destroyed = false; invinc_end = -1;
clearg();
};
@ -197,10 +199,14 @@ struct entity {
return (invinc_end < gframeid || (invinc_end - gframeid) % 50 < 25);
}
virtual void on_kill() {
existing = false;
}
virtual bool reduce_hp(int x) {
if(gframeid < invinc_end) return false;
hp -= x;
if(hp < 0) destroyed = true;
if(hp < 0) on_kill();
invinc_end = gframeid + 150;
return true;
}
@ -256,12 +262,15 @@ struct npc : public entity {
};
struct boar : public entity {
xy respawn;
int num_kills;
xy siz() override { return {18, 18}; }
string glyph() override { return "B"; }
color_t color() override { return 0x804000FF; }
void act() override;
boar() { postfix(); }
boar() { num_kills = 0; postfix(); }
void attacked(int s) override;
void on_kill() override { entity::on_kill(); num_kills++; }
};
struct hint : public entity {
@ -285,7 +294,7 @@ struct item : public entity {
if(intersect(get_pixel_bbox(), m.get_pixel_bbox())) {
addMessage(pickup_message);
powers[id].picked_up(qty);
destroyed = true;
existing = false;
}
}
};

View File

@ -250,7 +250,7 @@ void render_room_objects(room *r) {
initquickqueue();
if(r == current_room && m.visible_inv()) m.draw();
for(auto& e: r->entities)
if(e->visible(r) && e->visible_inv())
if(e->existing && e->visible(r) && e->visible_inv())
e->draw();
quickqueue();
}

View File

@ -99,7 +99,7 @@ void playing_frame() {
auto& ents = current_room->entities;
for(auto& e: ents) e->act();
for(auto& e: ents) if(e->existing) e->act();
auto mb = ents.begin();
for(auto& e: ents) if(!e->destroyed) *(mb++) = std::move(e);

View File

@ -131,6 +131,7 @@ void load_room(fhstream& f, cell *c) {
else if(cap == "BOAR") {
auto b = std::make_unique<boar>();
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 == "FERRIS") {