mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-06-26 07:02:49 +00:00
ru:: existing flag for entities, to handle magic fountains in the future
This commit is contained in:
parent
877660deb8
commit
7867902f82
@ -134,6 +134,7 @@ struct xy {
|
|||||||
struct entity {
|
struct entity {
|
||||||
virtual xy siz() = 0;
|
virtual xy siz() = 0;
|
||||||
xy where, vel;
|
xy where, vel;
|
||||||
|
bool existing;
|
||||||
|
|
||||||
xy dsiz() { return get_scale() * siz(); }
|
xy dsiz() { return get_scale() * siz(); }
|
||||||
|
|
||||||
@ -157,6 +158,7 @@ struct entity {
|
|||||||
entity() {
|
entity() {
|
||||||
where = xy(screen_x / 2., screen_y / 2.);
|
where = xy(screen_x / 2., screen_y / 2.);
|
||||||
vel = xy(0, 0);
|
vel = xy(0, 0);
|
||||||
|
existing = true;
|
||||||
destroyed = false; invinc_end = -1;
|
destroyed = false; invinc_end = -1;
|
||||||
clearg();
|
clearg();
|
||||||
};
|
};
|
||||||
@ -197,10 +199,14 @@ struct entity {
|
|||||||
return (invinc_end < gframeid || (invinc_end - gframeid) % 50 < 25);
|
return (invinc_end < gframeid || (invinc_end - gframeid) % 50 < 25);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual void on_kill() {
|
||||||
|
existing = false;
|
||||||
|
}
|
||||||
|
|
||||||
virtual bool reduce_hp(int x) {
|
virtual bool reduce_hp(int x) {
|
||||||
if(gframeid < invinc_end) return false;
|
if(gframeid < invinc_end) return false;
|
||||||
hp -= x;
|
hp -= x;
|
||||||
if(hp < 0) destroyed = true;
|
if(hp < 0) on_kill();
|
||||||
invinc_end = gframeid + 150;
|
invinc_end = gframeid + 150;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -256,12 +262,15 @@ struct npc : public entity {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct boar : public entity {
|
struct boar : public entity {
|
||||||
|
xy respawn;
|
||||||
|
int num_kills;
|
||||||
xy siz() override { return {18, 18}; }
|
xy siz() override { return {18, 18}; }
|
||||||
string glyph() override { return "B"; }
|
string glyph() override { return "B"; }
|
||||||
color_t color() override { return 0x804000FF; }
|
color_t color() override { return 0x804000FF; }
|
||||||
void act() override;
|
void act() override;
|
||||||
boar() { postfix(); }
|
boar() { num_kills = 0; postfix(); }
|
||||||
void attacked(int s) override;
|
void attacked(int s) override;
|
||||||
|
void on_kill() override { entity::on_kill(); num_kills++; }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct hint : public entity {
|
struct hint : public entity {
|
||||||
@ -285,7 +294,7 @@ struct item : public entity {
|
|||||||
if(intersect(get_pixel_bbox(), m.get_pixel_bbox())) {
|
if(intersect(get_pixel_bbox(), m.get_pixel_bbox())) {
|
||||||
addMessage(pickup_message);
|
addMessage(pickup_message);
|
||||||
powers[id].picked_up(qty);
|
powers[id].picked_up(qty);
|
||||||
destroyed = true;
|
existing = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -250,7 +250,7 @@ void render_room_objects(room *r) {
|
|||||||
initquickqueue();
|
initquickqueue();
|
||||||
if(r == current_room && m.visible_inv()) m.draw();
|
if(r == current_room && m.visible_inv()) m.draw();
|
||||||
for(auto& e: r->entities)
|
for(auto& e: r->entities)
|
||||||
if(e->visible(r) && e->visible_inv())
|
if(e->existing && e->visible(r) && e->visible_inv())
|
||||||
e->draw();
|
e->draw();
|
||||||
quickqueue();
|
quickqueue();
|
||||||
}
|
}
|
||||||
|
@ -99,7 +99,7 @@ void playing_frame() {
|
|||||||
|
|
||||||
auto& ents = current_room->entities;
|
auto& ents = current_room->entities;
|
||||||
|
|
||||||
for(auto& e: ents) e->act();
|
for(auto& e: ents) if(e->existing) e->act();
|
||||||
|
|
||||||
auto mb = ents.begin();
|
auto mb = ents.begin();
|
||||||
for(auto& e: ents) if(!e->destroyed) *(mb++) = std::move(e);
|
for(auto& e: ents) if(!e->destroyed) *(mb++) = std::move(e);
|
||||||
|
@ -131,6 +131,7 @@ void load_room(fhstream& f, cell *c) {
|
|||||||
else if(cap == "BOAR") {
|
else if(cap == "BOAR") {
|
||||||
auto b = std::make_unique<boar>();
|
auto b = std::make_unique<boar>();
|
||||||
sscanf(param.c_str(), "%lf%lf", &b->where.x, &b->where.y);
|
sscanf(param.c_str(), "%lf%lf", &b->where.x, &b->where.y);
|
||||||
|
b->respawn = b->where;
|
||||||
r.entities.emplace_back(std::move(b));
|
r.entities.emplace_back(std::move(b));
|
||||||
}
|
}
|
||||||
else if(cap == "FERRIS") {
|
else if(cap == "FERRIS") {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user