forked from jaildesigner-jailgames/jaildoctors_dilemma
linter
This commit is contained in:
@@ -28,8 +28,8 @@ void Item::render() {
|
||||
|
||||
// Obtiene su ubicación
|
||||
SDL_FPoint Item::getPos() {
|
||||
const SDL_FPoint p = {sprite_->getX(), sprite_->getY()};
|
||||
return p;
|
||||
const SDL_FPoint P = {sprite_->getX(), sprite_->getY()};
|
||||
return P;
|
||||
}
|
||||
|
||||
// Asigna los colores del objeto
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -63,12 +63,12 @@ struct PlayerData {
|
||||
};
|
||||
|
||||
class Player {
|
||||
public:
|
||||
private:
|
||||
// Constantes
|
||||
static constexpr int WIDTH_ = 8; // Ancho del jugador
|
||||
static constexpr int HEIGHT_ = 16; // ALto del jugador
|
||||
static constexpr int MAX_FALLING_HEIGHT_ = BLOCK * 4; // Altura maxima permitida de caída.
|
||||
static constexpr float MAX_VY_ = 1.2f; // Velocidad máxima que puede alcanzar al desplazarse en vertical
|
||||
static constexpr int WIDTH = 8; // Ancho del jugador
|
||||
static constexpr int HEIGHT = 16; // ALto del jugador
|
||||
static constexpr int MAX_FALLING_HEIGHT = BLOCK * 4; // Altura maxima permitida de caída.
|
||||
static constexpr float MAX_VY = 1.2F; // Velocidad máxima que puede alcanzar al desplazarse en vertical
|
||||
|
||||
// Objetos y punteros
|
||||
std::shared_ptr<Room> room_; // Objeto encargado de gestionar cada habitación del juego
|
||||
@@ -170,7 +170,7 @@ class Player {
|
||||
void renderDebugInfo();
|
||||
#endif
|
||||
|
||||
public:
|
||||
public:
|
||||
// Constructor
|
||||
explicit Player(const PlayerData& player);
|
||||
|
||||
@@ -184,16 +184,16 @@ class Player {
|
||||
void update();
|
||||
|
||||
// Indica si el jugador esta en uno de los cuatro bordes de la pantalla
|
||||
bool getOnBorder() { return is_on_border_; }
|
||||
bool getOnBorder() const { return is_on_border_; }
|
||||
|
||||
// Indica en cual de los cuatro bordes se encuentra
|
||||
RoomBorder getBorder() { return border_; }
|
||||
RoomBorder getBorder() const { return border_; }
|
||||
|
||||
// Cambia al jugador de un borde al opuesto. Util para el cambio de pantalla
|
||||
void switchBorders();
|
||||
|
||||
// Obtiene el rectangulo que delimita al jugador
|
||||
SDL_FRect getRect() { return {x_, y_, WIDTH_, HEIGHT_}; }
|
||||
SDL_FRect getRect() { return {x_, y_, WIDTH, HEIGHT}; }
|
||||
|
||||
// Obtiene el rectangulo de colision del jugador
|
||||
SDL_FRect& getCollider() { return collider_box_; }
|
||||
@@ -208,7 +208,7 @@ class Player {
|
||||
void setRoom(std::shared_ptr<Room> room) { room_ = room; }
|
||||
|
||||
// Comprueba si el jugador esta vivo
|
||||
bool isAlive() { return is_alive_; }
|
||||
bool isAlive() const { return is_alive_; }
|
||||
|
||||
// Pone el jugador en modo pausa
|
||||
void setPaused(bool value) { is_paused_ = value; }
|
||||
|
||||
@@ -385,49 +385,49 @@ void Room::fillMapTexture() {
|
||||
auto surface = Screen::get()->getRendererSurface();
|
||||
|
||||
// BottomSurfaces
|
||||
if (true) {
|
||||
{
|
||||
for (auto l : bottom_floors_) {
|
||||
surface->drawLine(l.x1, l.y, l.x2, l.y, static_cast<Uint8>(PaletteColor::BLUE));
|
||||
}
|
||||
}
|
||||
|
||||
// TopSurfaces
|
||||
if (true) {
|
||||
{
|
||||
for (auto l : top_floors_) {
|
||||
surface->drawLine(l.x1, l.y, l.x2, l.y, static_cast<Uint8>(PaletteColor::RED));
|
||||
}
|
||||
}
|
||||
|
||||
// LeftSurfaces
|
||||
if (true) {
|
||||
{
|
||||
for (auto l : left_walls_) {
|
||||
surface->drawLine(l.x, l.y1, l.x, l.y2, static_cast<Uint8>(PaletteColor::GREEN));
|
||||
}
|
||||
}
|
||||
|
||||
// RightSurfaces
|
||||
if (true) {
|
||||
{
|
||||
for (auto l : right_walls_) {
|
||||
surface->drawLine(l.x, l.y1, l.x, l.y2, static_cast<Uint8>(PaletteColor::MAGENTA));
|
||||
}
|
||||
}
|
||||
|
||||
// LeftSlopes
|
||||
if (true) {
|
||||
{
|
||||
for (auto l : left_slopes_) {
|
||||
surface->drawLine(l.x1, l.y1, l.x2, l.y2, static_cast<Uint8>(PaletteColor::CYAN));
|
||||
}
|
||||
}
|
||||
|
||||
// RightSlopes
|
||||
if (true) {
|
||||
{
|
||||
for (auto l : right_slopes_) {
|
||||
surface->drawLine(l.x1, l.y1, l.x2, l.y2, static_cast<Uint8>(PaletteColor::YELLOW));
|
||||
}
|
||||
}
|
||||
|
||||
// AutoSurfaces
|
||||
if (true) {
|
||||
{
|
||||
for (auto l : conveyor_belt_floors_) {
|
||||
surface->drawLine(l.x1, l.y, l.x2, l.y, static_cast<Uint8>(PaletteColor::WHITE));
|
||||
}
|
||||
@@ -540,17 +540,17 @@ TileType Room::getTile(int index) {
|
||||
}
|
||||
|
||||
// Las filas 18-20 es de tiles t_animated
|
||||
else if ((tile_map_[index] >= 18 * tile_set_width_) && (tile_map_[index] < 21 * tile_set_width_)) {
|
||||
if ((tile_map_[index] >= 18 * tile_set_width_) && (tile_map_[index] < 21 * tile_set_width_)) {
|
||||
return TileType::ANIMATED;
|
||||
}
|
||||
|
||||
// La fila 21 es de tiles t_slope_r
|
||||
else if ((tile_map_[index] >= 21 * tile_set_width_) && (tile_map_[index] < 22 * tile_set_width_)) {
|
||||
if ((tile_map_[index] >= 21 * tile_set_width_) && (tile_map_[index] < 22 * tile_set_width_)) {
|
||||
return TileType::SLOPE_R;
|
||||
}
|
||||
|
||||
// La fila 22 es de tiles t_slope_l
|
||||
else if ((tile_map_[index] >= 22 * tile_set_width_) && (tile_map_[index] < 23 * tile_set_width_)) {
|
||||
if ((tile_map_[index] >= 22 * tile_set_width_) && (tile_map_[index] < 23 * tile_set_width_)) {
|
||||
return TileType::SLOPE_L;
|
||||
}
|
||||
|
||||
|
||||
@@ -75,10 +75,10 @@ void Stats::addVisit(const std::string& name) {
|
||||
}
|
||||
|
||||
// Busca una entrada en la lista por nombre
|
||||
int Stats::findByName(const std::string& name, const std::vector<StatsData>& list_) {
|
||||
int Stats::findByName(const std::string& name, const std::vector<StatsData>& list) {
|
||||
int i = 0;
|
||||
|
||||
for (const auto& l : list_) {
|
||||
for (const auto& l : list) {
|
||||
if (l.name == name) {
|
||||
return i;
|
||||
}
|
||||
@@ -89,8 +89,8 @@ int Stats::findByName(const std::string& name, const std::vector<StatsData>& lis
|
||||
}
|
||||
|
||||
// Carga las estadisticas desde un fichero
|
||||
bool Stats::loadFromFile(const std::string& file_path, std::vector<StatsData>& list_) {
|
||||
list_.clear();
|
||||
bool Stats::loadFromFile(const std::string& file_path, std::vector<StatsData>& list) {
|
||||
list.clear();
|
||||
|
||||
// Indicador de éxito en la carga
|
||||
bool success = true;
|
||||
@@ -121,7 +121,7 @@ bool Stats::loadFromFile(const std::string& file_path, std::vector<StatsData>& l
|
||||
getline(ss, tmp, ';');
|
||||
stat.died = std::stoi(tmp);
|
||||
|
||||
list_.push_back(stat);
|
||||
list.push_back(stat);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,20 +132,20 @@ bool Stats::loadFromFile(const std::string& file_path, std::vector<StatsData>& l
|
||||
// El fichero no existe
|
||||
else {
|
||||
// Crea el fichero con los valores por defecto
|
||||
saveToFile(file_path, list_);
|
||||
saveToFile(file_path, list);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
// Guarda las estadisticas en un fichero
|
||||
void Stats::saveToFile(const std::string& file_path, const std::vector<StatsData>& list_) {
|
||||
void Stats::saveToFile(const std::string& file_path, const std::vector<StatsData>& list) {
|
||||
// Crea y abre el fichero de texto
|
||||
std::ofstream file(file_path);
|
||||
|
||||
// Escribe en el fichero
|
||||
file << "# ROOM NAME;VISITS;DEATHS" << std::endl;
|
||||
for (const auto& item : list_) {
|
||||
for (const auto& item : list) {
|
||||
file << item.name << ";" << item.visited << ";" << item.died << std::endl;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ class Stats {
|
||||
static int findByName(const std::string& name, const std::vector<StatsData>& list);
|
||||
|
||||
// Carga las estadisticas desde un fichero
|
||||
bool loadFromFile(const std::string& file_path, std::vector<StatsData>& list);
|
||||
static bool loadFromFile(const std::string& file_path, std::vector<StatsData>& list);
|
||||
|
||||
// Guarda las estadisticas en un fichero
|
||||
static void saveToFile(const std::string& file_path, const std::vector<StatsData>& list);
|
||||
|
||||
@@ -304,28 +304,28 @@ void Ending2::updateTexts() {
|
||||
|
||||
// Dibuja los sprites
|
||||
void Ending2::renderSprites() {
|
||||
const Uint8 colorA = static_cast<Uint8>(PaletteColor::RED);
|
||||
const Uint8 COLOR_A = static_cast<Uint8>(PaletteColor::RED);
|
||||
for (auto sprite : sprites_) {
|
||||
const bool A = sprite->getRect().y + sprite->getRect().h > 0;
|
||||
const bool B = sprite->getRect().y < Options::game.height;
|
||||
if (A && B) {
|
||||
sprite->render(1, colorA);
|
||||
sprite->render(1, COLOR_A);
|
||||
}
|
||||
}
|
||||
|
||||
// Pinta el ultimo elemento de otro color
|
||||
const Uint8 colorB = static_cast<Uint8>(PaletteColor::WHITE);
|
||||
sprites_.back()->render(1, colorB);
|
||||
const Uint8 COLOR_B = static_cast<Uint8>(PaletteColor::WHITE);
|
||||
sprites_.back()->render(1, COLOR_B);
|
||||
}
|
||||
|
||||
// Dibuja los sprites con el texto
|
||||
void Ending2::renderSpriteTexts() {
|
||||
const Uint8 color = static_cast<Uint8>(PaletteColor::WHITE);
|
||||
const Uint8 COLOR = static_cast<Uint8>(PaletteColor::WHITE);
|
||||
for (auto sprite : sprite_texts_) {
|
||||
const bool A = sprite->getRect().y + sprite->getRect().h > 0;
|
||||
const bool B = sprite->getRect().y < Options::game.height;
|
||||
if (A && B) {
|
||||
sprite->render(1, color);
|
||||
sprite->render(1, COLOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -345,7 +345,7 @@ void Ending2::renderTexts() {
|
||||
void Ending2::placeSprites() {
|
||||
for (int i = 0; i < static_cast<int>(sprites_.size()); ++i) {
|
||||
const float X = i % 2 == 0 ? FIRST_COL : SECOND_COL;
|
||||
const float Y = (i / 1) * (sprite_max_height_ + DIST_SPRITE_TEXT + Resource::get()->getText("smb2")->getCharacterSize() + DIST_SPRITE_SPRITE) + Options::game.height + 40;
|
||||
const float Y = ((i / 1) * (sprite_max_height_ + DIST_SPRITE_TEXT + Resource::get()->getText("smb2")->getCharacterSize() + DIST_SPRITE_SPRITE)) + Options::game.height + 40;
|
||||
const float W = sprites_.at(i)->getWidth();
|
||||
const float H = sprites_.at(i)->getHeight();
|
||||
const float DX = -(W / 2);
|
||||
@@ -357,7 +357,7 @@ void Ending2::placeSprites() {
|
||||
|
||||
// Recoloca el sprite del jugador, que es el último de la lista
|
||||
const float X = (Options::game.width - sprites_.back()->getWidth()) / 2;
|
||||
const float Y = sprites_.back()->getPosY() + sprite_max_height_ * 2;
|
||||
const float Y = sprites_.back()->getPosY() + (sprite_max_height_ * 2);
|
||||
sprites_.back()->setPos(X, Y);
|
||||
sprites_.back()->setCurrentAnimation("walk");
|
||||
}
|
||||
@@ -433,7 +433,7 @@ void Ending2::createTexts() {
|
||||
|
||||
// Crea los últimos textos
|
||||
// El primer texto va a continuación del ultimo spriteText
|
||||
const int START = sprite_texts_.back()->getPosY() + text->getCharacterSize() * 15;
|
||||
const int START = sprite_texts_.back()->getPosY() + (text->getCharacterSize() * 15);
|
||||
list.clear();
|
||||
list.push_back("THANK YOU");
|
||||
list.push_back("FOR PLAYING!");
|
||||
@@ -469,7 +469,7 @@ void Ending2::updateFinalFade() {
|
||||
}
|
||||
|
||||
// Actualiza el volumen de la musica
|
||||
void Ending2::updateMusicVolume() {
|
||||
void Ending2::updateMusicVolume() const {
|
||||
// Constante para la duración en milisegundos
|
||||
constexpr Uint32 VOLUME_FADE_DURATION = 3000;
|
||||
|
||||
|
||||
@@ -81,10 +81,10 @@ class Ending2 {
|
||||
void render();
|
||||
|
||||
// Comprueba el manejador de eventos
|
||||
void checkEvents();
|
||||
static void checkEvents();
|
||||
|
||||
// Comprueba las entradas
|
||||
void checkInput();
|
||||
static void checkInput();
|
||||
|
||||
// Actualiza el estado
|
||||
void updateState();
|
||||
@@ -126,7 +126,7 @@ class Ending2 {
|
||||
void updateFinalFade();
|
||||
|
||||
// Actualiza el volumen de la musica
|
||||
void updateMusicVolume();
|
||||
void updateMusicVolume() const;
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
|
||||
@@ -180,9 +180,9 @@ void Game::render() {
|
||||
#ifdef _DEBUG
|
||||
// Pasa la información de debug
|
||||
void Game::updateDebugInfo() {
|
||||
Debug::get()->add("X = " + std::to_string(static_cast<int>(player_->x_)) + ", Y = " + std::to_string(static_cast<int>(player_->y_)));
|
||||
Debug::get()->add("VX = " + std::to_string(player_->vx_).substr(0, 4) + ", VY = " + std::to_string(player_->vy_).substr(0, 4));
|
||||
Debug::get()->add("STATE = " + std::to_string(static_cast<int>(player_->state_)));
|
||||
//Debug::get()->add("X = " + std::to_string(static_cast<int>(player_->x_)) + ", Y = " + std::to_string(static_cast<int>(player_->y_)));
|
||||
//Debug::get()->add("VX = " + std::to_string(player_->vx_).substr(0, 4) + ", VY = " + std::to_string(player_->vy_).substr(0, 4));
|
||||
//Debug::get()->add("STATE = " + std::to_string(static_cast<int>(player_->state_)));
|
||||
}
|
||||
|
||||
// Pone la información de debug en pantalla
|
||||
@@ -216,7 +216,7 @@ void Game::renderDebugInfo() {
|
||||
|
||||
// Comprueba los eventos
|
||||
void Game::checkDebugEvents(const SDL_Event& event) {
|
||||
if (event.type == SDL_EVENT_KEY_DOWN && event.key.repeat == 0) {
|
||||
if (event.type == SDL_EVENT_KEY_DOWN && static_cast<int>(event.key.repeat) == 0) {
|
||||
switch (event.key.key) {
|
||||
case SDL_SCANCODE_G:
|
||||
Debug::get()->toggleEnabled();
|
||||
|
||||
@@ -79,7 +79,7 @@ class Game {
|
||||
void updateDebugInfo();
|
||||
|
||||
// Pone la información de debug en pantalla
|
||||
void renderDebugInfo();
|
||||
static void renderDebugInfo();
|
||||
|
||||
// Comprueba los eventos
|
||||
void checkDebugEvents(const SDL_Event& event);
|
||||
|
||||
@@ -54,8 +54,8 @@ void Notifier::update() {
|
||||
for (auto& notification : notifications_) {
|
||||
// Si la notificación anterior está "saliendo", no hagas nada
|
||||
if (!notifications_.empty() && ¬ification != ¬ifications_.front()) {
|
||||
const auto& PREVIOUS_NOTIFICATION = *(std::prev(¬ification));
|
||||
if (PREVIOUS_NOTIFICATION.state == NotificationStatus::RISING) {
|
||||
const auto& previous_notification = *(std::prev(¬ification));
|
||||
if (previous_notification.state == NotificationStatus::RISING) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -135,13 +135,13 @@ void Notifier::show(std::vector<std::string> texts, NotificationText text_is, Ui
|
||||
}
|
||||
|
||||
// Inicializa variables
|
||||
const int text_size = 6;
|
||||
const auto PADDING_IN_H = text_size;
|
||||
const auto PADDING_IN_V = text_size / 2;
|
||||
const int TEXT_SIZE = 6;
|
||||
const auto PADDING_IN_H = TEXT_SIZE;
|
||||
const auto PADDING_IN_V = TEXT_SIZE / 2;
|
||||
const int ICON_SPACE = icon >= 0 ? ICON_SIZE + PADDING_IN_H : 0;
|
||||
text_is = ICON_SPACE > 0 ? NotificationText::LEFT : text_is;
|
||||
const float WIDTH = Options::game.width - (PADDING_OUT * 2);
|
||||
const float HEIGHT = (text_size * texts.size()) + (PADDING_IN_V * 2);
|
||||
const float HEIGHT = (TEXT_SIZE * texts.size()) + (PADDING_IN_V * 2);
|
||||
const auto SHAPE = NotificationShape::SQUARED;
|
||||
|
||||
// Posición horizontal
|
||||
@@ -170,7 +170,7 @@ void Notifier::show(std::vector<std::string> texts, NotificationText text_is, Ui
|
||||
// Offset
|
||||
const auto TRAVEL_DIST = HEIGHT + PADDING_OUT;
|
||||
const int TRAVEL_MOD = (Options::notifications.getVerticalPosition() == Options::NotificationPosition::TOP) ? 1 : -1;
|
||||
const int OFFSET = !notifications_.empty() ? notifications_.back().y + TRAVEL_MOD * notifications_.back().travel_dist : DESP_V;
|
||||
const int OFFSET = !notifications_.empty() ? notifications_.back().y + (TRAVEL_MOD * notifications_.back().travel_dist) : DESP_V;
|
||||
|
||||
// Crea la notificacion
|
||||
Notification n;
|
||||
@@ -229,10 +229,10 @@ void Notifier::show(std::vector<std::string> texts, NotificationText text_is, Ui
|
||||
for (const auto& text : texts) {
|
||||
switch (text_is) {
|
||||
case NotificationText::LEFT:
|
||||
text_->writeColored(PADDING_IN_H + ICON_SPACE, PADDING_IN_V + iterator * (text_size + 1), text, COLOR);
|
||||
text_->writeColored(PADDING_IN_H + ICON_SPACE, PADDING_IN_V + (iterator * (TEXT_SIZE + 1)), text, COLOR);
|
||||
break;
|
||||
case NotificationText::CENTER:
|
||||
text_->writeDX(TEXT_CENTER | TEXT_COLOR, WIDTH / 2, PADDING_IN_V + iterator * (text_size + 1), text, 1, COLOR);
|
||||
text_->writeDX(TEXT_CENTER | TEXT_COLOR, WIDTH / 2, PADDING_IN_V + (iterator * (TEXT_SIZE + 1)), text, 1, COLOR);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user