mirror of
https://github.com/zenorogue/hyperrogue.git
synced 2026-11-27 16:23:08 +00:00
rogueviz::ru:: basic box physics
This commit is contained in:
1 parent
21f50a4d6c
commit
bf757814b8
5 files changed
+107
-10
No files matched your search
@@ -321,6 +321,8 @@ struct entity {
|
||||
|
||||
bool destroyed;
|
||||
void kino();
|
||||
void apply_walking(ld target_velx);
|
||||
virtual bool get_jump_control() { return false; }
|
||||
void apply_vel();
|
||||
void apply_walls();
|
||||
void apply_walls_reflect();
|
||||
@@ -483,6 +485,8 @@ struct man : public entity {
|
||||
|
||||
virtual void hs(stater& s);
|
||||
virtual double grav() { return entity::grav() / current.gravity_value; }
|
||||
|
||||
bool get_jump_control() override { return current.jump_control; }
|
||||
};
|
||||
|
||||
extern man m;
|
||||
@@ -506,6 +510,7 @@ struct moving_platform : public entity {
|
||||
string get_help() override { return "Moving platforms move."; }
|
||||
bool nonstatic() override { return false; }
|
||||
virtual void jumped_on() {}
|
||||
virtual void affected_others_vel(entity *who, xy v) {}
|
||||
};
|
||||
|
||||
struct freemoving_platform : public moving_platform {
|
||||
@@ -519,6 +524,19 @@ struct freemoving_platform : public moving_platform {
|
||||
}
|
||||
};
|
||||
|
||||
struct basic_box : public freemoving_platform {
|
||||
virtual int width() { return 1; }
|
||||
xy siz() override { return {20, 20}; }
|
||||
void act() override;
|
||||
string glyph() override { return "#"; }
|
||||
color_t color() override { return 0xFFFFC0FF; }
|
||||
string get_name() override { return "basic box"; }
|
||||
/* copied from located_entity */
|
||||
xy respawn;
|
||||
xy default_where() override { return respawn; }
|
||||
void affected_others_vel(entity *who, xy v) override;
|
||||
};
|
||||
|
||||
struct floating_bubble_platform : public freemoving_platform {
|
||||
virtual int width() { return 1; }
|
||||
xy siz() override { return {6.*width(), 6}; }
|
||||
|
||||
+32
-2
@@ -256,6 +256,7 @@ void entity::apply_walls() {
|
||||
}
|
||||
|
||||
if(loopcount < 100) for(auto& e: current_room->entities) if(auto p = e->as_platform()) {
|
||||
if(p == this) continue;
|
||||
auto opw = p->location_at(gframeid-1);
|
||||
auto npw = p->location_at(gframeid);
|
||||
|
||||
@@ -299,12 +300,15 @@ void entity::apply_walls() {
|
||||
}
|
||||
|
||||
else {
|
||||
rvel.x = -rvel.x;
|
||||
rvel.x = 0; // -rvel.x;
|
||||
reset = true;
|
||||
zero_vel = zvel;
|
||||
if(!on_floor) zero_vel = zvel;
|
||||
}
|
||||
|
||||
auto vel0 = vel;
|
||||
vel = (rmow + rvel - screen_ctr) * get_scale_at(npw.y) + npw - where;
|
||||
p->affected_others_vel(this, vel - vel0);
|
||||
|
||||
if(reset) goto again;
|
||||
}
|
||||
}
|
||||
@@ -388,6 +392,17 @@ void entity::kino() {
|
||||
gvel = ndelta * gvel + delta * (where - gwhere);
|
||||
}
|
||||
|
||||
void entity::apply_walking(ld target_velx) {
|
||||
if(on_floor || get_jump_control() || wallhug) {
|
||||
if(on_ice == 0) {
|
||||
vel.x = target_velx;
|
||||
}
|
||||
if(on_ice == 1) {
|
||||
vel.x = lerp(vel.x, target_velx, 10. / game_fps);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void missile::act() {
|
||||
kino();
|
||||
if(where.x > screen_x || where.x < 0 || where.y < 0 || where.y > screen_y) destroyed = true;
|
||||
@@ -1241,6 +1256,21 @@ void fight_trader::attacked(int dmg, power *p) {
|
||||
else trader::attacked(dmg, p);
|
||||
}
|
||||
|
||||
void basic_box::act() {
|
||||
if(position_time == gframeid) return;
|
||||
last_position = where;
|
||||
position_time = gframeid;
|
||||
stay_on_screen();
|
||||
kino();
|
||||
|
||||
apply_walking(lerp(vel.x, zero_vel.x, 5. / game_fps));
|
||||
}
|
||||
|
||||
void basic_box::affected_others_vel(entity *who, xy v) {
|
||||
if(who->as_platform()) vel -= v;
|
||||
else vel -= v * .1;
|
||||
}
|
||||
|
||||
void fight_trader::act() {
|
||||
if(!angered) { trader::act(); return; }
|
||||
if(stay_on_screen()) dir = -dir;
|
||||
|
||||
@@ -331,6 +331,11 @@ void load_room(fhstream& f, cell *c) {
|
||||
b->respawn_dir = get_int();
|
||||
r.entities.emplace_back(std::move(b));
|
||||
}
|
||||
else if(cap == "BOX") {
|
||||
auto b = std::make_unique<basic_box>(); nam(*b);
|
||||
b->respawn = get_xy();
|
||||
r.entities.emplace_back(std::move(b));
|
||||
}
|
||||
else if(cap == "NAGA") {
|
||||
auto b = std::make_unique<naga_warrior>(); nam(*b);
|
||||
b->respawn = get_xy();
|
||||
|
||||
+1
-8
@@ -154,14 +154,7 @@ void man::act() {
|
||||
if(next.hallucinating && !current.hallucinating)
|
||||
prepare_hallucination();
|
||||
|
||||
if(on_floor || current.jump_control || wallhug) {
|
||||
if(on_ice == 0) {
|
||||
vel.x = zero_vel.x + dat.dx * dat.d * dat.modv * 2.5;
|
||||
}
|
||||
if(on_ice == 1) {
|
||||
vel.x = lerp(vel.x, zero_vel.x + dat.dx * dat.d * dat.modv * 2.5, 10. / game_fps);
|
||||
}
|
||||
}
|
||||
apply_walking(zero_vel.x + dat.dx * dat.d * dat.modv * 2.5);
|
||||
|
||||
if(on_bounce) {
|
||||
vel.x += dat.dx * dat.d * dat.modv * 0.02;
|
||||
|
||||
@@ -3716,3 +3716,54 @@ 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
|
||||
OK
|
||||
|
||||
MOVE 0 Slope Slop Shop
|
||||
ROOM Ballbox Test
|
||||
# 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#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
|
||||
BOX B1 200 100
|
||||
BOX B2 210 150
|
||||
BOX B3 220 200
|
||||
BOX B4 230 250
|
||||
OK
|
||||
|
||||
Reference in new issue
Block a user