From ed2d963a8fe18aee69a1ac9747c8af99705a9f4f Mon Sep 17 00:00:00 2001 From: Treeki Date: Tue, 12 Feb 2013 23:41:03 +0100 Subject: jumping and player Z order fix for maps --- src/koopatlas/pathmanager.cpp | 47 ++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 12 deletions(-) (limited to 'src/koopatlas/pathmanager.cpp') diff --git a/src/koopatlas/pathmanager.cpp b/src/koopatlas/pathmanager.cpp index 169668b..0ef89fc 100644 --- a/src/koopatlas/pathmanager.cpp +++ b/src/koopatlas/pathmanager.cpp @@ -687,22 +687,45 @@ void dWMPathManager_c::moveThroughPath(int pressedDir) { VECScale(&move, &move, moveSpeed); if (isJumping) { - float ys = (float)from->y; - float ye = (float)to->y; - float midpoint = (from->y + to->y) / 2; + bool isFalling; + if (from->y == to->y) { + float xDistance = to->x - from->x; + if (xDistance < 0) + xDistance = -xDistance; + float currentPoint = max(to->x, from->x) - player->pos.x; + player->jumpOffset = (xDistance / 3.0f) * sin((currentPoint / xDistance) * 3.1415f); + + if (to->x > from->x) // Moving right + isFalling = (player->pos.x > (to->x - (move.x * 10.0f))); + else // Moving left + isFalling = (player->pos.x < (to->x + (move.x * 10.0f))); - float top, len; - if (ys > ye) { len = ys - ye; top = ys - midpoint + 10.0; } - else { len = ye - ys; top = ye - midpoint + 10.0; } + } else { + float ys = (float)from->y; + float ye = (float)to->y; + float midpoint = (from->y + to->y) / 2; + + float top, len; + if (ys > ye) { len = ys - ye; top = ys - midpoint + 10.0; } + else { len = ye - ys; top = ye - midpoint + 10.0; } + + if (len == 0.0) { len = 2.0; } - if (len == 0.0) { len = 2.0; } + float a; + if (timer > 0.0) { a = -timer; } + else { a = timer; } - float a; - if (timer > 0.0) { a = -timer; } - else { a = timer; } - player->jumpOffset = -sin(a * 3.14 / len) * top; - timer -= move.y; + player->jumpOffset = -sin(a * 3.14 / len) * top; + timer -= move.y; + + if (ye > ys) // Moving down + isFalling = (-player->pos.y) > (ye - (move.y * 10.0f)); + else // Moving up + isFalling = (-player->pos.y) < (ye + (move.y * 10.0f)); + } + if (isFalling) + player->startAnimation(jumped, 1.0f, 10.0f, 0.0f); } player->pos.x += move.x; -- cgit v1.2.3