Double jump!
This commit is contained in:
parent
47eca60cf5
commit
50369b036c
@ -20,18 +20,24 @@ void Player::Move(bool front, bool back, bool left, bool right, bool jump, bool
|
||||
static float accjmp = 0;
|
||||
static float yrotrad = 0;
|
||||
static float xrotrad = 0;
|
||||
static bool jumped = false;
|
||||
static bool jumped = true;
|
||||
static int dbljump = 0; // Peut sauter ou dasher tant que la variable est en dessous de 2.
|
||||
static int dashtimeout = 0;
|
||||
|
||||
if (dashtimeout > 0) {
|
||||
dash = false;
|
||||
--dashtimeout;
|
||||
}
|
||||
else if (dash) dashtimeout = 100;
|
||||
|
||||
if ((jump || dash) && !jumped) {
|
||||
accjmp = jump? m_jumpforce: 0.1f;
|
||||
if (jumped && !jump) jumped = false; // Anti-rebondissement du saut, pour pouvoir rebondir.
|
||||
|
||||
if (dash) dashtimeout = 100;
|
||||
|
||||
if ((jump || dash) && dbljump < 2 && !jumped ) {
|
||||
accjmp += jump? m_jumpforce: 0.1f;
|
||||
jumped = true;
|
||||
dbljump++;
|
||||
std::cout << accjmp << std::endl;
|
||||
}
|
||||
else if (m_position.y > -0.2f && accjmp != 0) {
|
||||
if (accjmp > 0.f) {
|
||||
@ -48,43 +54,40 @@ void Player::Move(bool front, bool back, bool left, bool right, bool jump, bool
|
||||
if (jump) accjmp -= elapsedTime * 0.7;
|
||||
else accjmp -= elapsedTime * 0.9;
|
||||
}
|
||||
//front = false; // Empêche le déplacement dans les airs.
|
||||
//back = false;
|
||||
//left = false;
|
||||
//right = false;
|
||||
}
|
||||
else accjmp = 0;
|
||||
|
||||
if (m_position.y < 0.f) { //&& jumped) { // Suivi de mouvement pour l'atterrissage.
|
||||
if (m_position.y < 0.f) { // Suivi de mouvement pour l'atterrissage.
|
||||
m_position.y += elapsedTime * 5.f;
|
||||
if (m_position.y > 0.f) {
|
||||
jumped = false;
|
||||
dbljump = 0;
|
||||
m_position.y = 0;
|
||||
}
|
||||
}
|
||||
|
||||
m_position.y += accjmp;
|
||||
|
||||
if (!jumped && ( left || right || front || back)) {
|
||||
if (dbljump < 1 && ( 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) accWS = m_topspeed; // Pour avoir un boost de vitesse vers l'avant si le dash est appuyé seul.
|
||||
}
|
||||
|
||||
m_position.y += accjmp;
|
||||
|
||||
if (front) {
|
||||
if (!jumped)
|
||||
if (jumped == 0)
|
||||
if (accWS < m_topspeed) accWS += elapsedTime * 30; else accWS = m_topspeed;
|
||||
if (dash) {
|
||||
accWS *= 3.f;
|
||||
++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.z += float(-cos(yrotrad)) * elapsedTime * accWS;
|
||||
}
|
||||
else if (back) {
|
||||
if (!jumped)
|
||||
if (jumped == 0)
|
||||
if (accWS > -m_topspeed) accWS -= elapsedTime * 30; else accWS = -m_topspeed;
|
||||
if (dash) {
|
||||
accWS *= 3.f;
|
||||
--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;
|
||||
@ -99,16 +102,16 @@ void Player::Move(bool front, bool back, bool left, bool right, bool jump, bool
|
||||
}
|
||||
|
||||
if (left) {
|
||||
if (!jumped)
|
||||
if (jumped == 0)
|
||||
if (accAD < m_topspeed) accAD += elapsedTime * 30; else accAD = m_topspeed;
|
||||
if (dash) accAD *= 3.f;
|
||||
if (dash) ++accAD *= 3.f;
|
||||
m_position.x += float(-cos(yrotrad)) * elapsedTime * accAD;
|
||||
m_position.z += float(-sin(yrotrad)) * elapsedTime * accAD;
|
||||
}
|
||||
else if (right) {
|
||||
if (!jumped)
|
||||
if (jumped == 0)
|
||||
if (accAD > -m_topspeed) accAD -= elapsedTime * 30; else accAD = -m_topspeed;
|
||||
if (dash) accAD *= 3.f;
|
||||
if (dash) --accAD *= 3.f;
|
||||
m_position.x += float(cos(yrotrad)) * elapsedTime * -accAD;
|
||||
m_position.z += float(sin(yrotrad)) * elapsedTime * -accAD;
|
||||
}
|
||||
|
@ -16,8 +16,8 @@ private:
|
||||
Vector3f m_position;
|
||||
float m_rotX = 0;
|
||||
float m_rotY = 0;
|
||||
float m_topspeed = 30;
|
||||
float m_jumpforce = 0.6f;
|
||||
float m_topspeed = 40;
|
||||
float m_jumpforce = .9f;
|
||||
|
||||
};
|
||||
#endif //_PLAYER_H__
|
||||
|
Loading…
Reference in New Issue
Block a user