1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2025-07-17 16:32:50 +00:00

ru:: spikes work as intended

This commit is contained in:
Zeno Rogue 2025-04-27 12:00:22 +02:00
parent 094a5a5f24
commit df3ae7b584
4 changed files with 40 additions and 6 deletions

View File

@ -116,6 +116,11 @@ struct entity {
double gwhere_x, gwhere_y;
double gvel_x, gvel_y;
int hp;
int invinc_end;
virtual int max_hp() { return 100; }
bool visible(room *r);
void clearg() {
@ -134,6 +139,10 @@ struct entity {
clearg();
};
void postfix() {
hp = max_hp();
}
struct bbox get_pixel_bbox_at(double x, double y);
struct bbox get_pixel_bbox() { return get_pixel_bbox_at(where_x, where_y); }
@ -155,6 +164,20 @@ struct entity {
virtual string glyph() = 0;
virtual color_t color() = 0;
virtual bool hurt_by_spikes() { return false; }
bool visible_inv() {
return (invinc_end < gframeid || (invinc_end - gframeid) % 50 < 25);
}
virtual bool reduce_hp(int x) {
if(gframeid < invinc_end) return false;
hp -= x;
if(hp < 0) destroyed = true;
invinc_end = gframeid + 150;
return true;
}
};
struct man : public entity {
@ -168,13 +191,14 @@ struct man : public entity {
int last_action;
man() { facing = 1; attack_facing = 1; }
man() { facing = 1; attack_facing = 1; postfix(); }
double sx() override { return 12; }
double sy() override { return 12; }
string glyph() override { return hallucinating ? "f" : "@"; }
color_t color() override { return hallucinating ? 0x808080FF : 0xFF8080FF; }
void act() override;
void draw() override;
virtual bool hurt_by_spikes() { return true; }
};
extern man m;

View File

@ -1,7 +1,5 @@
namespace rogue_unlike {
int gframeid = 0;
man m;
bbox entity::get_pixel_bbox_at(double x, double y) {
@ -50,6 +48,13 @@ void entity::kino() {
flagtype blocking = (vel_y < 0 || fallthru) ? W_BLOCK : (W_BLOCK | W_PLATFORM);
auto pain_effect = [&] {
if(!hurt_by_spikes()) return false;
reduce_hp(10);
vel_x = -vel_x; vel_y = -vel_y; apply_grav();
return true;
};
for(int x = obb.minx; x < obb.maxx; x++) for(int y = obb.maxy; y < jbb.maxy; y++) {
eWall b = current_room->at(x, y);
if(walls[b].flags & blocking) {
@ -65,6 +70,7 @@ void entity::kino() {
if(pixel_to_block(get_pixel_bbox_at(where_x + vel_x, where_y + vel_y)).maxy <= y) where_y += vel_y;
goto again;
}
if((walls[b].flags & W_PAIN) && pain_effect()) goto again;
}
for(int x = obb.minx; x < obb.maxx; x++) for(int y = jbb.miny; y < obb.miny; y++) {
@ -75,6 +81,7 @@ void entity::kino() {
if(pixel_to_block(get_pixel_bbox_at(where_x + vel_x, where_y + vel_y)).miny > y) where_y += vel_y;
goto again;
}
if((walls[b].flags & W_PAIN) && pain_effect()) goto again;
}
if(!fallthru) for(int x = nbb.minx; x < nbb.maxx; x++) for(int y = jbb.maxy-1; y < jbb.maxy; y++) {
@ -97,6 +104,7 @@ void entity::kino() {
wallhug = true;
goto again;
}
if((walls[b].flags & W_PAIN) && pain_effect()) goto again;
}
for(int x = jbb.minx; x < obb.minx; x++) for(int y = jbb.miny; y < jbb.maxy; y++) {
@ -111,6 +119,7 @@ void entity::kino() {
wallhug = true;
goto again;
}
if((walls[b].flags & W_PAIN) && pain_effect()) goto again;
}
int bx0 = floor(where_x / block_x);

View File

@ -34,6 +34,7 @@ constexpr int actual_screen_x = r_margin_at - l_margin_at;
constexpr int actual_screen_y = b_margin_at - t_margin_at;
int game_fps = 300;
int gframeid = 0;
bool bottom = 1;
constexpr auto yctr = (t_margin_at + b_margin_at) / 2.;
@ -67,7 +68,7 @@ ruwall walls[qwall] = {
{"air", ".", 0x40404080, W_TRANS},
{"wall", "#", 0xFFFFFFFF, W_BLOCK},
{"bouncy wall", "#", 0x80FF80FF, W_BLOCK | W_BOUNCY},
{"spike", "^", 0xC08080FF, W_BLOCK | W_TRANS},
{"spike", "^", 0xC08080FF, W_TRANS | W_PAIN},
{"water", "~", 0x0000FFFF, W_BLOCK | W_TRANS},
{"frozen water", "#", 0xC0C0FFFF, W_BLOCK | W_FROZEN},
{"door", "+", 0xC06000FF, W_BLOCK},

View File

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