Juego de logica de salto
Estoy creando un juego de Mario 2D.
La siguiente función está destinada a actualizar la posición de un jugador cuando se presiona una tecla en particular. El jugador puede moverse hacia la izquierda y hacia la derecha, y saltar en el mismo lugar, o saltar hacia la izquierda o hacia la derecha (para formar un arco).
bool updatePlayerPosition(Movement* mov){
if (this->keyPressed(SDLK_RIGHT)) {
mov->applyForce(1); // Changes the velocity in X
}
if (this->keyPressed(SDLK_LEFT)) {
mov->applyForce(-1); // Changes the velocity in X
}
if (this->keyPressed(SDLK_SPACE)) {
mov->jump(); // Changes the velocity in Y
}
if (this->keyPressed(SDLK_DOWN)) {
mov->fallDown(); // Changes the velocity in X and Y
}
Point* pos = mov->getPosition();
// Check whether the position is out of bounds
if(Level::allowsMove(pos)){
// If it is not, I update the player's current position
position->x = pos->x;
position->y = pos->y;
return true;
}
// If the movement is not allowed, I don't change the position
else {
mov->setPosition(*position);
return false;
}
}
Aquí está el error: cuando llego al final del nivel (que tiene un ancho fijo), y si intento moverme a la derecha y saltaral mismo tiempo, el jugador salta y se queda en el aire. Solo cuando suelto la barra espaciadora, el jugador llega al suelo.
¿Cómo puedo arreglar esto?