From 6dd74a8049976f1eec3faa328b9549f088cccce9 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Sun, 12 Feb 2006 13:02:11 +0000 Subject: [PATCH] applied patch from christoph sommer (thanks alot) SVN-Revision: 3057 --- src/object/player.cpp | 24 ++++++++++++++++++++++++ src/object/player.hpp | 1 + 2 files changed, 25 insertions(+) diff --git a/src/object/player.cpp b/src/object/player.cpp index 6ac97dd2c..1e354bdd8 100644 --- a/src/object/player.cpp +++ b/src/object/player.cpp @@ -141,6 +141,8 @@ Player::init() on_ground_flag = false; grabbed_object = 0; + floor_normal = Vector(0,-1); + physic.reset(); } @@ -329,6 +331,16 @@ Player::handle_horizontal_input() bbox.set_width(31.8); } + // on downward slopes, adjust vertical velocity to match slope angle + if (on_ground()) { + if (floor_normal.y != 0) { + if ((floor_normal.x * vx) > 0) { + // we overdo it a little, just to be on the safe side + vy = vx * (floor_normal.x / floor_normal.y) * 2; + } + } + } + physic.set_velocity(vx, vy); physic.set_acceleration(ax, ay); } @@ -720,6 +732,18 @@ Player::collision(GameObject& other, const CollisionHit& hit) if(physic.get_velocity_y() < 0) physic.set_velocity_y(0); on_ground_flag = true; + + // remember normal of this tile + if (hit.normal.y > -0.9) { + floor_normal.x = hit.normal.x; + floor_normal.y = hit.normal.y; + } else { + // slowly adjust to unisolid tiles. + // Necessary because our bounding box sometimes reaches through slopes and thus hits unisolid tiles + floor_normal.x = (floor_normal.x * 0.9) + (hit.normal.x * 0.1); + floor_normal.y = (floor_normal.y * 0.9) + (hit.normal.y * 0.1); + } + } else if(hit.normal.y > 0) { // bumped against the roof physic.set_velocity_y(.1); } diff --git a/src/object/player.hpp b/src/object/player.hpp index fa4b80fd4..880337275 100644 --- a/src/object/player.hpp +++ b/src/object/player.hpp @@ -178,6 +178,7 @@ private: Sprite* smalltux_gameover; Sprite* smalltux_star; Sprite* bigtux_star; + Vector floor_normal; }; #endif /*SUPERTUX_PLAYER_H*/ -- 2.11.0