From e982d5938570602f1959275c867cd894b2744fb8 Mon Sep 17 00:00:00 2001 From: jachoo Date: Sat, 19 Nov 2011 19:03:39 +0100 Subject: [PATCH] Crouching (C key) --- src/defaultsettings.cpp | 2 ++ src/game.cpp | 8 +++++--- src/player.cpp | 19 ++++++++++++++++++- src/player.h | 10 ++++++++-- 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/defaultsettings.cpp b/src/defaultsettings.cpp index c735d5a..d43f389 100644 --- a/src/defaultsettings.cpp +++ b/src/defaultsettings.cpp @@ -35,6 +35,8 @@ void set_default_settings(Settings *settings) settings->setDefault("keymap_right", "KEY_KEY_D"); settings->setDefault("keymap_jump", "KEY_SPACE"); settings->setDefault("keymap_sneak", "KEY_LSHIFT"); + //settings->setDefault("keymap_crouch", "Left Control"); + settings->setDefault("keymap_crouch", "KEY_KEY_C"); settings->setDefault("keymap_inventory", "KEY_KEY_I"); settings->setDefault("keymap_special1", "KEY_KEY_E"); settings->setDefault("keymap_chat", "KEY_KEY_T"); diff --git a/src/game.cpp b/src/game.cpp index 88b33ca..f75dfe8 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1558,7 +1558,8 @@ void the_game( false, false, camera_pitch, - camera_yaw + camera_yaw, + false ); client.setPlayerControl(control); } @@ -1580,9 +1581,10 @@ void the_game( input->isKeyDown(getKeySetting("keymap_right")), input->isKeyDown(getKeySetting("keymap_jump")), input->isKeyDown(getKeySetting("keymap_special1")), - input->isKeyDown(getKeySetting("keymap_sneak")), + input->isKeyDown(getKeySetting("keymap_sneak")) || input->isKeyDown(getKeySetting("keymap_crouch")), camera_pitch, - camera_yaw + camera_yaw, + input->isKeyDown(getKeySetting("keymap_crouch")) ); client.setPlayerControl(control); } diff --git a/src/player.cpp b/src/player.cpp index 6dd757e..5aa1176 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -48,7 +48,8 @@ Player::Player(): m_pitch(0), m_yaw(0), m_speed(0,0,0), - m_position(0,0,0) + m_position(0,0,0), + m_eyeOffset(0,BS+(5*BS)/8,0) { lastTeleportPos.X=FLT_MAX; updateName(""); @@ -1019,6 +1020,22 @@ void LocalPlayer::applyControl(float dtime) // Accelerate to target speed with maximum increment accelerate(speed, inc); + + //j + static const f32 eyes_max = BS+(5*BS)/8; + static const f32 eyes_min = BS * 0.9f; + static const f32 eyes_delta = 10.f; + if(control.crouch){ + //crouching + if(m_eyeOffset.Y > eyes_min + 0.01f) + m_eyeOffset.Y += (eyes_min-m_eyeOffset.Y) * eyes_delta * dtime; + else m_eyeOffset.Y = eyes_min; + }else{ + //standing + if(m_eyeOffset.Y < eyes_max - 0.01f) + m_eyeOffset.Y += (eyes_max-m_eyeOffset.Y) * eyes_delta * dtime; + else m_eyeOffset.Y = eyes_max; + } } #endif diff --git a/src/player.h b/src/player.h index faff2c2..049d663 100644 --- a/src/player.h +++ b/src/player.h @@ -76,7 +76,8 @@ public: // This is at the height of the eyes of the current figure // return v3f(0, BS+BS/2, 0); // This is more like in minecraft - return v3f(0,BS+(5*BS)/8,0); + //return v3f(0,BS+(5*BS)/8,0); + return m_eyeOffset; } v3f getEyePosition() @@ -196,6 +197,7 @@ protected: f32 m_yaw; v3f m_speed; v3f m_position; + v3f m_eyeOffset; public: @@ -336,6 +338,7 @@ struct PlayerControl sneak = false; pitch = 0; yaw = 0; + crouch = false; } PlayerControl( bool a_up, @@ -346,7 +349,8 @@ struct PlayerControl bool a_aux1, bool a_sneak, float a_pitch, - float a_yaw + float a_yaw, + bool a_crouch ) { up = a_up; @@ -358,6 +362,7 @@ struct PlayerControl sneak = a_sneak; pitch = a_pitch; yaw = a_yaw; + crouch = a_crouch; } bool up; bool down; @@ -368,6 +373,7 @@ struct PlayerControl bool sneak; float pitch; float yaw; + bool crouch; }; class LocalPlayer : public Player