From 6253c6c3e3639b6747371f3576912443f50d34b9 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sun, 5 May 2019 17:37:51 +0200 Subject: [PATCH] redone gravity in shmup --- game.cpp | 1 + graph.cpp | 22 +++++++++++++++++++--- shmup.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 3 files changed, 71 insertions(+), 8 deletions(-) diff --git a/game.cpp b/game.cpp index 704e391d..89fbad4d 100644 --- a/game.cpp +++ b/game.cpp @@ -589,6 +589,7 @@ bool passable(cell *w, cell *from, flagtype flags) { } if(from && strictlyAgainstGravity(w, from, vrevdir, flags) + && !((flags & P_ISPLAYER) && shmup::on) && !F(P_GRAVITY | P_BLOW | P_JUMP1 | P_JUMP2 | P_FLYING | P_BULLET | P_AETHER) ) return false; diff --git a/graph.cpp b/graph.cpp index 04cdca0c..a9b2ae48 100644 --- a/graph.cpp +++ b/graph.cpp @@ -4119,6 +4119,13 @@ void drawBoat(cell *c, const transmatrix*& Vboat, transmatrix& Vboat0, transmatr queuepoly(Vboat0, shBoatInner, incol); } +void shmup_gravity_floor(cell *c) { + if(DIM == 2 && cellEdgeUnstable(c)) + set_floor(shMFloor); + else + set_floor(shFullFloor); + } + void drawcell(cell *c, transmatrix V, int spinv, bool mirrored) { cells_drawn++; @@ -4671,7 +4678,10 @@ void drawcell(cell *c, transmatrix V, int spinv, bool mirrored) { break; case laMountain: - set_towerfloor(c, euclid ? celldist : c->master->alt ? celldistAltPlus : celldist); + if(shmup::on) + shmup_gravity_floor(c); + else + set_towerfloor(c, euclid ? celldist : c->master->alt ? celldistAltPlus : celldist); break; case laEmerald: @@ -4832,7 +4842,10 @@ void drawcell(cell *c, transmatrix V, int spinv, bool mirrored) { break; case laEndorian: - if(c->wall == waTrunk) + if(shmup::on) + shmup_gravity_floor(c); + + else if(c->wall == waTrunk) set_floor(shFloor); else if(c->wall == waCanopy || c->wall == waSolidBranch || c->wall == waWeakBranch) @@ -4843,7 +4856,10 @@ void drawcell(cell *c, transmatrix V, int spinv, bool mirrored) { break; case laIvoryTower: case laDungeon: case laWestWall: - set_towerfloor(c); + if(shmup::on) + shmup_gravity_floor(c); + else + set_towerfloor(c); break; case laBrownian: diff --git a/shmup.cpp b/shmup.cpp index 61163b6d..7083aafc 100644 --- a/shmup.cpp +++ b/shmup.cpp @@ -1309,7 +1309,7 @@ bool airCurrents(transmatrix& nat, monster *m, int delta) { bool carried = false; cell *c = m->base; #if CAP_COMPLEX2 - if(c->land == laWestWall) { + if(false && c->land == laWestWall) { cell *c2 = ts::left_of(c, westwall::coastvalEdge1); double spd = SCALE * delta / 900.; @@ -1543,7 +1543,11 @@ static const int reflectflag = P_MIRRORWALL; void movePlayer(monster *m, int delta) { - bool inertia_based = m->base->land == laAsteroids; + bool falling = isGravityLand(m->base) && cellEdgeUnstable(m->base); + if(m->base->land == laWestWall) falling = true; + if(items[itOrbAether]) falling = false; + + bool inertia_based = falling || m->base->land == laAsteroids; cpid = m->pid; @@ -1754,9 +1758,49 @@ void movePlayer(monster *m, int delta) { hyperpoint avg_inertia; if(inertia_based && canmove) { + using namespace hyperpoint_vec; avg_inertia = m->inertia; - m->inertia[frontdir()] += playergo[cpid] / 1000; - avg_inertia[frontdir()] += playergo[cpid] / 2000; + ld coef = m->base->land == laWestWall ? 0.65 : falling ? 0.15 : 1; + coef /= 1000; + m->inertia[frontdir()] += coef * playergo[cpid]; + avg_inertia[frontdir()] += coef * playergo[cpid] / 2; + if(falling) { + vector below; + manual_celllister mcl; + mcl.add(m->base); + for(int i=0; iland == laMountain) { + int d = celldistAlt(c); + forCellEx(c2, c) if(celldistAlt(c2) > d && gmatrix.count(c2)) + go = true, mcl.add(c2); + } + else { + int d = coastvalEdge(c); + forCellEx(c2, c) if(coastvalEdge(c2) < d && gmatrix.count(c2)) + go = true, mcl.add(c2); + } + if(!go) below.push_back(c); + } + ld cinertia = hypot_d(DIM, m->inertia); + hyperpoint drag = m->inertia * cinertia * delta / -1. / SCALE; + m->inertia += drag; + avg_inertia += drag/2; + transmatrix T = inverse(m->pat); + ld xp = SCALE / 60000. / isize(below) * delta / 15; + ld yp = 0; + if(cwt.at->land == laDungeon) xp = -xp; + if(cwt.at->land == laWestWall) yp = xp * 1, xp *= 0.7; + for(cell *c2: below) if(c2 != m->base) { + + hyperpoint h = rspintox(T * tC0(gmatrix[c2])) * hpxy(xp, yp); + + m->inertia += h; + avg_inertia += h/2; + } + } + // if(inertia_based) m->inertia = spin(-playerturn[cpid]) * m->inertia; } for(int igo=0; igo 1e-3) bulltime[cpid] = curtime; if(!go) { + using namespace hyperpoint_vec; playergo[cpid] = playergoturn[cpid] = playerstrafe[cpid] = 0; if(DIM == 3) playerturn[cpid] = playerturny[cpid] = 0; - m->inertia = Hypc; + if(falling) m->inertia = m->inertia * -1; + else m->inertia = Hypc; } if(go) {