linter
This commit is contained in:
@@ -69,27 +69,27 @@ void Player::checkInput() {
|
||||
if (!auto_movement_) {
|
||||
// Comprueba las entradas de desplazamiento lateral solo en el caso de no estar enganchado a una superficie automatica
|
||||
if (Input::get()->checkInput(InputAction::LEFT)) {
|
||||
vx_ = -0.6f;
|
||||
vx_ = -0.6F;
|
||||
sprite_->setFlip(SDL_FLIP_HORIZONTAL);
|
||||
}
|
||||
|
||||
else if (Input::get()->checkInput(InputAction::RIGHT)) {
|
||||
vx_ = 0.6f;
|
||||
vx_ = 0.6F;
|
||||
sprite_->setFlip(SDL_FLIP_NONE);
|
||||
}
|
||||
|
||||
else {
|
||||
// No se pulsa ninguna dirección
|
||||
vx_ = 0.0f;
|
||||
vx_ = 0.0F;
|
||||
if (isOnAutoSurface()) {
|
||||
// Si deja de moverse sobre una superficie se engancha
|
||||
auto_movement_ = true;
|
||||
}
|
||||
}
|
||||
} else { // El movimiento lo proporciona la superficie
|
||||
vx_ = 0.6f * room_->getAutoSurfaceDirection();
|
||||
vx_ = 0.6F * room_->getAutoSurfaceDirection();
|
||||
|
||||
if (vx_ > 0.0f) {
|
||||
if (vx_ > 0.0F) {
|
||||
sprite_->setFlip(SDL_FLIP_NONE);
|
||||
} else {
|
||||
sprite_->setFlip(SDL_FLIP_HORIZONTAL);
|
||||
@@ -104,7 +104,7 @@ void Player::checkInput() {
|
||||
|
||||
if (isOnFloor() || isOnAutoSurface()) {
|
||||
setState(PlayerState::JUMPING);
|
||||
vy_ = -MAX_VY_;
|
||||
vy_ = -MAX_VY;
|
||||
jump_init_pos_ = y_;
|
||||
jumping_counter_ = 0;
|
||||
}
|
||||
@@ -118,7 +118,7 @@ void Player::checkBorders() {
|
||||
is_on_border_ = true;
|
||||
}
|
||||
|
||||
else if (x_ + WIDTH_ > PLAY_AREA_RIGHT) {
|
||||
else if (x_ + WIDTH > PLAY_AREA_RIGHT) {
|
||||
border_ = RoomBorder::RIGHT;
|
||||
is_on_border_ = true;
|
||||
}
|
||||
@@ -128,7 +128,7 @@ void Player::checkBorders() {
|
||||
is_on_border_ = true;
|
||||
}
|
||||
|
||||
else if (y_ + HEIGHT_ > PLAY_AREA_BOTTOM) {
|
||||
else if (y_ + HEIGHT > PLAY_AREA_BOTTOM) {
|
||||
border_ = RoomBorder::BOTTOM;
|
||||
is_on_border_ = true;
|
||||
}
|
||||
@@ -142,23 +142,23 @@ void Player::checkBorders() {
|
||||
void Player::checkState() {
|
||||
// Actualiza las variables en función del estado
|
||||
if (state_ == PlayerState::FALLING) {
|
||||
vx_ = 0.0f;
|
||||
vy_ = MAX_VY_;
|
||||
vx_ = 0.0F;
|
||||
vy_ = MAX_VY;
|
||||
falling_counter_++;
|
||||
playFallSound();
|
||||
}
|
||||
|
||||
else if (state_ == PlayerState::STANDING) {
|
||||
if (previous_state_ == PlayerState::FALLING && falling_counter_ > MAX_FALLING_HEIGHT_) { // Si cae de muy alto, el jugador muere
|
||||
if (previous_state_ == PlayerState::FALLING && falling_counter_ > MAX_FALLING_HEIGHT) { // Si cae de muy alto, el jugador muere
|
||||
is_alive_ = false;
|
||||
}
|
||||
vy_ = 0.0f;
|
||||
vy_ = 0.0F;
|
||||
jumping_counter_ = 0;
|
||||
falling_counter_ = 0;
|
||||
if (!isOnFloor() && !isOnAutoSurface() && !isOnDownSlope()) {
|
||||
setState(PlayerState::FALLING);
|
||||
vx_ = 0.0f;
|
||||
vy_ = MAX_VY_;
|
||||
vx_ = 0.0F;
|
||||
vy_ = MAX_VY;
|
||||
falling_counter_++;
|
||||
playFallSound();
|
||||
}
|
||||
@@ -175,7 +175,7 @@ void Player::checkState() {
|
||||
void Player::switchBorders() {
|
||||
switch (border_) {
|
||||
case RoomBorder::TOP:
|
||||
y_ = PLAY_AREA_BOTTOM - HEIGHT_ - BLOCK;
|
||||
y_ = PLAY_AREA_BOTTOM - HEIGHT - BLOCK;
|
||||
setState(PlayerState::STANDING);
|
||||
break;
|
||||
|
||||
@@ -189,7 +189,7 @@ void Player::switchBorders() {
|
||||
break;
|
||||
|
||||
case RoomBorder::LEFT:
|
||||
x_ = PLAY_AREA_RIGHT - WIDTH_;
|
||||
x_ = PLAY_AREA_RIGHT - WIDTH;
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -203,15 +203,13 @@ void Player::switchBorders() {
|
||||
|
||||
// Aplica gravedad al jugador
|
||||
void Player::applyGravity() {
|
||||
constexpr float GRAVITY_FORCE = 0.035f;
|
||||
constexpr float GRAVITY_FORCE = 0.035F;
|
||||
|
||||
// La gravedad solo se aplica cuando el jugador esta saltando
|
||||
// Nunca mientras cae o esta de pie
|
||||
if (state_ == PlayerState::JUMPING) {
|
||||
vy_ += GRAVITY_FORCE;
|
||||
if (vy_ > MAX_VY_) {
|
||||
vy_ = MAX_VY_;
|
||||
}
|
||||
vy_ = std::min(vy_, MAX_VY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,12 +224,12 @@ void Player::move() {
|
||||
#endif
|
||||
|
||||
// Se mueve hacia la izquierda
|
||||
if (vx_ < 0.0f) {
|
||||
if (vx_ < 0.0F) {
|
||||
// Crea el rectangulo de proyección en el eje X para ver si colisiona
|
||||
SDL_FRect proj;
|
||||
proj.x = static_cast<int>(x_ + vx_);
|
||||
proj.y = static_cast<int>(y_);
|
||||
proj.h = HEIGHT_;
|
||||
proj.h = HEIGHT;
|
||||
proj.w = static_cast<int>(std::ceil(std::fabs(vx_))); // Para evitar que tenga un ancho de 0 pixels
|
||||
|
||||
#ifdef _DEBUG
|
||||
@@ -252,10 +250,10 @@ void Player::move() {
|
||||
|
||||
// Si ha tocado alguna rampa mientras camina (sin saltar), asciende
|
||||
if (state_ != PlayerState::JUMPING) {
|
||||
const LineVertical LEFT_SIDE = {static_cast<int>(x_), static_cast<int>(y_) + static_cast<int>(HEIGHT_) - 2, static_cast<int>(y_) + static_cast<int>(HEIGHT_) - 1}; // Comprueba solo los dos pixels de abajo
|
||||
const LineVertical LEFT_SIDE = {static_cast<int>(x_), static_cast<int>(y_) + static_cast<int>(HEIGHT) - 2, static_cast<int>(y_) + static_cast<int>(HEIGHT) - 1}; // Comprueba solo los dos pixels de abajo
|
||||
const int LY = room_->checkLeftSlopes(&LEFT_SIDE);
|
||||
if (LY > -1) {
|
||||
y_ = LY - HEIGHT_;
|
||||
y_ = LY - HEIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,12 +264,12 @@ void Player::move() {
|
||||
}
|
||||
|
||||
// Se mueve hacia la derecha
|
||||
else if (vx_ > 0.0f) {
|
||||
else if (vx_ > 0.0F) {
|
||||
// Crea el rectangulo de proyección en el eje X para ver si colisiona
|
||||
SDL_FRect proj;
|
||||
proj.x = x_ + WIDTH_;
|
||||
proj.x = x_ + WIDTH;
|
||||
proj.y = y_;
|
||||
proj.h = HEIGHT_;
|
||||
proj.h = HEIGHT;
|
||||
proj.w = ceil(vx_); // Para evitar que tenga un ancho de 0 pixels
|
||||
|
||||
#ifdef _DEBUG
|
||||
@@ -287,15 +285,15 @@ void Player::move() {
|
||||
x_ += vx_;
|
||||
} else {
|
||||
// Si hay colisión lo mueve hasta donde no colisiona
|
||||
x_ = POS - WIDTH_;
|
||||
x_ = POS - WIDTH;
|
||||
}
|
||||
|
||||
// Si ha tocado alguna rampa mientras camina (sin saltar), asciende
|
||||
if (state_ != PlayerState::JUMPING) {
|
||||
const LineVertical RIGHT_SIDE = {static_cast<int>(x_) + static_cast<int>(WIDTH_) - 1, static_cast<int>(y_) + static_cast<int>(HEIGHT_) - 2, static_cast<int>(y_) + static_cast<int>(HEIGHT_) - 1}; // Comprueba solo los dos pixels de abajo
|
||||
const LineVertical RIGHT_SIDE = {static_cast<int>(x_) + static_cast<int>(WIDTH) - 1, static_cast<int>(y_) + static_cast<int>(HEIGHT) - 2, static_cast<int>(y_) + static_cast<int>(HEIGHT) - 1}; // Comprueba solo los dos pixels de abajo
|
||||
const int RY = room_->checkRightSlopes(&RIGHT_SIDE);
|
||||
if (RY > -1) {
|
||||
y_ = RY - HEIGHT_;
|
||||
y_ = RY - HEIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -320,13 +318,13 @@ void Player::move() {
|
||||
}
|
||||
|
||||
// Se mueve hacia arriba
|
||||
if (vy_ < 0.0f) {
|
||||
if (vy_ < 0.0F) {
|
||||
// Crea el rectangulo de proyección en el eje Y para ver si colisiona
|
||||
SDL_FRect proj;
|
||||
proj.x = static_cast<int>(x_);
|
||||
proj.y = static_cast<int>(y_ + vy_);
|
||||
proj.h = static_cast<int>(std::ceil(std::fabs(vy_))); // Para evitar que tenga una altura de 0 pixels
|
||||
proj.w = WIDTH_;
|
||||
proj.w = WIDTH;
|
||||
|
||||
#ifdef _DEBUG
|
||||
debug_rect_y_ = proj;
|
||||
@@ -347,13 +345,13 @@ void Player::move() {
|
||||
}
|
||||
|
||||
// Se mueve hacia abajo
|
||||
else if (vy_ > 0.0f) {
|
||||
else if (vy_ > 0.0F) {
|
||||
// Crea el rectangulo de proyección en el eje Y para ver si colisiona
|
||||
SDL_FRect proj;
|
||||
proj.x = x_;
|
||||
proj.y = y_ + HEIGHT_;
|
||||
proj.y = y_ + HEIGHT;
|
||||
proj.h = ceil(vy_); // Para evitar que tenga una altura de 0 pixels
|
||||
proj.w = WIDTH_;
|
||||
proj.w = WIDTH;
|
||||
|
||||
#ifdef _DEBUG
|
||||
debug_rect_y_ = proj;
|
||||
@@ -363,7 +361,7 @@ void Player::move() {
|
||||
const float POS = std::max(room_->checkTopSurfaces(&proj), room_->checkAutoSurfaces(&proj));
|
||||
if (POS > -1) {
|
||||
// Si hay colisión lo mueve hasta donde no colisiona y pasa a estar sobre la superficie
|
||||
y_ = POS - HEIGHT_;
|
||||
y_ = POS - HEIGHT;
|
||||
setState(PlayerState::STANDING);
|
||||
|
||||
// Deja de estar enganchado a la superficie automatica
|
||||
@@ -378,11 +376,11 @@ void Player::move() {
|
||||
if (POINT > -1) {
|
||||
// No está saltando y hay colisión con una rampa
|
||||
// Calcula la nueva posición
|
||||
y_ = POINT - HEIGHT_;
|
||||
y_ = POINT - HEIGHT;
|
||||
setState(PlayerState::STANDING);
|
||||
#ifdef _DEBUG
|
||||
debug_color_ = static_cast<Uint8>(PaletteColor::YELLOW);
|
||||
debug_point_ = {x_ + (WIDTH_ / 2), POINT};
|
||||
debug_point_ = {x_ + (WIDTH / 2), POINT};
|
||||
#endif
|
||||
} else {
|
||||
// No está saltando y no hay colisón con una rampa
|
||||
@@ -423,7 +421,7 @@ void Player::checkJumpEnd() {
|
||||
if (y_ >= jump_init_pos_) {
|
||||
// Si alcanza la altura de salto inicial, pasa al estado de caída
|
||||
setState(PlayerState::FALLING);
|
||||
vy_ = MAX_VY_;
|
||||
vy_ = MAX_VY;
|
||||
jumping_counter_ = 0;
|
||||
}
|
||||
}
|
||||
@@ -467,7 +465,7 @@ bool Player::isOnFloor() {
|
||||
}
|
||||
|
||||
// Comprueba las rampas
|
||||
on_slope_l = room_->checkLeftSlopes(&under_feet_[0]);
|
||||
on_slope_l = room_->checkLeftSlopes(under_feet_.data());
|
||||
on_slope_r = room_->checkRightSlopes(&under_feet_[1]);
|
||||
|
||||
#ifdef _DEBUG
|
||||
@@ -519,7 +517,7 @@ bool Player::isOnDownSlope() {
|
||||
under_feet_[1].y += 1;
|
||||
|
||||
// Comprueba las rampas
|
||||
on_slope |= room_->checkLeftSlopes(&under_feet_[0]);
|
||||
on_slope |= room_->checkLeftSlopes(under_feet_.data());
|
||||
on_slope |= room_->checkRightSlopes(&under_feet_[1]);
|
||||
|
||||
#ifdef _DEBUG
|
||||
@@ -560,26 +558,26 @@ void Player::setColor() {
|
||||
|
||||
// Actualiza los puntos de colisión
|
||||
void Player::updateColliderPoints() {
|
||||
const SDL_FRect rect = getRect();
|
||||
collider_points_[0] = {rect.x, rect.y};
|
||||
collider_points_[1] = {rect.x + 7, rect.y};
|
||||
collider_points_[2] = {rect.x + 7, rect.y + 7};
|
||||
collider_points_[3] = {rect.x, rect.y + 7};
|
||||
collider_points_[4] = {rect.x, rect.y + 8};
|
||||
collider_points_[5] = {rect.x + 7, rect.y + 8};
|
||||
collider_points_[6] = {rect.x + 7, rect.y + 15};
|
||||
collider_points_[7] = {rect.x, rect.y + 15};
|
||||
const SDL_FRect RECT = getRect();
|
||||
collider_points_[0] = {RECT.x, RECT.y};
|
||||
collider_points_[1] = {RECT.x + 7, RECT.y};
|
||||
collider_points_[2] = {RECT.x + 7, RECT.y + 7};
|
||||
collider_points_[3] = {RECT.x, RECT.y + 7};
|
||||
collider_points_[4] = {RECT.x, RECT.y + 8};
|
||||
collider_points_[5] = {RECT.x + 7, RECT.y + 8};
|
||||
collider_points_[6] = {RECT.x + 7, RECT.y + 15};
|
||||
collider_points_[7] = {RECT.x, RECT.y + 15};
|
||||
}
|
||||
|
||||
// Actualiza los puntos de los pies
|
||||
void Player::updateFeet() {
|
||||
const SDL_FPoint p = {x_, y_};
|
||||
const SDL_FPoint P = {x_, y_};
|
||||
|
||||
under_feet_[0] = {p.x, p.y + HEIGHT_};
|
||||
under_feet_[1] = {p.x + 7, p.y + HEIGHT_};
|
||||
under_feet_[0] = {P.x, P.y + HEIGHT};
|
||||
under_feet_[1] = {P.x + 7, P.y + HEIGHT};
|
||||
|
||||
feet_[0] = {p.x, p.y + HEIGHT_ - 1};
|
||||
feet_[1] = {p.x + 7, p.y + HEIGHT_ - 1};
|
||||
feet_[0] = {P.x, P.y + HEIGHT - 1};
|
||||
feet_[1] = {P.x + 7, P.y + HEIGHT - 1};
|
||||
}
|
||||
|
||||
// Cambia el estado del jugador
|
||||
@@ -596,11 +594,11 @@ void Player::initSounds() {
|
||||
falling_sound_.clear();
|
||||
|
||||
for (int i = 1; i <= 24; ++i) {
|
||||
std::string soundFile = "jump" + std::to_string(i) + ".wav";
|
||||
jumping_sound_.push_back(Resource::get()->getSound(soundFile));
|
||||
std::string sound_file = "jump" + std::to_string(i) + ".wav";
|
||||
jumping_sound_.push_back(Resource::get()->getSound(sound_file));
|
||||
|
||||
if (i >= 11) {
|
||||
falling_sound_.push_back(Resource::get()->getSound(soundFile));
|
||||
falling_sound_.push_back(Resource::get()->getSound(sound_file));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -622,8 +620,8 @@ void Player::initSprite(const std::string& surface_path, const std::string& anim
|
||||
auto animations = Resource::get()->getAnimations(animations_path);
|
||||
|
||||
sprite_ = std::make_shared<SurfaceAnimatedSprite>(surface, animations);
|
||||
sprite_->setWidth(WIDTH_);
|
||||
sprite_->setHeight(HEIGHT_);
|
||||
sprite_->setWidth(WIDTH);
|
||||
sprite_->setHeight(HEIGHT);
|
||||
sprite_->setCurrentAnimation("walk");
|
||||
}
|
||||
|
||||
@@ -642,10 +640,10 @@ void Player::renderDebugInfo() {
|
||||
surface->drawRectBorder(&rect, static_cast<Uint8>(PaletteColor::BRIGHT_CYAN));
|
||||
|
||||
// Pinta el rectangulo de movimiento
|
||||
if (vx_ != 0.0f) {
|
||||
if (vx_ != 0.0F) {
|
||||
surface->fillRect(&debug_rect_x_, static_cast<Uint8>(PaletteColor::BRIGHT_RED));
|
||||
}
|
||||
if (vy_ != 0.0f) {
|
||||
if (vy_ != 0.0F) {
|
||||
surface->fillRect(&debug_rect_y_, static_cast<Uint8>(PaletteColor::BRIGHT_RED));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user