Getting there...

This commit is contained in:
MarcEricMartel 2021-11-15 22:54:01 -05:00
parent cee946028a
commit aa1d19d93d
3 changed files with 34 additions and 20 deletions

View File

@ -301,7 +301,7 @@ void Engine::Render(float elapsedTime) {
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
if (m_player.GetPosition().y < -10.f) m_player = Player(Vector3f(64, 64, 64));
if (m_player.GetPosition().y < -10.f) m_player = Player(Vector3f(64, 34, 64));
}
void Engine::KeyPressEvent(unsigned char key)

View File

@ -52,7 +52,7 @@ private:
Shader m_shader01;
Audio m_audio = Audio(AUDIO_PATH "music01.wav");
Player m_player = Player(Vector3f(64, 64, 64));
Player m_player = Player(Vector3f(64, 34, 64));
bool m_keyW = false;
bool m_keyA = false;

View File

@ -30,13 +30,9 @@ Vector3f Player::GetInput(bool front, bool back, bool left, bool right, bool jum
-sin(m_rotX / 57.2957795056f),
sin(m_rotY / 57.2957795056f) * cos(m_rotX / 57.2957795056f));
//if (m_airborne && !jump) m_airborne = false; // Anti-rebondissement du saut, pour pouvoir rebondir.
if ((jump || dash) && !m_airborne) {
delta.y += jump ? m_jumpforce : 0.01f;
delta.y += jump ? m_jumpforce : 0.1f;
m_airborne = true;
//m_jumped = true;
m_dbljump++;
}
if (dashtimeout > 0.f) { // Gestion du timeout de dash pour ne pas pouvoir spammer le dash.
@ -46,13 +42,13 @@ Vector3f Player::GetInput(bool front, bool back, bool left, bool right, bool jum
else dashtimeout = 0;
if (dash) dashtimeout = 2;
if ((m_dbljump < 1 && (left || right || front || back)) ||
if ((!m_airborne && (left || right || front || back)) ||
(dash && !(left || right || front || back))) {
yrotrad = (m_rotY / 57.2957795056f); // 180/Pi = 57.295...
xrotrad = (m_rotX / 57.2957795056f);
if (dash) {
delta.x += float(sin(yrotrad)) * elapsedTime;
delta.z += float(-cos(yrotrad)) * elapsedTime;
delta.x += float(sin(yrotrad)) * elapsedTime * 20.f;
delta.z += float(-cos(yrotrad)) * elapsedTime * 20.f;
}
}
@ -189,29 +185,47 @@ void Player::ApplyPhysics(Vector3f input, World world, float elapsedTime) {
/* Gestion de collisions */
BlockType bt1, bt2, bt3;
if (m_velocity.x * m_velocity.x + m_velocity.z * m_velocity.z >= .005f) {
m_velocity.x *= 0.9f;
m_velocity.z *= 0.9f;
}
if (!m_airborne) {
m_velocity.x = input.x ? m_velocity.x + input.x * 4.f * elapsedTime : -.1f * m_velocity.x * elapsedTime;
m_velocity.z = input.z ? m_velocity.z + input.z * 4.f * elapsedTime : -.1f * m_velocity.z * elapsedTime;
}
else {
m_velocity.x += -.1f * m_velocity.x * elapsedTime;
m_velocity.z += -.1f * m_velocity.x * elapsedTime;
}
bt1 = world.BlockAt(m_position.x, m_position.y + input.y, m_position.z);
bt2 = world.BlockAt(m_position.x, m_position.y + input.y - 0.9f, m_position.z);
bt3 = world.BlockAt(m_position.x, m_position.y + input.y - 1.7f, m_position.z);
if (bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) {
m_dbljump = 0;
if (input.y < 0.f) {
input.y = 0;
}
m_velocity.y = input.y;
if (!m_airborne) m_position.y = (int)m_position.y + .7f;
bt1 = world.BlockAt(m_position.x, m_position.y + .3f, m_position.z);
if (bt1 == BTYPE_AIR) m_position.y = (int)m_position.y + .7f;
m_velocity.y = input.y = 0;
m_airborne = false;
}
else if (m_airborne) {
else {
if (abs(m_velocity.y) < 1.1f) m_velocity.y += input.y - 1.1f * elapsedTime;
m_airborne = true;
bt3 = world.BlockAt(m_position.x, m_position.y + m_velocity.y - 1.7f, m_position.z);
if (bt3 != BTYPE_AIR) {
m_velocity.y = 0;
m_airborne = false;
}
else m_airborne = true;
}
bt1 = world.BlockAt(m_position.x + input.x, m_position.y, m_position.z);
bt2 = world.BlockAt(m_position.x + input.x, m_position.y - 0.9f, m_position.z);
bt3 = world.BlockAt(m_position.x + input.x, m_position.y - 1.7f, m_position.z);
if (bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) {
input.x = 0;
m_velocity.x = 0;
}
bt1 = world.BlockAt(m_position.x, m_position.y, m_position.z + input.z);
@ -219,12 +233,12 @@ void Player::ApplyPhysics(Vector3f input, World world, float elapsedTime) {
bt3 = world.BlockAt(m_position.x, m_position.y - 1.7f, m_position.z + input.z);
if (bt1 != BTYPE_AIR || bt2 != BTYPE_AIR || bt3 != BTYPE_AIR) {
input.z = 0;
m_velocity.z = 0;
}
/* Fin gestion de collisions */
m_position += input;
if (m_airborne) m_position.y += m_velocity.y;
m_position += m_velocity;
static float bobbingtime = 0; // Gestion de la caméra
if (bobbingtime <= 360.f) bobbingtime += elapsedTime * m_topspeed / 2; else bobbingtime = 0;