From 1f9f1b4bc882e007a0f2e117c8ad8494f74c60ce Mon Sep 17 00:00:00 2001 From: ac_stef Date: Sat, 4 Oct 2008 15:09:51 +0000 Subject: [PATCH] fixed nade bounce on 45 degree walls git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@2818 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/physics.cpp | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/source/src/physics.cpp b/source/src/physics.cpp index ca9842e3..db8a7155 100644 --- a/source/src/physics.cpp +++ b/source/src/physics.cpp @@ -146,9 +146,11 @@ bool objcollide(physent *d, vec &objpos, float objrad, float objheight) // colli // all collision happens here // spawn is a dirty side effect used in spawning // drop & rise are supplied by the physics below to indicate gravity/push for current mini-timestep +static int cornersurface = 0; bool collide(physent *d, bool spawn, float drop, float rise) { + cornersurface = 0; const float fx1 = d->o.x-d->radius; // figure out integer cube rectangle this entity covers in map const float fy1 = d->o.y-d->radius; const float fx2 = d->o.x+d->radius; @@ -175,11 +177,13 @@ bool collide(physent *d, bool spawn, float drop, float rise) case CORNER: { int bx = x, by = y, bs = 1; - if((x==x1 && y==y1 && cornertest(0, x, y, -1, -1, bx, by, bs) && fx1-bx+fy1-by<=bs) - || (x==x2 && y==y1 && cornertest(0, x, y, 1, -1, bx, by, bs) && fx2-bx>=fy1-by) - || (x==x1 && y==y2 && cornertest(0, x, y, -1, 1, bx, by, bs) && fx1-bx<=fy2-by) + cornersurface = 1; + if((x==x1 && y==y2 && cornertest(0, x, y, -1, 1, bx, by, bs) && fx1-bx<=fy2-by) + || (x==x2 && y==y1 && cornertest(0, x, y, 1, -1, bx, by, bs) && fx2-bx>=fy1-by) || !(++cornersurface) + || (x==x1 && y==y1 && cornertest(0, x, y, -1, -1, bx, by, bs) && fx1-bx+fy1-by<=bs) || (x==x2 && y==y2 && cornertest(0, x, y, 1, 1, bx, by, bs) && fx2-bx+fy2-by>=bs)) - return false; + return false; + cornersurface = 0; break; } @@ -418,6 +422,25 @@ void moveplayer(physent *pl, int moveres, bool local, int curtime) hitplayer = NULL; if(collide(pl, false, drop, rise)) continue; else collided = true; + if(pl->type==ENT_BOUNCE && cornersurface) + { // try corner bounce + float ct2f = cornersurface == 2 ? -1.0 : 1.0; + vec oo = pl->o, xd = d; + xd.x = d.y * ct2f; + xd.y = d.x * ct2f; + pl->o.x += f * (-d.x + xd.x); + pl->o.y += f * (-d.y + xd.y); + if(collide(pl, false, drop, rise)) + { + d = xd; + float sw = pl->vel.x * ct2f; + pl->vel.x = pl->vel.y * ct2f; + pl->vel.y = sw; + pl->vel.mul(0.7f); + continue; + } + pl->o == oo; + } if(pl->type==ENT_CAMERA) return; if(pl->type==ENT_PLAYER && hitplayer) {