forked from jaildesigner-jailgames/jaildoctors_dilemma
Depurando los saltos con colisiones
This commit is contained in:
@@ -44,6 +44,8 @@ Player::Player(std::string _tileset, SDL_Renderer *_renderer, Asset *_asset, Inp
|
||||
sprite->setAnimationFrames(0, 2, 8 * 2, 0, 8, 16);
|
||||
sprite->setAnimationFrames(0, 3, 8 * 3, 0, 8, 16);
|
||||
sprite->setSpriteClip(sprite->getAnimationClip(0, 0));
|
||||
|
||||
lastPosition = getRect();
|
||||
}
|
||||
|
||||
// Destructor
|
||||
@@ -68,6 +70,7 @@ void Player::draw()
|
||||
// Actualiza las variables del objeto
|
||||
void Player::update()
|
||||
{
|
||||
setLastPosition();
|
||||
checkInput();
|
||||
sprite->update();
|
||||
checkBorders();
|
||||
@@ -77,12 +80,6 @@ void Player::update()
|
||||
// Comprueba las entradas y modifica variables
|
||||
void Player::checkInput()
|
||||
{
|
||||
// if (mInput->checkInput(INPUT_UP, REPEAT_FALSE))
|
||||
// changeRoom(mRoom->getRoomUp());
|
||||
//
|
||||
// if (mInput->checkInput(INPUT_DOWN, REPEAT_FALSE))
|
||||
// changeRoom(mRoom->getRoomDown());
|
||||
|
||||
// Se mueve en horizontal solo cuando no esté cayendo
|
||||
if ((input->checkInput(INPUT_LEFT, REPEAT_TRUE)) && (status != STATUS_FALLING))
|
||||
{
|
||||
@@ -187,7 +184,7 @@ SDL_Point Player::getLeftFoot()
|
||||
// Obtiene el valor del pixel inferior derecho del jugador
|
||||
SDL_Point Player::getRightFoot()
|
||||
{
|
||||
SDL_Point point = {(int)sprite->getPosX() + sprite->getWidth(), (int)sprite->getPosY() + sprite->getHeight()};
|
||||
SDL_Point point = {(int)sprite->getPosX() + sprite->getWidth() - 1, (int)sprite->getPosY() + sprite->getHeight()};
|
||||
return point;
|
||||
}
|
||||
|
||||
@@ -233,6 +230,19 @@ void Player::applyGravity()
|
||||
// Obtiene el rectangulo que delimita al jugador
|
||||
SDL_Rect Player::getRect()
|
||||
{
|
||||
SDL_Rect rect = {sprite->getPosX(), sprite->getPosY(), sprite->getWidth(), sprite->getHeight()};
|
||||
SDL_Rect rect = {(int)sprite->getPosX(), (int)sprite->getPosY(), sprite->getWidth(), sprite->getHeight()};
|
||||
return rect;
|
||||
}
|
||||
|
||||
// Guarda la posición actual en la variable lastPosition
|
||||
void Player::setLastPosition()
|
||||
{
|
||||
lastPosition = getRect();
|
||||
}
|
||||
|
||||
// Deshace el ultimo movimiento
|
||||
void Player::undoLastMove()
|
||||
{
|
||||
sprite->setPosX(lastPosition.x);
|
||||
sprite->setPosY(lastPosition.y);
|
||||
}
|
||||
Reference in New Issue
Block a user