forked from jaildesigner-jailgames/jaildoctors_dilemma
corregida logica de atravesar el fondo de la pantalla a velocitat terminal
This commit is contained in:
@@ -48,7 +48,7 @@ void Player::update(float delta_time) {
|
||||
updateState(delta_time);
|
||||
move(delta_time);
|
||||
animate(delta_time);
|
||||
handleBorders();
|
||||
border_ = handleBorders();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -125,21 +125,18 @@ void Player::transitionToState(State state) {
|
||||
|
||||
switch (state) {
|
||||
case State::ON_GROUND:
|
||||
// std::cout << "ON_GROUND\n";
|
||||
vy_ = 0;
|
||||
handleDeathByFalling();
|
||||
resetSoundControllersOnLanding();
|
||||
current_slope_ = nullptr;
|
||||
break;
|
||||
case State::ON_SLOPE:
|
||||
// std::cout << "ON_SLOPE\n";
|
||||
vy_ = 0;
|
||||
handleDeathByFalling();
|
||||
resetSoundControllersOnLanding();
|
||||
updateCurrentSlope();
|
||||
break;
|
||||
case State::JUMPING:
|
||||
// std::cout << "JUMPING\n";
|
||||
// Puede saltar desde ON_GROUND o ON_SLOPE
|
||||
if (previous_state_ == State::ON_GROUND || previous_state_ == State::ON_SLOPE) {
|
||||
vy_ = -MAX_VY;
|
||||
@@ -150,7 +147,6 @@ void Player::transitionToState(State state) {
|
||||
}
|
||||
break;
|
||||
case State::FALLING:
|
||||
// std::cout << "FALLING\n";
|
||||
fall_start_position_ = static_cast<int>(y_);
|
||||
last_grounded_position_ = static_cast<int>(y_);
|
||||
vy_ = MAX_VY;
|
||||
@@ -378,30 +374,27 @@ void Player::moveFalling(float delta_time) {
|
||||
}
|
||||
|
||||
// Comprueba si está situado en alguno de los cuatro bordes de la habitación
|
||||
void Player::handleBorders() {
|
||||
auto Player::handleBorders() -> Room::Border {
|
||||
if (x_ < PlayArea::LEFT) {
|
||||
border_ = Room::Border::LEFT;
|
||||
is_on_border_ = true;
|
||||
return Room::Border::LEFT;
|
||||
}
|
||||
|
||||
else if (x_ + WIDTH > PlayArea::RIGHT) {
|
||||
border_ = Room::Border::RIGHT;
|
||||
is_on_border_ = true;
|
||||
if (x_ + WIDTH > PlayArea::RIGHT) {
|
||||
return Room::Border::RIGHT;
|
||||
}
|
||||
|
||||
else if (y_ < PlayArea::TOP) {
|
||||
border_ = Room::Border::TOP;
|
||||
is_on_border_ = true;
|
||||
if (y_ < PlayArea::TOP) {
|
||||
return Room::Border::TOP;
|
||||
}
|
||||
|
||||
else if (y_ + HEIGHT > PlayArea::BOTTOM) {
|
||||
border_ = Room::Border::BOTTOM;
|
||||
is_on_border_ = true;
|
||||
if (y_ + HEIGHT > PlayArea::BOTTOM) {
|
||||
// Si llega en estado terminal, muere y no cruza
|
||||
const bool SHOULD_DIE = static_cast<int>(y_) - last_grounded_position_ > MAX_FALLING_HEIGHT;
|
||||
if (SHOULD_DIE) { markAsDead(); }
|
||||
return is_alive_ ? Room::Border::BOTTOM : Room::Border::NONE;
|
||||
}
|
||||
|
||||
else {
|
||||
is_on_border_ = false;
|
||||
}
|
||||
return Room::Border::NONE;
|
||||
}
|
||||
|
||||
// Cambia al jugador de un borde al opuesto. Util para el cambio de pantalla
|
||||
@@ -433,8 +426,8 @@ void Player::switchBorders() {
|
||||
break;
|
||||
}
|
||||
|
||||
is_on_border_ = false;
|
||||
placeSprite();
|
||||
border_ = Room::Border::NONE;
|
||||
syncSpriteAndCollider();
|
||||
}
|
||||
|
||||
// Aplica gravedad al jugador
|
||||
@@ -599,8 +592,8 @@ auto Player::handleKillingTiles() -> bool {
|
||||
if (std::ranges::any_of(collider_points_, [this](const auto& c) {
|
||||
return room_->getTile(c) == Room::Tile::KILL;
|
||||
})) {
|
||||
is_alive_ = false; // Mata al jugador inmediatamente
|
||||
return true; // Retorna en cuanto se detecta una colisión
|
||||
markAsDead(); // Mata al jugador inmediatamente
|
||||
return true; // Retorna en cuanto se detecta una colisión
|
||||
}
|
||||
|
||||
return false; // No se encontró ninguna colisión
|
||||
@@ -772,13 +765,9 @@ void Player::placeSprite() {
|
||||
|
||||
// Gestiona la muerta al ccaer desde muy alto
|
||||
void Player::handleDeathByFalling() {
|
||||
if (Options::cheats.invincible == Options::Cheat::State::ENABLED) {
|
||||
return;
|
||||
}
|
||||
|
||||
const int FALL_DISTANCE = static_cast<int>(y_) - last_grounded_position_;
|
||||
if (previous_state_ == State::FALLING && FALL_DISTANCE > MAX_FALLING_HEIGHT) {
|
||||
is_alive_ = false; // Muere si cae más de 32 píxeles
|
||||
markAsDead(); // Muere si cae más de 32 píxeles
|
||||
}
|
||||
}
|
||||
|
||||
@@ -908,6 +897,15 @@ auto Player::getProjection(Direction direction, float displacement) -> SDL_FRect
|
||||
}
|
||||
}
|
||||
|
||||
// Marca al jugador como muerto
|
||||
void Player::markAsDead() {
|
||||
if (Options::cheats.invincible == Options::Cheat::State::ENABLED) {
|
||||
is_alive_ = true; // No puede morir
|
||||
} else {
|
||||
is_alive_ = false; // Muere
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
// Establece la posición del jugador directamente (debug)
|
||||
void Player::setDebugPosition(float x, float y) {
|
||||
|
||||
Reference in New Issue
Block a user