1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2025-06-29 08:22:51 +00:00

moving platforms v0

This commit is contained in:
Zeno Rogue 2025-05-03 00:24:30 +02:00
parent 49257338ee
commit 63bbb2f098
7 changed files with 130 additions and 16 deletions

View File

@ -138,6 +138,7 @@ struct entity {
xy dsiz() { return get_scale() * siz(); } xy dsiz() { return get_scale() * siz(); }
xy gwhere, gvel; xy gwhere, gvel;
xy zero_vel; /* relative to the platform */
virtual struct moving_platform* as_platform() { return nullptr; } virtual struct moving_platform* as_platform() { return nullptr; }
@ -227,6 +228,22 @@ struct man : public entity {
extern man m; extern man m;
struct moving_platform : public entity {
xy ctr;
ld radius, shift;
xy siz() override { return {36, 12}; }
string glyph() override { return "#"; }
color_t color() override { return 0xFFFFFFFF; }
virtual xy location_at(ld t) = 0;
void draw() override;
void act() override;
virtual moving_platform* as_platform() { return this; }
};
struct ferris_platform : public moving_platform {
xy location_at(ld t) override;
};
struct npc : public entity { struct npc : public entity {
string sglyph, name; string sglyph, name;
color_t col; color_t col;

View File

@ -42,6 +42,7 @@ void entity::kino() {
on_ice = false; on_ice = false;
wallhug = false; wallhug = false;
on_bounce = false; on_bounce = false;
zero_vel = xy(0, 0);
// ld modv = 60. / game_fps; // ld modv = 60. / game_fps;
@ -128,6 +129,22 @@ void entity::kino() {
if((walls[b].flags & W_PAIN) && pain_effect()) goto again; if((walls[b].flags & W_PAIN) && pain_effect()) goto again;
} }
for(auto& e: current_room->entities) if(e->as_platform() && intersect(e->get_pixel_bbox(), get_pixel_bbox())) {
auto p = e->as_platform();
auto oldpos = p->location_at(gframeid-1);
auto newpos = p->location_at(gframeid-0);
auto oldscale = get_scale_at(oldpos.y);
auto newscale = get_scale_at(newpos.y);
auto new_where = (where - oldpos) / oldscale * newscale + newpos;
zero_vel = new_where - where;
vel.y -= zero_vel.y;
bool err = vel.y == 0;
if(abs(vel.y) < 1e-6) vel.y = 0; else vel.y /= 2;
vel.y += zero_vel.y;
on_floor = true;
if(!err) goto again;
}
int bx0 = floor(where.x / block_x); int bx0 = floor(where.x / block_x);
int by0 = floor(where.y / block_y); int by0 = floor(where.y / block_y);
where += vel; where += vel;
@ -243,4 +260,24 @@ void hint::act() {
state = cur; state = cur;
} }
xy ferris_platform::location_at(ld t) {
return from_hyper(rgpushxto0(to_hyper(ctr)) * xspinpush0(t / game_fps + shift, radius));
}
void moving_platform::draw() {
double d = get_scale();
for(int w=-1; w<=1; w++) {
ld minx = where.x + siz().x * d * (w - 0.5) / 3;
ld miny = where.y - siz().y * d / 2;
ld maxx = where.x + siz().x * d * (w + 0.5) / 3;
ld maxy = where.y + siz().y * d / 2;
asciiletter(minx, miny, maxx, maxy, "#", 0xFFFFFFFF);
}
}
void moving_platform::act() {
where = location_at(gframeid);
}
} }

View File

@ -140,5 +140,6 @@ void sync_map();
void render_room_objects(room *r); void render_room_objects(room *r);
void asciiletter(ld minx, ld miny, ld maxx, ld maxy, const string& ch, color_t col);
} }

View File

@ -17,7 +17,7 @@ void man::act() {
handle_powers(dat); handle_powers(dat);
if((on_floor || jump_control || wallhug) && !on_ice) { if((on_floor || jump_control || wallhug) && !on_ice) {
vel.x = zero_speed + dat.dx * dat.d * dat.modv * 2.5; vel.x = zero_vel.x + dat.dx * dat.d * dat.modv * 2.5;
} }
if(on_bounce) { if(on_bounce) {

View File

@ -1015,20 +1015,20 @@ MAP
#####################################################################........... #####################################################################...........
#####################################################################........... #####################################################################...........
#####################################################################........... #####################################################################...........
#####################################################################........... .####################################################################...........
#####################################################################........... .####################################################################...........
####################################################################+........... ....................................................................+...........
####################################################################+........... ....................................................................+...........
######################################################################.......... ..####################################################################..........
#############################################################################... ...##########################################################################...
################################################################################ ...#############################################################################
################################################################################ ...#############################################################################
################################################################################ ..##############################################################################
################################################################################ ..##############################################################################
################################################################################ ..##############################################################################
################################################################################ ..##############################################################################
################################################################################ .###############################################################################
################################################################################ .###############################################################################
################################################################################ ################################################################################
################################################################################ ################################################################################
################################################################################ ################################################################################
@ -1043,3 +1043,51 @@ MAP
################################################################################ ################################################################################
#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b #b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b
OK OK
MOVE 2 Central Cavern Bottom Left
ROOM Ferris Wheel
# wall
. air
MAP
################################################################################
#####################.................................##########################
################....................................................############
#############..........................................................#########
##########...............................................................#######
#########.................................................................######
########...................................................................#####
#######....................................................................#####
######.....................................................................#####
#####......................................................................#####
####........................................................................####
####........................................................................####
###.........................................................................####
###..........................................................................###
##...........................................................................###
##..............................................................................
##..............................................................................
#.............................................................................##
#..............................................................................#
#..............................................................................#
#..............................................................................#
#.............................................................................##
##............................................................................##
##............................................................................##
##............................................................................##
###..........................................................................###
###..........................................................................###
####........................................................................####
####........................................................................####
#####.......................................................................####
######.....................................................................#####
#######...................................................................######
########..................................................................######
##########...............................................................#######
############............................................................########
#b#b#b#b#b#b............................................................#b#b#b#b
####################................................................############
#b#b#b#b#b#b#b#b#b#b................................................#b#b#b#b#b#b
################################################################################
#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b#b
FERRIS 320 140 0.277 8
OK

View File

@ -88,7 +88,7 @@ void gen_powers() {
if(d.keystate & 1) { if(d.keystate & 1) {
bool can_jump = m.on_floor; bool can_jump = m.on_floor;
if(gframeid <= m.on_floor_when + m.coyote_time) can_jump = true; 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 = m.zero_vel.y-(non_hyperbolic ? 3 : 5) * d.d * d.modv, m.on_floor_when = -1000;
} }
} }
).is_starting(), ).is_starting(),

View File

@ -133,6 +133,17 @@ void load_room(fhstream& f, cell *c) {
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)); r.entities.emplace_back(std::move(b));
} }
else if(cap == "FERRIS") {
ld cx, cy, radius; int qty;
sscanf(param.c_str(), "%lf%lf%lf%d", &cx, &cy, &radius, &qty);
for(int i=0; i<qty; i++) {
auto b = std::make_unique<ferris_platform>();
b->ctr = {cx, cy}; b->radius = radius;
b->shift = i * TAU / qty;
r.entities.emplace_back(std::move(b));
}
}
else if(cap == "HINT") { else if(cap == "HINT") {
auto b = std::make_unique<hint>(); auto b = std::make_unique<hint>();
sscanf(param.c_str(), "%lf%lf%lf%lf", &b->where.x, &b->where.y, &b->size.x, &b->size.y); sscanf(param.c_str(), "%lf%lf%lf%lf", &b->where.x, &b->where.y, &b->size.x, &b->size.y);