Crouching (C key)

This commit is contained in:
jachoo 2011-11-19 19:03:39 +01:00
parent 9905999298
commit e982d59385
4 changed files with 33 additions and 6 deletions

View File

@ -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");

View File

@ -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);
}

View File

@ -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("<not set>");
@ -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

View File

@ -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