linter
This commit is contained in:
@@ -55,14 +55,14 @@ void Player::update(float delta_time) {
|
||||
// Comprueba las entradas y modifica variables
|
||||
void Player::handleInput() {
|
||||
if (Input::get()->checkAction(InputAction::LEFT)) {
|
||||
wannaGo = Direction::LEFT;
|
||||
wanna_go_ = Direction::LEFT;
|
||||
} else if (Input::get()->checkAction(InputAction::RIGHT)) {
|
||||
wannaGo = Direction::RIGHT;
|
||||
wanna_go_ = Direction::RIGHT;
|
||||
} else {
|
||||
wannaGo = Direction::NONE;
|
||||
wanna_go_ = Direction::NONE;
|
||||
}
|
||||
|
||||
wannaJump = Input::get()->checkAction(InputAction::JUMP);
|
||||
wanna_jump_ = Input::get()->checkAction(InputAction::JUMP);
|
||||
}
|
||||
|
||||
// La lógica de movimiento está distribuida en move
|
||||
@@ -89,7 +89,7 @@ void Player::move(float delta_time) {
|
||||
}
|
||||
|
||||
void Player::handleConveyorBelts() {
|
||||
if (!auto_movement_ and isOnConveyorBelt() and wannaGo == Direction::NONE) {
|
||||
if (!auto_movement_ and isOnConveyorBelt() and wanna_go_ == Direction::NONE) {
|
||||
auto_movement_ = true;
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ void Player::updateOnGround(float delta_time) {
|
||||
handleShouldFall(); // Verifica si debe caer (no tiene suelo)
|
||||
|
||||
// Verifica si el jugador quiere saltar
|
||||
if (wannaJump) { transitionToState(State::JUMPING); }
|
||||
if (wanna_jump_) { transitionToState(State::JUMPING); }
|
||||
}
|
||||
|
||||
// Actualización lógica del estado ON_SLOPE
|
||||
@@ -182,7 +182,7 @@ void Player::updateOnSlope(float delta_time) {
|
||||
// todas las condiciones de salida de la rampa (out of bounds, transición a superficie plana)
|
||||
|
||||
// Verifica si el jugador quiere saltar
|
||||
if (wannaJump) { transitionToState(State::JUMPING); }
|
||||
if (wanna_jump_) { transitionToState(State::JUMPING); }
|
||||
}
|
||||
|
||||
// Actualización lógica del estado JUMPING
|
||||
@@ -200,7 +200,7 @@ void Player::updateFalling(float delta_time) {
|
||||
|
||||
// Movimiento físico del estado ON_GROUND
|
||||
void Player::moveOnGround(float delta_time) {
|
||||
// Determinama cuál debe ser la velocidad a partir de automovement o de wannaGo
|
||||
// Determinama cuál debe ser la velocidad a partir de automovement o de wanna_go_
|
||||
updateVelocity();
|
||||
|
||||
if (vx_ == 0.0F) { return; }
|
||||
@@ -229,7 +229,7 @@ void Player::moveOnGround(float delta_time) {
|
||||
|
||||
// Movimiento físico del estado ON_SLOPE
|
||||
void Player::moveOnSlope(float delta_time) {
|
||||
// Determinama cuál debe ser la velocidad a partir de automovement o de wannaGo
|
||||
// Determinama cuál debe ser la velocidad a partir de automovement o de wanna_go_
|
||||
updateVelocity();
|
||||
|
||||
if (vx_ == 0.0F) { return; }
|
||||
@@ -636,35 +636,35 @@ void Player::initSounds() {
|
||||
|
||||
// Implementación de JumpSoundController::start
|
||||
void Player::JumpSoundController::start() {
|
||||
current_index_ = 0;
|
||||
elapsed_time_ = 0.0F;
|
||||
active_ = true;
|
||||
current_index = 0;
|
||||
elapsed_time = 0.0F;
|
||||
active = true;
|
||||
}
|
||||
|
||||
// Implementación de JumpSoundController::reset
|
||||
void Player::JumpSoundController::reset() {
|
||||
active_ = false;
|
||||
current_index_ = 0;
|
||||
elapsed_time_ = 0.0F;
|
||||
active = false;
|
||||
current_index = 0;
|
||||
elapsed_time = 0.0F;
|
||||
}
|
||||
|
||||
// Implementación de JumpSoundController::shouldPlay
|
||||
auto Player::JumpSoundController::shouldPlay(float delta_time, size_t& out_index) -> bool {
|
||||
if (!active_) {
|
||||
if (!active) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Acumula el tiempo transcurrido durante el salto
|
||||
elapsed_time_ += delta_time;
|
||||
elapsed_time += delta_time;
|
||||
|
||||
// Calcula qué sonido debería estar sonando según el tiempo
|
||||
size_t target_index = FIRST_SOUND + static_cast<size_t>(elapsed_time_ / SECONDS_PER_SOUND);
|
||||
size_t target_index = FIRST_SOUND + static_cast<size_t>(elapsed_time / SECONDS_PER_SOUND);
|
||||
target_index = std::min(target_index, LAST_SOUND);
|
||||
|
||||
// Reproduce si hemos avanzado a un nuevo sonido
|
||||
if (target_index > current_index_) {
|
||||
current_index_ = target_index;
|
||||
out_index = current_index_;
|
||||
if (target_index > current_index) {
|
||||
current_index = target_index;
|
||||
out_index = current_index;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -673,42 +673,42 @@ auto Player::JumpSoundController::shouldPlay(float delta_time, size_t& out_index
|
||||
|
||||
// Implementación de FallSoundController::start
|
||||
void Player::FallSoundController::start(float start_y) {
|
||||
current_index_ = 0;
|
||||
distance_traveled_ = 0.0F;
|
||||
last_y_ = start_y;
|
||||
active_ = true;
|
||||
current_index = 0;
|
||||
distance_traveled = 0.0F;
|
||||
last_y = start_y;
|
||||
active = true;
|
||||
}
|
||||
|
||||
// Implementación de FallSoundController::reset
|
||||
void Player::FallSoundController::reset() {
|
||||
active_ = false;
|
||||
current_index_ = 0;
|
||||
distance_traveled_ = 0.0F;
|
||||
active = false;
|
||||
current_index = 0;
|
||||
distance_traveled = 0.0F;
|
||||
}
|
||||
|
||||
// Implementación de FallSoundController::shouldPlay
|
||||
auto Player::FallSoundController::shouldPlay(float delta_time, float current_y, size_t& out_index) -> bool {
|
||||
(void)delta_time; // No usado actualmente, pero recibido por consistencia
|
||||
|
||||
if (!active_) {
|
||||
if (!active) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Acumula la distancia recorrida (solo hacia abajo)
|
||||
if (current_y > last_y_) {
|
||||
distance_traveled_ += (current_y - last_y_);
|
||||
if (current_y > last_y) {
|
||||
distance_traveled += (current_y - last_y);
|
||||
}
|
||||
last_y_ = current_y;
|
||||
last_y = current_y;
|
||||
|
||||
// Calcula qué sonido debería estar sonando según el intervalo
|
||||
size_t target_index = FIRST_SOUND + static_cast<size_t>(distance_traveled_ / PIXELS_PER_SOUND);
|
||||
size_t target_index = FIRST_SOUND + static_cast<size_t>(distance_traveled / PIXELS_PER_SOUND);
|
||||
|
||||
// El sonido a reproducir se limita a LAST_SOUND (13), pero el índice interno sigue creciendo
|
||||
size_t sound_to_play = std::min(target_index, LAST_SOUND);
|
||||
|
||||
// Reproduce si hemos avanzado a un nuevo índice (permite repetición de sonido 13)
|
||||
if (target_index > current_index_) {
|
||||
current_index_ = target_index; // Guardamos el índice real (puede ser > LAST_SOUND)
|
||||
if (target_index > current_index) {
|
||||
current_index = target_index; // Guardamos el índice real (puede ser > LAST_SOUND)
|
||||
out_index = sound_to_play; // Pero reproducimos LAST_SOUND cuando corresponde
|
||||
return true;
|
||||
}
|
||||
@@ -768,7 +768,7 @@ void Player::updateVelocity() {
|
||||
sprite_->setFlip(vx_ < 0.0F ? Flip::LEFT : Flip::RIGHT);
|
||||
} else {
|
||||
// El jugador tiene el control
|
||||
switch (wannaGo) {
|
||||
switch (wanna_go_) {
|
||||
case Direction::LEFT:
|
||||
vx_ = -HORIZONTAL_VELOCITY;
|
||||
sprite_->setFlip(Flip::LEFT);
|
||||
|
||||
@@ -61,13 +61,13 @@ class Player {
|
||||
static constexpr size_t LAST_SOUND = 17; // Último sonido a reproducir (índice 17)
|
||||
static constexpr float SECONDS_PER_SOUND = JUMP_DURATION / (LAST_SOUND - FIRST_SOUND + 1);
|
||||
|
||||
size_t current_index_ = 0; // Índice del sonido actual
|
||||
float elapsed_time_ = 0.0F; // Tiempo transcurrido durante el salto
|
||||
bool active_ = false; // Indica si el controlador está activo
|
||||
size_t current_index = 0; // Índice del sonido actual
|
||||
float elapsed_time = 0.0F; // Tiempo transcurrido durante el salto
|
||||
bool active = false; // Indica si el controlador está activo
|
||||
|
||||
void start(); // Inicia el controlador
|
||||
void reset(); // Resetea el controlador
|
||||
bool shouldPlay(float delta_time, size_t& out_index); // Comprueba si debe reproducir un sonido
|
||||
auto shouldPlay(float delta_time, size_t& out_index) -> bool; // Comprueba si debe reproducir un sonido
|
||||
};
|
||||
|
||||
struct FallSoundController {
|
||||
@@ -75,14 +75,14 @@ class Player {
|
||||
static constexpr size_t FIRST_SOUND = 1; // Primer sonido a reproducir (índice 1)
|
||||
static constexpr size_t LAST_SOUND = 13; // Último sonido a reproducir (índice 13)
|
||||
|
||||
size_t current_index_ = 0; // Índice del sonido actual
|
||||
float distance_traveled_ = 0.0F; // Distancia acumulada durante la caída
|
||||
float last_y_ = 0.0F; // Última posición Y registrada
|
||||
bool active_ = false; // Indica si el controlador está activo
|
||||
size_t current_index = 0; // Índice del sonido actual
|
||||
float distance_traveled = 0.0F; // Distancia acumulada durante la caída
|
||||
float last_y = 0.0F; // Última posición Y registrada
|
||||
bool active = false; // Indica si el controlador está activo
|
||||
|
||||
void start(float start_y); // Inicia el controlador
|
||||
void reset(); // Resetea el controlador
|
||||
bool shouldPlay(float delta_time, float current_y, size_t& out_index); // Comprueba si debe reproducir un sonido
|
||||
auto shouldPlay(float delta_time, float current_y, size_t& out_index) -> bool; // Comprueba si debe reproducir un sonido
|
||||
};
|
||||
|
||||
// --- Constructor y Destructor ---
|
||||
@@ -97,7 +97,7 @@ class Player {
|
||||
void switchBorders(); // Cambia al jugador de un borde al opuesto. Util para el cambio de pantalla
|
||||
auto getRect() -> SDL_FRect { return {x_, y_, WIDTH, HEIGHT}; } // Obtiene el rectangulo que delimita al jugador
|
||||
auto getCollider() -> SDL_FRect& { return collider_box_; } // Obtiene el rectangulo de colision del jugador
|
||||
auto getSpawnParams() -> SpawnData { return {x_, y_, vx_, vy_, last_grounded_position_, state_, sprite_->getFlip()}; } // Obtiene el estado de reaparición del jugador
|
||||
auto getSpawnParams() -> SpawnData { return {.x = x_, .y = y_, .vx = vx_, .vy = vy_, .last_grounded_position = last_grounded_position_, .state = state_, .flip = sprite_->getFlip()}; } // Obtiene el estado de reaparición del jugador
|
||||
void setColor(); // Establece el color del jugador
|
||||
void setRoom(std::shared_ptr<Room> room) { room_ = std::move(room); } // Establece la habitación en la que se encuentra el jugador
|
||||
[[nodiscard]] auto isAlive() const -> bool { return is_alive_; } // Comprueba si el jugador esta vivo
|
||||
@@ -120,8 +120,8 @@ class Player {
|
||||
float vx_ = 0.0F; // Velocidad/desplazamiento del jugador en el eje X
|
||||
float vy_ = 0.0F; // Velocidad/desplazamiento del jugador en el eje Y
|
||||
|
||||
Direction wannaGo = Direction::NONE;
|
||||
bool wannaJump = false;
|
||||
Direction wanna_go_ = Direction::NONE;
|
||||
bool wanna_jump_ = false;
|
||||
|
||||
// --- Variables de estado ---
|
||||
State state_ = State::ON_GROUND; // Estado en el que se encuentra el jugador. Util apara saber si está saltando o cayendo
|
||||
|
||||
@@ -9,8 +9,8 @@ class Cheevos {
|
||||
// Tipos anidados (públicos porque se usan en la interfaz)
|
||||
struct Achievement {
|
||||
int id{0}; // Identificador del logro
|
||||
std::string caption{}; // Texto con el nombre del logro
|
||||
std::string description{}; // Texto que describe el logro
|
||||
std::string caption; // Texto con el nombre del logro
|
||||
std::string description; // Texto que describe el logro
|
||||
int icon{0}; // Indice del icono a utilizar en la notificación
|
||||
bool completed{false}; // Indica si se ha obtenido el logro
|
||||
bool obtainable{true}; // Indica si se puede obtener el logro
|
||||
|
||||
@@ -44,8 +44,8 @@ class CollisionMap {
|
||||
auto operator=(CollisionMap&&) -> CollisionMap& = delete;
|
||||
|
||||
// --- Queries de tipo de tile ---
|
||||
auto getTile(SDL_FPoint point) const -> Tile; // Devuelve el tipo de tile en un punto (pixel)
|
||||
auto getTile(int index) const -> Tile; // Devuelve el tipo de tile en un índice del tilemap
|
||||
[[nodiscard]] auto getTile(SDL_FPoint point) const -> Tile; // Devuelve el tipo de tile en un punto (pixel)
|
||||
[[nodiscard]] auto getTile(int index) const -> Tile; // Devuelve el tipo de tile en un índice del tilemap
|
||||
|
||||
// --- Queries de colisión con superficies ---
|
||||
auto checkRightSurfaces(const SDL_FRect& rect) -> int; // Colisión con paredes derechas (retorna X)
|
||||
@@ -63,7 +63,7 @@ class CollisionMap {
|
||||
auto checkLeftSlopes(const SDL_FPoint& p) -> bool; // Colisión punto con rampas izquierdas
|
||||
auto checkRightSlopes(const LineVertical& line) -> int; // Colisión línea con rampas derechas (retorna Y)
|
||||
auto checkRightSlopes(const SDL_FPoint& p) -> bool; // Colisión punto con rampas derechas
|
||||
auto getSlopeAtPoint(const SDL_FPoint& p) const -> const LineDiagonal*; // Obtiene puntero a slope en un punto
|
||||
[[nodiscard]] auto getSlopeAtPoint(const SDL_FPoint& p) const -> const LineDiagonal*; // Obtiene puntero a slope en un punto
|
||||
|
||||
// --- Métodos estáticos ---
|
||||
static auto getTileSize() -> int { return TILE_SIZE; } // Tamaño del tile en pixels
|
||||
|
||||
@@ -23,15 +23,15 @@ class EnemyManager {
|
||||
|
||||
// Prohibir copia y movimiento para evitar duplicación accidental
|
||||
EnemyManager(const EnemyManager&) = delete;
|
||||
EnemyManager& operator=(const EnemyManager&) = delete;
|
||||
auto operator=(const EnemyManager&) -> EnemyManager& = delete;
|
||||
EnemyManager(EnemyManager&&) = delete;
|
||||
EnemyManager& operator=(EnemyManager&&) = delete;
|
||||
auto operator=(EnemyManager&&) -> EnemyManager& = delete;
|
||||
|
||||
// Gestión de enemigos
|
||||
void addEnemy(std::shared_ptr<Enemy> enemy); // Añade un enemigo a la colección
|
||||
void clear(); // Elimina todos los enemigos
|
||||
void removeLastEnemy(); // Elimina el último enemigo de la colección
|
||||
auto isEmpty() const -> bool; // Comprueba si no hay enemigos
|
||||
[[nodiscard]] auto isEmpty() const -> bool; // Comprueba si no hay enemigos
|
||||
|
||||
// Actualización y renderizado
|
||||
void update(float delta_time); // Actualiza todos los enemigos
|
||||
|
||||
@@ -32,9 +32,9 @@ class ItemManager {
|
||||
|
||||
// Prohibir copia y movimiento para evitar duplicación accidental
|
||||
ItemManager(const ItemManager&) = delete;
|
||||
ItemManager& operator=(const ItemManager&) = delete;
|
||||
auto operator=(const ItemManager&) -> ItemManager& = delete;
|
||||
ItemManager(ItemManager&&) = delete;
|
||||
ItemManager& operator=(ItemManager&&) = delete;
|
||||
auto operator=(ItemManager&&) -> ItemManager& = delete;
|
||||
|
||||
// Gestión de items
|
||||
void addItem(std::shared_ptr<Item> item); // Añade un item a la colección
|
||||
|
||||
@@ -20,8 +20,8 @@ class ItemTracker {
|
||||
private:
|
||||
// Tipos anidados privados
|
||||
struct Data {
|
||||
std::string name{}; // Nombre de la habitación donde se encuentra el objeto
|
||||
std::vector<SDL_FPoint> pos{}; // Lista de objetos cogidos de la habitación
|
||||
std::string name; // Nombre de la habitación donde se encuentra el objeto
|
||||
std::vector<SDL_FPoint> pos; // Lista de objetos cogidos de la habitación
|
||||
|
||||
// Constructor para facilitar creación con posición inicial
|
||||
Data(std::string name, const SDL_FPoint& position)
|
||||
|
||||
@@ -166,15 +166,15 @@ auto Room::getRoom(Border border) -> std::string {
|
||||
// Devuelve el tipo de tile que hay en ese pixel
|
||||
auto Room::getTile(SDL_FPoint point) -> Tile {
|
||||
// Delega a CollisionMap y convierte el resultado
|
||||
const auto collision_tile = collision_map_->getTile(point);
|
||||
return static_cast<Tile>(collision_tile);
|
||||
const auto COLLISION_TILE = collision_map_->getTile(point);
|
||||
return static_cast<Tile>(COLLISION_TILE);
|
||||
}
|
||||
|
||||
// Devuelve el tipo de tile en un índice del tilemap
|
||||
auto Room::getTile(int index) -> Tile {
|
||||
// Delega a CollisionMap y convierte el resultado
|
||||
const auto collision_tile = collision_map_->getTile(index);
|
||||
return static_cast<Tile>(collision_tile);
|
||||
const auto COLLISION_TILE = collision_map_->getTile(index);
|
||||
return static_cast<Tile>(COLLISION_TILE);
|
||||
}
|
||||
|
||||
// Indica si hay colision con un enemigo a partir de un rectangulo
|
||||
@@ -190,8 +190,8 @@ auto Room::itemCollision(SDL_FRect& rect) -> bool {
|
||||
// Obten la coordenada de la cuesta a partir de un punto perteneciente a ese tile
|
||||
auto Room::getSlopeHeight(SDL_FPoint p, Tile slope) -> int {
|
||||
// Delega a CollisionMap (método estático)
|
||||
const auto collision_tile = static_cast<CollisionMap::Tile>(slope);
|
||||
return CollisionMap::getSlopeHeight(p, collision_tile);
|
||||
const auto COLLISION_TILE = static_cast<CollisionMap::Tile>(slope);
|
||||
return CollisionMap::getSlopeHeight(p, COLLISION_TILE);
|
||||
}
|
||||
|
||||
// === Métodos de colisión (delegados a CollisionMap) ===
|
||||
|
||||
@@ -38,21 +38,21 @@ class Room {
|
||||
};
|
||||
|
||||
struct Data {
|
||||
std::string number{}; // Numero de la habitación
|
||||
std::string name{}; // Nombre de la habitación
|
||||
std::string bg_color{}; // Color de fondo de la habitación
|
||||
std::string border_color{}; // Color del borde de la pantalla
|
||||
std::string item_color1{}; // Color 1 para los items de la habitación
|
||||
std::string item_color2{}; // Color 2 para los items de la habitación
|
||||
std::string upper_room{}; // Identificador de la habitación que se encuentra arriba
|
||||
std::string lower_room{}; // Identificador de la habitación que se encuentra abajo
|
||||
std::string left_room{}; // Identificador de la habitación que se encuentra a la izquierda
|
||||
std::string right_room{}; // Identificador de la habitación que se encuentra a la derecha
|
||||
std::string tile_set_file{}; // Imagen con los gráficos para la habitación
|
||||
std::string number; // Numero de la habitación
|
||||
std::string name; // Nombre de la habitación
|
||||
std::string bg_color; // Color de fondo de la habitación
|
||||
std::string border_color; // Color del borde de la pantalla
|
||||
std::string item_color1; // Color 1 para los items de la habitación
|
||||
std::string item_color2; // Color 2 para los items de la habitación
|
||||
std::string upper_room; // Identificador de la habitación que se encuentra arriba
|
||||
std::string lower_room; // Identificador de la habitación que se encuentra abajo
|
||||
std::string left_room; // Identificador de la habitación que se encuentra a la izquierda
|
||||
std::string right_room; // Identificador de la habitación que se encuentra a la derecha
|
||||
std::string tile_set_file; // Imagen con los gráficos para la habitación
|
||||
int conveyor_belt_direction{0}; // Sentido en el que arrastran las superficies automáticas de la habitación
|
||||
std::vector<int> tile_map{}; // Índice de los tiles a dibujar en la habitación (embebido desde YAML)
|
||||
std::vector<Enemy::Data> enemies{}; // Listado con los enemigos de la habitación
|
||||
std::vector<Item::Data> items{}; // Listado con los items que hay en la habitación
|
||||
std::vector<int> tile_map; // Índice de los tiles a dibujar en la habitación (embebido desde YAML)
|
||||
std::vector<Enemy::Data> enemies; // Listado con los enemigos de la habitación
|
||||
std::vector<Item::Data> items; // Listado con los items que hay en la habitación
|
||||
};
|
||||
|
||||
// Constructor y destructor
|
||||
@@ -88,7 +88,7 @@ class Room {
|
||||
auto checkLeftSlopes(const SDL_FPoint& p) -> bool; // Comprueba las colisiones
|
||||
auto checkRightSlopes(const LineVertical& line) -> int; // Comprueba las colisiones
|
||||
auto checkRightSlopes(const SDL_FPoint& p) -> bool; // Comprueba las colisiones
|
||||
auto getSlopeAtPoint(const SDL_FPoint& p) const -> const LineDiagonal*; // Obtiene puntero a slope en un punto
|
||||
[[nodiscard]] auto getSlopeAtPoint(const SDL_FPoint& p) const -> const LineDiagonal*; // Obtiene puntero a slope en un punto
|
||||
void setPaused(bool value); // Pone el mapa en modo pausa
|
||||
[[nodiscard]] auto getConveyorBeltDirection() const -> int { return conveyor_belt_direction_; } // Obten la direccion de las superficies automaticas
|
||||
|
||||
|
||||
@@ -26,9 +26,13 @@ auto RoomLoader::convertAutoSurface(const fkyaml::node& node) -> int {
|
||||
return node.get_value<int>();
|
||||
}
|
||||
if (node.is_string()) {
|
||||
const std::string value = node.get_value<std::string>();
|
||||
if (value == "left") return -1;
|
||||
if (value == "right") return 1;
|
||||
const auto VALUE = node.get_value<std::string>();
|
||||
if (VALUE == "left") {
|
||||
return -1;
|
||||
}
|
||||
if (VALUE == "right") {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0; // "none" o default
|
||||
}
|
||||
|
||||
@@ -276,7 +276,7 @@ void init() {
|
||||
|
||||
// Establece la ruta del fichero de configuración
|
||||
void setConfigFile(const std::string& path) {
|
||||
config_file_path_ = path;
|
||||
config_file_path = path;
|
||||
}
|
||||
|
||||
// Carga las opciones desde el fichero configurado
|
||||
@@ -286,10 +286,10 @@ auto loadFromFile() -> bool {
|
||||
version = "";
|
||||
|
||||
// Intenta abrir y leer el fichero
|
||||
std::ifstream file(config_file_path_);
|
||||
std::ifstream file(config_file_path);
|
||||
if (!file.good()) {
|
||||
if (console) {
|
||||
std::cout << "Config file not found, creating default: " << config_file_path_ << '\n';
|
||||
std::cout << "Config file not found, creating default: " << config_file_path << '\n';
|
||||
}
|
||||
saveToFile();
|
||||
return true;
|
||||
@@ -301,7 +301,7 @@ auto loadFromFile() -> bool {
|
||||
|
||||
try {
|
||||
if (console) {
|
||||
std::cout << "Reading config file: " << config_file_path_ << '\n';
|
||||
std::cout << "Reading config file: " << config_file_path << '\n';
|
||||
}
|
||||
|
||||
// Parsea el YAML
|
||||
@@ -351,7 +351,7 @@ auto loadFromFile() -> bool {
|
||||
// filter (ahora es string)
|
||||
if (vid.contains("filter")) {
|
||||
try {
|
||||
std::string filter_str = vid["filter"].get_value<std::string>();
|
||||
auto filter_str = vid["filter"].get_value<std::string>();
|
||||
video.filter = stringToFilter(filter_str);
|
||||
} catch (...) {
|
||||
video.filter = GameDefaults::VIDEO_FILTER;
|
||||
@@ -392,7 +392,7 @@ auto loadFromFile() -> bool {
|
||||
|
||||
if (vid.contains("palette")) {
|
||||
try {
|
||||
std::string palette_str = vid["palette"].get_value<std::string>();
|
||||
auto palette_str = vid["palette"].get_value<std::string>();
|
||||
if (isValidPalette(palette_str)) {
|
||||
video.palette = palette_str;
|
||||
} else {
|
||||
@@ -417,7 +417,7 @@ auto loadFromFile() -> bool {
|
||||
|
||||
if (border.contains("width")) {
|
||||
try {
|
||||
float val = border["width"].get_value<float>();
|
||||
auto val = border["width"].get_value<float>();
|
||||
video.border.width = (val > 0) ? val : GameDefaults::BORDER_WIDTH;
|
||||
} catch (...) {
|
||||
video.border.width = GameDefaults::BORDER_WIDTH;
|
||||
@@ -426,7 +426,7 @@ auto loadFromFile() -> bool {
|
||||
|
||||
if (border.contains("height")) {
|
||||
try {
|
||||
float val = border["height"].get_value<float>();
|
||||
auto val = border["height"].get_value<float>();
|
||||
video.border.height = (val > 0) ? val : GameDefaults::BORDER_HEIGHT;
|
||||
} catch (...) {
|
||||
video.border.height = GameDefaults::BORDER_HEIGHT;
|
||||
@@ -441,7 +441,7 @@ auto loadFromFile() -> bool {
|
||||
|
||||
if (ctrl.contains("key_left")) {
|
||||
try {
|
||||
std::string key_str = ctrl["key_left"].get_value<std::string>();
|
||||
auto key_str = ctrl["key_left"].get_value<std::string>();
|
||||
keyboard_controls.key_left = stringToScancode(key_str, GameDefaults::CONTROL_KEY_LEFT);
|
||||
} catch (...) {
|
||||
keyboard_controls.key_left = GameDefaults::CONTROL_KEY_LEFT;
|
||||
@@ -450,7 +450,7 @@ auto loadFromFile() -> bool {
|
||||
|
||||
if (ctrl.contains("key_right")) {
|
||||
try {
|
||||
std::string key_str = ctrl["key_right"].get_value<std::string>();
|
||||
auto key_str = ctrl["key_right"].get_value<std::string>();
|
||||
keyboard_controls.key_right = stringToScancode(key_str, GameDefaults::CONTROL_KEY_RIGHT);
|
||||
} catch (...) {
|
||||
keyboard_controls.key_right = GameDefaults::CONTROL_KEY_RIGHT;
|
||||
@@ -459,7 +459,7 @@ auto loadFromFile() -> bool {
|
||||
|
||||
if (ctrl.contains("key_jump")) {
|
||||
try {
|
||||
std::string key_str = ctrl["key_jump"].get_value<std::string>();
|
||||
auto key_str = ctrl["key_jump"].get_value<std::string>();
|
||||
keyboard_controls.key_jump = stringToScancode(key_str, GameDefaults::CONTROL_KEY_JUMP);
|
||||
} catch (...) {
|
||||
keyboard_controls.key_jump = GameDefaults::CONTROL_KEY_JUMP;
|
||||
@@ -473,7 +473,7 @@ auto loadFromFile() -> bool {
|
||||
|
||||
if (gp.contains("button_left")) {
|
||||
try {
|
||||
std::string button_str = gp["button_left"].get_value<std::string>();
|
||||
auto button_str = gp["button_left"].get_value<std::string>();
|
||||
gamepad_controls.button_left = stringToGamepadButton(button_str, GameDefaults::GAMEPAD_BUTTON_LEFT);
|
||||
} catch (...) {
|
||||
gamepad_controls.button_left = GameDefaults::GAMEPAD_BUTTON_LEFT;
|
||||
@@ -482,7 +482,7 @@ auto loadFromFile() -> bool {
|
||||
|
||||
if (gp.contains("button_right")) {
|
||||
try {
|
||||
std::string button_str = gp["button_right"].get_value<std::string>();
|
||||
auto button_str = gp["button_right"].get_value<std::string>();
|
||||
gamepad_controls.button_right = stringToGamepadButton(button_str, GameDefaults::GAMEPAD_BUTTON_RIGHT);
|
||||
} catch (...) {
|
||||
gamepad_controls.button_right = GameDefaults::GAMEPAD_BUTTON_RIGHT;
|
||||
@@ -491,7 +491,7 @@ auto loadFromFile() -> bool {
|
||||
|
||||
if (gp.contains("button_jump")) {
|
||||
try {
|
||||
std::string button_str = gp["button_jump"].get_value<std::string>();
|
||||
auto button_str = gp["button_jump"].get_value<std::string>();
|
||||
gamepad_controls.button_jump = stringToGamepadButton(button_str, GameDefaults::GAMEPAD_BUTTON_JUMP);
|
||||
} catch (...) {
|
||||
gamepad_controls.button_jump = GameDefaults::GAMEPAD_BUTTON_JUMP;
|
||||
@@ -519,16 +519,16 @@ auto loadFromFile() -> bool {
|
||||
// Guarda las opciones al fichero configurado
|
||||
auto saveToFile() -> bool {
|
||||
// Abre el fichero para escritura
|
||||
std::ofstream file(config_file_path_);
|
||||
std::ofstream file(config_file_path);
|
||||
if (!file.is_open()) {
|
||||
if (console) {
|
||||
std::cerr << "Error: Unable to open file " << config_file_path_ << " for writing\n";
|
||||
std::cerr << "Error: Unable to open file " << config_file_path << " for writing\n";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (console) {
|
||||
std::cout << "Writing config file: " << config_file_path_ << '\n';
|
||||
std::cout << "Writing config file: " << config_file_path << '\n';
|
||||
}
|
||||
|
||||
// Escribe el fichero manualmente para controlar el orden y los comentarios
|
||||
|
||||
@@ -85,7 +85,7 @@ struct Video {
|
||||
bool keep_aspect{GameDefaults::VIDEO_KEEP_ASPECT}; // Indica si se ha de mantener la relación de aspecto al poner el modo a pantalla completa
|
||||
Border border{}; // Borde de la pantalla
|
||||
std::string palette{GameDefaults::PALETTE_NAME}; // Paleta de colores a usar en el juego
|
||||
std::string info{}; // Información sobre el modo de vídeo
|
||||
std::string info; // Información sobre el modo de vídeo
|
||||
};
|
||||
|
||||
// Estructura para las opciones de musica
|
||||
@@ -127,7 +127,7 @@ inline KeyboardControls keyboard_controls{}; // Teclas usadas para jugar
|
||||
inline GamepadControls gamepad_controls{}; // Botones del gamepad usados para jugar
|
||||
|
||||
// Ruta completa del fichero de configuración (establecida mediante setConfigFile)
|
||||
inline std::string config_file_path_{};
|
||||
inline std::string config_file_path{};
|
||||
|
||||
// --- Funciones ---
|
||||
void init(); // Crea e inicializa las opciones del programa
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
// Constructor
|
||||
Ending2::Ending2()
|
||||
: delta_timer_(std::make_unique<DeltaTimer>()),
|
||||
state_{EndingState::PRE_CREDITS, STATE_PRE_CREDITS_DURATION} {
|
||||
state_{.state = EndingState::PRE_CREDITS, .duration = STATE_PRE_CREDITS_DURATION} {
|
||||
// Establece la escena
|
||||
SceneManager::current = SceneManager::Scene::ENDING2;
|
||||
SceneManager::options = SceneManager::Options::NONE;
|
||||
|
||||
@@ -576,7 +576,7 @@ void Game::checkEndGameCheevos() {
|
||||
// Inicializa al jugador
|
||||
void Game::initPlayer(const Player::SpawnData& spawn_point, std::shared_ptr<Room> room) {
|
||||
std::string player_animations = Options::cheats.alternate_skin == Options::Cheat::State::ENABLED ? "player2.yaml" : "player.yaml";
|
||||
const Player::Data PLAYER{spawn_point, player_animations, std::move(room)};
|
||||
const Player::Data PLAYER{.spawn_data = spawn_point, .animations_path = player_animations, .room = std::move(room)};
|
||||
player_ = std::make_shared<Player>(PLAYER);
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ class Game {
|
||||
struct DemoData {
|
||||
float time_accumulator{0.0F}; // Acumulador de tiempo para el modo demo
|
||||
int room_index{0}; // Índice para el vector de habitaciones
|
||||
std::vector<std::string> rooms{}; // Listado con los mapas de la demo
|
||||
std::vector<std::string> rooms; // Listado con los mapas de la demo
|
||||
};
|
||||
|
||||
// --- Métodos ---
|
||||
|
||||
@@ -76,20 +76,20 @@ void Logo::updateJAILGAMES(float delta_time) {
|
||||
}
|
||||
|
||||
// Calcular el progreso de la animación (0.0 a 1.0)
|
||||
const float progress = std::clamp(state_time_ / JAILGAMES_SLIDE_DURATION, 0.0F, 1.0F);
|
||||
const float PROGRESS = std::clamp(state_time_ / JAILGAMES_SLIDE_DURATION, 0.0F, 1.0F);
|
||||
|
||||
// Aplicar función de suavizado seleccionada aleatoriamente (permite overshoot para efecto de rebote)
|
||||
// La posición final exacta se garantiza en updateState() antes de transicionar
|
||||
const float eased_progress = easing_function_(progress);
|
||||
const float EASED_PROGRESS = easing_function_(PROGRESS);
|
||||
|
||||
// Actualizar cada línea del sprite JAILGAMES interpolando con easing
|
||||
for (size_t i = 0; i < jailgames_sprite_.size(); ++i) {
|
||||
// Interpolar entre posición inicial y destino usando el progreso suavizado
|
||||
const float initial_x = static_cast<float>(jailgames_initial_x_[i]);
|
||||
const float dest_x = static_cast<float>(JAILGAMES_DEST_X);
|
||||
const float new_x = initial_x + (dest_x - initial_x) * eased_progress;
|
||||
const auto INITIAL_X = static_cast<float>(jailgames_initial_x_[i]);
|
||||
const auto DEST_X = static_cast<float>(JAILGAMES_DEST_X);
|
||||
const float NEW_X = INITIAL_X + ((DEST_X - INITIAL_X) * EASED_PROGRESS);
|
||||
|
||||
jailgames_sprite_[i]->setX(new_x);
|
||||
jailgames_sprite_[i]->setX(NEW_X);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,10 +275,10 @@ void Logo::initSprites() {
|
||||
|
||||
// Calcular posición inicial (alternando entre derecha e izquierda)
|
||||
constexpr int LINE_OFFSET = 6;
|
||||
const int initial_x = (i % 2 == 0) ? (256 + (i * LINE_OFFSET)) : (static_cast<int>(-WIDTH) - (i * LINE_OFFSET));
|
||||
jailgames_initial_x_.push_back(initial_x);
|
||||
const int INITIAL_X = (i % 2 == 0) ? (256 + (i * LINE_OFFSET)) : (static_cast<int>(-WIDTH) - (i * LINE_OFFSET));
|
||||
jailgames_initial_x_.push_back(INITIAL_X);
|
||||
|
||||
jailgames_sprite_.at(i)->setX(initial_x);
|
||||
jailgames_sprite_.at(i)->setX(INITIAL_X);
|
||||
jailgames_sprite_.at(i)->setY(83 + i);
|
||||
}
|
||||
}
|
||||
@@ -90,7 +90,7 @@ void Notifier::update(float delta_time) {
|
||||
if (notification.rect.y >= notification.y) {
|
||||
notification.rect.y = notification.y;
|
||||
notification.state = Status::STAY;
|
||||
notification.elapsed_time = 0.0f;
|
||||
notification.elapsed_time = 0.0F;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -163,7 +163,7 @@ void Notifier::show(std::vector<std::string> texts, const Style& style, int icon
|
||||
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;
|
||||
const TextAlign text_is = ICON_SPACE > 0 ? TextAlign::LEFT : style.text_align;
|
||||
const TextAlign TEXT_IS = ICON_SPACE > 0 ? TextAlign::LEFT : style.text_align;
|
||||
const float WIDTH = Options::game.width - (PADDING_OUT * 2);
|
||||
const float HEIGHT = (TEXT_SIZE * texts.size()) + (PADDING_IN_V * 2);
|
||||
const auto SHAPE = style.shape;
|
||||
@@ -235,7 +235,7 @@ void Notifier::show(std::vector<std::string> texts, const Style& style, int icon
|
||||
const auto COLOR = style.text_color;
|
||||
int iterator = 0;
|
||||
for (const auto& text : texts) {
|
||||
switch (text_is) {
|
||||
switch (TEXT_IS) {
|
||||
case TextAlign::LEFT:
|
||||
text_->writeColored(PADDING_IN_H + ICON_SPACE, PADDING_IN_V + (iterator * (TEXT_SIZE + 1)), text, COLOR);
|
||||
break;
|
||||
|
||||
@@ -71,17 +71,17 @@ class Notifier {
|
||||
struct Notification {
|
||||
std::shared_ptr<Surface> surface{nullptr};
|
||||
std::shared_ptr<SurfaceSprite> sprite{nullptr};
|
||||
std::vector<std::string> texts{};
|
||||
std::vector<std::string> texts;
|
||||
Status state{Status::RISING};
|
||||
Shape shape{Shape::SQUARED};
|
||||
SDL_FRect rect{0.0F, 0.0F, 0.0F, 0.0F};
|
||||
int y{0};
|
||||
int travel_dist{0};
|
||||
std::string code{};
|
||||
std::string code;
|
||||
bool can_be_removed{true};
|
||||
int height{0};
|
||||
float elapsed_time{0.0f};
|
||||
float display_duration{0.0f};
|
||||
float elapsed_time{0.0F};
|
||||
float display_duration{0.0F};
|
||||
};
|
||||
|
||||
// Constantes
|
||||
|
||||
Reference in New Issue
Block a user