Done?
This commit is contained in:
@@ -18,7 +18,7 @@ void Player::TurnTopBottom(float value) {
|
||||
else if (m_rotX < -80) m_rotX = -80;
|
||||
}
|
||||
|
||||
Vector3f Player::GetInput(bool front, bool back, bool left, bool right, bool jump, bool dash, float elapsedTime) {
|
||||
Vector3f Player::GetInput(bool front, bool back, bool left, bool right, bool jump, bool shoot, float elapsedTime) {
|
||||
|
||||
Vector3f delta = Vector3f(0, 0, 0);
|
||||
|
||||
@@ -53,16 +53,20 @@ Vector3f Player::GetInput(bool front, bool back, bool left, bool right, bool jum
|
||||
delta.x *= .6f;
|
||||
delta.z *= .6f;
|
||||
|
||||
if (jump && !m_airborne) {
|
||||
delta.y += .32f;
|
||||
if ((jump || shoot ) && !m_airborne) {
|
||||
delta.y += jump? .32f: shoot? .1f : 0.f;
|
||||
m_airborne = true;
|
||||
}
|
||||
|
||||
if (shoot) // Recoil!
|
||||
TurnTopBottom(-1);
|
||||
|
||||
return delta;
|
||||
}
|
||||
|
||||
void Player::ApplyPhysics(Vector3f input, World world, float elapsedTime) {
|
||||
|
||||
void Player::ApplyPhysics(Vector3f input, World world, float elapsedTime, Audio* audio) {
|
||||
static irrklang::ISound* step; // Pour les sons de pas.
|
||||
static float timing = 0.f;
|
||||
/* Gestion de collisions */
|
||||
BlockType bt1, bt2, bt3;
|
||||
|
||||
@@ -81,6 +85,10 @@ void Player::ApplyPhysics(Vector3f input, World world, float elapsedTime) {
|
||||
bt1 = world.BlockAt(GetPosition().x, GetPosition().y + .3f, GetPosition().z);
|
||||
if (bt3 != BTYPE_AIR) {
|
||||
m_velocity.y = 0;
|
||||
if (timing == 0.f) {
|
||||
if (m_airborne) audio->Create3DAudioObj(step, AUDIO_PATH "hit.wav", GetPosition(), GetVelocity(), 1.f);
|
||||
timing = .3f;
|
||||
}
|
||||
m_airborne = false;
|
||||
}
|
||||
else if (bt1 != BTYPE_AIR) {
|
||||
@@ -89,6 +97,9 @@ void Player::ApplyPhysics(Vector3f input, World world, float elapsedTime) {
|
||||
else m_airborne = true;
|
||||
}
|
||||
|
||||
if (timing > 0.f) timing -= elapsedTime;
|
||||
if (timing < 0.f) timing = 0.f;
|
||||
|
||||
bt1 = world.BlockAt(GetPosition().x + input.x, GetPosition().y, GetPosition().z);
|
||||
bt2 = world.BlockAt(GetPosition().x + input.x, GetPosition().y - 0.9f, GetPosition().z);
|
||||
bt3 = world.BlockAt(GetPosition().x + input.x, GetPosition().y - 1.7f, GetPosition().z);
|
||||
@@ -137,7 +148,22 @@ void Player::ApplyPhysics(Vector3f input, World world, float elapsedTime) {
|
||||
m_position += m_velocity;
|
||||
|
||||
static float bobbingtime = 0; // Gestion de la cam<61>ra
|
||||
if (bobbingtime <= 360.f) bobbingtime += elapsedTime * 20.f; else bobbingtime = 0;
|
||||
static bool leftright = false;
|
||||
static bool isStep = false;
|
||||
if (bobbingtime <= 360.f)
|
||||
bobbingtime += elapsedTime * 20.f; else bobbingtime = 0;
|
||||
|
||||
if ((sin(bobbingtime) - 0.5f) * (abs(m_velocity.x) + abs(m_velocity.z)) < -.2f && !m_airborne) {
|
||||
Vector3f vstep;
|
||||
if (leftright)
|
||||
vstep = Vector3f(GetPosition().x - GetDirection().x, GetPosition().y, GetPosition().z + GetDirection().z);
|
||||
else vstep = Vector3f(GetPosition().x + GetDirection().x, GetPosition().y, GetPosition().z - GetDirection().z);
|
||||
if (!isStep) {
|
||||
audio->Create3DAudioObj(step, AUDIO_PATH "step.wav", vstep, GetVelocity(), .8f);
|
||||
}
|
||||
isStep = true;
|
||||
}
|
||||
else isStep = false;
|
||||
m_POV = m_position.y;
|
||||
m_POV += m_airborne ? 0 : (sin(bobbingtime) - 0.5f) * (abs(m_velocity.x) + abs(m_velocity.z)) * .2f;
|
||||
}
|
||||
|
Reference in New Issue
Block a user