mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2025-07-22 10:52:49 +00:00
ru:: using struct xy instead of ld pair
This commit is contained in:
parent
4ff77aa64e
commit
49257338ee
@ -114,37 +114,48 @@ struct room {
|
||||
void create_texture();
|
||||
};
|
||||
|
||||
struct xy {
|
||||
ld x, y;
|
||||
xy() {}
|
||||
xy(ld x, ld y) : x(x), y(y) {}
|
||||
xy operator + (xy b) { return xy(x+b.x, y+b.y); }
|
||||
xy operator - (xy b) { return xy(x-b.x, y-b.y); }
|
||||
xy operator * (ld s) { return xy(x*s, y*s); }
|
||||
xy operator / (ld s) { return xy(x/s, y/s); }
|
||||
xy operator * (xy b) { return xy(x*b.x, y*b.y); }
|
||||
xy operator / (xy b) { return xy(x/b.x, y/b.y); }
|
||||
friend xy operator * (ld s, xy a) { return xy(s*a.x, s*a.y); }
|
||||
xy& operator += (xy b) { x += b.x; y += b.y; return self; }
|
||||
xy& operator -= (xy b) { x -= b.x; y -= b.y; return self; }
|
||||
xy& operator *= (ld s) { x *= s; y *= s; return self; }
|
||||
xy& operator /= (ld s) { x /= s; y /= s; return self; }
|
||||
};
|
||||
|
||||
struct entity {
|
||||
virtual double sx() = 0;
|
||||
virtual double sy() = 0;
|
||||
double where_x, where_y;
|
||||
double vel_x, vel_y;
|
||||
virtual xy siz() = 0;
|
||||
xy where, vel;
|
||||
|
||||
ld dsx() { return get_scale() * sx(); }
|
||||
ld dsy() { return get_scale() * sy(); }
|
||||
xy dsiz() { return get_scale() * siz(); }
|
||||
|
||||
double gwhere_x, gwhere_y;
|
||||
double gvel_x, gvel_y;
|
||||
xy gwhere, gvel;
|
||||
|
||||
virtual struct moving_platform* as_platform() { return nullptr; }
|
||||
|
||||
int hp;
|
||||
int invinc_end;
|
||||
|
||||
virtual int max_hp() { return 100; }
|
||||
|
||||
bool visible(room *r);
|
||||
virtual bool visible(room *r);
|
||||
|
||||
void clearg() {
|
||||
gwhere_x = where_x;
|
||||
gwhere_y = where_y;
|
||||
gvel_x = vel_x;
|
||||
gvel_y = vel_y;
|
||||
gwhere = where;
|
||||
gvel = vel;
|
||||
}
|
||||
|
||||
entity() {
|
||||
where_x = screen_x / 2.;
|
||||
where_y = screen_y / 2.;
|
||||
vel_x = 0;
|
||||
vel_y = 0;
|
||||
where = xy(screen_x / 2., screen_y / 2.);
|
||||
vel = xy(0, 0);
|
||||
destroyed = false; invinc_end = -1;
|
||||
clearg();
|
||||
};
|
||||
@ -155,8 +166,8 @@ struct entity {
|
||||
|
||||
data get_dat();
|
||||
|
||||
struct bbox get_pixel_bbox_at(double x, double y);
|
||||
struct bbox get_pixel_bbox() { return get_pixel_bbox_at(where_x, where_y); }
|
||||
struct bbox get_pixel_bbox_at(xy);
|
||||
struct bbox get_pixel_bbox() { return get_pixel_bbox_at(where); }
|
||||
|
||||
virtual double grav() { return 0.1; }
|
||||
|
||||
@ -168,7 +179,7 @@ struct entity {
|
||||
void apply_portal_grav();
|
||||
virtual void act() { kino(); }
|
||||
|
||||
double get_scale() { return get_scale_at(where_y); }
|
||||
double get_scale() { return get_scale_at(where.y); }
|
||||
virtual bool freezing() { return false; }
|
||||
virtual void hit_wall() {};
|
||||
|
||||
@ -206,8 +217,7 @@ struct man : public entity {
|
||||
int last_action;
|
||||
|
||||
man() { facing = 1; attack_facing = 1; postfix(); }
|
||||
double sx() override { return 12; }
|
||||
double sy() override { return 12; }
|
||||
xy siz() override { return {12, 12}; }
|
||||
string glyph() override { return hallucinating ? "f" : "@"; }
|
||||
color_t color() override { return hallucinating ? 0x808080FF : 0xFF8080FF; }
|
||||
void act() override;
|
||||
@ -222,16 +232,14 @@ struct npc : public entity {
|
||||
color_t col;
|
||||
string text;
|
||||
int talk_on;
|
||||
double sx() override { return 12; }
|
||||
double sy() override { return 12; }
|
||||
xy siz() override { return {12, 12}; }
|
||||
string glyph() override { return sglyph; }
|
||||
color_t color() override { return col; }
|
||||
void act() override;
|
||||
};
|
||||
|
||||
struct boar : public entity {
|
||||
double sx() override { return 18; }
|
||||
double sy() override { return 18; }
|
||||
xy siz() override { return {18, 18}; }
|
||||
string glyph() override { return "B"; }
|
||||
color_t color() override { return 0x804000FF; }
|
||||
void act() override;
|
||||
@ -242,9 +250,8 @@ struct boar : public entity {
|
||||
struct hint : public entity {
|
||||
string hint_text;
|
||||
int state;
|
||||
int width, height;
|
||||
double sx() override { return width; }
|
||||
double sy() override { return height; }
|
||||
xy size;
|
||||
xy siz() override { return size; }
|
||||
string glyph() override { return " "; }
|
||||
color_t color() override { return 0; }
|
||||
void act() override;
|
||||
@ -253,8 +260,7 @@ struct hint : public entity {
|
||||
struct item : public entity {
|
||||
int id, qty;
|
||||
string pickup_message;
|
||||
double sx() override { return 12; }
|
||||
double sy() override { return 12; }
|
||||
xy siz() override { return {12, 12}; }
|
||||
string glyph() override { return powers[id].get_glyph(); }
|
||||
color_t color() override { return powers[id].get_color(); }
|
||||
void act() override {
|
||||
@ -269,8 +275,7 @@ struct item : public entity {
|
||||
|
||||
struct missile : public entity {
|
||||
missile() { destroyed = false; }
|
||||
double sx() override { return 4; }
|
||||
double sy() override { return 4; }
|
||||
xy siz() override { return {4, 4}; }
|
||||
string glyph() override { return "*"; }
|
||||
color_t color() override { return 0x8080FFFF; }
|
||||
void act() override;
|
||||
|
@ -2,15 +2,15 @@ namespace rogue_unlike {
|
||||
|
||||
man m;
|
||||
|
||||
bbox entity::get_pixel_bbox_at(double x, double y) {
|
||||
bbox entity::get_pixel_bbox_at(xy p) {
|
||||
bbox b;
|
||||
double d = get_scale_at(y);
|
||||
double man_x = sx();
|
||||
double man_y = sy();
|
||||
b.minx = x - man_x * d / 2;
|
||||
b.maxx = x + man_x * d / 2 + 1;
|
||||
b.miny = y - man_y * d / 2;
|
||||
b.maxy = y + man_y * d / 2 + 1;
|
||||
double d = get_scale_at(p.y);
|
||||
double man_x = siz().x;
|
||||
double man_y = siz().y;
|
||||
b.minx = p.x - man_x * d / 2;
|
||||
b.maxx = p.x + man_x * d / 2 + 1;
|
||||
b.miny = p.y - man_y * d / 2;
|
||||
b.maxy = p.y + man_y * d / 2 + 1;
|
||||
return b;
|
||||
}
|
||||
|
||||
@ -34,7 +34,7 @@ void entity::apply_grav() {
|
||||
if(non_hyperbolic) return apply_portal_grav();
|
||||
|
||||
auto dat = get_dat();
|
||||
vel_y += dat.d * grav() * dat.moda * 16/9.;
|
||||
vel.y += dat.d * grav() * dat.moda * 16/9.;
|
||||
}
|
||||
|
||||
void entity::kino() {
|
||||
@ -49,31 +49,31 @@ void entity::kino() {
|
||||
again:
|
||||
|
||||
auto obb = pixel_to_block(get_pixel_bbox());
|
||||
auto nbb = pixel_to_block(get_pixel_bbox_at(where_x + vel_x, where_y + vel_y));
|
||||
auto nbb = pixel_to_block(get_pixel_bbox_at(where + vel));
|
||||
auto jbb = join(obb, nbb);
|
||||
|
||||
flagtype blocking = (vel_y < 0 || fallthru) ? W_BLOCK : (W_BLOCK | W_PLATFORM);
|
||||
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();
|
||||
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) {
|
||||
if(walls[b].flags & W_BOUNCY) { vel_y = -vel_y; on_bounce = true; goto again; }
|
||||
if(walls[b].flags & W_BOUNCY) { vel.y = -vel.y; on_bounce = true; goto again; }
|
||||
on_floor = true;
|
||||
if(walls[b].flags & W_FROZEN) on_ice = true;
|
||||
vel_y /= 2;
|
||||
if(abs(vel_y) < 1e-6) vel_y = 0;
|
||||
vel.y /= 2;
|
||||
if(abs(vel.y) < 1e-6) vel.y = 0;
|
||||
if(freezing()) {
|
||||
if(b == wWater) current_room->replace_block(x, y, wFrozen);
|
||||
else if(b != wFrozen) hit_wall();
|
||||
}
|
||||
if(pixel_to_block(get_pixel_bbox_at(where_x + vel_x, where_y + vel_y)).maxy <= y) where_y += vel_y;
|
||||
if(pixel_to_block(get_pixel_bbox_at(where + vel)).maxy <= y) where.y += vel.y;
|
||||
goto again;
|
||||
}
|
||||
if((walls[b].flags & W_PAIN) && pain_effect()) goto again;
|
||||
@ -82,9 +82,9 @@ void entity::kino() {
|
||||
for(int x = obb.minx; x < obb.maxx; x++) for(int y = jbb.miny; y < obb.miny; y++) {
|
||||
eWall b = current_room->at(x, y);
|
||||
if(walls[b].flags & W_BLOCK) {
|
||||
vel_y /= 2;
|
||||
if(abs(vel_y) < 1e-6) vel_y = 0;
|
||||
if(pixel_to_block(get_pixel_bbox_at(where_x + vel_x, where_y + vel_y)).miny > y) where_y += vel_y;
|
||||
vel.y /= 2;
|
||||
if(abs(vel.y) < 1e-6) vel.y = 0;
|
||||
if(pixel_to_block(get_pixel_bbox_at(where + vel)).miny > y) where.y += vel.y;
|
||||
goto again;
|
||||
}
|
||||
if((walls[b].flags & W_PAIN) && pain_effect()) goto again;
|
||||
@ -94,7 +94,7 @@ void entity::kino() {
|
||||
eWall b = current_room->at(x, y);
|
||||
if(walls[b].flags & W_STAIRCASE) {
|
||||
on_floor = true;
|
||||
if(vel_y > 0) { vel_y = 0; goto again; }
|
||||
if(vel.y > 0) { vel.y = 0; goto again; }
|
||||
}
|
||||
}
|
||||
|
||||
@ -106,7 +106,7 @@ void entity::kino() {
|
||||
}
|
||||
if(walls[b].flags & W_BLOCK) {
|
||||
if(freezing()) { hit_wall(); }
|
||||
vel_x = (vel_x - max<ld>(vel_y, 0)/10) / 2;
|
||||
vel.x = (vel.x - max<ld>(vel.y, 0)/10) / 2;
|
||||
wallhug = true;
|
||||
goto again;
|
||||
}
|
||||
@ -121,42 +121,41 @@ void entity::kino() {
|
||||
}
|
||||
if(walls[b].flags & W_BLOCK) {
|
||||
if(freezing()) { hit_wall(); }
|
||||
vel_x = (vel_x + max<ld>(vel_y, 0)/10) / 2;
|
||||
vel.x = (vel.x + max<ld>(vel.y, 0)/10) / 2;
|
||||
wallhug = true;
|
||||
goto again;
|
||||
}
|
||||
if((walls[b].flags & W_PAIN) && pain_effect()) goto again;
|
||||
}
|
||||
|
||||
int bx0 = floor(where_x / block_x);
|
||||
int by0 = floor(where_y / block_y);
|
||||
where_x += vel_x;
|
||||
where_y += vel_y;
|
||||
int bx0 = floor(where.x / block_x);
|
||||
int by0 = floor(where.y / block_y);
|
||||
where += vel;
|
||||
|
||||
int bx1 = floor(where_x / block_x);
|
||||
int by1 = floor(where_y / block_y);
|
||||
int bx1 = floor(where.x / block_x);
|
||||
int by1 = floor(where.y / block_y);
|
||||
|
||||
if(non_hyperbolic) {
|
||||
auto& loc = all_locations[by0][bx0];
|
||||
if(bx1 > bx0) {
|
||||
auto& loc1 = loc.get(0);
|
||||
where_x += block_x * (loc1.x - (loc.x + 1));
|
||||
where_y += block_y * (loc1.y - loc.y);
|
||||
where.x += block_x * (loc1.x - (loc.x + 1));
|
||||
where.y += block_y * (loc1.y - loc.y);
|
||||
}
|
||||
if(bx1 < bx0) {
|
||||
auto& loc1 = loc.get(2);
|
||||
where_x += block_x * (loc1.x - (loc.x - 1));
|
||||
where_y += block_x * (loc1.y - loc.y);
|
||||
where.x += block_x * (loc1.x - (loc.x - 1));
|
||||
where.y += block_x * (loc1.y - loc.y);
|
||||
}
|
||||
if(by1 < by0) {
|
||||
auto& loc1 = loc.get(1);
|
||||
where_x += block_x * (loc1.x - loc.x);
|
||||
where_y += block_x * (loc1.y - (loc.y - 1));
|
||||
where.x += block_x * (loc1.x - loc.x);
|
||||
where.y += block_x * (loc1.y - (loc.y - 1));
|
||||
}
|
||||
if(by1 > by0) {
|
||||
auto& loc1 = loc.get(3);
|
||||
where_x += block_x * (loc1.x - loc.x);
|
||||
where_y += block_x * (loc1.y - (loc.y + 1));
|
||||
where.x += block_x * (loc1.x - loc.x);
|
||||
where.y += block_x * (loc1.y - (loc.y + 1));
|
||||
}
|
||||
}
|
||||
|
||||
@ -167,30 +166,27 @@ void entity::kino() {
|
||||
exit(1); */
|
||||
|
||||
if(true || !non_hyperbolic) {
|
||||
hyperpoint h_at = to_hyper(where_x, where_y);
|
||||
hyperpoint h_was = to_hyper(where_x - vel_x, where_y - vel_y);
|
||||
hyperpoint h_at = to_hyper(where);
|
||||
hyperpoint h_was = to_hyper(where - vel);
|
||||
hyperpoint h_willbe = rgpushxto0(h_at) * MirrorX * MirrorY * gpushxto0(h_at) * h_was;
|
||||
ld next_x, next_y;
|
||||
tie(next_x, next_y) = from_hyper(h_willbe);
|
||||
vel_x = next_x - where_x;
|
||||
vel_y = next_y - where_y;
|
||||
xy next = from_hyper(h_willbe);
|
||||
vel = next - where;
|
||||
}
|
||||
|
||||
apply_grav();
|
||||
|
||||
gwhere_x += gvel_x;
|
||||
gwhere_y += gvel_y;
|
||||
gwhere += gvel;
|
||||
|
||||
ld delta = 1/60.;
|
||||
if((where_x - gwhere_x) * (gvel_x - vel_x) + (where_y - gwhere_y) * (gvel_y - vel_y) < 0) delta *= 2;
|
||||
auto z = (where - gwhere) * (gvel - vel);
|
||||
if(z.x + z.y < 0) delta *= 2;
|
||||
ld ndelta = 1-delta;
|
||||
gvel_x = ndelta * gvel_x + delta * (where_x - gwhere_x);
|
||||
gvel_y = ndelta * gvel_y + delta * (where_y - gwhere_y);
|
||||
gvel = ndelta * gvel + delta * (where - gwhere);
|
||||
}
|
||||
|
||||
void missile::act() {
|
||||
kino();
|
||||
if(where_x > screen_x || where_x < 0 || where_y < 0 || where_y > screen_y) destroyed = true;
|
||||
if(where.x > screen_x || where.x < 0 || where.y < 0 || where.y > screen_y) destroyed = true;
|
||||
}
|
||||
|
||||
void npc::act() {
|
||||
@ -213,20 +209,20 @@ void boar::act() {
|
||||
kino();
|
||||
if(intersect(get_pixel_bbox(), m.get_pixel_bbox())) {
|
||||
addMessage("The wild boar gores you!");
|
||||
int s = where_x < m.where_x ? -1 : 1;
|
||||
int s = where.x < m.where.x ? -1 : 1;
|
||||
m.reduce_hp(15);
|
||||
auto dat = get_dat();
|
||||
auto mdat = m.get_dat();
|
||||
if(m.on_floor) m.vel_x = mdat.d * mdat.modv * -s * 1.5, m.vel_y = -mdat.d * mdat.modv * 2;
|
||||
if(on_floor) vel_x = dat.d * dat.modv * s * 1.5;
|
||||
if(m.on_floor) m.vel.x = mdat.d * mdat.modv * -s * 1.5, m.vel.y = -mdat.d * mdat.modv * 2;
|
||||
if(on_floor) vel.x = dat.d * dat.modv * s * 1.5;
|
||||
}
|
||||
if(on_floor) {
|
||||
auto dat = get_dat();
|
||||
if(vel_x > 0) vel_x = max<ld>(vel_x - dat.d * dat.moda * 0.05, 0);
|
||||
if(vel_x < 0) vel_x = min<ld>(vel_x + dat.d * dat.moda * 0.05, 0);
|
||||
if(vel.x > 0) vel.x = max<ld>(vel.x - dat.d * dat.moda * 0.05, 0);
|
||||
if(vel.x < 0) vel.x = min<ld>(vel.x + dat.d * dat.moda * 0.05, 0);
|
||||
if(gframeid > invinc_end) {
|
||||
if(intersect(extend(get_pixel_bbox(), 60 * dat.d, 0, 0, 0), m.get_pixel_bbox())) vel_x -= dat.d * dat.moda * 0.2;
|
||||
if(intersect(extend(get_pixel_bbox(), 0, 60 * dat.d, 0, 0), m.get_pixel_bbox())) vel_x += dat.d * dat.moda * 0.2;
|
||||
if(intersect(extend(get_pixel_bbox(), 60 * dat.d, 0, 0, 0), m.get_pixel_bbox())) vel.x -= dat.d * dat.moda * 0.2;
|
||||
if(intersect(extend(get_pixel_bbox(), 0, 60 * dat.d, 0, 0), m.get_pixel_bbox())) vel.x += dat.d * dat.moda * 0.2;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -235,8 +231,8 @@ void boar::attacked(int dmg) {
|
||||
reduce_hp(dmg);
|
||||
if(destroyed) addMessage("You kill the wild boar."); else addMessage("You hit the wild boar.");
|
||||
auto dat = get_dat();
|
||||
int s = where_x < m.where_x ? -1 : 1;
|
||||
if(on_floor) vel_x = dat.d * dat.modv * s * 2, vel_y = -dat.d * dat.modv * 2.5;
|
||||
int s = where.x < m.where.x ? -1 : 1;
|
||||
if(on_floor) vel.x = dat.d * dat.modv * s * 2, vel.y = -dat.d * dat.modv * 2.5;
|
||||
}
|
||||
|
||||
void hint::act() {
|
||||
|
@ -20,7 +20,10 @@ hyperpoint to_hyper(ld x, ld y) {
|
||||
return perspective_to_space(h, 1, gcHyperbolic);
|
||||
}
|
||||
|
||||
pair<ld, ld> from_hyper(hyperpoint h) {
|
||||
hyperpoint to_hyper(xy xy) { return to_hyper(xy.x, xy.y); }
|
||||
|
||||
|
||||
xy from_hyper(hyperpoint h) {
|
||||
if(non_hyperbolic) return {h[0], h[1]};
|
||||
h = spin90() * h; h[0] = -h[0];
|
||||
h[2] += 1;
|
||||
|
@ -17,18 +17,18 @@ void man::act() {
|
||||
handle_powers(dat);
|
||||
|
||||
if((on_floor || jump_control || wallhug) && !on_ice) {
|
||||
vel_x = dat.dx * dat.d * dat.modv * 2.5;
|
||||
vel.x = zero_speed + dat.dx * dat.d * dat.modv * 2.5;
|
||||
}
|
||||
|
||||
if(on_bounce) {
|
||||
vel_x += dat.dx * dat.d * dat.modv * 0.02;
|
||||
vel.x += dat.dx * dat.d * dat.modv * 0.02;
|
||||
}
|
||||
|
||||
if(!(on_floor && !dat.dx)) last_action = gframeid;
|
||||
|
||||
if(dat.dx) facing = dat.dx;
|
||||
|
||||
current_room->fov_from(where_x / block_x, where_y / block_y);
|
||||
current_room->fov_from(where.x / block_x, where.y / block_y);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,13 +8,13 @@ array<array<location, 256>, 256> all_locations;
|
||||
|
||||
void entity::apply_portal_grav() {
|
||||
auto dat = get_dat();
|
||||
int bx0 = floor(where_x / block_x);
|
||||
int by0 = floor(where_y / block_y);
|
||||
int bx0 = floor(where.x / block_x);
|
||||
int by0 = floor(where.y / block_y);
|
||||
auto& loc = all_locations[by0][bx0];
|
||||
auto px = (loc.get(0).potential - loc.get(2).potential) * 255 / 2;
|
||||
auto py = (loc.get(3).potential - loc.get(1).potential) * 255 / 2;
|
||||
vel_x += dat.d * grav() * dat.moda * px * 16/9.;
|
||||
vel_y += dat.d * grav() * dat.moda * py * 16/9.;
|
||||
vel.x += dat.d * grav() * dat.moda * px * 16/9.;
|
||||
vel.y += dat.d * grav() * dat.moda * py * 16/9.;
|
||||
}
|
||||
|
||||
void load_nonhyperbolic() {
|
||||
|
@ -88,7 +88,7 @@ void gen_powers() {
|
||||
if(d.keystate & 1) {
|
||||
bool can_jump = m.on_floor;
|
||||
if(gframeid <= m.on_floor_when + m.coyote_time) can_jump = true;
|
||||
if(can_jump) m.vel_y = -(non_hyperbolic ? 3 : 5) * d.d * d.modv, m.on_floor_when = -1000;
|
||||
if(can_jump) m.vel.y = -(non_hyperbolic ? 3 : 5) * d.d * d.modv, m.on_floor_when = -1000;
|
||||
}
|
||||
}
|
||||
).is_starting(),
|
||||
@ -115,7 +115,7 @@ void gen_powers() {
|
||||
[] (data& d) {
|
||||
if(d.keystate != 1) return;
|
||||
m.attack_facing = m.facing; m.attack_when = gframeid;
|
||||
auto pb = m.get_pixel_bbox_at(m.where_x + m.attack_facing * m.dsx(), m.where_y);
|
||||
auto pb = m.get_pixel_bbox_at(xy{m.where.x + m.attack_facing * m.dsiz().x, m.where.y});
|
||||
auto bb = pixel_to_block(pb);
|
||||
for(auto& e: current_room->entities) if(intersect(e->get_pixel_bbox(), pb)) e->attacked(15);
|
||||
for(int y=bb.miny; y<bb.maxy; y++)
|
||||
|
@ -219,12 +219,14 @@ void entity::draw() {
|
||||
|
||||
double d = get_scale();
|
||||
|
||||
gwhere_x = where_x; gwhere_y = where_y;
|
||||
gwhere = where;
|
||||
|
||||
ld minx = min(where_x, gwhere_x) - sx() * d / 2;
|
||||
ld miny = min(where_y, gwhere_y) - sy() * d / 2;
|
||||
ld maxx = max(where_x, gwhere_x) + sx() * d / 2;
|
||||
ld maxy = max(where_y, gwhere_y) + sy() * d / 2;
|
||||
auto si = siz();
|
||||
|
||||
ld minx = min(where.x, gwhere.x) - si.x * d / 2;
|
||||
ld miny = min(where.y, gwhere.y) - si.y * d / 2;
|
||||
ld maxx = max(where.x, gwhere.x) + si.x * d / 2;
|
||||
ld maxy = max(where.y, gwhere.y) + si.y * d / 2;
|
||||
|
||||
asciiletter(minx, miny, maxx, maxy, glyph(), color());
|
||||
}
|
||||
@ -235,9 +237,10 @@ void man::draw() {
|
||||
ld t = gframeid - attack_when;
|
||||
if(t < 50) {
|
||||
auto af = attack_facing * (1 - t * 0.01);
|
||||
auto ds = dsiz();
|
||||
asciiletter(
|
||||
where_x + af * dsx() - dsx()/2, where_y - dsy()/2,
|
||||
where_x + af * dsx() + dsx()/2, where_y + dsy()/2,
|
||||
where.x + af * ds.x - ds.x/2, where.y - ds.y/2,
|
||||
where.x + af * ds.x + ds.x/2, where.y + ds.y/2,
|
||||
attack_facing == -1 ? "(" : ")", 0xFFFFFF00 + (255 - t * 5)
|
||||
);
|
||||
}
|
||||
|
@ -119,8 +119,8 @@ void room::fov_from(int sx, int sy) {
|
||||
for(int l=0; l<len; l++) {
|
||||
auto h = lerp(sh, th, l * 1. / len);
|
||||
auto xy = from_hyper(h);
|
||||
int cx = int(xy.first / block_x);
|
||||
int cy = int(xy.second / block_y);
|
||||
int cx = int(xy.x / block_x);
|
||||
int cy = int(xy.y / block_y);
|
||||
if(cx < 0 || cy < 0 || cx >= room_x || cy >= room_y) break;
|
||||
if(!(walls[at(cx, cy)].flags & W_TRANS)) break;
|
||||
reveal_around(cx, cy);
|
||||
|
@ -91,7 +91,7 @@ void editmap_frame() {
|
||||
dialog::display();
|
||||
});
|
||||
if(keypressed('f')) floodfill_pick(mousepx / block_x, mousepy / block_y);
|
||||
if(keypressed('t')) { m.where_x = mousepx; m.where_y = mousepy; m.vel_x = 0; m.vel_y = 0; }
|
||||
if(keypressed('t')) { m.where = xy(mousepx, mousepy); m.vel = xy(0, 0); }
|
||||
}
|
||||
|
||||
void playing_frame() {
|
||||
@ -104,46 +104,46 @@ void playing_frame() {
|
||||
auto mb = ents.begin();
|
||||
for(auto& e: ents) if(!e->destroyed) *(mb++) = std::move(e);
|
||||
ents.resize(mb - ents.begin());
|
||||
|
||||
|
||||
auto& nonh = non_hyperbolic;
|
||||
if(one_room) return;
|
||||
|
||||
if(m.where_x < l_margin_at) {
|
||||
m.where_x += actual_screen_x;
|
||||
if(m.where.x < l_margin_at) {
|
||||
m.where.x += actual_screen_x;
|
||||
switch_to_adjacent_room(2);
|
||||
m.clearg();
|
||||
}
|
||||
if(m.where_x > r_margin_at) {
|
||||
m.where_x -= actual_screen_x;
|
||||
if(m.where.x > r_margin_at) {
|
||||
m.where.x -= actual_screen_x;
|
||||
switch_to_adjacent_room(nonh ? 0 : 4);
|
||||
m.clearg();
|
||||
}
|
||||
|
||||
if(m.where_y < t_margin_at && !nonh) {
|
||||
m.where_y = (m.where_y - t_margin_at) * 2 + b_margin_at;
|
||||
m.where_x -= l_margin_at;
|
||||
m.where_x = 2 * m.where_x;
|
||||
if(m.where_x > actual_screen_x) {
|
||||
m.where_x -= actual_screen_x;
|
||||
if(m.where.y < t_margin_at && !nonh) {
|
||||
m.where.y = (m.where.y - t_margin_at) * 2 + b_margin_at;
|
||||
m.where.x -= l_margin_at;
|
||||
m.where.x = 2 * m.where.x;
|
||||
if(m.where.x > actual_screen_x) {
|
||||
m.where.x -= actual_screen_x;
|
||||
switch_to_adjacent_room(0);
|
||||
}
|
||||
else
|
||||
switch_to_adjacent_room(1);
|
||||
m.where_x += l_margin_at;
|
||||
m.vel_x *= 2; m.vel_y *= 2;
|
||||
m.where.x += l_margin_at;
|
||||
m.vel *= 2;
|
||||
m.clearg();
|
||||
}
|
||||
if(m.where_y > b_margin_at && !nonh) {
|
||||
m.where_x -= l_margin_at;
|
||||
m.where_y -= b_margin_at;
|
||||
m.where_y /= 2;
|
||||
m.where_y += t_margin_at;
|
||||
if(m.where.y > b_margin_at && !nonh) {
|
||||
m.where.x -= l_margin_at;
|
||||
m.where.y -= b_margin_at;
|
||||
m.where.y /= 2;
|
||||
m.where.y += t_margin_at;
|
||||
if(is_right(current_room))
|
||||
m.where_x += actual_screen_x;
|
||||
m.where.x += actual_screen_x;
|
||||
switch_to_adjacent_room(3);
|
||||
m.where_x /= 2;
|
||||
m.where_x += l_margin_at;
|
||||
m.vel_x /= 2; m.vel_y /= 2;
|
||||
m.where.x /= 2;
|
||||
m.where.x += l_margin_at;
|
||||
m.vel /= 2;
|
||||
m.clearg();
|
||||
}
|
||||
}
|
||||
@ -155,7 +155,7 @@ void sync_map() {
|
||||
View = cspin90(1, 0);
|
||||
// if(cmode == mode::playing) View = View * inverse(parabolic13_at(to_hyper(m.where_x, m.where_y)));
|
||||
if(cmode == mode::playing) {
|
||||
hyperpoint p = to_hyper(m.where_x, m.where_y);
|
||||
hyperpoint p = to_hyper(m.where);
|
||||
transmatrix T = iso_inverse(parabolic13_at(deparabolic13(p)));
|
||||
View = View * T;
|
||||
}
|
||||
@ -202,7 +202,8 @@ void render_the_map() {
|
||||
}
|
||||
if(!mouseout()) {
|
||||
auto h = inverse_shift(ggmatrix(current_room->where), mouseh);
|
||||
tie(mousepx, mousepy) = from_hyper(h);
|
||||
auto fh = from_hyper(h);
|
||||
tie(mousepx, mousepy) = pair(fh.x, fh.y);
|
||||
}
|
||||
if(cmode == mode::editmap) {
|
||||
getcstat = '-';
|
||||
@ -397,10 +398,10 @@ void add_platf_hooks() {
|
||||
}
|
||||
f.write<int>(-1);
|
||||
f.write(mapstream::cellids[current_room->where]);
|
||||
f.write(m.where_x);
|
||||
f.write(m.where_y);
|
||||
f.write(m.vel_x);
|
||||
f.write(m.vel_y);
|
||||
f.write(m.where.x);
|
||||
f.write(m.where.y);
|
||||
f.write(m.vel.x);
|
||||
f.write(m.vel.y);
|
||||
});
|
||||
|
||||
pushScreen(run);
|
||||
@ -424,10 +425,10 @@ auto chk = arg::add3("-ru", enable)
|
||||
}
|
||||
int id = f.get<int>();
|
||||
current_room = get_room_at(mapstream::cellbyid[id]);
|
||||
f.read(m.where_x);
|
||||
f.read(m.where_y);
|
||||
f.read(m.vel_x);
|
||||
f.read(m.vel_y);
|
||||
f.read(m.where.x);
|
||||
f.read(m.where.y);
|
||||
f.read(m.vel.x);
|
||||
f.read(m.vel.y);
|
||||
add_platf_hooks();
|
||||
println(hlog, "done");
|
||||
set_sval();
|
||||
|
@ -106,12 +106,12 @@ void load_room(fhstream& f, cell *c) {
|
||||
string param = s.substr(pos+1);
|
||||
if(cap == "START") {
|
||||
current_room = &r;
|
||||
sscanf(param.c_str(), "%lf%lf", &m.where_x, &m.where_y);
|
||||
sscanf(param.c_str(), "%lf%lf", &m.where.x, &m.where.y);
|
||||
}
|
||||
else if(cap == "ITEM") {
|
||||
auto b = std::make_unique<item>();
|
||||
b->qty = 1;
|
||||
sscanf(param.c_str(), "%lf%lf%d", &b->where_x, &b->where_y, &b->qty);
|
||||
sscanf(param.c_str(), "%lf%lf%d", &b->where.x, &b->where.y, &b->qty);
|
||||
s = scanline_noblank(f);
|
||||
b->id = -1;
|
||||
for(int i=0; i<isize(powers); i++) if(powers[i].name == s) b->id = i;
|
||||
@ -121,7 +121,7 @@ void load_room(fhstream& f, cell *c) {
|
||||
}
|
||||
else if(cap == "NPC") {
|
||||
auto b = std::make_unique<npc>();
|
||||
sscanf(param.c_str(), "%lf%lf%08x", &b->where_x, &b->where_y, &b->col);
|
||||
sscanf(param.c_str(), "%lf%lf%08x", &b->where.x, &b->where.y, &b->col);
|
||||
s = scanline_noblank(f);
|
||||
b->sglyph = s[0];
|
||||
b->name = s.substr(1);
|
||||
@ -130,12 +130,12 @@ 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);
|
||||
sscanf(param.c_str(), "%lf%lf", &b->where.x, &b->where.y);
|
||||
r.entities.emplace_back(std::move(b));
|
||||
}
|
||||
else if(cap == "HINT") {
|
||||
auto b = std::make_unique<hint>();
|
||||
sscanf(param.c_str(), "%lf%lf%d%d", &b->where_x, &b->where_y, &b->width, &b->height);
|
||||
sscanf(param.c_str(), "%lf%lf%lf%lf", &b->where.x, &b->where.y, &b->size.x, &b->size.y);
|
||||
b->hint_text = scanline_noblank(f);
|
||||
r.entities.emplace_back(std::move(b));
|
||||
}
|
||||
@ -173,7 +173,7 @@ void load_cheat(string fname) {
|
||||
for(auto& [c,r]: rooms) if(r.roomname == param) current_room = &r;
|
||||
}
|
||||
else if(cap == "POS") {
|
||||
sscanf(param.c_str(), "%lf%lf", &m.where_x, &m.where_y);
|
||||
sscanf(param.c_str(), "%lf%lf", &m.where.x, &m.where.y);
|
||||
}
|
||||
else if(cap == "ITEM") {
|
||||
bool found = false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user