forked from jaildesigner-jailgames/jaildoctors_dilemma
posss.. mes merdes que no van a cap lloc
This commit is contained in:
@@ -63,19 +63,18 @@ void Player::move(float delta_time) {
|
||||
|
||||
void Player::handleHorizontalMovement(float delta_time) {
|
||||
if (state_ == State::STANDING) {
|
||||
// 1. Primero, determinamos cuál debe ser la velocidad (vx_)
|
||||
// Determinama cuál debe ser la velocidad a partir de automovement o de wannaGo
|
||||
updateVelocity();
|
||||
}
|
||||
|
||||
// 2. Ahora, aplicamos el movimiento y el flip basado en la velocidad resultante
|
||||
// Aplica el movimiento y el flip basado en la velocidad resultante
|
||||
if (vx_ < 0.0F) {
|
||||
moveHorizontal(delta_time, -1);
|
||||
moveHorizontal(delta_time, Direction::LEFT);
|
||||
sprite_->setFlip(SDL_FLIP_HORIZONTAL);
|
||||
} else if (vx_ > 0.0F) {
|
||||
moveHorizontal(delta_time, 1);
|
||||
moveHorizontal(delta_time, Direction::RIGHT);
|
||||
sprite_->setFlip(SDL_FLIP_NONE);
|
||||
}
|
||||
// Si vx_ es 0.0F, no se llama a moveHorizontal, lo cual es correcto.
|
||||
}
|
||||
|
||||
void Player::handleVerticalMovement(float delta_time) {
|
||||
@@ -95,9 +94,6 @@ void Player::handleVerticalMovement(float delta_time) {
|
||||
}
|
||||
}
|
||||
|
||||
void Player::moveAndCollide(float delta_time) {
|
||||
}
|
||||
|
||||
void Player::handleConveyorBelts() {
|
||||
if (!auto_movement_ and isOnConveyorBelt() and wannaGo == Direction::STAY) {
|
||||
auto_movement_ = true;
|
||||
@@ -200,9 +196,7 @@ void Player::handleState(float delta_time) {
|
||||
} else if (state_ == State::STANDING) {
|
||||
// Si no tiene suelo debajo y no está en rampa descendente -> FALLING
|
||||
if (!isOnFloor() && !isOnConveyorBelt() && !isOnDownSlope()) {
|
||||
last_grounded_position_ = static_cast<int>(y_); // Guarda Y actual al SALIR de STANDING
|
||||
transitionToState(State::FALLING); // setState() establece vx_=0, vy_=MAX_VY
|
||||
playFallSound(delta_time);
|
||||
}
|
||||
} else if (state_ == State::JUMPING) {
|
||||
playJumpSound(delta_time);
|
||||
@@ -251,8 +245,7 @@ void Player::applyGravity(float delta_time) {
|
||||
}
|
||||
|
||||
// Maneja el movimiento sobre rampas
|
||||
// direction: -1 para izquierda, 1 para derecha
|
||||
void Player::handleSlopeMovement(int direction) {
|
||||
void Player::handleSlopeMovement(Direction direction) {
|
||||
// No procesa rampas durante el salto (permite atravesarlas cuando salta con movimiento horizontal)
|
||||
// Pero SÍ procesa en STANDING y FALLING (para pegarse a las rampas)
|
||||
if (state_ == State::JUMPING) {
|
||||
@@ -267,16 +260,16 @@ void Player::handleSlopeMovement(int direction) {
|
||||
|
||||
// Regla: Si está STANDING y tropieza lateralmente con una Slope, se pega a la slope
|
||||
// Comprueba si hay rampa en contacto lateral (solo los dos pixels inferiores)
|
||||
const int SIDE_X = direction < 0 ? static_cast<int>(x_) : static_cast<int>(x_) + WIDTH - 1;
|
||||
const int SIDE_X = direction == Direction::LEFT ? static_cast<int>(x_) : static_cast<int>(x_) + WIDTH - 1;
|
||||
const LineVertical SIDE = {
|
||||
.x = SIDE_X,
|
||||
.y1 = static_cast<int>(y_) + HEIGHT - 2,
|
||||
.y2 = static_cast<int>(y_) + HEIGHT - 1};
|
||||
|
||||
// Comprueba la rampa correspondiente según la dirección
|
||||
const int SLOPE_Y = direction < 0 ? room_->checkLeftSlopes(&SIDE) : room_->checkRightSlopes(&SIDE);
|
||||
const int SLOPE_Y = direction == Direction::LEFT ? room_->checkLeftSlopes(SIDE) : room_->checkRightSlopes(SIDE);
|
||||
|
||||
if (SLOPE_Y > -1) {
|
||||
if (SLOPE_Y != Collision::NONE) {
|
||||
// Hay rampa: sube al jugador para pegarlo a la rampa
|
||||
|
||||
// --- INICIO DE LA CORRECCIÓN ---
|
||||
@@ -300,38 +293,44 @@ void Player::handleSlopeMovement(int direction) {
|
||||
}
|
||||
|
||||
// Maneja el movimiento horizontal
|
||||
// direction: -1 para izquierda, 1 para derecha
|
||||
void Player::moveHorizontal(float delta_time, int direction) {
|
||||
void Player::moveHorizontal(float delta_time, Direction direction) {
|
||||
const float DISPLACEMENT = vx_ * delta_time;
|
||||
|
||||
// Crea el rectangulo de proyección en el eje X para ver si colisiona
|
||||
SDL_FRect proj;
|
||||
if (direction < 0) {
|
||||
// Movimiento a la izquierda
|
||||
proj = {
|
||||
.x = x_ + DISPLACEMENT,
|
||||
.y = y_,
|
||||
.w = std::ceil(std::fabs(DISPLACEMENT)),
|
||||
.h = HEIGHT};
|
||||
} else {
|
||||
// Movimiento a la derecha
|
||||
proj = {
|
||||
.x = x_ + WIDTH,
|
||||
.y = y_,
|
||||
.w = std::ceil(DISPLACEMENT),
|
||||
.h = HEIGHT};
|
||||
switch (direction) {
|
||||
case Direction::LEFT:
|
||||
// Movimiento a la izquierda
|
||||
proj = {
|
||||
.x = x_ + DISPLACEMENT,
|
||||
.y = y_,
|
||||
.w = std::ceil(std::fabs(DISPLACEMENT)),
|
||||
.h = HEIGHT};
|
||||
break;
|
||||
|
||||
case Direction::RIGHT:
|
||||
// Movimiento a la derecha
|
||||
proj = {
|
||||
.x = x_ + WIDTH,
|
||||
.y = y_,
|
||||
.w = std::ceil(DISPLACEMENT),
|
||||
.h = HEIGHT};
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Comprueba la colisión con las superficies
|
||||
const int POS = direction < 0 ? room_->checkRightSurfaces(&proj) : room_->checkLeftSurfaces(&proj);
|
||||
const int POS = direction == Direction::LEFT ? room_->checkRightSurfaces(proj) : room_->checkLeftSurfaces(proj);
|
||||
|
||||
// Calcula la nueva posición
|
||||
if (POS == -1) {
|
||||
if (POS == Collision::NONE) {
|
||||
// No hay colisión: mueve al jugador
|
||||
x_ += DISPLACEMENT;
|
||||
} else {
|
||||
// Hay colisión: reposiciona al jugador en el punto de colisión
|
||||
x_ = direction < 0 ? POS + 1 : POS - WIDTH;
|
||||
x_ = direction == Direction::LEFT ? POS + 1 : POS - WIDTH;
|
||||
}
|
||||
|
||||
// Maneja el movimiento sobre rampas
|
||||
@@ -350,10 +349,10 @@ void Player::moveVerticalUp(float delta_time) {
|
||||
};
|
||||
|
||||
// Comprueba la colisión
|
||||
const int POS = room_->checkBottomSurfaces(&proj);
|
||||
const int POS = room_->checkBottomSurfaces(proj);
|
||||
|
||||
// Calcula la nueva posición
|
||||
if (POS == -1) {
|
||||
if (POS == Collision::NONE) {
|
||||
// Si no hay colisión
|
||||
y_ += DISPLACEMENT;
|
||||
} else {
|
||||
@@ -376,21 +375,11 @@ void Player::moveVerticalDown(float delta_time) {
|
||||
};
|
||||
|
||||
// Comprueba la colisión con las superficies normales y las automáticas
|
||||
const float POS = std::max(room_->checkTopSurfaces(&proj), room_->checkAutoSurfaces(&proj));
|
||||
if (POS > -1) {
|
||||
const float POS = std::max(room_->checkTopSurfaces(proj), room_->checkAutoSurfaces(proj));
|
||||
if (POS != Collision::NONE) {
|
||||
// Si hay colisión lo mueve hasta donde no colisiona y pasa a estar sobre la superficie
|
||||
y_ = POS - HEIGHT;
|
||||
|
||||
// VERIFICAR MUERTE ANTES de cambiar de estado (PLAYER_MECHANICS.md línea 1268-1274)
|
||||
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
|
||||
}
|
||||
|
||||
transitionToState(State::STANDING);
|
||||
last_grounded_position_ = static_cast<int>(y_); // Actualizar AL ENTRAR en STANDING
|
||||
// Deja de estar enganchado a la superficie automatica
|
||||
auto_movement_ = false;
|
||||
} else {
|
||||
// Si no hay colisión con los muros, comprueba la colisión con las rampas
|
||||
// CORRECCIÓN: FALLING siempre se pega a rampas, JUMPING se pega solo si vx_ == 0
|
||||
@@ -399,20 +388,12 @@ void Player::moveVerticalDown(float delta_time) {
|
||||
auto rect = toSDLRect(proj);
|
||||
const LineVertical LEFT_SIDE = {.x = rect.x, .y1 = rect.y, .y2 = rect.y + rect.h};
|
||||
const LineVertical RIGHT_SIDE = {.x = rect.x + rect.w - 1, .y1 = rect.y, .y2 = rect.y + rect.h};
|
||||
const float POINT = std::max(room_->checkRightSlopes(&RIGHT_SIDE), room_->checkLeftSlopes(&LEFT_SIDE));
|
||||
if (POINT > -1) {
|
||||
const float POINT = std::max(room_->checkRightSlopes(RIGHT_SIDE), room_->checkLeftSlopes(LEFT_SIDE));
|
||||
if (POINT != Collision::NONE) {
|
||||
// No está saltando y hay colisión con una rampa
|
||||
// Calcula la nueva posición
|
||||
y_ = POINT - HEIGHT;
|
||||
|
||||
// VERIFICAR MUERTE ANTES de cambiar de estado (PLAYER_MECHANICS.md línea 1268-1274)
|
||||
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
|
||||
}
|
||||
|
||||
transitionToState(State::STANDING);
|
||||
last_grounded_position_ = static_cast<int>(y_); // Actualizar AL ENTRAR en STANDING
|
||||
} else {
|
||||
// No está saltando y no hay colisón con una rampa
|
||||
// Calcula la nueva posición
|
||||
@@ -452,7 +433,6 @@ void Player::playJumpSound(float delta_time) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Calcula y reproduce el sonido de caída basado en distancia vertical recorrida
|
||||
void Player::playFallSound(float delta_time) {
|
||||
size_t sound_index;
|
||||
@@ -466,18 +446,19 @@ void Player::playFallSound(float delta_time) {
|
||||
// Comprueba si el jugador tiene suelo debajo de los pies
|
||||
auto Player::isOnFloor() -> bool {
|
||||
bool on_floor = false;
|
||||
|
||||
updateFeet();
|
||||
|
||||
// Comprueba las superficies
|
||||
for (auto f : under_feet_) {
|
||||
on_floor |= room_->checkTopSurfaces(&f);
|
||||
on_floor |= room_->checkConveyorBelts(&f);
|
||||
}
|
||||
on_floor |= room_->checkTopSurfaces(under_left_foot_);
|
||||
on_floor |= room_->checkTopSurfaces(under_right_foot_);
|
||||
|
||||
// Comprueba las cintas transportadoras
|
||||
on_floor |= room_->checkConveyorBelts(under_left_foot_);
|
||||
on_floor |= room_->checkConveyorBelts(under_right_foot_);
|
||||
|
||||
// Comprueba las rampas
|
||||
auto on_slope_l = room_->checkLeftSlopes(under_feet_.data());
|
||||
auto on_slope_r = room_->checkRightSlopes(&under_feet_[1]);
|
||||
auto on_slope_l = room_->checkLeftSlopes(under_left_foot_);
|
||||
auto on_slope_r = room_->checkRightSlopes(under_right_foot_);
|
||||
|
||||
return on_floor || on_slope_l || on_slope_r;
|
||||
}
|
||||
@@ -485,13 +466,11 @@ auto Player::isOnFloor() -> bool {
|
||||
// Comprueba si el jugador esta sobre una superficie automática
|
||||
auto Player::isOnConveyorBelt() -> bool {
|
||||
bool on_conveyor_belt = false;
|
||||
|
||||
updateFeet();
|
||||
|
||||
// Comprueba las superficies
|
||||
for (auto f : under_feet_) {
|
||||
on_conveyor_belt |= room_->checkConveyorBelts(&f);
|
||||
}
|
||||
on_conveyor_belt |= room_->checkConveyorBelts(under_left_foot_);
|
||||
on_conveyor_belt |= room_->checkConveyorBelts(under_right_foot_);
|
||||
|
||||
return on_conveyor_belt;
|
||||
}
|
||||
@@ -499,19 +478,18 @@ auto Player::isOnConveyorBelt() -> bool {
|
||||
// Comprueba si el jugador está sobre una rampa hacia abajo
|
||||
auto Player::isOnDownSlope() -> bool {
|
||||
bool on_slope = false;
|
||||
|
||||
updateFeet();
|
||||
|
||||
// Cuando el jugador baja una escalera, se queda volando
|
||||
// Hay que mirar otro pixel más por debajo
|
||||
SDL_FPoint foot0 = under_feet_[0];
|
||||
SDL_FPoint foot1 = under_feet_[1];
|
||||
foot0.y += 1.0F;
|
||||
foot1.y += 1.0F;
|
||||
SDL_FPoint left_foot = under_left_foot_;
|
||||
SDL_FPoint right_foot = under_right_foot_;
|
||||
left_foot.y += 1.0F;
|
||||
right_foot.y += 1.0F;
|
||||
|
||||
// Comprueba las rampas
|
||||
on_slope |= room_->checkLeftSlopes(&foot0);
|
||||
on_slope |= room_->checkRightSlopes(&foot1);
|
||||
on_slope |= room_->checkLeftSlopes(left_foot);
|
||||
on_slope |= room_->checkRightSlopes(right_foot);
|
||||
|
||||
return on_slope;
|
||||
}
|
||||
@@ -555,13 +533,12 @@ void Player::updateColliderPoints() {
|
||||
|
||||
// Actualiza los puntos de los pies
|
||||
void Player::updateFeet() {
|
||||
const SDL_FPoint P = {x_, y_};
|
||||
|
||||
under_feet_[0] = {.x = P.x, .y = P.y + HEIGHT};
|
||||
under_feet_[1] = {.x = P.x + 7, .y = P.y + HEIGHT};
|
||||
|
||||
feet_[0] = {.x = P.x, .y = P.y + HEIGHT - 1};
|
||||
feet_[1] = {.x = P.x + 7, .y = P.y + HEIGHT - 1};
|
||||
under_left_foot_ = {
|
||||
.x = x_,
|
||||
.y = y_ + HEIGHT};
|
||||
under_right_foot_ = {
|
||||
.x = x_ + WIDTH - 1,
|
||||
.y = y_ + HEIGHT};
|
||||
}
|
||||
|
||||
// Inicializa los sonidos de salto y caida
|
||||
@@ -570,7 +547,7 @@ void Player::initSounds() {
|
||||
std::string sound_file = "jump" + std::to_string(i + 1) + ".wav";
|
||||
jumping_sound_[i] = Resource::get()->getSound(sound_file);
|
||||
|
||||
if (i >= 10) { // i+1 >= 11
|
||||
if (i >= 10) { // i+1 >= 11
|
||||
falling_sound_[i - 10] = Resource::get()->getSound(sound_file);
|
||||
}
|
||||
}
|
||||
@@ -658,7 +635,6 @@ auto Player::FallSoundController::shouldPlay(float delta_time, float current_y,
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Aplica los valores de spawn al jugador
|
||||
void Player::applySpawnValues(const SpawnData& spawn) {
|
||||
x_ = spawn.x;
|
||||
|
||||
Reference in New Issue
Block a user