forked from jaildesigner-jailgames/jaildoctors_dilemma
linter
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
#include "game/entities/enemy.hpp"
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <stdlib.h> // Para rand
|
||||
|
||||
#include <cstdlib> // Para rand
|
||||
|
||||
#include "core/rendering/surface_animated_sprite.hpp" // Para SAnimatedSprite
|
||||
#include "core/resources/resource.hpp" // Para Resource
|
||||
@@ -87,11 +88,11 @@ void Enemy::checkPath() {
|
||||
}
|
||||
|
||||
// Devuelve el rectangulo que contiene al enemigo
|
||||
SDL_FRect Enemy::getRect() {
|
||||
auto Enemy::getRect() -> SDL_FRect {
|
||||
return sprite_->getRect();
|
||||
}
|
||||
|
||||
// Obtiene el rectangulo de colision del enemigo
|
||||
SDL_FRect& Enemy::getCollider() {
|
||||
auto Enemy::getCollider() -> SDL_FRect& {
|
||||
return collider_;
|
||||
}
|
||||
@@ -59,8 +59,8 @@ class Enemy {
|
||||
void update();
|
||||
|
||||
// Devuelve el rectangulo que contiene al enemigo
|
||||
SDL_FRect getRect();
|
||||
auto getRect() -> SDL_FRect;
|
||||
|
||||
// Obtiene el rectangulo de colision del enemigo
|
||||
SDL_FRect& getCollider();
|
||||
auto getCollider() -> SDL_FRect&;
|
||||
};
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include "core/resources/resource.hpp" // Para Resource
|
||||
|
||||
// Constructor
|
||||
Item::Item(ItemData item)
|
||||
Item::Item(const ItemData &item)
|
||||
: sprite_(std::make_shared<SurfaceSprite>(Resource::get()->getSurface(item.tile_set_file), item.x, item.y, ITEM_SIZE, ITEM_SIZE)),
|
||||
change_color_speed_(4) {
|
||||
// Inicia variables
|
||||
@@ -21,13 +21,13 @@ Item::Item(ItemData item)
|
||||
}
|
||||
|
||||
// Pinta el objeto en pantalla
|
||||
void Item::render() {
|
||||
void Item::render() const {
|
||||
const int INDEX = (counter_ / change_color_speed_) % color_.size();
|
||||
sprite_->render(1, color_.at(INDEX));
|
||||
}
|
||||
|
||||
// Obtiene su ubicación
|
||||
SDL_FPoint Item::getPos() {
|
||||
auto Item::getPos() -> SDL_FPoint {
|
||||
const SDL_FPoint P = {sprite_->getX(), sprite_->getY()};
|
||||
return P;
|
||||
}
|
||||
|
||||
@@ -9,21 +9,15 @@ class SurfaceSprite;
|
||||
|
||||
struct ItemData {
|
||||
std::string tile_set_file; // Ruta al fichero con los gráficos del item
|
||||
float x; // Posición del item en pantalla
|
||||
float y; // Posición del item en pantalla
|
||||
int tile; // Número de tile dentro de la textura
|
||||
int counter; // Contador inicial. Es el que lo hace cambiar de color
|
||||
Uint8 color1; // Uno de los dos colores que se utiliza para el item
|
||||
Uint8 color2; // Uno de los dos colores que se utiliza para el item
|
||||
float x{0}; // Posición del item en pantalla
|
||||
float y{0}; // Posición del item en pantalla
|
||||
int tile{0}; // Número de tile dentro de la textura
|
||||
int counter{0}; // Contador inicial. Es el que lo hace cambiar de color
|
||||
Uint8 color1{}; // Uno de los dos colores que se utiliza para el item
|
||||
Uint8 color2{}; // Uno de los dos colores que se utiliza para el item
|
||||
|
||||
// Constructor
|
||||
ItemData()
|
||||
: x(0),
|
||||
y(0),
|
||||
tile(0),
|
||||
counter(0),
|
||||
color1(),
|
||||
color2() {}
|
||||
ItemData() = default;
|
||||
};
|
||||
|
||||
class Item {
|
||||
@@ -42,22 +36,22 @@ class Item {
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
explicit Item(ItemData item);
|
||||
explicit Item(const ItemData &item);
|
||||
|
||||
// Destructor
|
||||
~Item() = default;
|
||||
|
||||
// Pinta el objeto en pantalla
|
||||
void render();
|
||||
void render() const;
|
||||
|
||||
// Actualiza las variables del objeto
|
||||
void update() { counter_++; }
|
||||
|
||||
// Obtiene el rectangulo de colision del objeto
|
||||
SDL_FRect& getCollider() { return collider_; }
|
||||
auto getCollider() -> SDL_FRect& { return collider_; }
|
||||
|
||||
// Obtiene su ubicación
|
||||
SDL_FPoint getPos();
|
||||
auto getPos() -> SDL_FPoint;
|
||||
|
||||
// Asigna los colores del objeto
|
||||
void setColors(Uint8 col1, Uint8 col2);
|
||||
|
||||
@@ -32,10 +32,10 @@ Player::Player(const PlayerData& player)
|
||||
feet_.resize(feet_.size() + 2, {0, 0});
|
||||
|
||||
#ifdef _DEBUG
|
||||
debug_rect_x_ = {0, 0, 0, 0};
|
||||
debug_rect_y_ = {0, 0, 0, 0};
|
||||
debug_rect_x_ = {.x = 0, .y = 0, .w = 0, .h = 0};
|
||||
debug_rect_y_ = {.x = 0, .y = 0, .w = 0, .h = 0};
|
||||
debug_color_ = static_cast<Uint8>(PaletteColor::GREEN);
|
||||
debug_point_ = {0, 0};
|
||||
debug_point_ = {.x = 0, .y = 0};
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -241,7 +241,7 @@ void Player::moveHorizontalLeft() {
|
||||
|
||||
// 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 = {.x = static_cast<int>(x_), .y1 = static_cast<int>(y_) + static_cast<int>(HEIGHT) - 2, .y2 = 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;
|
||||
@@ -261,7 +261,7 @@ void Player::moveHorizontalRight() {
|
||||
proj.x = x_ + WIDTH;
|
||||
proj.y = y_;
|
||||
proj.h = HEIGHT;
|
||||
proj.w = ceil(vx_); // Para evitar que tenga un ancho de 0 pixels
|
||||
proj.w = std::ceil(vx_); // Para evitar que tenga un ancho de 0 pixels
|
||||
|
||||
#ifdef _DEBUG
|
||||
debug_rect_x_ = proj;
|
||||
@@ -281,7 +281,7 @@ void Player::moveHorizontalRight() {
|
||||
|
||||
// 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 = {.x = static_cast<int>(x_) + static_cast<int>(WIDTH) - 1, .y1 = static_cast<int>(y_) + static_cast<int>(HEIGHT) - 2, .y2 = 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;
|
||||
@@ -327,7 +327,7 @@ void Player::moveVerticalDown() {
|
||||
SDL_FRect proj;
|
||||
proj.x = x_;
|
||||
proj.y = y_ + HEIGHT;
|
||||
proj.h = ceil(vy_); // Para evitar que tenga una altura de 0 pixels
|
||||
proj.h = std::ceil(vy_); // Para evitar que tenga una altura de 0 pixels
|
||||
proj.w = WIDTH;
|
||||
|
||||
#ifdef _DEBUG
|
||||
@@ -347,8 +347,8 @@ void Player::moveVerticalDown() {
|
||||
// Si no hay colisión con los muros, comprueba la colisión con las rampas
|
||||
if (state_ != PlayerState::JUMPING) { // Las rampas no se miran si se está saltando
|
||||
auto rect = toSDLRect(proj);
|
||||
const LineVertical LEFT_SIDE = {rect.x, rect.y, rect.y + rect.h - 1};
|
||||
const LineVertical RIGHT_SIDE = {rect.x + rect.w - 1, rect.y, rect.y + rect.h - 1};
|
||||
const LineVertical LEFT_SIDE = {.x = rect.x, .y1 = rect.y, .y2 = rect.y + rect.h - 1};
|
||||
const LineVertical RIGHT_SIDE = {.x = rect.x + rect.w - 1, .y1 = rect.y, .y2 = rect.y + rect.h - 1};
|
||||
const float POINT = std::max(room_->checkRightSlopes(&RIGHT_SIDE), room_->checkLeftSlopes(&LEFT_SIDE));
|
||||
if (POINT > -1) {
|
||||
// No está saltando y hay colisión con una rampa
|
||||
@@ -357,7 +357,7 @@ void Player::moveVerticalDown() {
|
||||
setState(PlayerState::STANDING);
|
||||
#ifdef _DEBUG
|
||||
debug_color_ = static_cast<Uint8>(PaletteColor::YELLOW);
|
||||
debug_point_ = {x_ + (WIDTH / 2), POINT};
|
||||
debug_point_ = {.x = x_ + (WIDTH / 2), .y = POINT};
|
||||
#endif
|
||||
} else {
|
||||
// No está saltando y no hay colisón con una rampa
|
||||
@@ -377,7 +377,7 @@ void Player::moveVerticalDown() {
|
||||
|
||||
// Recalcula la posición del jugador y su animación
|
||||
void Player::move() {
|
||||
last_position_ = {x_, y_}; // Guarda la posicion actual antes de modificarla
|
||||
last_position_ = {.x = x_, .y = y_}; // Guarda la posicion actual antes de modificarla
|
||||
applyGravity(); // Aplica gravedad al jugador
|
||||
checkState(); // Comprueba el estado del jugador
|
||||
|
||||
@@ -463,7 +463,7 @@ void Player::playFallSound() {
|
||||
}
|
||||
|
||||
// Comprueba si el jugador tiene suelo debajo de los pies
|
||||
bool Player::isOnFloor() {
|
||||
auto Player::isOnFloor() -> bool {
|
||||
bool on_floor = false;
|
||||
bool on_slope_l = false;
|
||||
bool on_slope_r = false;
|
||||
@@ -498,7 +498,7 @@ bool Player::isOnFloor() {
|
||||
}
|
||||
|
||||
// Comprueba si el jugador esta sobre una superficie automática
|
||||
bool Player::isOnAutoSurface() {
|
||||
auto Player::isOnAutoSurface() -> bool {
|
||||
bool on_auto_surface = false;
|
||||
|
||||
updateFeet();
|
||||
@@ -518,7 +518,7 @@ bool Player::isOnAutoSurface() {
|
||||
}
|
||||
|
||||
// Comprueba si el jugador está sobre una rampa hacia abajo
|
||||
bool Player::isOnDownSlope() {
|
||||
auto Player::isOnDownSlope() -> bool {
|
||||
bool on_slope = false;
|
||||
|
||||
updateFeet();
|
||||
@@ -542,7 +542,7 @@ bool Player::isOnDownSlope() {
|
||||
}
|
||||
|
||||
// Comprueba que el jugador no toque ningun tile de los que matan
|
||||
bool Player::checkKillingTiles() {
|
||||
auto Player::checkKillingTiles() -> bool {
|
||||
// Actualiza los puntos de colisión
|
||||
updateColliderPoints();
|
||||
|
||||
@@ -571,25 +571,25 @@ 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};
|
||||
collider_points_[0] = {.x = RECT.x, .y = RECT.y};
|
||||
collider_points_[1] = {.x = RECT.x + 7, .y = RECT.y};
|
||||
collider_points_[2] = {.x = RECT.x + 7, .y = RECT.y + 7};
|
||||
collider_points_[3] = {.x = RECT.x, .y = RECT.y + 7};
|
||||
collider_points_[4] = {.x = RECT.x, .y = RECT.y + 8};
|
||||
collider_points_[5] = {.x = RECT.x + 7, .y = RECT.y + 8};
|
||||
collider_points_[6] = {.x = RECT.x + 7, .y = RECT.y + 15};
|
||||
collider_points_[7] = {.x = RECT.x, .y = RECT.y + 15};
|
||||
}
|
||||
|
||||
// Actualiza los puntos de los pies
|
||||
void Player::updateFeet() {
|
||||
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] = {.x = P.x, .y = P.y + HEIGHT};
|
||||
under_feet_[1] = {.x = P.x + 7, .y = P.y + HEIGHT};
|
||||
|
||||
feet_[0] = {P.x, P.y + HEIGHT - 1};
|
||||
feet_[1] = {P.x + 7, P.y + HEIGHT - 1};
|
||||
feet_[0] = {.x = P.x, .y = P.y + HEIGHT - 1};
|
||||
feet_[1] = {.x = P.x + 7, .y = P.y + HEIGHT - 1};
|
||||
}
|
||||
|
||||
// Cambia el estado del jugador
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <memory> // Para shared_ptr, __shared_ptr_access
|
||||
#include <string> // Para string
|
||||
#include <utility>
|
||||
#include <vector> // Para vector
|
||||
|
||||
#include "core/rendering/surface_animated_sprite.hpp" // Para SAnimatedSprite
|
||||
@@ -57,9 +58,9 @@ struct PlayerData {
|
||||
// Constructor
|
||||
PlayerData(PlayerSpawn spawn, std::string texture_path, std::string animations_path, std::shared_ptr<Room> room)
|
||||
: spawn(spawn),
|
||||
texture_path(texture_path),
|
||||
animations_path(animations_path),
|
||||
room(room) {}
|
||||
texture_path(std::move(std::move(texture_path))),
|
||||
animations_path(std::move(std::move(animations_path))),
|
||||
room(std::move(std::move(room))) {}
|
||||
};
|
||||
|
||||
class Player {
|
||||
@@ -145,16 +146,16 @@ class Player {
|
||||
void playFallSound();
|
||||
|
||||
// Comprueba si el jugador tiene suelo debajo de los pies
|
||||
bool isOnFloor();
|
||||
auto isOnFloor() -> bool;
|
||||
|
||||
// Comprueba si el jugador esta sobre una superficie automática
|
||||
bool isOnAutoSurface();
|
||||
auto isOnAutoSurface() -> bool;
|
||||
|
||||
// Comprueba si el jugador está sobre una rampa hacia abajo
|
||||
bool isOnDownSlope();
|
||||
auto isOnDownSlope() -> bool;
|
||||
|
||||
// Comprueba que el jugador no toque ningun tile de los que matan
|
||||
bool checkKillingTiles();
|
||||
auto checkKillingTiles() -> bool;
|
||||
|
||||
// Actualiza los puntos de colisión
|
||||
void updateColliderPoints();
|
||||
@@ -196,31 +197,31 @@ public:
|
||||
void update();
|
||||
|
||||
// Indica si el jugador esta en uno de los cuatro bordes de la pantalla
|
||||
bool getOnBorder() const { return is_on_border_; }
|
||||
[[nodiscard]] auto getOnBorder() const -> bool { return is_on_border_; }
|
||||
|
||||
// Indica en cual de los cuatro bordes se encuentra
|
||||
RoomBorder getBorder() const { return border_; }
|
||||
[[nodiscard]] auto getBorder() const -> RoomBorder { 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}; }
|
||||
auto getRect() -> SDL_FRect { return {x_, y_, WIDTH, HEIGHT}; }
|
||||
|
||||
// Obtiene el rectangulo de colision del jugador
|
||||
SDL_FRect& getCollider() { return collider_box_; }
|
||||
auto getCollider() -> SDL_FRect& { return collider_box_; }
|
||||
|
||||
// Obtiene el estado de reaparición del jugador
|
||||
PlayerSpawn getSpawnParams() { return {x_, y_, vx_, vy_, jump_init_pos_, state_, sprite_->getFlip()}; }
|
||||
auto getSpawnParams() -> PlayerSpawn { return {x_, y_, vx_, vy_, jump_init_pos_, state_, sprite_->getFlip()}; }
|
||||
|
||||
// Establece el color del jugador
|
||||
void setColor();
|
||||
|
||||
// Establece la habitación en la que se encuentra el jugador
|
||||
void setRoom(std::shared_ptr<Room> room) { room_ = room; }
|
||||
void setRoom(std::shared_ptr<Room> room) { room_ = std::move(room); }
|
||||
|
||||
// Comprueba si el jugador esta vivo
|
||||
bool isAlive() const { return is_alive_; }
|
||||
[[nodiscard]] auto isAlive() const -> bool { return is_alive_; }
|
||||
|
||||
// Pone el jugador en modo pausa
|
||||
void setPaused(bool value) { is_paused_ = value; }
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
#include "game/gameplay/cheevos.hpp"
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <stddef.h> // Para NULL
|
||||
|
||||
#include <cstddef> // Para NULL
|
||||
#include <fstream> // Para basic_ostream, operator<<, basic_ofstream
|
||||
#include <iostream> // Para cout, cerr
|
||||
#include <utility>
|
||||
|
||||
#include "game/options.hpp" // Para Options, options
|
||||
#include "game/ui/notifier.hpp" // Para Notifier
|
||||
#include "game/options.hpp" // Para Options, options
|
||||
#include "game/ui/notifier.hpp" // Para Notifier
|
||||
|
||||
// [SINGLETON]
|
||||
Cheevos* Cheevos::cheevos = nullptr;
|
||||
@@ -23,13 +24,13 @@ void Cheevos::destroy() {
|
||||
}
|
||||
|
||||
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||
Cheevos* Cheevos::get() {
|
||||
auto Cheevos::get() -> Cheevos* {
|
||||
return Cheevos::cheevos;
|
||||
}
|
||||
|
||||
// Constructor
|
||||
Cheevos::Cheevos(const std::string& file)
|
||||
: file_(file) {
|
||||
Cheevos::Cheevos(std::string file)
|
||||
: file_(std::move(file)) {
|
||||
init();
|
||||
loadFromFile();
|
||||
}
|
||||
@@ -57,7 +58,7 @@ void Cheevos::init() {
|
||||
}
|
||||
|
||||
// Busca un logro por id y devuelve el indice
|
||||
int Cheevos::find(int id) {
|
||||
auto Cheevos::find(int id) -> int {
|
||||
for (int i = 0; i < (int)cheevos_list_.size(); ++i) {
|
||||
if (cheevos_list_[i].id == id) {
|
||||
return i;
|
||||
@@ -103,7 +104,7 @@ void Cheevos::loadFromFile() {
|
||||
// El fichero no existe
|
||||
if (!file) {
|
||||
if (Options::console) {
|
||||
std::cout << "Warning: Unable to open " << file_ << "! Creating new file..." << std::endl;
|
||||
std::cout << "Warning: Unable to open " << file_ << "! Creating new file..." << '\n';
|
||||
}
|
||||
|
||||
// Crea el fichero en modo escritura (binario)
|
||||
@@ -111,7 +112,7 @@ void Cheevos::loadFromFile() {
|
||||
|
||||
if (new_file) {
|
||||
if (Options::console) {
|
||||
std::cout << "New " << file_ << " created!" << std::endl;
|
||||
std::cout << "New " << file_ << " created!" << '\n';
|
||||
}
|
||||
|
||||
// Guarda la información
|
||||
@@ -120,14 +121,14 @@ void Cheevos::loadFromFile() {
|
||||
}
|
||||
} else {
|
||||
if (Options::console) {
|
||||
std::cerr << "Error: Unable to create " << file_ << "!" << std::endl;
|
||||
std::cerr << "Error: Unable to create " << file_ << "!" << '\n';
|
||||
}
|
||||
}
|
||||
}
|
||||
// El fichero existe
|
||||
else {
|
||||
if (Options::console) {
|
||||
std::cout << "Reading " << file_ << std::endl;
|
||||
std::cout << "Reading " << file_ << '\n';
|
||||
}
|
||||
|
||||
// Carga los datos
|
||||
@@ -143,21 +144,21 @@ void Cheevos::saveToFile() {
|
||||
SDL_IOStream* file = SDL_IOFromFile(this->file_.c_str(), "w+b");
|
||||
if (file != nullptr) {
|
||||
// Guarda la información
|
||||
for (int i = 0; i < (int)cheevos_list_.size(); ++i) {
|
||||
SDL_WriteIO(file, &cheevos_list_[i].completed, sizeof(bool));
|
||||
for (auto& i : cheevos_list_) {
|
||||
SDL_WriteIO(file, &i.completed, sizeof(bool));
|
||||
}
|
||||
|
||||
// Cierra el fichero
|
||||
SDL_CloseIO(file);
|
||||
} else {
|
||||
if (Options::console) {
|
||||
std::cout << "Error: Unable to save file! " << SDL_GetError() << std::endl;
|
||||
std::cout << "Error: Unable to save file! " << SDL_GetError() << '\n';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Devuelve el número total de logros desbloqueados
|
||||
int Cheevos::getTotalUnlockedAchievements() {
|
||||
auto Cheevos::getTotalUnlockedAchievements() -> int {
|
||||
int count = 0;
|
||||
for (const auto& cheevo : cheevos_list_) {
|
||||
if (cheevo.completed) {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <string> // Para string
|
||||
#include <utility>
|
||||
#include <vector> // Para vector
|
||||
|
||||
// Struct para los logros
|
||||
@@ -20,10 +21,10 @@ struct Achievement {
|
||||
obtainable(true) {}
|
||||
|
||||
// Constructor parametrizado
|
||||
Achievement(int id, const std::string& caption, const std::string& description, int icon, bool completed = false, bool obtainable = true)
|
||||
Achievement(int id, std::string caption, std::string description, int icon, bool completed = false, bool obtainable = true)
|
||||
: id(id),
|
||||
caption(caption),
|
||||
description(description),
|
||||
caption(std::move(caption)),
|
||||
description(std::move(description)),
|
||||
icon(icon),
|
||||
completed(completed),
|
||||
obtainable(obtainable) {}
|
||||
@@ -43,7 +44,7 @@ class Cheevos {
|
||||
void init();
|
||||
|
||||
// Busca un logro por id y devuelve el índice
|
||||
int find(int id);
|
||||
auto find(int id) -> int;
|
||||
|
||||
// Carga el estado de los logros desde un fichero
|
||||
void loadFromFile();
|
||||
@@ -52,7 +53,7 @@ class Cheevos {
|
||||
void saveToFile();
|
||||
|
||||
// Constructor
|
||||
explicit Cheevos(const std::string& file);
|
||||
explicit Cheevos(std::string file);
|
||||
|
||||
// Destructor
|
||||
~Cheevos();
|
||||
@@ -65,7 +66,7 @@ class Cheevos {
|
||||
static void destroy();
|
||||
|
||||
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||
static Cheevos* get();
|
||||
static auto get() -> Cheevos*;
|
||||
|
||||
// Desbloquea un logro
|
||||
void unlock(int id);
|
||||
@@ -80,11 +81,11 @@ class Cheevos {
|
||||
void enable(bool value) { enabled_ = value; }
|
||||
|
||||
// Lista los logros
|
||||
const std::vector<Achievement>& list() const { return cheevos_list_; }
|
||||
[[nodiscard]] auto list() const -> const std::vector<Achievement>& { return cheevos_list_; }
|
||||
|
||||
// Devuelve el número total de logros desbloqueados
|
||||
int getTotalUnlockedAchievements();
|
||||
auto getTotalUnlockedAchievements() -> int;
|
||||
|
||||
// Devuelve el número total de logros
|
||||
int size() { return cheevos_list_.size(); }
|
||||
auto size() -> int { return cheevos_list_.size(); }
|
||||
};
|
||||
|
||||
@@ -14,12 +14,12 @@ void ItemTracker::destroy() {
|
||||
}
|
||||
|
||||
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||
ItemTracker* ItemTracker::get() {
|
||||
auto ItemTracker::get() -> ItemTracker* {
|
||||
return ItemTracker::item_tracker;
|
||||
}
|
||||
|
||||
// Comprueba si el objeto ya ha sido cogido
|
||||
bool ItemTracker::hasBeenPicked(const std::string& name, SDL_FPoint pos) {
|
||||
auto ItemTracker::hasBeenPicked(const std::string& name, SDL_FPoint pos) -> bool {
|
||||
// Primero busca si ya hay una entrada con ese nombre
|
||||
if (const int INDEX = findByName(name); INDEX != -1) {
|
||||
// Luego busca si existe ya una entrada con esa posición
|
||||
@@ -47,7 +47,7 @@ void ItemTracker::addItem(const std::string& name, SDL_FPoint pos) {
|
||||
}
|
||||
|
||||
// Busca una entrada en la lista por nombre
|
||||
int ItemTracker::findByName(const std::string& name) {
|
||||
auto ItemTracker::findByName(const std::string& name) -> int {
|
||||
int i = 0;
|
||||
|
||||
for (const auto& l : item_list_) {
|
||||
@@ -61,7 +61,7 @@ int ItemTracker::findByName(const std::string& name) {
|
||||
}
|
||||
|
||||
// Busca una entrada en la lista por posición
|
||||
int ItemTracker::findByPos(int index, SDL_FPoint pos) {
|
||||
auto ItemTracker::findByPos(int index, SDL_FPoint pos) -> int {
|
||||
int i = 0;
|
||||
|
||||
for (const auto& l : item_list_[index].pos) {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <string> // Para string, basic_string
|
||||
#include <utility>
|
||||
#include <vector> // Para vector
|
||||
|
||||
struct ItemTrackerData {
|
||||
@@ -10,8 +11,8 @@ struct ItemTrackerData {
|
||||
std::vector<SDL_FPoint> pos; // Lista de objetos cogidos de la habitación
|
||||
|
||||
// Constructor
|
||||
ItemTrackerData(const std::string& name, const SDL_FPoint& position)
|
||||
: name(name) {
|
||||
ItemTrackerData(std::string name, const SDL_FPoint& position)
|
||||
: name(std::move(name)) {
|
||||
pos.push_back(position);
|
||||
}
|
||||
};
|
||||
@@ -25,10 +26,10 @@ class ItemTracker {
|
||||
std::vector<ItemTrackerData> item_list_; // Lista con todos los objetos recogidos
|
||||
|
||||
// Busca una entrada en la lista por nombre
|
||||
int findByName(const std::string& name);
|
||||
auto findByName(const std::string& name) -> int;
|
||||
|
||||
// Busca una entrada en la lista por posición
|
||||
int findByPos(int index, SDL_FPoint pos);
|
||||
auto findByPos(int index, SDL_FPoint pos) -> int;
|
||||
|
||||
// Constructor
|
||||
ItemTracker() = default;
|
||||
@@ -44,10 +45,10 @@ class ItemTracker {
|
||||
static void destroy();
|
||||
|
||||
// [SINGLETON] Con este método obtenemos el objeto y podemos trabajar con él
|
||||
static ItemTracker* get();
|
||||
static auto get() -> ItemTracker*;
|
||||
|
||||
// Comprueba si el objeto ya ha sido cogido
|
||||
bool hasBeenPicked(const std::string& name, SDL_FPoint pos);
|
||||
auto hasBeenPicked(const std::string& name, SDL_FPoint pos) -> bool;
|
||||
|
||||
// Añade el objeto a la lista de objetos cogidos
|
||||
void addItem(const std::string& name, SDL_FPoint pos);
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <fstream> // Para basic_ostream, operator<<, basic_istream
|
||||
#include <iostream> // Para cout, cerr
|
||||
#include <sstream> // Para basic_stringstream
|
||||
#include <utility>
|
||||
|
||||
#include "core/rendering/screen.hpp" // Para Screen
|
||||
#include "core/rendering/surface.hpp" // Para Surface
|
||||
@@ -19,7 +20,7 @@
|
||||
#include "utils/utils.hpp" // Para LineHorizontal, LineDiagonal, LineVertical
|
||||
|
||||
// Carga las variables y texturas desde un fichero de mapa de tiles
|
||||
std::vector<int> loadRoomTileFile(const std::string& file_path, bool verbose) {
|
||||
auto loadRoomTileFile(const std::string& file_path, bool verbose) -> std::vector<int> {
|
||||
std::vector<int> tile_map_file;
|
||||
const std::string FILENAME = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
std::ifstream file(file_path);
|
||||
@@ -47,14 +48,14 @@ std::vector<int> loadRoomTileFile(const std::string& file_path, bool verbose) {
|
||||
|
||||
// Cierra el fichero
|
||||
if (verbose) {
|
||||
std::cout << "TileMap loaded: " << FILENAME.c_str() << std::endl;
|
||||
std::cout << "TileMap loaded: " << FILENAME.c_str() << '\n';
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
|
||||
else { // El fichero no se puede abrir
|
||||
if (verbose) {
|
||||
std::cout << "Warning: Unable to open " << FILENAME.c_str() << " file" << std::endl;
|
||||
std::cout << "Warning: Unable to open " << FILENAME.c_str() << " file" << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,8 +63,8 @@ std::vector<int> loadRoomTileFile(const std::string& file_path, bool verbose) {
|
||||
}
|
||||
|
||||
// Parsea una línea en key y value separados por '='
|
||||
std::pair<std::string, std::string> parseKeyValue(const std::string& line) {
|
||||
int pos = line.find("=");
|
||||
auto parseKeyValue(const std::string& line) -> std::pair<std::string, std::string> {
|
||||
int pos = line.find('=');
|
||||
std::string key = line.substr(0, pos);
|
||||
std::string value = line.substr(pos + 1, line.length());
|
||||
return {key, value};
|
||||
@@ -72,12 +73,12 @@ std::pair<std::string, std::string> parseKeyValue(const std::string& line) {
|
||||
// Muestra un warning de parámetro desconocido
|
||||
void logUnknownParameter(const std::string& file_name, const std::string& key, bool verbose) {
|
||||
if (verbose) {
|
||||
std::cout << "Warning: file " << file_name.c_str() << "\n, unknown parameter \"" << key.c_str() << "\"" << std::endl;
|
||||
std::cout << "Warning: file " << file_name.c_str() << "\n, unknown parameter \"" << key.c_str() << "\"" << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
// Carga un bloque [enemy]...[/enemy] desde un archivo
|
||||
EnemyData loadEnemyFromFile(std::ifstream& file, const std::string& file_name, bool verbose) {
|
||||
auto loadEnemyFromFile(std::ifstream& file, const std::string& file_name, bool verbose) -> EnemyData {
|
||||
EnemyData enemy;
|
||||
enemy.flip = false;
|
||||
enemy.mirror = false;
|
||||
@@ -97,7 +98,7 @@ EnemyData loadEnemyFromFile(std::ifstream& file, const std::string& file_name, b
|
||||
}
|
||||
|
||||
// Carga un bloque [item]...[/item] desde un archivo
|
||||
ItemData loadItemFromFile(std::ifstream& file, const std::string& file_name, bool verbose) {
|
||||
auto loadItemFromFile(std::ifstream& file, const std::string& file_name, bool verbose) -> ItemData {
|
||||
ItemData item;
|
||||
item.counter = 0;
|
||||
item.color1 = stringToColor("yellow");
|
||||
@@ -117,14 +118,14 @@ ItemData loadItemFromFile(std::ifstream& file, const std::string& file_name, boo
|
||||
}
|
||||
|
||||
// Carga las variables desde un fichero de mapa
|
||||
RoomData loadRoomFile(const std::string& file_path, bool verbose) {
|
||||
auto loadRoomFile(const std::string& file_path, bool verbose) -> RoomData {
|
||||
RoomData room;
|
||||
room.item_color1 = "yellow";
|
||||
room.item_color2 = "magenta";
|
||||
room.conveyor_belt_direction = 1;
|
||||
|
||||
const std::string FILE_NAME = file_path.substr(file_path.find_last_of("\\/") + 1);
|
||||
room.number = FILE_NAME.substr(0, FILE_NAME.find_last_of("."));
|
||||
room.number = FILE_NAME.substr(0, FILE_NAME.find_last_of('.'));
|
||||
|
||||
std::ifstream file(file_path);
|
||||
|
||||
@@ -152,20 +153,20 @@ RoomData loadRoomFile(const std::string& file_path, bool verbose) {
|
||||
|
||||
// Cierra el fichero
|
||||
if (verbose) {
|
||||
std::cout << "Room loaded: " << FILE_NAME.c_str() << std::endl;
|
||||
std::cout << "Room loaded: " << FILE_NAME.c_str() << '\n';
|
||||
}
|
||||
file.close();
|
||||
}
|
||||
// El fichero no se puede abrir
|
||||
else {
|
||||
std::cout << "Warning: Unable to open " << FILE_NAME.c_str() << " file" << std::endl;
|
||||
std::cout << "Warning: Unable to open " << FILE_NAME.c_str() << " file" << '\n';
|
||||
}
|
||||
|
||||
return room;
|
||||
}
|
||||
|
||||
// Asigna variables a una estructura RoomData
|
||||
bool setRoom(RoomData* room, const std::string& key, const std::string& value) {
|
||||
auto setRoom(RoomData* room, const std::string& key, const std::string& value) -> bool {
|
||||
// Indicador de éxito en la asignación
|
||||
bool success = true;
|
||||
|
||||
@@ -200,7 +201,7 @@ bool setRoom(RoomData* room, const std::string& key, const std::string& value) {
|
||||
success = false;
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << "Error al asignar la clave " << key << " con valor " << value << ": " << e.what() << std::endl;
|
||||
std::cerr << "Error al asignar la clave " << key << " con valor " << value << ": " << e.what() << '\n';
|
||||
success = false;
|
||||
}
|
||||
|
||||
@@ -208,7 +209,7 @@ bool setRoom(RoomData* room, const std::string& key, const std::string& value) {
|
||||
}
|
||||
|
||||
// Asigna variables a una estructura EnemyData
|
||||
bool setEnemy(EnemyData* enemy, const std::string& key, const std::string& value) {
|
||||
auto setEnemy(EnemyData* enemy, const std::string& key, const std::string& value) -> bool {
|
||||
// Indicador de éxito en la asignación
|
||||
bool success = true;
|
||||
|
||||
@@ -251,7 +252,7 @@ bool setEnemy(EnemyData* enemy, const std::string& key, const std::string& value
|
||||
success = false;
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << "Error al asignar la clave " << key << " con valor " << value << ": " << e.what() << std::endl;
|
||||
std::cerr << "Error al asignar la clave " << key << " con valor " << value << ": " << e.what() << '\n';
|
||||
success = false;
|
||||
}
|
||||
|
||||
@@ -259,7 +260,7 @@ bool setEnemy(EnemyData* enemy, const std::string& key, const std::string& value
|
||||
}
|
||||
|
||||
// Asigna variables a una estructura ItemData
|
||||
bool setItem(ItemData* item, const std::string& key, const std::string& value) {
|
||||
auto setItem(ItemData* item, const std::string& key, const std::string& value) -> bool {
|
||||
// Indicador de éxito en la asignación
|
||||
bool success = true;
|
||||
|
||||
@@ -280,7 +281,7 @@ bool setItem(ItemData* item, const std::string& key, const std::string& value) {
|
||||
success = false;
|
||||
}
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << "Error al asignar la clave " << key << " con valor " << value << ": " << e.what() << std::endl;
|
||||
std::cerr << "Error al asignar la clave " << key << " con valor " << value << ": " << e.what() << '\n';
|
||||
success = false;
|
||||
}
|
||||
|
||||
@@ -289,7 +290,7 @@ bool setItem(ItemData* item, const std::string& key, const std::string& value) {
|
||||
|
||||
// Constructor
|
||||
Room::Room(const std::string& room_path, std::shared_ptr<ScoreboardData> data)
|
||||
: data_(data) {
|
||||
: data_(std::move(std::move(data))) {
|
||||
auto room = Resource::get()->getRoom(room_path);
|
||||
initializeRoom(*room);
|
||||
|
||||
@@ -482,19 +483,19 @@ void Room::update() {
|
||||
// Actualiza los tiles animados
|
||||
updateAnimatedTiles();
|
||||
|
||||
for (auto enemy : enemies_) {
|
||||
for (const auto& enemy : enemies_) {
|
||||
// Actualiza los enemigos
|
||||
enemy->update();
|
||||
}
|
||||
|
||||
for (auto item : items_) {
|
||||
for (const auto& item : items_) {
|
||||
// Actualiza los items
|
||||
item->update();
|
||||
}
|
||||
}
|
||||
|
||||
// Devuelve la cadena del fichero de la habitación contigua segun el borde
|
||||
std::string Room::getRoom(RoomBorder border) {
|
||||
auto Room::getRoom(RoomBorder border) -> std::string {
|
||||
switch (border) {
|
||||
case RoomBorder::TOP:
|
||||
return upper_room_;
|
||||
@@ -519,13 +520,13 @@ std::string Room::getRoom(RoomBorder border) {
|
||||
}
|
||||
|
||||
// Devuelve el tipo de tile que hay en ese pixel
|
||||
TileType Room::getTile(SDL_FPoint point) {
|
||||
auto Room::getTile(SDL_FPoint point) -> TileType {
|
||||
const int POS = ((point.y / TILE_SIZE) * MAP_WIDTH) + (point.x / TILE_SIZE);
|
||||
return getTile(POS);
|
||||
}
|
||||
|
||||
// Devuelve el tipo de tile que hay en ese indice
|
||||
TileType Room::getTile(int index) {
|
||||
auto Room::getTile(int index) -> TileType {
|
||||
// const bool onRange = (index > -1) && (index < mapWidth * mapHeight);
|
||||
const bool ON_RANGE = (index > -1) && (index < (int)tile_map_.size());
|
||||
|
||||
@@ -565,14 +566,14 @@ TileType Room::getTile(int index) {
|
||||
}
|
||||
|
||||
// Indica si hay colision con un enemigo a partir de un rectangulo
|
||||
bool Room::enemyCollision(SDL_FRect& rect) {
|
||||
auto Room::enemyCollision(SDL_FRect& rect) -> bool {
|
||||
return std::ranges::any_of(enemies_, [&rect](const auto& enemy) {
|
||||
return checkCollision(rect, enemy->getCollider());
|
||||
});
|
||||
}
|
||||
|
||||
// Indica si hay colision con un objeto a partir de un rectangulo
|
||||
bool Room::itemCollision(SDL_FRect& rect) {
|
||||
auto Room::itemCollision(SDL_FRect& rect) -> bool {
|
||||
for (int i = 0; i < static_cast<int>(items_.size()); ++i) {
|
||||
if (checkCollision(rect, items_.at(i)->getCollider())) {
|
||||
ItemTracker::get()->addItem(name_, items_.at(i)->getPos());
|
||||
@@ -588,7 +589,7 @@ bool Room::itemCollision(SDL_FRect& rect) {
|
||||
}
|
||||
|
||||
// Obten la coordenada de la cuesta a partir de un punto perteneciente a ese tile
|
||||
int Room::getSlopeHeight(SDL_FPoint p, TileType slope) {
|
||||
auto Room::getSlopeHeight(SDL_FPoint p, TileType slope) -> int {
|
||||
// Calcula la base del tile
|
||||
int base = ((p.y / TILE_SIZE) * TILE_SIZE) + TILE_SIZE;
|
||||
#ifdef _DEBUG
|
||||
@@ -618,7 +619,7 @@ int Room::getSlopeHeight(SDL_FPoint p, TileType slope) {
|
||||
}
|
||||
|
||||
// Helper: recopila tiles inferiores (muros sin muro debajo)
|
||||
std::vector<int> Room::collectBottomTiles() {
|
||||
auto Room::collectBottomTiles() -> std::vector<int> {
|
||||
std::vector<int> tile;
|
||||
|
||||
// Busca todos los tiles de tipo muro que no tengan debajo otro muro
|
||||
@@ -640,7 +641,7 @@ std::vector<int> Room::collectBottomTiles() {
|
||||
}
|
||||
|
||||
// Helper: recopila tiles superiores (muros o pasables sin muro encima)
|
||||
std::vector<int> Room::collectTopTiles() {
|
||||
auto Room::collectTopTiles() -> std::vector<int> {
|
||||
std::vector<int> tile;
|
||||
|
||||
// Busca todos los tiles de tipo muro o pasable que no tengan encima un muro
|
||||
@@ -867,7 +868,7 @@ void Room::setRightSlopes() {
|
||||
|
||||
// Calcula las superficies automaticas
|
||||
// Helper: recopila tiles animados (para superficies automaticas/conveyor belts)
|
||||
std::vector<int> Room::collectAnimatedTiles() {
|
||||
auto Room::collectAnimatedTiles() -> std::vector<int> {
|
||||
std::vector<int> tile;
|
||||
|
||||
// Busca todos los tiles de tipo animado
|
||||
@@ -943,7 +944,7 @@ void Room::renderAnimatedTiles() {
|
||||
}
|
||||
|
||||
// Comprueba las colisiones
|
||||
int Room::checkRightSurfaces(SDL_FRect* rect) {
|
||||
auto Room::checkRightSurfaces(SDL_FRect* rect) -> int {
|
||||
for (const auto& s : right_walls_) {
|
||||
if (checkCollision(s, *rect)) {
|
||||
return s.x;
|
||||
@@ -954,7 +955,7 @@ int Room::checkRightSurfaces(SDL_FRect* rect) {
|
||||
}
|
||||
|
||||
// Comprueba las colisiones
|
||||
int Room::checkLeftSurfaces(SDL_FRect* rect) {
|
||||
auto Room::checkLeftSurfaces(SDL_FRect* rect) -> int {
|
||||
for (const auto& s : left_walls_) {
|
||||
if (checkCollision(s, *rect)) {
|
||||
return s.x;
|
||||
@@ -965,7 +966,7 @@ int Room::checkLeftSurfaces(SDL_FRect* rect) {
|
||||
}
|
||||
|
||||
// Comprueba las colisiones
|
||||
int Room::checkTopSurfaces(SDL_FRect* rect) {
|
||||
auto Room::checkTopSurfaces(SDL_FRect* rect) -> int {
|
||||
for (const auto& s : top_floors_) {
|
||||
if (checkCollision(s, *rect)) {
|
||||
return s.y;
|
||||
@@ -976,7 +977,7 @@ int Room::checkTopSurfaces(SDL_FRect* rect) {
|
||||
}
|
||||
|
||||
// Comprueba las colisiones
|
||||
int Room::checkBottomSurfaces(SDL_FRect* rect) {
|
||||
auto Room::checkBottomSurfaces(SDL_FRect* rect) -> int {
|
||||
for (const auto& s : bottom_floors_) {
|
||||
if (checkCollision(s, *rect)) {
|
||||
return s.y;
|
||||
@@ -987,7 +988,7 @@ int Room::checkBottomSurfaces(SDL_FRect* rect) {
|
||||
}
|
||||
|
||||
// Comprueba las colisiones
|
||||
int Room::checkAutoSurfaces(SDL_FRect* rect) {
|
||||
auto Room::checkAutoSurfaces(SDL_FRect* rect) -> int {
|
||||
for (const auto& s : conveyor_belt_floors_) {
|
||||
if (checkCollision(s, *rect)) {
|
||||
return s.y;
|
||||
@@ -998,21 +999,21 @@ int Room::checkAutoSurfaces(SDL_FRect* rect) {
|
||||
}
|
||||
|
||||
// Comprueba las colisiones
|
||||
bool Room::checkTopSurfaces(SDL_FPoint* p) {
|
||||
auto Room::checkTopSurfaces(SDL_FPoint* p) -> bool {
|
||||
return std::ranges::any_of(top_floors_, [&](const auto& s) {
|
||||
return checkCollision(s, *p);
|
||||
});
|
||||
}
|
||||
|
||||
// Comprueba las colisiones
|
||||
bool Room::checkAutoSurfaces(SDL_FPoint* p) {
|
||||
auto Room::checkAutoSurfaces(SDL_FPoint* p) -> bool {
|
||||
return std::ranges::any_of(conveyor_belt_floors_, [&](const auto& s) {
|
||||
return checkCollision(s, *p);
|
||||
});
|
||||
}
|
||||
|
||||
// Comprueba las colisiones
|
||||
int Room::checkLeftSlopes(const LineVertical* line) {
|
||||
auto Room::checkLeftSlopes(const LineVertical* line) -> int {
|
||||
for (const auto& slope : left_slopes_) {
|
||||
const auto P = checkCollision(slope, *line);
|
||||
if (P.x != -1) {
|
||||
@@ -1024,14 +1025,14 @@ int Room::checkLeftSlopes(const LineVertical* line) {
|
||||
}
|
||||
|
||||
// Comprueba las colisiones
|
||||
bool Room::checkLeftSlopes(SDL_FPoint* p) {
|
||||
auto Room::checkLeftSlopes(SDL_FPoint* p) -> bool {
|
||||
return std::ranges::any_of(left_slopes_, [&](const auto& slope) {
|
||||
return checkCollision(*p, slope);
|
||||
});
|
||||
}
|
||||
|
||||
// Comprueba las colisiones
|
||||
int Room::checkRightSlopes(const LineVertical* line) {
|
||||
auto Room::checkRightSlopes(const LineVertical* line) -> int {
|
||||
for (const auto& slope : right_slopes_) {
|
||||
const auto P = checkCollision(slope, *line);
|
||||
if (P.x != -1) {
|
||||
@@ -1043,7 +1044,7 @@ int Room::checkRightSlopes(const LineVertical* line) {
|
||||
}
|
||||
|
||||
// Comprueba las colisiones
|
||||
bool Room::checkRightSlopes(SDL_FPoint* p) {
|
||||
auto Room::checkRightSlopes(SDL_FPoint* p) -> bool {
|
||||
return std::ranges::any_of(right_slopes_, [&](const auto& slope) {
|
||||
return checkCollision(*p, slope);
|
||||
});
|
||||
|
||||
@@ -55,19 +55,19 @@ struct RoomData {
|
||||
};
|
||||
|
||||
// Carga las variables desde un fichero de mapa
|
||||
RoomData loadRoomFile(const std::string& file_path, bool verbose = false);
|
||||
auto loadRoomFile(const std::string& file_path, bool verbose = false) -> RoomData;
|
||||
|
||||
// Carga las variables y texturas desde un fichero de mapa de tiles
|
||||
std::vector<int> loadRoomTileFile(const std::string& file_path, bool verbose = false);
|
||||
auto loadRoomTileFile(const std::string& file_path, bool verbose = false) -> std::vector<int>;
|
||||
|
||||
// Asigna variables a una estructura RoomData
|
||||
bool setRoom(RoomData* room, const std::string& key, const std::string& value);
|
||||
auto setRoom(RoomData* room, const std::string& key, const std::string& value) -> bool;
|
||||
|
||||
// Asigna variables a una estructura EnemyData
|
||||
bool setEnemy(EnemyData* enemy, const std::string& key, const std::string& value);
|
||||
auto setEnemy(EnemyData* enemy, const std::string& key, const std::string& value) -> bool;
|
||||
|
||||
// Asigna variables a una estructura ItemData
|
||||
bool setItem(ItemData* item, const std::string& key, const std::string& value);
|
||||
auto setItem(ItemData* item, const std::string& key, const std::string& value) -> bool;
|
||||
|
||||
class Room {
|
||||
private:
|
||||
@@ -116,13 +116,13 @@ class Room {
|
||||
void fillMapTexture();
|
||||
|
||||
// Helper para recopilar tiles inferiores
|
||||
std::vector<int> collectBottomTiles();
|
||||
auto collectBottomTiles() -> std::vector<int>;
|
||||
|
||||
// Helper para recopilar tiles superiores
|
||||
std::vector<int> collectTopTiles();
|
||||
auto collectTopTiles() -> std::vector<int>;
|
||||
|
||||
// Helper para recopilar tiles animados (para superficies automaticas)
|
||||
std::vector<int> collectAnimatedTiles();
|
||||
auto collectAnimatedTiles() -> std::vector<int>;
|
||||
|
||||
// Helper para construir lineas horizontales a partir de tiles consecutivos
|
||||
static void buildHorizontalLines(const std::vector<int>& tiles, std::vector<LineHorizontal>& lines, bool is_bottom_surface);
|
||||
@@ -158,7 +158,7 @@ class Room {
|
||||
void renderAnimatedTiles();
|
||||
|
||||
// Devuelve el tipo de tile que hay en ese indice
|
||||
TileType getTile(int index);
|
||||
auto getTile(int index) -> TileType;
|
||||
|
||||
// Abre la jail para poder entrar
|
||||
void openTheJail();
|
||||
@@ -174,13 +174,13 @@ class Room {
|
||||
~Room() = default;
|
||||
|
||||
// Devuelve el nombre de la habitación
|
||||
const std::string& getName() const { return name_; }
|
||||
[[nodiscard]] auto getName() const -> const std::string& { return name_; }
|
||||
|
||||
// Devuelve el color de la habitación
|
||||
Uint8 getBGColor() const { return stringToColor(bg_color_); }
|
||||
[[nodiscard]] auto getBGColor() const -> Uint8 { return stringToColor(bg_color_); }
|
||||
|
||||
// Devuelve el color del borde
|
||||
Uint8 getBorderColor() const { return stringToColor(border_color_); }
|
||||
[[nodiscard]] auto getBorderColor() const -> Uint8 { return stringToColor(border_color_); }
|
||||
|
||||
// Dibuja el mapa en pantalla
|
||||
void renderMap();
|
||||
@@ -195,59 +195,59 @@ class Room {
|
||||
void update();
|
||||
|
||||
// Devuelve la cadena del fichero de la habitación contigua segun el borde
|
||||
std::string getRoom(RoomBorder border);
|
||||
auto getRoom(RoomBorder border) -> std::string;
|
||||
|
||||
// Devuelve el tipo de tile que hay en ese pixel
|
||||
TileType getTile(SDL_FPoint point);
|
||||
auto getTile(SDL_FPoint point) -> TileType;
|
||||
|
||||
// Indica si hay colision con un enemigo a partir de un rectangulo
|
||||
bool enemyCollision(SDL_FRect& rect);
|
||||
auto enemyCollision(SDL_FRect& rect) -> bool;
|
||||
|
||||
// Indica si hay colision con un objeto a partir de un rectangulo
|
||||
bool itemCollision(SDL_FRect& rect);
|
||||
auto itemCollision(SDL_FRect& rect) -> bool;
|
||||
|
||||
// Obten el tamaño del tile
|
||||
static int getTileSize() { return TILE_SIZE; }
|
||||
static auto getTileSize() -> int { return TILE_SIZE; }
|
||||
|
||||
// Obten la coordenada de la cuesta a partir de un punto perteneciente a ese tile
|
||||
static int getSlopeHeight(SDL_FPoint p, TileType slope);
|
||||
static auto getSlopeHeight(SDL_FPoint p, TileType slope) -> int;
|
||||
|
||||
// Comprueba las colisiones
|
||||
int checkRightSurfaces(SDL_FRect* rect);
|
||||
auto checkRightSurfaces(SDL_FRect* rect) -> int;
|
||||
|
||||
// Comprueba las colisiones
|
||||
int checkLeftSurfaces(SDL_FRect* rect);
|
||||
auto checkLeftSurfaces(SDL_FRect* rect) -> int;
|
||||
|
||||
// Comprueba las colisiones
|
||||
int checkTopSurfaces(SDL_FRect* rect);
|
||||
auto checkTopSurfaces(SDL_FRect* rect) -> int;
|
||||
|
||||
// Comprueba las colisiones
|
||||
int checkBottomSurfaces(SDL_FRect* rect);
|
||||
auto checkBottomSurfaces(SDL_FRect* rect) -> int;
|
||||
|
||||
// Comprueba las colisiones
|
||||
int checkAutoSurfaces(SDL_FRect* rect);
|
||||
auto checkAutoSurfaces(SDL_FRect* rect) -> int;
|
||||
|
||||
// Comprueba las colisiones
|
||||
bool checkTopSurfaces(SDL_FPoint* p);
|
||||
auto checkTopSurfaces(SDL_FPoint* p) -> bool;
|
||||
|
||||
// Comprueba las colisiones
|
||||
bool checkAutoSurfaces(SDL_FPoint* p);
|
||||
auto checkAutoSurfaces(SDL_FPoint* p) -> bool;
|
||||
|
||||
// Comprueba las colisiones
|
||||
int checkLeftSlopes(const LineVertical* line);
|
||||
auto checkLeftSlopes(const LineVertical* line) -> int;
|
||||
|
||||
// Comprueba las colisiones
|
||||
bool checkLeftSlopes(SDL_FPoint* p);
|
||||
auto checkLeftSlopes(SDL_FPoint* p) -> bool;
|
||||
|
||||
// Comprueba las colisiones
|
||||
int checkRightSlopes(const LineVertical* line);
|
||||
auto checkRightSlopes(const LineVertical* line) -> int;
|
||||
|
||||
// Comprueba las colisiones
|
||||
bool checkRightSlopes(SDL_FPoint* p);
|
||||
auto checkRightSlopes(SDL_FPoint* p) -> bool;
|
||||
|
||||
// Pone el mapa en modo pausa
|
||||
void setPaused(bool value) { is_paused_ = value; };
|
||||
|
||||
// Obten la direccion de las superficies automaticas
|
||||
int getAutoSurfaceDirection() const { return conveyor_belt_direction_; }
|
||||
[[nodiscard]] auto getAutoSurfaceDirection() const -> int { return conveyor_belt_direction_; }
|
||||
};
|
||||
@@ -3,12 +3,12 @@
|
||||
#include <algorithm> // Para std::ranges::any_of
|
||||
|
||||
// Comprueba si la habitación ya ha sido visitada
|
||||
bool RoomTracker::hasBeenVisited(const std::string& name) {
|
||||
auto RoomTracker::hasBeenVisited(const std::string& name) -> bool {
|
||||
return std::ranges::any_of(list_, [&name](const auto& l) { return l == name; });
|
||||
}
|
||||
|
||||
// Añade la habitación a la lista
|
||||
bool RoomTracker::addRoom(const std::string& name) {
|
||||
auto RoomTracker::addRoom(const std::string& name) -> bool {
|
||||
// Comprueba si la habitación ya ha sido visitada
|
||||
if (!hasBeenVisited(name)) {
|
||||
// En caso contrario añádela a la lista
|
||||
|
||||
@@ -9,7 +9,7 @@ class RoomTracker {
|
||||
std::vector<std::string> list_; // Lista con las habitaciones visitadas
|
||||
|
||||
// Comprueba si la habitación ya ha sido visitada
|
||||
bool hasBeenVisited(const std::string& name);
|
||||
auto hasBeenVisited(const std::string& name) -> bool;
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
@@ -19,5 +19,5 @@ class RoomTracker {
|
||||
~RoomTracker() = default;
|
||||
|
||||
// Añade la habitación a la lista
|
||||
bool addRoom(const std::string& name);
|
||||
auto addRoom(const std::string& name) -> bool;
|
||||
};
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <utility>
|
||||
|
||||
#include "core/rendering/screen.hpp" // Para Screen
|
||||
#include "core/rendering/surface.hpp" // Para Surface
|
||||
#include "core/rendering/surface_animated_sprite.hpp" // Para SAnimatedSprite
|
||||
@@ -14,7 +16,7 @@
|
||||
// Constructor
|
||||
Scoreboard::Scoreboard(std::shared_ptr<ScoreboardData> data)
|
||||
: item_surface_(Resource::get()->getSurface("items.gif")),
|
||||
data_(data) {
|
||||
data_(std::move(std::move(data))) {
|
||||
const float SURFACE_WIDTH = Options::game.width;
|
||||
constexpr float SURFACE_HEIGHT = 6.0F * BLOCK;
|
||||
|
||||
@@ -25,7 +27,7 @@ Scoreboard::Scoreboard(std::shared_ptr<ScoreboardData> data)
|
||||
player_sprite_->setCurrentAnimation("walk_menu");
|
||||
|
||||
surface_ = std::make_shared<Surface>(SURFACE_WIDTH, SURFACE_HEIGHT);
|
||||
surface_dest_ = {0, Options::game.height - SURFACE_HEIGHT, SURFACE_WIDTH, SURFACE_HEIGHT};
|
||||
surface_dest_ = {.x = 0, .y = Options::game.height - SURFACE_HEIGHT, .w = SURFACE_WIDTH, .h = SURFACE_HEIGHT};
|
||||
|
||||
// Inicializa las variables
|
||||
counter_ = 0;
|
||||
@@ -65,7 +67,7 @@ void Scoreboard::update() {
|
||||
}
|
||||
|
||||
// Obtiene el tiempo transcurrido de partida
|
||||
Scoreboard::ClockData Scoreboard::getTime() {
|
||||
auto Scoreboard::getTime() -> Scoreboard::ClockData {
|
||||
const Uint32 TIME_ELAPSED = SDL_GetTicks() - data_->ini_clock - paused_time_elapsed_;
|
||||
|
||||
ClockData time;
|
||||
@@ -109,7 +111,7 @@ void Scoreboard::updateItemsColor() {
|
||||
}
|
||||
|
||||
// Devuelve la cantidad de minutos de juego transcurridos
|
||||
int Scoreboard::getMinutes() {
|
||||
auto Scoreboard::getMinutes() -> int {
|
||||
return getTime().minutes;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <memory> // Para shared_ptr
|
||||
#include <string> // Para string, basic_string
|
||||
#include <utility>
|
||||
#include <vector> // Para vector
|
||||
class SurfaceAnimatedSprite; // lines 10-10
|
||||
class Surface; // lines 11-11
|
||||
@@ -54,11 +55,11 @@ class Scoreboard {
|
||||
separator(":") {}
|
||||
|
||||
// Constructor parametrizado
|
||||
ClockData(int h, int m, int s, const std::string& sep)
|
||||
ClockData(int h, int m, int s, std::string sep)
|
||||
: hours(h),
|
||||
minutes(m),
|
||||
seconds(s),
|
||||
separator(sep) {}
|
||||
separator(std::move(sep)) {}
|
||||
};
|
||||
|
||||
// Objetos y punteros
|
||||
@@ -79,7 +80,7 @@ class Scoreboard {
|
||||
SDL_FRect surface_dest_; // Rectangulo donde dibujar la surface del marcador
|
||||
|
||||
// Obtiene el tiempo transcurrido de partida
|
||||
ClockData getTime();
|
||||
auto getTime() -> ClockData;
|
||||
|
||||
// Actualiza el color de la cantidad de items recogidos
|
||||
void updateItemsColor();
|
||||
@@ -104,5 +105,5 @@ class Scoreboard {
|
||||
void setPaused(bool value);
|
||||
|
||||
// Devuelve la cantidad de minutos de juego transcurridos
|
||||
int getMinutes();
|
||||
auto getMinutes() -> int;
|
||||
};
|
||||
|
||||
@@ -2,13 +2,14 @@
|
||||
|
||||
#include <fstream> // Para basic_ostream, basic_ifstream, basic_istream
|
||||
#include <sstream> // Para basic_stringstream
|
||||
#include <utility>
|
||||
|
||||
#include "game/options.hpp" // Para Options, OptionsStats, options
|
||||
|
||||
// Constructor
|
||||
Stats::Stats(const std::string& file, const std::string& buffer)
|
||||
: buffer_path_(buffer),
|
||||
file_path_(file) {}
|
||||
Stats::Stats(std::string file, std::string buffer)
|
||||
: buffer_path_(std::move(buffer)),
|
||||
file_path_(std::move(file)) {}
|
||||
|
||||
// Destructor
|
||||
Stats::~Stats() {
|
||||
@@ -75,7 +76,7 @@ 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) {
|
||||
auto Stats::findByName(const std::string& name, const std::vector<StatsData>& list) -> int {
|
||||
int i = 0;
|
||||
|
||||
for (const auto& l : list) {
|
||||
@@ -89,7 +90,7 @@ 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) {
|
||||
auto Stats::loadFromFile(const std::string& file_path, std::vector<StatsData>& list) -> bool {
|
||||
list.clear();
|
||||
|
||||
// Indicador de éxito en la carga
|
||||
@@ -144,9 +145,9 @@ void Stats::saveToFile(const std::string& file_path, const std::vector<StatsData
|
||||
std::ofstream file(file_path);
|
||||
|
||||
// Escribe en el fichero
|
||||
file << "# ROOM NAME;VISITS;DEATHS" << std::endl;
|
||||
file << "# ROOM NAME;VISITS;DEATHS" << '\n';
|
||||
for (const auto& item : list) {
|
||||
file << item.name << ";" << item.visited << ";" << item.died << std::endl;
|
||||
file << item.name << ";" << item.visited << ";" << item.died << '\n';
|
||||
}
|
||||
|
||||
// Cierra el fichero
|
||||
|
||||
@@ -24,10 +24,10 @@ class Stats {
|
||||
std::string file_path_; // Fichero con las estadísticas completas
|
||||
|
||||
// Busca una entrada en la lista por nombre
|
||||
static int findByName(const std::string& name, const std::vector<StatsData>& list);
|
||||
static auto findByName(const std::string& name, const std::vector<StatsData>& list) -> int;
|
||||
|
||||
// Carga las estadisticas desde un fichero
|
||||
static bool loadFromFile(const std::string& file_path, std::vector<StatsData>& list);
|
||||
static auto loadFromFile(const std::string& file_path, std::vector<StatsData>& list) -> bool;
|
||||
|
||||
// Guarda las estadisticas en un fichero
|
||||
static void saveToFile(const std::string& file_path, const std::vector<StatsData>& list);
|
||||
@@ -39,9 +39,9 @@ class Stats {
|
||||
void updateListFromBuffer();
|
||||
|
||||
public:
|
||||
// Constructor
|
||||
Stats(const std::string& file, const std::string& buffer);
|
||||
|
||||
// Constructostd::string nst stdstd::string nst std::string& buffer);
|
||||
Stats(std::string file, std::string buffer);
|
||||
|
||||
// Destructor
|
||||
~Stats();
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <fstream> // Para basic_ostream, operator<<, basic_ofstream
|
||||
#include <functional> // Para function
|
||||
#include <iostream> // Para cout, cerr
|
||||
#include <ranges>
|
||||
#include <sstream> // Para basic_istringstream
|
||||
#include <string> // Para char_traits, string, operator<<, hash
|
||||
#include <unordered_map> // Para unordered_map, operator==, _Node_const_i...
|
||||
@@ -16,11 +17,11 @@
|
||||
|
||||
namespace Options {
|
||||
// Declaración de funciones internas
|
||||
bool setOptions(const std::string& var, const std::string& value);
|
||||
std::string trimLine(const std::string& line);
|
||||
bool isCommentOrEmpty(const std::string& line);
|
||||
bool processConfigLine(const std::string& line);
|
||||
bool readConfigFile(const std::string& file_path);
|
||||
auto setOptions(const std::string& var, const std::string& value) -> bool;
|
||||
auto trimLine(const std::string& line) -> std::string;
|
||||
auto isCommentOrEmpty(const std::string& line) -> bool;
|
||||
auto processConfigLine(const std::string& line) -> bool;
|
||||
auto readConfigFile(const std::string& file_path) -> bool;
|
||||
|
||||
// Crea e inicializa las opciones del programa
|
||||
void init() {
|
||||
@@ -32,19 +33,19 @@ void init() {
|
||||
}
|
||||
|
||||
// Elimina espacios en blanco al inicio y final de una línea
|
||||
std::string trimLine(const std::string& line) {
|
||||
auto start = std::find_if(line.begin(), line.end(), [](int ch) { return !std::isspace(ch); });
|
||||
auto end = std::find_if(line.rbegin(), line.rend(), [](int ch) { return !std::isspace(ch); }).base();
|
||||
return std::string(start, end);
|
||||
auto trimLine(const std::string& line) -> std::string {
|
||||
auto start = std::ranges::find_if(line, [](int ch) { return !std::isspace(ch); });
|
||||
auto end = std::ranges::find_if(std::ranges::reverse_view(line), [](int ch) { return !std::isspace(ch); }).base();
|
||||
return {start, end};
|
||||
}
|
||||
|
||||
// Verifica si una línea es comentario o está vacía
|
||||
bool isCommentOrEmpty(const std::string& line) {
|
||||
auto isCommentOrEmpty(const std::string& line) -> bool {
|
||||
return line.empty() || line[0] == '#';
|
||||
}
|
||||
|
||||
// Procesa una línea de configuración individual
|
||||
bool processConfigLine(const std::string& line) {
|
||||
auto processConfigLine(const std::string& line) -> bool {
|
||||
std::istringstream iss(line);
|
||||
std::string key;
|
||||
std::string value;
|
||||
@@ -53,7 +54,7 @@ bool processConfigLine(const std::string& line) {
|
||||
if (!setOptions(key, value)) {
|
||||
if (console) {
|
||||
std::cout << "Warning: file config.txt\n";
|
||||
std::cout << "unknown parameter " << key << std::endl;
|
||||
std::cout << "unknown parameter " << key << '\n';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -62,7 +63,7 @@ bool processConfigLine(const std::string& line) {
|
||||
}
|
||||
|
||||
// Lee y procesa el fichero de configuración
|
||||
bool readConfigFile(const std::string& file_path) {
|
||||
auto readConfigFile(const std::string& file_path) -> bool {
|
||||
std::ifstream file(file_path);
|
||||
if (!file.good()) {
|
||||
return false;
|
||||
@@ -95,7 +96,7 @@ bool readConfigFile(const std::string& file_path) {
|
||||
}
|
||||
|
||||
// Carga las opciones desde un fichero
|
||||
bool loadFromFile(const std::string& file_path) {
|
||||
auto loadFromFile(const std::string& file_path) -> bool {
|
||||
// Versión actual del fichero
|
||||
const std::string CONFIG_VERSION = version;
|
||||
version = "";
|
||||
@@ -122,7 +123,7 @@ bool loadFromFile(const std::string& file_path) {
|
||||
}
|
||||
|
||||
// Guarda las opciones en un fichero
|
||||
bool saveToFile(const std::string& file_path) {
|
||||
auto saveToFile(const std::string& file_path) -> bool {
|
||||
// Crea y abre el fichero de texto
|
||||
std::ofstream file(file_path);
|
||||
bool success = file.is_open(); // Verifica si el archivo se abrió correctamente
|
||||
@@ -130,13 +131,13 @@ bool saveToFile(const std::string& file_path) {
|
||||
if (!success) // Si no se pudo abrir el archivo, muestra un mensaje de error y devuelve false
|
||||
{
|
||||
if (console) {
|
||||
std::cerr << "Error: Unable to open file " << file_path << " for writing." << std::endl;
|
||||
std::cerr << "Error: Unable to open file " << file_path << " for writing." << '\n';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (console) {
|
||||
std::cout << file_path << " open for writing" << std::endl;
|
||||
std::cout << file_path << " open for writing" << '\n';
|
||||
}
|
||||
|
||||
// Escribe en el fichero
|
||||
@@ -179,7 +180,7 @@ bool saveToFile(const std::string& file_path) {
|
||||
return success;
|
||||
}
|
||||
|
||||
bool setOptions(const std::string& var, const std::string& value) {
|
||||
auto setOptions(const std::string& var, const std::string& value) -> bool {
|
||||
static const std::unordered_map<std::string, std::function<void(const std::string&)>> OPTION_HANDLERS = {
|
||||
{"version", [](const std::string& v) { version = v; }},
|
||||
{"keys", [](const std::string& v) {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <string> // Para string, basic_string
|
||||
#include <utility>
|
||||
|
||||
#include "core/rendering/screen.hpp" // Para ScreenFilter
|
||||
#include "utils/utils.hpp" // Para Color, Palette
|
||||
@@ -15,7 +16,7 @@ namespace Options {
|
||||
// VOLUME HELPERS - Conversión de volumen 0-100 a 0-128
|
||||
// =============================================================================
|
||||
namespace VolumeHelpers {
|
||||
constexpr int convertVolume(int volume_percent) {
|
||||
constexpr auto convertVolume(int volume_percent) -> int {
|
||||
return (volume_percent * 128) / 100;
|
||||
}
|
||||
} // namespace VolumeHelpers
|
||||
@@ -77,7 +78,7 @@ struct Cheat {
|
||||
alternate_skin(alt_skin) {}
|
||||
|
||||
// Método para comprobar si alguno de los tres primeros trucos está activo
|
||||
bool enabled() const {
|
||||
[[nodiscard]] auto enabled() const -> bool {
|
||||
return infinite_lives == State::ENABLED ||
|
||||
invincible == State::ENABLED ||
|
||||
jail_is_open == State::ENABLED;
|
||||
@@ -96,10 +97,10 @@ struct Stats {
|
||||
items(0) {}
|
||||
|
||||
// Constructor
|
||||
Stats(int room_count, int item_count, const std::string& worst_nightmare_room)
|
||||
Stats(int room_count, int item_count, std::string worst_nightmare_room)
|
||||
: rooms(room_count),
|
||||
items(item_count),
|
||||
worst_nightmare(worst_nightmare_room) {}
|
||||
worst_nightmare(std::move(worst_nightmare_room)) {}
|
||||
};
|
||||
|
||||
// Estructura con opciones de la ventana
|
||||
@@ -164,7 +165,7 @@ struct Video {
|
||||
palette(GameDefaults::PALETTE_NAME) {}
|
||||
|
||||
// Constructor
|
||||
Video(bool is_fullscreen, ScreenFilter screen_filter, bool vsync, bool use_shaders, bool int_scale, bool keep_aspect_ratio, Border video_border, const std::string& palette_name)
|
||||
Video(bool is_fullscreen, ScreenFilter screen_filter, bool vsync, bool use_shaders, bool int_scale, bool keep_aspect_ratio, Border video_border, std::string palette_name)
|
||||
: fullscreen(is_fullscreen),
|
||||
filter(screen_filter),
|
||||
vertical_sync(vsync),
|
||||
@@ -172,7 +173,7 @@ struct Video {
|
||||
integer_scale(int_scale),
|
||||
keep_aspect(keep_aspect_ratio),
|
||||
border(video_border),
|
||||
palette(palette_name) {}
|
||||
palette(std::move(palette_name)) {}
|
||||
};
|
||||
|
||||
// Estructura para las opciones de musica
|
||||
@@ -269,7 +270,7 @@ inline ControlScheme keys{GameDefaults::CONTROL_SCHEME}; // Teclas usadas para
|
||||
|
||||
// --- Funciones ---
|
||||
void init(); // Crea e inicializa las opciones del programa
|
||||
bool loadFromFile(const std::string& file_path); // Carga las opciones desde un fichero
|
||||
bool saveToFile(const std::string& file_path); // Guarda las opciones a un fichero
|
||||
auto loadFromFile(const std::string& file_path) -> bool; // Carga las opciones desde un fichero
|
||||
auto saveToFile(const std::string& file_path) -> bool; // Guarda las opciones a un fichero
|
||||
|
||||
} // namespace Options
|
||||
@@ -439,7 +439,7 @@ void Ending::fillCoverTexture() {
|
||||
cover_surface_->clear(static_cast<Uint8>(PaletteColor::TRANSPARENT));
|
||||
|
||||
// Los primeros 8 pixels crea una malla
|
||||
const Uint8 COLOR = static_cast<Uint8>(PaletteColor::BLACK);
|
||||
const auto COLOR = static_cast<Uint8>(PaletteColor::BLACK);
|
||||
auto surface = Screen::get()->getRendererSurface();
|
||||
for (int i = 0; i < 256; i += 2) {
|
||||
surface->putPixel(i + 0, Options::game.height + 0, COLOR);
|
||||
|
||||
@@ -106,7 +106,7 @@ void Ending2::render() {
|
||||
renderTexts();
|
||||
|
||||
// Dibuja una trama arriba y abajo
|
||||
Uint8 color = static_cast<Uint8>(PaletteColor::BLACK);
|
||||
auto color = static_cast<Uint8>(PaletteColor::BLACK);
|
||||
auto surface = Screen::get()->getRendererSurface();
|
||||
for (int i = 0; i < 256; i += 2) {
|
||||
surface->putPixel(i + 0, 0, color);
|
||||
@@ -196,75 +196,75 @@ void Ending2::iniSpriteList() {
|
||||
sprite_list_.clear();
|
||||
|
||||
// Añade los valores
|
||||
sprite_list_.push_back("bin");
|
||||
sprite_list_.push_back("floppy");
|
||||
sprite_list_.push_back("bird");
|
||||
sprite_list_.push_back("chip");
|
||||
sprite_list_.push_back("jeannine");
|
||||
sprite_list_.push_back("spark");
|
||||
sprite_list_.push_back("code");
|
||||
sprite_list_.push_back("paco");
|
||||
sprite_list_.push_back("elsa");
|
||||
sprite_list_.push_back("z80");
|
||||
sprite_list_.emplace_back("bin");
|
||||
sprite_list_.emplace_back("floppy");
|
||||
sprite_list_.emplace_back("bird");
|
||||
sprite_list_.emplace_back("chip");
|
||||
sprite_list_.emplace_back("jeannine");
|
||||
sprite_list_.emplace_back("spark");
|
||||
sprite_list_.emplace_back("code");
|
||||
sprite_list_.emplace_back("paco");
|
||||
sprite_list_.emplace_back("elsa");
|
||||
sprite_list_.emplace_back("z80");
|
||||
|
||||
sprite_list_.push_back("bell");
|
||||
sprite_list_.push_back("dong");
|
||||
sprite_list_.emplace_back("bell");
|
||||
sprite_list_.emplace_back("dong");
|
||||
|
||||
sprite_list_.push_back("amstrad_cs");
|
||||
sprite_list_.push_back("breakout");
|
||||
sprite_list_.emplace_back("amstrad_cs");
|
||||
sprite_list_.emplace_back("breakout");
|
||||
|
||||
sprite_list_.push_back("flying_arounder");
|
||||
sprite_list_.push_back("stopped_arounder");
|
||||
sprite_list_.push_back("walking_arounder");
|
||||
sprite_list_.push_back("arounders_door");
|
||||
sprite_list_.push_back("arounders_machine");
|
||||
sprite_list_.emplace_back("flying_arounder");
|
||||
sprite_list_.emplace_back("stopped_arounder");
|
||||
sprite_list_.emplace_back("walking_arounder");
|
||||
sprite_list_.emplace_back("arounders_door");
|
||||
sprite_list_.emplace_back("arounders_machine");
|
||||
|
||||
sprite_list_.push_back("abad");
|
||||
sprite_list_.push_back("abad_bell");
|
||||
sprite_list_.push_back("lord_abad");
|
||||
sprite_list_.emplace_back("abad");
|
||||
sprite_list_.emplace_back("abad_bell");
|
||||
sprite_list_.emplace_back("lord_abad");
|
||||
|
||||
sprite_list_.push_back("bat");
|
||||
sprite_list_.push_back("batman_bell");
|
||||
sprite_list_.push_back("batman_fire");
|
||||
sprite_list_.push_back("batman");
|
||||
sprite_list_.emplace_back("bat");
|
||||
sprite_list_.emplace_back("batman_bell");
|
||||
sprite_list_.emplace_back("batman_fire");
|
||||
sprite_list_.emplace_back("batman");
|
||||
|
||||
sprite_list_.push_back("demon");
|
||||
sprite_list_.push_back("heavy");
|
||||
sprite_list_.push_back("dimallas");
|
||||
sprite_list_.push_back("guitar");
|
||||
sprite_list_.emplace_back("demon");
|
||||
sprite_list_.emplace_back("heavy");
|
||||
sprite_list_.emplace_back("dimallas");
|
||||
sprite_list_.emplace_back("guitar");
|
||||
|
||||
sprite_list_.push_back("jailbattle_alien");
|
||||
sprite_list_.push_back("jailbattle_human");
|
||||
sprite_list_.emplace_back("jailbattle_alien");
|
||||
sprite_list_.emplace_back("jailbattle_human");
|
||||
|
||||
sprite_list_.push_back("jailer_#1");
|
||||
sprite_list_.push_back("jailer_#2");
|
||||
sprite_list_.push_back("jailer_#3");
|
||||
sprite_list_.push_back("bry");
|
||||
sprite_list_.push_back("upv_student");
|
||||
sprite_list_.emplace_back("jailer_#1");
|
||||
sprite_list_.emplace_back("jailer_#2");
|
||||
sprite_list_.emplace_back("jailer_#3");
|
||||
sprite_list_.emplace_back("bry");
|
||||
sprite_list_.emplace_back("upv_student");
|
||||
|
||||
sprite_list_.push_back("lamp");
|
||||
sprite_list_.push_back("robot");
|
||||
sprite_list_.push_back("congo");
|
||||
sprite_list_.push_back("crosshair");
|
||||
sprite_list_.push_back("tree_thing");
|
||||
sprite_list_.emplace_back("lamp");
|
||||
sprite_list_.emplace_back("robot");
|
||||
sprite_list_.emplace_back("congo");
|
||||
sprite_list_.emplace_back("crosshair");
|
||||
sprite_list_.emplace_back("tree_thing");
|
||||
|
||||
sprite_list_.push_back("matatunos");
|
||||
sprite_list_.push_back("tuno");
|
||||
sprite_list_.emplace_back("matatunos");
|
||||
sprite_list_.emplace_back("tuno");
|
||||
|
||||
sprite_list_.push_back("mummy");
|
||||
sprite_list_.push_back("sam");
|
||||
sprite_list_.emplace_back("mummy");
|
||||
sprite_list_.emplace_back("sam");
|
||||
|
||||
sprite_list_.push_back("qvoid");
|
||||
sprite_list_.push_back("sigmasua");
|
||||
sprite_list_.emplace_back("qvoid");
|
||||
sprite_list_.emplace_back("sigmasua");
|
||||
|
||||
sprite_list_.push_back("tv_panel");
|
||||
sprite_list_.push_back("tv");
|
||||
sprite_list_.emplace_back("tv_panel");
|
||||
sprite_list_.emplace_back("tv");
|
||||
|
||||
sprite_list_.push_back("spider");
|
||||
sprite_list_.push_back("shock");
|
||||
sprite_list_.push_back("wave");
|
||||
sprite_list_.emplace_back("spider");
|
||||
sprite_list_.emplace_back("shock");
|
||||
sprite_list_.emplace_back("wave");
|
||||
|
||||
sprite_list_.push_back("player");
|
||||
sprite_list_.emplace_back("player");
|
||||
}
|
||||
|
||||
// Carga todos los sprites desde una lista
|
||||
@@ -283,29 +283,29 @@ void Ending2::loadSprites() {
|
||||
|
||||
// Actualiza los sprites
|
||||
void Ending2::updateSprites() {
|
||||
for (auto sprite : sprites_) {
|
||||
for (const auto& sprite : sprites_) {
|
||||
sprite->update();
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza los sprites de texto
|
||||
void Ending2::updateTextSprites() {
|
||||
for (auto sprite : sprite_texts_) {
|
||||
for (const auto& sprite : sprite_texts_) {
|
||||
sprite->update();
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza los sprites de texto del final
|
||||
void Ending2::updateTexts() {
|
||||
for (auto sprite : texts_) {
|
||||
for (const auto& sprite : texts_) {
|
||||
sprite->update();
|
||||
}
|
||||
}
|
||||
|
||||
// Dibuja los sprites
|
||||
void Ending2::renderSprites() {
|
||||
const Uint8 COLOR_A = static_cast<Uint8>(PaletteColor::RED);
|
||||
for (auto sprite : sprites_) {
|
||||
const auto COLOR_A = static_cast<Uint8>(PaletteColor::RED);
|
||||
for (const 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) {
|
||||
@@ -314,14 +314,14 @@ void Ending2::renderSprites() {
|
||||
}
|
||||
|
||||
// Pinta el ultimo elemento de otro color
|
||||
const Uint8 COLOR_B = static_cast<Uint8>(PaletteColor::WHITE);
|
||||
const auto 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);
|
||||
for (auto sprite : sprite_texts_) {
|
||||
const auto COLOR = static_cast<Uint8>(PaletteColor::WHITE);
|
||||
for (const 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) {
|
||||
@@ -332,7 +332,7 @@ void Ending2::renderSpriteTexts() {
|
||||
|
||||
// Dibuja los sprites con el texto del final
|
||||
void Ending2::renderTexts() {
|
||||
for (auto sprite : texts_) {
|
||||
for (const auto& sprite : texts_) {
|
||||
const bool A = sprite->getRect().y + sprite->getRect().h > 0;
|
||||
const bool B = sprite->getRect().y < Options::game.height;
|
||||
if (A && B) {
|
||||
@@ -370,7 +370,7 @@ void Ending2::createSpriteTexts() {
|
||||
|
||||
// Procesa y ajusta el texto del sprite actual
|
||||
std::string txt = sprite_list_[i];
|
||||
std::replace(txt.begin(), txt.end(), '_', ' '); // Reemplaza '_' por ' '
|
||||
std::ranges::replace(txt, '_', ' '); // Reemplaza '_' por ' '
|
||||
if (txt == "player") {
|
||||
txt = "JAILDOCTOR"; // Reemplaza "player" por "JAILDOCTOR"
|
||||
}
|
||||
@@ -405,7 +405,7 @@ void Ending2::createSpriteTexts() {
|
||||
void Ending2::createTexts() {
|
||||
// Crea los primeros textos
|
||||
std::vector<std::string> list;
|
||||
list.push_back("STARRING");
|
||||
list.emplace_back("STARRING");
|
||||
|
||||
auto text = Resource::get()->getText("smb2");
|
||||
|
||||
@@ -435,8 +435,8 @@ void Ending2::createTexts() {
|
||||
// El primer texto va a continuación del ultimo spriteText
|
||||
const int START = sprite_texts_.back()->getPosY() + (text->getCharacterSize() * 15);
|
||||
list.clear();
|
||||
list.push_back("THANK YOU");
|
||||
list.push_back("FOR PLAYING!");
|
||||
list.emplace_back("THANK YOU");
|
||||
list.emplace_back("FOR PLAYING!");
|
||||
|
||||
// Crea los sprites de texto a partir de la lista
|
||||
for (size_t i = 0; i < list.size(); ++i) {
|
||||
@@ -463,7 +463,7 @@ void Ending2::createTexts() {
|
||||
|
||||
// Actualiza el fade final
|
||||
void Ending2::updateFinalFade() {
|
||||
for (auto sprite : texts_) {
|
||||
for (const auto& sprite : texts_) {
|
||||
sprite->getSurface()->fadeSubPalette(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ class Ending2 {
|
||||
duration(state_duration) {}
|
||||
|
||||
// Método para comprobar si el estado ha terminado y verifica el nombre del estado
|
||||
bool hasEnded(EndingState expected_state) const {
|
||||
[[nodiscard]] auto hasEnded(EndingState expected_state) const -> bool {
|
||||
// Comprobar si el estado actual coincide con el estado esperado
|
||||
if (state != expected_state) {
|
||||
return false; // Si no coincide, considerar que no ha terminado
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <utility>
|
||||
#include <vector> // Para vector
|
||||
|
||||
#include "core/input/global_inputs.hpp" // Para check
|
||||
@@ -263,7 +264,7 @@ void Game::renderRoomName() {
|
||||
}
|
||||
|
||||
// Cambia de habitación
|
||||
bool Game::changeRoom(const std::string& room_path) {
|
||||
auto Game::changeRoom(const std::string& room_path) -> bool {
|
||||
// En las habitaciones los limites tienen la cadena del fichero o un 0 en caso de no limitar con nada
|
||||
if (room_path == "0") {
|
||||
return false;
|
||||
@@ -313,7 +314,7 @@ void Game::checkPlayerIsOnBorder() {
|
||||
}
|
||||
|
||||
// Comprueba las colisiones del jugador con los enemigos
|
||||
bool Game::checkPlayerAndEnemies() {
|
||||
auto Game::checkPlayerAndEnemies() -> bool {
|
||||
const bool DEATH = room_->enemyCollision(player_->getCollider());
|
||||
if (DEATH) {
|
||||
killPlayer();
|
||||
@@ -415,7 +416,7 @@ void Game::setScoreBoardColor() {
|
||||
}
|
||||
|
||||
// Comprueba si ha finalizado el juego
|
||||
bool Game::checkEndGame() {
|
||||
auto Game::checkEndGame() -> bool {
|
||||
const bool IS_ON_THE_ROOM = room_->getName() == "THE JAIL"; // Estar en la habitación que toca
|
||||
const bool HAVE_THE_ITEMS = board_->items >= int(total_items_ * 0.9F) || Options::cheats.jail_is_open == Options::Cheat::State::ENABLED; // Con mas del 90% de los items recogidos
|
||||
const bool IS_ON_THE_DOOR = player_->getRect().x <= 128; // Y en la ubicación que toca (En la puerta)
|
||||
@@ -436,7 +437,7 @@ bool Game::checkEndGame() {
|
||||
}
|
||||
|
||||
// Obtiene la cantidad total de items que hay en el mapeado del juego
|
||||
int Game::getTotalItems() {
|
||||
auto Game::getTotalItems() -> int {
|
||||
int items = 0;
|
||||
auto rooms = Resource::get()->getRooms();
|
||||
|
||||
@@ -572,7 +573,7 @@ void Game::checkEndGameCheevos() {
|
||||
void Game::initPlayer(const PlayerSpawn& spawn_point, std::shared_ptr<Room> room) {
|
||||
std::string player_texture = Options::cheats.alternate_skin == Options::Cheat::State::ENABLED ? "player2.gif" : "player.gif";
|
||||
std::string player_animations = Options::cheats.alternate_skin == Options::Cheat::State::ENABLED ? "player2.ani" : "player.ani";
|
||||
const PlayerData PLAYER(spawn_point, player_texture, player_animations, room);
|
||||
const PlayerData PLAYER(spawn_point, player_texture, player_animations, std::move(room));
|
||||
player_ = std::make_shared<Player>(PLAYER);
|
||||
}
|
||||
|
||||
@@ -582,7 +583,7 @@ void Game::createRoomNameTexture() {
|
||||
room_name_surface_ = std::make_shared<Surface>(Options::game.width, text->getCharacterSize() * 2);
|
||||
|
||||
// Establece el destino de la textura
|
||||
room_name_rect_ = {0.0F, PLAY_AREA_HEIGHT, Options::game.width, text->getCharacterSize() * 2.0F};
|
||||
room_name_rect_ = {.x = 0.0F, .y = PLAY_AREA_HEIGHT, .w = Options::game.width, .h = text->getCharacterSize() * 2.0F};
|
||||
}
|
||||
|
||||
// Hace sonar la música
|
||||
|
||||
@@ -89,7 +89,7 @@ class Game {
|
||||
void renderRoomName();
|
||||
|
||||
// Cambia de habitación
|
||||
bool changeRoom(const std::string& room_path);
|
||||
auto changeRoom(const std::string& room_path) -> bool;
|
||||
|
||||
// Comprueba el teclado
|
||||
void checkInput();
|
||||
@@ -98,7 +98,7 @@ class Game {
|
||||
void checkPlayerIsOnBorder();
|
||||
|
||||
// Comprueba las colisiones del jugador con los enemigos
|
||||
bool checkPlayerAndEnemies();
|
||||
auto checkPlayerAndEnemies() -> bool;
|
||||
|
||||
// Comprueba las colisiones del jugador con los objetos
|
||||
void checkPlayerAndItems();
|
||||
@@ -125,10 +125,10 @@ class Game {
|
||||
void setScoreBoardColor();
|
||||
|
||||
// Comprueba si ha finalizado el juego
|
||||
bool checkEndGame();
|
||||
auto checkEndGame() -> bool;
|
||||
|
||||
// Obtiene la cantidad total de items que hay en el mapeado del juego
|
||||
static int getTotalItems();
|
||||
static auto getTotalItems() -> int;
|
||||
|
||||
// Pone el juego en pausa
|
||||
void togglePause();
|
||||
|
||||
@@ -20,10 +20,7 @@
|
||||
// Constructor
|
||||
GameOver::GameOver()
|
||||
: player_sprite_(std::make_shared<SurfaceAnimatedSprite>(Resource::get()->getSurface("player_game_over.gif"), Resource::get()->getAnimations("player_game_over.ani"))),
|
||||
tv_sprite_(std::make_shared<SurfaceAnimatedSprite>(Resource::get()->getSurface("tv.gif"), Resource::get()->getAnimations("tv.ani"))),
|
||||
pre_counter_(0),
|
||||
counter_(0),
|
||||
ticks_(0) {
|
||||
tv_sprite_(std::make_shared<SurfaceAnimatedSprite>(Resource::get()->getSurface("tv.gif"), Resource::get()->getAnimations("tv.ani"))) {
|
||||
SceneManager::current = SceneManager::Scene::GAME_OVER;
|
||||
SceneManager::options = SceneManager::Options::NONE;
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#include "game/scenes/loading_screen.hpp"
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <stdlib.h> // Para rand
|
||||
|
||||
#include <cstdlib> // Para rand
|
||||
|
||||
#include "core/audio/audio.hpp" // Para Audio
|
||||
#include "core/input/global_inputs.hpp" // Para check
|
||||
@@ -9,10 +10,10 @@
|
||||
#include "core/rendering/surface.hpp" // Para Surface
|
||||
#include "core/rendering/surface_sprite.hpp" // Para SSprite
|
||||
#include "core/resources/resource.hpp" // Para Resource
|
||||
#include "core/system/global_events.hpp" // Para check
|
||||
#include "game/options.hpp" // Para Options, options, SectionState, Options...
|
||||
#include "game/scene_manager.hpp" // Para SceneManager
|
||||
#include "utils/defines.hpp" // Para GAME_SPEED
|
||||
#include "core/system/global_events.hpp" // Para check
|
||||
#include "utils/utils.hpp" // Para stringToColor, PaletteColor
|
||||
|
||||
// Constructor
|
||||
@@ -252,7 +253,7 @@ void LoadingScreen::renderYellowBorder() {
|
||||
border->clear(static_cast<Uint8>(PaletteColor::BLUE));
|
||||
|
||||
// Añade lineas amarillas
|
||||
const Uint8 COLOR = static_cast<Uint8>(PaletteColor::YELLOW);
|
||||
const auto COLOR = static_cast<Uint8>(PaletteColor::YELLOW);
|
||||
const int WIDTH = Options::game.width + (Options::video.border.width * 2);
|
||||
const int HEIGHT = Options::game.height + (Options::video.border.height * 2);
|
||||
bool draw_enabled = rand() % 2 == 0;
|
||||
@@ -279,7 +280,7 @@ void LoadingScreen::renderRedBorder() {
|
||||
border->clear(static_cast<Uint8>(PaletteColor::CYAN));
|
||||
|
||||
// Añade lineas rojas
|
||||
const Uint8 COLOR = static_cast<Uint8>(PaletteColor::RED);
|
||||
const auto COLOR = static_cast<Uint8>(PaletteColor::RED);
|
||||
const int WIDTH = Options::game.width + (Options::video.border.width * 2);
|
||||
const int HEIGHT = Options::game.height + (Options::video.border.height * 2);
|
||||
bool draw_enabled = true;
|
||||
|
||||
@@ -83,7 +83,7 @@ void Logo::updateJAILGAMES(float delta_time) {
|
||||
}
|
||||
|
||||
// Calcula el índice de color según el progreso (0.0-1.0)
|
||||
int Logo::getColorIndex(float progress) const {
|
||||
auto Logo::getColorIndex(float progress) const -> int {
|
||||
// Asegurar que progress esté en el rango [0.0, 1.0]
|
||||
progress = std::clamp(progress, 0.0F, 1.0F);
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ class Logo {
|
||||
void updateTextureColors(); // Gestiona el color de las texturas
|
||||
void updateState(float delta_time); // Actualiza el estado actual
|
||||
void transitionToState(LogoState new_state); // Transiciona a un nuevo estado
|
||||
int getColorIndex(float progress) const; // Calcula el índice de color según el progreso (0.0-1.0)
|
||||
[[nodiscard]] auto getColorIndex(float progress) const -> int; // Calcula el índice de color según el progreso (0.0-1.0)
|
||||
static void endSection(); // Termina la sección
|
||||
void initColors(); // Inicializa el vector de colores
|
||||
void initSprites(); // Crea los sprites de cada linea
|
||||
|
||||
@@ -328,7 +328,7 @@ void Title::createCheevosTexture() {
|
||||
Screen::get()->setRendererSurface(cheevos_surface_);
|
||||
|
||||
// Rellena la textura con color sólido
|
||||
const Uint8 CHEEVOS_BG_COLOR = static_cast<Uint8>(PaletteColor::BLACK);
|
||||
const auto CHEEVOS_BG_COLOR = static_cast<Uint8>(PaletteColor::BLACK);
|
||||
cheevos_surface_->clear(CHEEVOS_BG_COLOR);
|
||||
|
||||
// Escribe la lista de logros en la textura
|
||||
@@ -358,7 +358,7 @@ void Title::createCheevosTexture() {
|
||||
|
||||
// Crea el sprite para el listado de logros
|
||||
cheevos_sprite_ = std::make_shared<SurfaceSprite>(cheevos_surface_, (GAMECANVAS_WIDTH - cheevos_surface_->getWidth()) / 2, CHEEVOS_TEXTURE_POS_Y, cheevos_surface_->getWidth(), cheevos_surface_->getHeight());
|
||||
cheevos_surface_view_ = {0, 0, cheevos_surface_->getWidth(), CHEEVOS_TEXTURE_VIEW_HEIGHT};
|
||||
cheevos_surface_view_ = {.x = 0, .y = 0, .w = cheevos_surface_->getWidth(), .h = CHEEVOS_TEXTURE_VIEW_HEIGHT};
|
||||
cheevos_sprite_->setClip(cheevos_surface_view_);
|
||||
}
|
||||
|
||||
|
||||
@@ -55,41 +55,41 @@ void Notifier::update() {
|
||||
// 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) {
|
||||
if (previous_notification.state == Status::RISING) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch (notification.state) {
|
||||
case NotificationStatus::RISING: {
|
||||
case Status::RISING: {
|
||||
const int DIRECTION = 1;
|
||||
notification.rect.y += DIRECTION;
|
||||
|
||||
if (notification.rect.y == notification.y) {
|
||||
notification.state = NotificationStatus::STAY;
|
||||
notification.state = Status::STAY;
|
||||
notification.start_time = SDL_GetTicks();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NotificationStatus::STAY: {
|
||||
case Status::STAY: {
|
||||
notification.elapsed_time = SDL_GetTicks() - notification.start_time;
|
||||
if (notification.elapsed_time >= notification.display_duration) {
|
||||
notification.state = NotificationStatus::VANISHING;
|
||||
notification.state = Status::VANISHING;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case NotificationStatus::VANISHING: {
|
||||
case Status::VANISHING: {
|
||||
const int DIRECTION = -1;
|
||||
notification.rect.y += DIRECTION;
|
||||
|
||||
if (notification.rect.y == notification.y - notification.travel_dist) {
|
||||
notification.state = NotificationStatus::FINISHED;
|
||||
notification.state = Status::FINISHED;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case NotificationStatus::FINISHED:
|
||||
case Status::FINISHED:
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -106,7 +106,7 @@ void Notifier::update() {
|
||||
void Notifier::clearFinishedNotifications() {
|
||||
notifications_.erase(
|
||||
std::remove_if(notifications_.begin(), notifications_.end(), [](const Notification& notification) {
|
||||
return notification.state == NotificationStatus::FINISHED;
|
||||
return notification.state == Status::FINISHED;
|
||||
}),
|
||||
notifications_.end());
|
||||
}
|
||||
@@ -142,7 +142,7 @@ void Notifier::show(std::vector<std::string> texts, NotificationText text_is, Ui
|
||||
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 auto SHAPE = NotificationShape::SQUARED;
|
||||
const auto SHAPE = Shape::SQUARED;
|
||||
|
||||
// Posición horizontal
|
||||
float desp_h = ((Options::game.width / 2) - (WIDTH / 2));
|
||||
@@ -179,7 +179,7 @@ void Notifier::show(std::vector<std::string> texts, NotificationText text_is, Ui
|
||||
|
||||
// Dibuja el fondo de la notificación
|
||||
SDL_FRect rect;
|
||||
if (SHAPE == NotificationShape::ROUNDED) {
|
||||
if (SHAPE == Shape::ROUNDED) {
|
||||
rect = {4, 0, WIDTH - (4 * 2), HEIGHT};
|
||||
n.surface->fillRect(&rect, bg_color_);
|
||||
|
||||
@@ -193,7 +193,7 @@ void Notifier::show(std::vector<std::string> texts, NotificationText text_is, Ui
|
||||
n.surface->fillRect(&rect, bg_color_);
|
||||
}
|
||||
|
||||
else if (SHAPE == NotificationShape::SQUARED) {
|
||||
else if (SHAPE == Shape::SQUARED) {
|
||||
n.surface->clear(bg_color_);
|
||||
SDL_FRect squared_rect = {0, 0, n.surface->getWidth(), n.surface->getHeight()};
|
||||
n.surface->drawRectBorder(&squared_rect, static_cast<Uint8>(PaletteColor::CYAN));
|
||||
@@ -245,7 +245,7 @@ bool Notifier::isActive() { return !notifications_.empty(); }
|
||||
void Notifier::clearNotifications() {
|
||||
for (auto& notification : notifications_) {
|
||||
if (notification.can_be_removed) {
|
||||
notification.state = NotificationStatus::FINISHED;
|
||||
notification.state = Status::FINISHED;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,50 +28,36 @@ class Notifier {
|
||||
// [SINGLETON] Objeto notifier
|
||||
static Notifier* notifier;
|
||||
|
||||
enum class NotificationStatus {
|
||||
enum class Status {
|
||||
RISING,
|
||||
STAY,
|
||||
VANISHING,
|
||||
FINISHED,
|
||||
};
|
||||
|
||||
enum class NotificationShape {
|
||||
enum class Shape {
|
||||
ROUNDED,
|
||||
SQUARED,
|
||||
};
|
||||
|
||||
struct Notification {
|
||||
std::shared_ptr<Surface> surface; // Superficie asociada a la notificación
|
||||
std::shared_ptr<SurfaceSprite> sprite; // Sprite asociado para gráficos o animaciones
|
||||
std::vector<std::string> texts; // Lista de textos incluidos en la notificación
|
||||
NotificationStatus state; // Estado actual de la notificación (RISING, SHOWING, etc.)
|
||||
NotificationShape shape; // Forma de la notificación (ej. SQUARED o ROUNDED)
|
||||
SDL_FRect rect; // Dimensiones y posición de la notificación en pantalla
|
||||
int y; // Posición actual en el eje Y
|
||||
int travel_dist; // Distancia a recorrer (por ejemplo, en animaciones)
|
||||
std::string code; // Código identificador único para esta notificación
|
||||
bool can_be_removed; // Indica si la notificación puede ser eliminada
|
||||
int height; // Altura de la notificación
|
||||
Uint32 start_time; // Momento en que se creó la notificación
|
||||
Uint32 elapsed_time; // Tiempo transcurrido desde la creación
|
||||
Uint32 display_duration; // Duración total para mostrar la notificación
|
||||
std::shared_ptr<Surface> surface{nullptr}; // Superficie asociada a la notificación
|
||||
std::shared_ptr<SurfaceSprite> sprite{nullptr}; // Sprite asociado para gráficos o animaciones
|
||||
std::vector<std::string> texts; // Lista de textos incluidos en la notificación
|
||||
Status state{Status::RISING}; // Estado actual de la notificación (RISING, SHOWING, etc.)
|
||||
Shape shape{Shape::SQUARED}; // Forma de la notificación (ej. SQUARED o ROUNDED)
|
||||
SDL_FRect rect{0, 0, 0, 0}; // Dimensiones y posición de la notificación en pantalla
|
||||
int y{0}; // Posición actual en el eje Y
|
||||
int travel_dist{0}; // Distancia a recorrer (por ejemplo, en animaciones)
|
||||
std::string code; // Código identificador único para esta notificación
|
||||
bool can_be_removed{true}; // Indica si la notificación puede ser eliminada
|
||||
int height{0}; // Altura de la notificación
|
||||
Uint32 start_time{0}; // Momento en que se creó la notificación
|
||||
Uint32 elapsed_time{0}; // Tiempo transcurrido desde la creación
|
||||
Uint32 display_duration{0}; // Duración total para mostrar la notificación
|
||||
|
||||
// Constructor
|
||||
explicit Notification()
|
||||
: surface(nullptr), // Inicializar superficie como nula
|
||||
sprite(nullptr), // Inicializar lista de textos vacía
|
||||
state(NotificationStatus::RISING), // Estado inicial como "RISING"
|
||||
shape(NotificationShape::SQUARED), // Forma inicial como "SQUARED"
|
||||
rect{0, 0, 0, 0}, // Rectángulo inicial vacío
|
||||
y(0), // Posición Y inicializada a 0
|
||||
travel_dist(0), // Código identificador vacío
|
||||
can_be_removed(true), // Inicialmente se puede eliminar
|
||||
height(0), // Altura inicializada a 0
|
||||
start_time(0), // Tiempo de creación inicializado a 0
|
||||
elapsed_time(0), // Tiempo transcurrido inicializado a 0
|
||||
display_duration(0) // Duración inicializada a 0
|
||||
{
|
||||
}
|
||||
explicit Notification() = default;
|
||||
};
|
||||
|
||||
std::shared_ptr<Surface> icon_surface_; // Textura para los iconos de las notificaciones
|
||||
|
||||
Reference in New Issue
Block a user