From 1c59cff8328bd85d6aed7df38b7eaddbeeca0aec Mon Sep 17 00:00:00 2001 From: Mark Holmquist Date: Wed, 27 Jul 2011 14:38:48 -0700 Subject: Ladders implemented! --- src/player.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'src/player.cpp') diff --git a/src/player.cpp b/src/player.cpp index c43276ef1..3846cd8f9 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -375,6 +375,21 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d, in_water_stable = false; } + /* + Check if player is climbing + */ + + try { + v3s16 pp = floatToInt(position + v3f(0,0.5*BS,0), BS); + v3s16 pp2 = floatToInt(position + v3f(0,-0.2*BS,0), BS); + is_climbing = (content_features(map.getNode(pp).d).climbable || + content_features(map.getNode(pp2).d).climbable); + } + catch(InvalidPositionException &e) + { + is_climbing = false; + } + /* Collision uncertainty radius Make it a bit larger than the maximum distance of movement @@ -461,7 +476,7 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d, Player is allowed to jump when this is true. */ touching_ground = false; - + /*std::cout<<"Checking collisions for (" < (" @@ -814,6 +829,19 @@ void LocalPlayer::applyControl(float dtime) } } + if (is_climbing) { + if (control.up || control.left || control.right || control.down) { + v3f speed = getSpeed(); + speed.Y = 2*BS; + setSpeed(speed); + } + else { + v3f speed = getSpeed(); + speed.Y = -2*BS; + setSpeed(speed); + } + } + // The speed of the player (Y is ignored) if(superspeed) speed = speed.normalize() * walkspeed_max * 5.0; -- cgit v1.2.3 From 8e67f4c4e617a8fcbb9176de1bf0b267acfc6e2f Mon Sep 17 00:00:00 2001 From: Mark Holmquist Date: Sat, 30 Jul 2011 17:26:13 -0700 Subject: Fixed a few problems in the ladder update, and changed the speed to account for gravity --- src/player.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/player.cpp') diff --git a/src/player.cpp b/src/player.cpp index 3846cd8f9..270f795b5 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -382,8 +382,8 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d, try { v3s16 pp = floatToInt(position + v3f(0,0.5*BS,0), BS); v3s16 pp2 = floatToInt(position + v3f(0,-0.2*BS,0), BS); - is_climbing = (content_features(map.getNode(pp).d).climbable || - content_features(map.getNode(pp2).d).climbable); + is_climbing = (content_features(map.getNode(pp).getContent()).climbable || + content_features(map.getNode(pp2).getContent()).climbable); } catch(InvalidPositionException &e) { @@ -832,7 +832,7 @@ void LocalPlayer::applyControl(float dtime) if (is_climbing) { if (control.up || control.left || control.right || control.down) { v3f speed = getSpeed(); - speed.Y = 2*BS; + speed.Y = 2.5*BS; setSpeed(speed); } else { -- cgit v1.2.3 From 267744a56871f6eecbb80c7999c2fcd79989fc1e Mon Sep 17 00:00:00 2001 From: Mark Holmquist Date: Sat, 30 Jul 2011 21:53:05 -0700 Subject: Fixing ladders again --- src/player.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'src/player.cpp') diff --git a/src/player.cpp b/src/player.cpp index 270f795b5..be478e869 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -382,8 +382,8 @@ void LocalPlayer::move(f32 dtime, Map &map, f32 pos_max_d, try { v3s16 pp = floatToInt(position + v3f(0,0.5*BS,0), BS); v3s16 pp2 = floatToInt(position + v3f(0,-0.2*BS,0), BS); - is_climbing = (content_features(map.getNode(pp).getContent()).climbable || - content_features(map.getNode(pp2).getContent()).climbable); + is_climbing = ((content_features(map.getNode(pp).getContent()).climbable || + content_features(map.getNode(pp2).getContent()).climbable) && !free_move); } catch(InvalidPositionException &e) { @@ -738,7 +738,7 @@ void LocalPlayer::applyControl(float dtime) bool fast_move = g_settings.getBool("fast_move"); bool continuous_forward = g_settings.getBool("continuous_forward"); - if(free_move) + if(free_move || is_climbing) { v3f speed = getSpeed(); speed.Y = 0; @@ -765,6 +765,12 @@ void LocalPlayer::applyControl(float dtime) speed.Y = -walkspeed_max; setSpeed(speed); } + else if(is_climbing) + { + v3f speed = getSpeed(); + speed.Y = -3*BS; + setSpeed(speed); + } else { // If not free movement but fast is allowed, aux1 is @@ -827,17 +833,10 @@ void LocalPlayer::applyControl(float dtime) setSpeed(speed); swimming_up = true; } - } - - if (is_climbing) { - if (control.up || control.left || control.right || control.down) { - v3f speed = getSpeed(); - speed.Y = 2.5*BS; - setSpeed(speed); - } - else { - v3f speed = getSpeed(); - speed.Y = -2*BS; + else if(is_climbing) + { + v3f speed = getSpeed(); + speed.Y = 3*BS; setSpeed(speed); } } -- cgit v1.2.3