forked from jaildesigner-jailgames/jaildoctors_dilemma
El salto ya hace el arco y luego cae
This commit is contained in:
@@ -11,7 +11,6 @@ Player::Player(std::string _tileset, SDL_Renderer *_renderer, Asset *_asset, Inp
|
||||
asset = _asset;
|
||||
renderer = _renderer;
|
||||
input = _input;
|
||||
room = _room;
|
||||
|
||||
// Crea objetos
|
||||
texture = new LTexture();
|
||||
@@ -24,6 +23,8 @@ Player::Player(std::string _tileset, SDL_Renderer *_renderer, Asset *_asset, Inp
|
||||
color = stringToColor("white");
|
||||
onBorder = false;
|
||||
border = BORDER_TOP;
|
||||
|
||||
jump_ini = 0;
|
||||
status = STATUS_STANDING;
|
||||
|
||||
sprite->setPosX(2 * 8);
|
||||
@@ -76,6 +77,7 @@ void Player::update()
|
||||
move(); // Recalcula la posición del jugador y su animación
|
||||
checkBorders(); // Comprueba si está situado en alguno de los cuatro bordes de la habitación
|
||||
applyGravity(); // Aplica gravedad al jugador
|
||||
checkJump(); // Comprueba si ha finalizado el salto
|
||||
}
|
||||
|
||||
// Comprueba las entradas y modifica variables
|
||||
@@ -167,12 +169,6 @@ void Player::switchBorders()
|
||||
onBorder = false;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Player::setRoom(Room *_room)
|
||||
{
|
||||
room = _room;
|
||||
}
|
||||
|
||||
// Obtiene el valor del pixel inferior izquierdo del jugador
|
||||
SDL_Point Player::getLeftFoot()
|
||||
{
|
||||
@@ -195,6 +191,7 @@ void Player::setStatus(int value)
|
||||
{
|
||||
status = STATUS_JUMPING;
|
||||
sprite->setVelY(-MAX_VY);
|
||||
jump_ini = sprite->getPosY();
|
||||
}
|
||||
|
||||
// Modifica el estado a 'cayendo'
|
||||
@@ -234,7 +231,6 @@ void Player::applyGravity()
|
||||
if (sprite->getVelY() > MAX_VY)
|
||||
{
|
||||
sprite->setVelY(MAX_VY);
|
||||
// status = STATUS_FALLING;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -268,3 +264,14 @@ void Player::move()
|
||||
sprite->animate(0);
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba si ha finalizado el salto
|
||||
void Player::checkJump()
|
||||
{
|
||||
if (status == STATUS_JUMPING)
|
||||
if (sprite->getVelY() > 0)
|
||||
if (sprite->getPosY() > jump_ini)
|
||||
{
|
||||
status = STATUS_FALLING;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user