Ajout du Dash!

This commit is contained in:
Marc-Eric Martel 2021-10-04 15:01:25 -04:00
parent b85a25cbac
commit 47eca60cf5
3 changed files with 37 additions and 21 deletions

View File

@ -152,7 +152,7 @@ void OpenglContext::ShowCrossCursor() const
void OpenglContext::InitWindow(int width, int height) void OpenglContext::InitWindow(int width, int height)
{ {
m_app.create((m_fullscreen ? sf::VideoMode::getFullscreenModes()[0] : sf::VideoMode(width, height, 32)), m_title.c_str(), m_fullscreen ? sf::Style::Fullscreen : (sf::Style::Resize | sf::Style::Close), sf::ContextSettings(32, 8, 4)); m_app.create((m_fullscreen ? sf::VideoMode::getFullscreenModes()[0] : sf::VideoMode(width, height, 32)), m_title.c_str(), m_fullscreen ? sf::Style::Fullscreen : (sf::Style::Resize | sf::Style::Close), sf::ContextSettings(32, 8, 8));
} }
OpenglContext::MOUSE_BUTTON OpenglContext::ConvertMouseButton(sf::Mouse::Button button) const OpenglContext::MOUSE_BUTTON OpenglContext::ConvertMouseButton(sf::Mouse::Button button) const

View File

@ -21,9 +21,16 @@ void Player::Move(bool front, bool back, bool left, bool right, bool jump, bool
static float yrotrad = 0; static float yrotrad = 0;
static float xrotrad = 0; static float xrotrad = 0;
static bool jumped = false; static bool jumped = false;
static int dashtimeout = 0;
if (jump && !jumped) { if (dashtimeout > 0) {
accjmp = m_jumpforce; dash = false;
--dashtimeout;
}
else if (dash) dashtimeout = 100;
if ((jump || dash) && !jumped) {
accjmp = jump? m_jumpforce: 0.1f;
jumped = true; jumped = true;
} }
else if (m_position.y > -0.2f && accjmp != 0) { else if (m_position.y > -0.2f && accjmp != 0) {
@ -41,10 +48,10 @@ void Player::Move(bool front, bool back, bool left, bool right, bool jump, bool
if (jump) accjmp -= elapsedTime * 0.7; if (jump) accjmp -= elapsedTime * 0.7;
else accjmp -= elapsedTime * 0.9; else accjmp -= elapsedTime * 0.9;
} }
front = false; // Empêche le déplacement dans les airs. //front = false; // Empêche le déplacement dans les airs.
back = false; //back = false;
left = false; //left = false;
right = false; //right = false;
} }
else accjmp = 0; else accjmp = 0;
@ -58,27 +65,33 @@ void Player::Move(bool front, bool back, bool left, bool right, bool jump, bool
m_position.y += accjmp; m_position.y += accjmp;
if (!jumped || left || right || front || back) { if (!jumped && ( left || right || front || back)) {
yrotrad = (m_rotY / 57.2957795056f); // 180/Pi = 57.295... yrotrad = (m_rotY / 57.2957795056f); // 180/Pi = 57.295...
xrotrad = (m_rotX / 57.2957795056f); xrotrad = (m_rotX / 57.2957795056f);
} }
if (front) { if (front) {
if (!jumped)
if (accWS < m_topspeed) accWS += elapsedTime * 30; else accWS = m_topspeed; if (accWS < m_topspeed) accWS += elapsedTime * 30; else accWS = m_topspeed;
if (dash) {
accWS *= 3.f;
//m_position.y += float(-sin(xrotrad)) * elapsedTime * 70; // à remettre pour implémenter une fonction de vol.
}
m_position.x += float(sin(yrotrad)) * elapsedTime * accWS; m_position.x += float(sin(yrotrad)) * elapsedTime * accWS;
m_position.z += float(-cos(yrotrad)) * elapsedTime * accWS; m_position.z += float(-cos(yrotrad)) * elapsedTime * accWS;
// m_position.y += float(-sin(xrotrad)) * elapsedTime * 20; // à remettre pour implémenter une fonction de vol.
} }
else if (back) { else if (back) {
if (!jumped)
if (accWS > -m_topspeed) accWS -= elapsedTime * 30; else accWS = -m_topspeed; if (accWS > -m_topspeed) accWS -= elapsedTime * 30; else accWS = -m_topspeed;
if (dash) {
accWS *= 3.f;
//m_position.y += float(sin(xrotrad)) * elapsedTime * 20; // à remettre pour implémenter une fonction de vol.
}
m_position.x += float(-sin(yrotrad)) * elapsedTime * -accWS; m_position.x += float(-sin(yrotrad)) * elapsedTime * -accWS;
m_position.z += float(cos(yrotrad)) * elapsedTime * -accWS; m_position.z += float(cos(yrotrad)) * elapsedTime * -accWS;
// m_position.y += float(sin(xrotrad)) * elapsedTime * 20; // à remettre pour implémenter une fonction de vol.
} }
else if (accWS != 0) { else if (accWS != 0) {
accWS = accWS > 0 ? accWS - elapsedTime * (m_position.y > 0.f ? 10 : 60) : accWS + elapsedTime * (m_position.y > 0.f ? 10 : 60); accWS = accWS > 0 ? accWS - elapsedTime * (m_position.y > 0.f ? 10 : 120) : accWS + elapsedTime * (m_position.y > 0.f ? 10 : 120);
m_position.x += float(sin(yrotrad)) * elapsedTime * accWS; m_position.x += float(sin(yrotrad)) * elapsedTime * accWS;
m_position.z += float(-cos(yrotrad)) * elapsedTime * accWS; m_position.z += float(-cos(yrotrad)) * elapsedTime * accWS;
@ -86,17 +99,21 @@ void Player::Move(bool front, bool back, bool left, bool right, bool jump, bool
} }
if (left) { if (left) {
if (!jumped)
if (accAD < m_topspeed) accAD += elapsedTime * 30; else accAD = m_topspeed; if (accAD < m_topspeed) accAD += elapsedTime * 30; else accAD = m_topspeed;
if (dash) accAD *= 3.f;
m_position.x += float(-cos(yrotrad)) * elapsedTime * accAD; m_position.x += float(-cos(yrotrad)) * elapsedTime * accAD;
m_position.z += float(-sin(yrotrad)) * elapsedTime * accAD; m_position.z += float(-sin(yrotrad)) * elapsedTime * accAD;
} }
else if (right) { else if (right) {
if (!jumped)
if (accAD > -m_topspeed) accAD -= elapsedTime * 30; else accAD = -m_topspeed; if (accAD > -m_topspeed) accAD -= elapsedTime * 30; else accAD = -m_topspeed;
if (dash) accAD *= 3.f;
m_position.x += float(cos(yrotrad)) * elapsedTime * -accAD; m_position.x += float(cos(yrotrad)) * elapsedTime * -accAD;
m_position.z += float(sin(yrotrad)) * elapsedTime * -accAD; m_position.z += float(sin(yrotrad)) * elapsedTime * -accAD;
} }
else if (accAD != 0) { else if (accAD != 0) {
accAD = accAD > 0 ? accAD - elapsedTime * (m_position.y > 0.f ? 10 : 60) : accAD + elapsedTime * (m_position.y > 0.f ? 10 : 60); accAD = accAD > 0 ? accAD - elapsedTime * (m_position.y > 0.f ? 10 : 120) : accAD + elapsedTime * (m_position.y > 0.f ? 10 : 120);
m_position.x += float(-cos(yrotrad)) * elapsedTime * accAD; m_position.x += float(-cos(yrotrad)) * elapsedTime * accAD;
m_position.z += float(-sin(yrotrad)) * elapsedTime * accAD; m_position.z += float(-sin(yrotrad)) * elapsedTime * accAD;
if (accAD < 1 && accAD > -1) accAD = 0; if (accAD < 1 && accAD > -1) accAD = 0;

View File

@ -16,9 +16,8 @@ private:
Vector3f m_position; Vector3f m_position;
float m_rotX = 0; float m_rotX = 0;
float m_rotY = 0; float m_rotY = 0;
float m_topspeed = 20; float m_topspeed = 30;
float m_jumpforce = 0.4f; float m_jumpforce = 0.6f;
}; };
#endif //_PLAYER_H__ #endif //_PLAYER_H__