From a0230035601b8cb7650233ad94f2c40767ceb004 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sat, 5 Oct 2019 15:37:13 +0200 Subject: [PATCH] stuck prevention and wall sliding --- shmup.cpp | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/shmup.cpp b/shmup.cpp index b3290f48..f691a895 100644 --- a/shmup.cpp +++ b/shmup.cpp @@ -294,6 +294,7 @@ EX void degradeDemons() { // we need these for the Mimics! EX double playerturn[MAXPLAYER], playergo[MAXPLAYER], playerstrafe[MAXPLAYER], playerturny[MAXPLAYER], playergoturn[MAXPLAYER], godir[MAXPLAYER]; +EX transmatrix playersmallspin[MAXPLAYER]; bool playerfire[MAXPLAYER]; void awakenMimics(monster *m, cell *c2) { @@ -976,28 +977,41 @@ void movePlayer(monster *m, int delta) { } // if(inertia_based) m->inertia = spin(-playerturn[cpid]) * m->inertia; } + + bool have_speed = false; + + int fspin = 0; for(int igo=0; igoori, rspintox(avg_inertia) * xtangent(r * delta)); if(WDIM == 3) rotate_object(nat, m->ori, cspin(0, 2, playerturn[cpid]) * cspin(1, 2, playerturny[cpid])); m->vel = r * (600/SCALE); } else if(WDIM == 3) { - nat = parallel_transport(nat1, m->ori, point3(playerstrafe[cpid], 0, playergo[cpid])); + playersmallspin[cpid] = Id; + if(igo) { + fspin += 30; + playersmallspin[cpid] = cspin(0, 1, fspin) * cspin(2, 0, igospan[igo]); + if(fspin < 360) igo--; else fspin = 0; + } + have_speed = playerstrafe[cpid] || playergo[cpid]; + nat = parallel_transport(nat1, m->ori, playersmallspin[cpid] * point3(playerstrafe[cpid], 0, playergo[cpid])); rotate_object(nat, m->ori, cspin(0, 2, playerturn[cpid]) * cspin(1, 2, playerturny[cpid])); m->inertia[0] = playerstrafe[cpid] / delta; m->inertia[1] = 0; m->inertia[2] = playergo[cpid] / delta; } else if(playergo[cpid]) { + playergoturn[cpid] = igospan[igo]+godir[cpid]; + have_speed = true; nat = parallel_transport(nat1, m->ori, spin(playergoturn[cpid]) * xtangent(playergo[cpid])); m->inertia = spin(playergoturn[cpid]) * xtangent(playergo[cpid] / delta); } @@ -1173,6 +1187,22 @@ void movePlayer(monster *m, int delta) { } } + if(!go && !have_speed) { + /* sometimes, when we move too fast, we may get stuck */ + cell *c2 = m->findbase(nat0, 1); + if(c2 != m->base) { + hyperpoint v; + for(int i=0; iori, v); + transmatrix B = ggmatrix(m->base); + horo_distance d0(tC0(nat0), B); + horo_distance d1(tC0(nat), B); + horo_distance d2(tC0(nat0), ggmatrix(c2)); + if(d1 < d0) nat0 = nat; + } + } + if(go) m->rebasePat(nat, c2); else m->rebasePat(nat0, m->base);