clang-format
This commit is contained in:
@@ -218,7 +218,7 @@ void handle() {
|
||||
break;
|
||||
|
||||
case InputAction::TOGGLE_DEBUG:
|
||||
//handleToggleDebug();
|
||||
// handleToggleDebug();
|
||||
break;
|
||||
|
||||
#ifdef _DEBUG
|
||||
|
||||
@@ -68,8 +68,7 @@ auto Pack::addFile(const std::string& filepath, const std::string& pack_name)
|
||||
.filename = pack_name,
|
||||
.offset = data_.size(),
|
||||
.size = file_data.size(),
|
||||
.checksum = calculateChecksum(file_data)
|
||||
};
|
||||
.checksum = calculateChecksum(file_data)};
|
||||
|
||||
// Append file data to the data block
|
||||
data_.insert(data_.end(), file_data.begin(), file_data.end());
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
|
||||
// Constructor
|
||||
CollisionMap::CollisionMap(std::vector<int> tile_map, int tile_set_width, int conveyor_belt_direction)
|
||||
: tile_map_(std::move(tile_map))
|
||||
, tile_set_width_(tile_set_width)
|
||||
, conveyor_belt_direction_(conveyor_belt_direction) {
|
||||
: tile_map_(std::move(tile_map)),
|
||||
tile_set_width_(tile_set_width),
|
||||
conveyor_belt_direction_(conveyor_belt_direction) {
|
||||
// Inicializa todas las superficies de colisión
|
||||
initializeSurfaces();
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
#include <algorithm> // Para std::ranges::any_of
|
||||
|
||||
#include "utils/utils.hpp" // Para checkCollision
|
||||
#include "game/entities/enemy.hpp" // Para Enemy
|
||||
#include "utils/utils.hpp" // Para checkCollision
|
||||
|
||||
// Añade un enemigo a la colección
|
||||
void EnemyManager::addEnemy(std::shared_ptr<Enemy> enemy) {
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
#include "item_manager.hpp"
|
||||
|
||||
#include "core/audio/audio.hpp" // Para Audio
|
||||
#include "utils/utils.hpp" // Para checkCollision
|
||||
#include "game/entities/item.hpp" // Para Item
|
||||
#include "game/options.hpp" // Para Options
|
||||
#include "item_tracker.hpp" // Para ItemTracker
|
||||
#include "scoreboard.hpp" // Para Scoreboard::Data
|
||||
#include "game/options.hpp" // Para Options
|
||||
#include "utils/utils.hpp" // Para checkCollision
|
||||
|
||||
// Constructor
|
||||
ItemManager::ItemManager(std::string room_name, std::shared_ptr<Scoreboard::Data> scoreboard_data)
|
||||
: room_name_(std::move(room_name))
|
||||
, data_(std::move(scoreboard_data)) {
|
||||
: room_name_(std::move(room_name)),
|
||||
data_(std::move(scoreboard_data)) {
|
||||
}
|
||||
|
||||
// Añade un item a la colección
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
#include <exception> // Para exception
|
||||
#include <iostream> // Para cout, cerr
|
||||
#include "external/fkyaml_node.hpp" // Para fkyaml::node
|
||||
|
||||
#include "core/resources/resource_helper.hpp" // Para Resource::Helper
|
||||
#include "external/fkyaml_node.hpp" // Para fkyaml::node
|
||||
#include "utils/defines.hpp" // Para Tile::SIZE
|
||||
#include "utils/utils.hpp" // Para stringToColor
|
||||
|
||||
|
||||
@@ -25,23 +25,13 @@ Ending::Ending()
|
||||
SceneManager::current = SceneManager::Scene::ENDING;
|
||||
SceneManager::options = SceneManager::Options::NONE;
|
||||
|
||||
// Inicializa los textos
|
||||
iniTexts();
|
||||
iniTexts(); // Inicializa los textos
|
||||
iniPics(); // Inicializa las imagenes
|
||||
iniScenes(); // Inicializa las escenas
|
||||
|
||||
// Inicializa las imagenes
|
||||
iniPics();
|
||||
|
||||
// Inicializa las escenas
|
||||
iniScenes();
|
||||
|
||||
// Cambia el color del borde
|
||||
Screen::get()->setBorderColor(static_cast<Uint8>(PaletteColor::BLACK));
|
||||
|
||||
// Crea la textura para cubrir el texto
|
||||
cover_surface_ = std::make_shared<Surface>(Options::game.width, Options::game.height + 8);
|
||||
|
||||
// Rellena la textura para la cortinilla
|
||||
fillCoverTexture();
|
||||
Screen::get()->setBorderColor(static_cast<Uint8>(PaletteColor::BLACK)); // Cambia el color del borde
|
||||
cover_surface_ = std::make_shared<Surface>(Options::game.width, Options::game.height + 8); // Crea la textura para cubrir el texto
|
||||
fillCoverTexture(); // Rellena la textura para la cortinilla
|
||||
}
|
||||
|
||||
// Actualiza el objeto
|
||||
@@ -446,55 +436,55 @@ void Ending::updateSpriteCovers() {
|
||||
const float PIXELS_REVEALED = TIME_SINCE_TRIGGER * TEXT_REVEAL_SPEED;
|
||||
|
||||
// Obtiene el sprite
|
||||
auto SPRITE_TEXT = sprite_texts_.at(ti.index);
|
||||
auto sprite_text = sprite_texts_.at(ti.index);
|
||||
|
||||
// Obtener altura inicial de la superficie
|
||||
const float INITIAL_HEIGHT = SPRITE_TEXT.image_surface->getHeight();
|
||||
const float Y_INITIAL = SPRITE_TEXT.image_sprite->getY();
|
||||
const float INITIAL_HEIGHT = sprite_text.image_surface->getHeight();
|
||||
const float Y_INITIAL = sprite_text.image_sprite->getY();
|
||||
|
||||
// Fase 1: Revelar malla decorativa (8 píxeles)
|
||||
if (PIXELS_REVEALED < 8.0F) {
|
||||
SPRITE_TEXT.cover_clip_desp = static_cast<int>(8.0F - PIXELS_REVEALED);
|
||||
SPRITE_TEXT.cover_clip_height = static_cast<int>(INITIAL_HEIGHT);
|
||||
SPRITE_TEXT.cover_sprite->setY(Y_INITIAL);
|
||||
sprite_text.cover_clip_desp = static_cast<int>(8.0F - PIXELS_REVEALED);
|
||||
sprite_text.cover_clip_height = static_cast<int>(INITIAL_HEIGHT);
|
||||
sprite_text.cover_sprite->setY(Y_INITIAL);
|
||||
}
|
||||
// Fase 2: Revelar contenido
|
||||
else {
|
||||
SPRITE_TEXT.cover_clip_desp = 0;
|
||||
sprite_text.cover_clip_desp = 0;
|
||||
const int CONTENT_PIXELS = PIXELS_REVEALED - 8.0F;
|
||||
SPRITE_TEXT.cover_clip_height = std::max(0, static_cast<int>(INITIAL_HEIGHT - CONTENT_PIXELS));
|
||||
SPRITE_TEXT.cover_sprite->setY(Y_INITIAL + static_cast<int>(CONTENT_PIXELS));
|
||||
sprite_text.cover_clip_height = std::max(0, static_cast<int>(INITIAL_HEIGHT - CONTENT_PIXELS));
|
||||
sprite_text.cover_sprite->setY(Y_INITIAL + static_cast<int>(CONTENT_PIXELS));
|
||||
}
|
||||
|
||||
SPRITE_TEXT.cover_sprite->setClip(
|
||||
sprite_text.cover_sprite->setClip(
|
||||
0,
|
||||
SPRITE_TEXT.cover_clip_desp,
|
||||
SPRITE_TEXT.cover_sprite->getWidth(),
|
||||
SPRITE_TEXT.cover_clip_height);
|
||||
sprite_text.cover_clip_desp,
|
||||
sprite_text.cover_sprite->getWidth(),
|
||||
sprite_text.cover_clip_height);
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza la cortinilla de las imágenes (revelación continua desde el inicio de la escena)
|
||||
auto SPRITE_PICS = sprite_pics_.at(current_scene_);
|
||||
auto sprite_pics = sprite_pics_.at(current_scene_);
|
||||
const float PIXELS_REVEALED = state_time_ * IMAGE_REVEAL_SPEED;
|
||||
const float INITIAL_HEIGHT = SPRITE_PICS.image_surface->getHeight();
|
||||
const float Y_INITIAL = SPRITE_PICS.image_sprite->getY();
|
||||
const float INITIAL_HEIGHT = sprite_pics.image_surface->getHeight();
|
||||
const float Y_INITIAL = sprite_pics.image_sprite->getY();
|
||||
|
||||
// Fase 1: Revelar malla decorativa (8 píxeles)
|
||||
if (PIXELS_REVEALED < 8.0F) {
|
||||
SPRITE_PICS.cover_clip_desp = static_cast<int>(8.0F - PIXELS_REVEALED);
|
||||
SPRITE_PICS.cover_clip_height = static_cast<int>(INITIAL_HEIGHT);
|
||||
SPRITE_PICS.cover_sprite->setY(Y_INITIAL);
|
||||
sprite_pics.cover_clip_desp = static_cast<int>(8.0F - PIXELS_REVEALED);
|
||||
sprite_pics.cover_clip_height = static_cast<int>(INITIAL_HEIGHT);
|
||||
sprite_pics.cover_sprite->setY(Y_INITIAL);
|
||||
}
|
||||
// Fase 2: Revelar contenido
|
||||
else {
|
||||
SPRITE_PICS.cover_clip_desp = 0;
|
||||
sprite_pics.cover_clip_desp = 0;
|
||||
const int CONTENT_PIXELS = PIXELS_REVEALED - 8.0F;
|
||||
SPRITE_PICS.cover_clip_height = std::max(0, static_cast<int>(INITIAL_HEIGHT - CONTENT_PIXELS));
|
||||
SPRITE_PICS.cover_sprite->setY(Y_INITIAL + static_cast<int>(CONTENT_PIXELS));
|
||||
sprite_pics.cover_clip_height = std::max(0, static_cast<int>(INITIAL_HEIGHT - CONTENT_PIXELS));
|
||||
sprite_pics.cover_sprite->setY(Y_INITIAL + static_cast<int>(CONTENT_PIXELS));
|
||||
}
|
||||
|
||||
SPRITE_PICS.cover_sprite->setClip(0, SPRITE_PICS.cover_clip_desp, SPRITE_PICS.cover_sprite->getWidth(), SPRITE_PICS.cover_clip_height);
|
||||
sprite_pics.cover_sprite->setClip(0, sprite_pics.cover_clip_desp, sprite_pics.cover_sprite->getWidth(), sprite_pics.cover_clip_height);
|
||||
}
|
||||
|
||||
// Comprueba si se ha de cambiar de escena
|
||||
|
||||
@@ -82,13 +82,21 @@ void Game::handleEvents() {
|
||||
void Game::handleInput() {
|
||||
Input::get()->update();
|
||||
|
||||
// Inputs globales siempre funcionan
|
||||
if (Input::get()->checkAction(InputAction::TOGGLE_MUSIC, Input::DO_NOT_ALLOW_REPEAT)) {
|
||||
board_->music = !board_->music;
|
||||
board_->music ? Audio::get()->resumeMusic() : Audio::get()->pauseMusic();
|
||||
Notifier::get()->show({"MUSIC " + std::string(board_->music ? "ENABLED" : "DISABLED")});
|
||||
}
|
||||
|
||||
else if (Input::get()->checkAction(InputAction::PAUSE, Input::DO_NOT_ALLOW_REPEAT)) {
|
||||
// Durante fade/postfade, solo procesar inputs globales
|
||||
if (state_ != State::PLAYING) {
|
||||
GlobalInputs::handle();
|
||||
return;
|
||||
}
|
||||
|
||||
// Input de pausa solo en estado PLAYING
|
||||
if (Input::get()->checkAction(InputAction::PAUSE, Input::DO_NOT_ALLOW_REPEAT)) {
|
||||
togglePause();
|
||||
Notifier::get()->show({std::string(paused_ ? "GAME PAUSED" : "GAME RUNNING")});
|
||||
}
|
||||
@@ -124,28 +132,18 @@ void Game::update() {
|
||||
Debug::get()->clear();
|
||||
#endif
|
||||
|
||||
// Actualiza los objetos
|
||||
room_->update(DELTA_TIME);
|
||||
switch (mode_) {
|
||||
case Mode::GAME:
|
||||
player_->update(DELTA_TIME);
|
||||
checkPlayerIsOnBorder();
|
||||
checkPlayerAndItems();
|
||||
checkPlayerAndEnemies();
|
||||
checkIfPlayerIsAlive();
|
||||
checkGameOver();
|
||||
checkEndGame();
|
||||
checkRestoringJail(DELTA_TIME);
|
||||
checkSomeCheevos();
|
||||
// Dispatch por estado
|
||||
switch (state_) {
|
||||
case State::PLAYING:
|
||||
updatePlaying(DELTA_TIME);
|
||||
break;
|
||||
|
||||
case Mode::DEMO:
|
||||
demoCheckRoomChange(DELTA_TIME);
|
||||
case State::FADE_TO_ENDING:
|
||||
updateFadeToEnding(DELTA_TIME);
|
||||
break;
|
||||
case State::POST_FADE_ENDING:
|
||||
updatePostFadeEnding(DELTA_TIME);
|
||||
break;
|
||||
}
|
||||
scoreboard_->update(DELTA_TIME);
|
||||
keepMusicPlaying();
|
||||
updateBlackScreen(DELTA_TIME);
|
||||
|
||||
Audio::update(); // Actualiza el objeto Audio
|
||||
Screen::get()->update(DELTA_TIME); // Actualiza el objeto Screen
|
||||
@@ -155,6 +153,73 @@ void Game::update() {
|
||||
#endif
|
||||
}
|
||||
|
||||
// Actualiza el juego en estado PLAYING
|
||||
void Game::updatePlaying(float delta_time) {
|
||||
// Actualiza los objetos
|
||||
room_->update(delta_time);
|
||||
switch (mode_) {
|
||||
case Mode::GAME:
|
||||
player_->update(delta_time);
|
||||
checkPlayerIsOnBorder();
|
||||
checkPlayerAndItems();
|
||||
checkPlayerAndEnemies();
|
||||
checkIfPlayerIsAlive();
|
||||
checkGameOver();
|
||||
checkEndGame();
|
||||
checkRestoringJail(delta_time);
|
||||
checkSomeCheevos();
|
||||
break;
|
||||
|
||||
case Mode::DEMO:
|
||||
demoCheckRoomChange(delta_time);
|
||||
break;
|
||||
}
|
||||
scoreboard_->update(delta_time);
|
||||
keepMusicPlaying();
|
||||
updateBlackScreen(delta_time);
|
||||
}
|
||||
|
||||
// Actualiza el juego en estado FADE_TO_ENDING
|
||||
void Game::updateFadeToEnding(float delta_time) {
|
||||
// Actualiza room, enemies, items (todo sigue funcionando)
|
||||
room_->update(delta_time);
|
||||
|
||||
// NO actualizar player (congelar movimiento)
|
||||
// player_->update(delta_time); -- COMENTADO INTENCIONALMENTE
|
||||
|
||||
// Actualiza scoreboard
|
||||
scoreboard_->update(delta_time);
|
||||
keepMusicPlaying();
|
||||
|
||||
// Aplica el fade progresivo
|
||||
fade_accumulator_ += delta_time;
|
||||
if (fade_accumulator_ >= FADE_STEP_INTERVAL) {
|
||||
fade_accumulator_ = 0.0F;
|
||||
if (Screen::get()->getRendererSurface()->fadeSubPalette()) {
|
||||
// Fade completado, transicionar a POST_FADE
|
||||
transitionToState(State::POST_FADE_ENDING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza el juego en estado POST_FADE_ENDING
|
||||
void Game::updatePostFadeEnding(float delta_time) {
|
||||
// Pantalla negra estática, acumular tiempo
|
||||
state_time_ += delta_time;
|
||||
|
||||
// Después del delay, cambiar a la escena de ending
|
||||
if (state_time_ >= POST_FADE_DELAY) {
|
||||
SceneManager::current = SceneManager::Scene::ENDING;
|
||||
}
|
||||
}
|
||||
|
||||
// Cambia al estado especificado y resetea los timers
|
||||
void Game::transitionToState(State new_state) {
|
||||
state_ = new_state;
|
||||
state_time_ = 0.0F;
|
||||
fade_accumulator_ = 0.0F;
|
||||
}
|
||||
|
||||
// Pinta los objetos en pantalla
|
||||
void Game::render() {
|
||||
// Prepara para dibujar el frame
|
||||
@@ -434,7 +499,9 @@ auto Game::checkEndGame() -> bool {
|
||||
// Comprueba los logros de completar el juego
|
||||
checkEndGameCheevos();
|
||||
|
||||
SceneManager::current = SceneManager::Scene::ENDING;
|
||||
// Iniciar transición de fade en vez de cambio inmediato de escena
|
||||
transitionToState(State::FADE_TO_ENDING);
|
||||
Audio::get()->fadeOutMusic(1000); // Fade out de música en 1 segundo
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,12 @@ class Game {
|
||||
GAME
|
||||
};
|
||||
|
||||
enum class State {
|
||||
PLAYING, // Normal gameplay
|
||||
FADE_TO_ENDING, // Fade out transition
|
||||
POST_FADE_ENDING, // Black screen delay before ending
|
||||
};
|
||||
|
||||
// --- Constructor y Destructor ---
|
||||
explicit Game(Mode mode);
|
||||
~Game();
|
||||
@@ -36,6 +42,8 @@ class Game {
|
||||
static constexpr float GAME_OVER_THRESHOLD = 0.255F; // Tiempo antes del game over en segundos (17 frames a 66.67fps)
|
||||
static constexpr float DEMO_ROOM_DURATION = 6.0F; // Duración de cada habitación en modo demo en segundos (400 frames)
|
||||
static constexpr float JAIL_RESTORE_INTERVAL = 1.5F; // Intervalo de restauración de vidas en la Jail en segundos (100 frames)
|
||||
static constexpr float FADE_STEP_INTERVAL = 0.05F; // Intervalo entre pasos de fade en segundos
|
||||
static constexpr float POST_FADE_DELAY = 1.0F; // Duración de la pantalla negra después del fade
|
||||
|
||||
// --- Estructuras ---
|
||||
struct DemoData {
|
||||
@@ -49,6 +57,10 @@ class Game {
|
||||
void render(); // Pinta los objetos en pantalla
|
||||
void handleEvents(); // Comprueba los eventos de la cola
|
||||
void renderRoomName(); // Escribe el nombre de la pantalla
|
||||
void transitionToState(State new_state); // Cambia al estado especificado y resetea los timers
|
||||
void updatePlaying(float delta_time); // Actualiza el juego en estado PLAYING
|
||||
void updateFadeToEnding(float delta_time); // Actualiza el juego en estado FADE_TO_ENDING
|
||||
void updatePostFadeEnding(float delta_time); // Actualiza el juego en estado POST_FADE_ENDING
|
||||
auto changeRoom(const std::string& room_path) -> bool; // Cambia de habitación
|
||||
void handleInput(); // Comprueba el teclado
|
||||
void checkPlayerIsOnBorder(); // Comprueba si el jugador esta en el borde de la pantalla y actua
|
||||
@@ -92,11 +104,14 @@ class Game {
|
||||
|
||||
// Variables de estado del juego
|
||||
Mode mode_; // Modo del juego
|
||||
State state_{State::PLAYING}; // Estado actual de la escena
|
||||
DeltaTimer delta_timer_; // Timer para calcular delta time
|
||||
std::string current_room_; // Fichero de la habitación actual
|
||||
Player::SpawnData spawn_data_; // Lugar de la habitación donde aparece el jugador
|
||||
int total_items_; // Cantidad total de items que hay en el mapeado del juego
|
||||
bool paused_{false}; // Indica si el juego se encuentra en pausa
|
||||
float state_time_{0.0F}; // Tiempo acumulado en el estado actual
|
||||
float fade_accumulator_{0.0F}; // Acumulador de tiempo para el fade
|
||||
|
||||
// Variables de demo mode
|
||||
DemoData demo_; // Variables para el modo demo
|
||||
|
||||
Reference in New Issue
Block a user