Compare commits
4 Commits
d1e4a5eb07
...
efe8628a3c
| Author | SHA1 | Date | |
|---|---|---|---|
| efe8628a3c | |||
| c98cb0d29f | |||
| c16fc1bae5 | |||
| fa0af1179a |
@@ -125,6 +125,7 @@ add_executable(${PROJECT_NAME} ${APP_SOURCES} ${EXTERNAL_SOURCES})
|
|||||||
target_include_directories(${PROJECT_NAME} PUBLIC
|
target_include_directories(${PROJECT_NAME} PUBLIC
|
||||||
"${CMAKE_SOURCE_DIR}/source"
|
"${CMAKE_SOURCE_DIR}/source"
|
||||||
"${CMAKE_SOURCE_DIR}/source/external"
|
"${CMAKE_SOURCE_DIR}/source/external"
|
||||||
|
"${CMAKE_BINARY_DIR}"
|
||||||
)
|
)
|
||||||
|
|
||||||
# Enlazar la librería SDL3
|
# Enlazar la librería SDL3
|
||||||
@@ -139,6 +140,9 @@ target_compile_options(${PROJECT_NAME} PRIVATE $<$<CONFIG:RELEASE>:-Os -ffunctio
|
|||||||
# Definir _DEBUG en modo Debug
|
# Definir _DEBUG en modo Debug
|
||||||
target_compile_definitions(${PROJECT_NAME} PRIVATE $<$<CONFIG:DEBUG>:_DEBUG>)
|
target_compile_definitions(${PROJECT_NAME} PRIVATE $<$<CONFIG:DEBUG>:_DEBUG>)
|
||||||
|
|
||||||
|
# Descomentar la siguiente línea para activar el modo grabación de demos
|
||||||
|
# target_compile_definitions(${PROJECT_NAME} PRIVATE RECORDING)
|
||||||
|
|
||||||
|
|
||||||
# Configuración específica para cada plataforma
|
# Configuración específica para cada plataforma
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ DATA|${PREFIX}/config/stages.txt
|
|||||||
# Archivos con los datos de la demo
|
# Archivos con los datos de la demo
|
||||||
DEMODATA|${PREFIX}/data/demo/demo1.bin
|
DEMODATA|${PREFIX}/data/demo/demo1.bin
|
||||||
DEMODATA|${PREFIX}/data/demo/demo2.bin
|
DEMODATA|${PREFIX}/data/demo/demo2.bin
|
||||||
|
DEMODATA|${PREFIX}/data/demo/demo3.bin
|
||||||
|
|
||||||
# Música
|
# Música
|
||||||
MUSIC|${PREFIX}/data/music/congratulations.ogg
|
MUSIC|${PREFIX}/data/music/congratulations.ogg
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
BIN
data/demo/demo3.bin
Normal file
BIN
data/demo/demo3.bin
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 12 KiB |
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <SDL3/SDL.h> // Para SDL_LogCategory, SDL_LogInfo, SDL_LogError, SDL_LogWarn
|
#include <SDL3/SDL.h> // Para SDL_LogCategory, SDL_LogInfo, SDL_LogError, SDL_LogWarn
|
||||||
|
|
||||||
|
#include <algorithm> // Para std::sort
|
||||||
#include <cstddef> // Para size_t
|
#include <cstddef> // Para size_t
|
||||||
#include <exception> // Para exception
|
#include <exception> // Para exception
|
||||||
#include <filesystem> // Para std::filesystem
|
#include <filesystem> // Para std::filesystem
|
||||||
@@ -299,6 +300,9 @@ auto Asset::getListByType(Type type) const -> std::vector<std::string> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Ordenar alfabéticamente para garantizar orden consistente
|
||||||
|
std::sort(list.begin(), list.end());
|
||||||
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ Director::Director(int argc, std::span<char *> argv) {
|
|||||||
Section::name = Section::Name::GAME;
|
Section::name = Section::Name::GAME;
|
||||||
Section::options = Section::Options::GAME_PLAY_1P;
|
Section::options = Section::Options::GAME_PLAY_1P;
|
||||||
#elif _DEBUG
|
#elif _DEBUG
|
||||||
Section::name = Section::Name::GAME;
|
Section::name = Section::Name::TITLE;
|
||||||
Section::options = Section::Options::GAME_PLAY_1P;
|
Section::options = Section::Options::GAME_PLAY_1P;
|
||||||
#else // NORMAL GAME
|
#else // NORMAL GAME
|
||||||
Section::name = Section::Name::LOGO;
|
Section::name = Section::Name::LOGO;
|
||||||
|
|||||||
@@ -217,6 +217,10 @@ class Player {
|
|||||||
[[nodiscard]] auto getUsesKeyboard() const -> bool { return uses_keyboard_; }
|
[[nodiscard]] auto getUsesKeyboard() const -> bool { return uses_keyboard_; }
|
||||||
[[nodiscard]] auto getController() const -> int { return controller_index_; }
|
[[nodiscard]] auto getController() const -> int { return controller_index_; }
|
||||||
|
|
||||||
|
// Demo file management
|
||||||
|
[[nodiscard]] auto getDemoFile() const -> size_t { return demo_file_; }
|
||||||
|
void setDemoFile(size_t demo_file) { demo_file_ = demo_file; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// --- Constantes de física y movimiento ---
|
// --- Constantes de física y movimiento ---
|
||||||
static constexpr float BASE_SPEED = 90.0f; // Velocidad base del jugador (pixels/segundo)
|
static constexpr float BASE_SPEED = 90.0f; // Velocidad base del jugador (pixels/segundo)
|
||||||
@@ -304,6 +308,7 @@ class Player {
|
|||||||
int power_up_x_offset_ = 0; // Desplazamiento del sprite de PowerUp respecto al sprite del jugador
|
int power_up_x_offset_ = 0; // Desplazamiento del sprite de PowerUp respecto al sprite del jugador
|
||||||
int continue_counter_ = 10; // Contador para poder continuar
|
int continue_counter_ = 10; // Contador para poder continuar
|
||||||
int controller_index_ = 0; // Índice del array de mandos que utilizará para moverse
|
int controller_index_ = 0; // Índice del array de mandos que utilizará para moverse
|
||||||
|
size_t demo_file_ = 0; // Indice del fichero de datos para el modo demo
|
||||||
float name_entry_idle_time_accumulator_ = 0.0f; // Tiempo idle acumulado para poner nombre (milisegundos)
|
float name_entry_idle_time_accumulator_ = 0.0f; // Tiempo idle acumulado para poner nombre (milisegundos)
|
||||||
float name_entry_total_time_accumulator_ = 0.0f; // Tiempo total acumulado poniendo nombre (milisegundos)
|
float name_entry_total_time_accumulator_ = 0.0f; // Tiempo total acumulado poniendo nombre (milisegundos)
|
||||||
int step_counter_ = 0; // Cuenta los pasos para los estados en los que camina automáticamente
|
int step_counter_ = 0; // Cuenta los pasos para los estados en los que camina automáticamente
|
||||||
|
|||||||
@@ -12,13 +12,13 @@
|
|||||||
|
|
||||||
#include "asset.h" // Para Asset
|
#include "asset.h" // Para Asset
|
||||||
#include "color.h" // Para Color
|
#include "color.h" // Para Color
|
||||||
#include "version.h" // Para Version::APP_NAME y Version::GIT_HASH
|
|
||||||
#include "external/jail_audio.h" // Para JA_LoadMusic, JA_LoadSound, JA_DeleteMusic, JA_DeleteSound
|
#include "external/jail_audio.h" // Para JA_LoadMusic, JA_LoadSound, JA_DeleteMusic, JA_DeleteSound
|
||||||
#include "lang.h" // Para getText
|
#include "lang.h" // Para getText
|
||||||
#include "param.h" // Para Param, param, ParamResource, ParamGame
|
#include "param.h" // Para Param, param, ParamResource, ParamGame
|
||||||
#include "resource_helper.h" // Para ResourceHelper
|
#include "resource_helper.h" // Para ResourceHelper
|
||||||
#include "screen.h" // Para Screen
|
#include "screen.h" // Para Screen
|
||||||
#include "text.h" // Para Text
|
#include "text.h" // Para Text
|
||||||
|
#include "version.h" // Para Version::APP_NAME y Version::GIT_HASH
|
||||||
|
|
||||||
struct JA_Music_t; // lines 11-11
|
struct JA_Music_t; // lines 11-11
|
||||||
struct JA_Sound_t; // lines 12-12
|
struct JA_Sound_t; // lines 12-12
|
||||||
@@ -316,6 +316,11 @@ auto Resource::getAnimation(const std::string &name) -> AnimationsFileBuffer & {
|
|||||||
|
|
||||||
// Obtiene el fichero con los datos para el modo demostración a partir de un índice
|
// Obtiene el fichero con los datos para el modo demostración a partir de un índice
|
||||||
auto Resource::getDemoData(int index) -> DemoData& {
|
auto Resource::getDemoData(int index) -> DemoData& {
|
||||||
|
if (index < 0 || index >= static_cast<int>(demos_.size())) {
|
||||||
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Index %d out of range for demo data (size: %d)", index, static_cast<int>(demos_.size()));
|
||||||
|
static DemoData empty_demo;
|
||||||
|
return empty_demo;
|
||||||
|
}
|
||||||
return demos_.at(index);
|
return demos_.at(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -538,12 +543,13 @@ void Resource::loadAnimations() {
|
|||||||
// Carga los datos para el modo demostración
|
// Carga los datos para el modo demostración
|
||||||
void Resource::loadDemoData() {
|
void Resource::loadDemoData() {
|
||||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> DEMO FILES");
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> DEMO FILES");
|
||||||
|
auto list = Asset::get()->getListByType(Asset::Type::DEMODATA);
|
||||||
|
demos_.clear();
|
||||||
|
|
||||||
constexpr std::array<const char *, 2> DEMO_FILES = {"demo1.bin", "demo2.bin"};
|
for (const auto& l : list) {
|
||||||
|
auto name = getFileName(l);
|
||||||
for (const auto &file : DEMO_FILES) {
|
updateLoadingProgress(name);
|
||||||
updateLoadingProgress(file);
|
demos_.emplace_back(loadDemoDataFromFile(l));
|
||||||
demos_.emplace_back(loadDemoDataFromFile(Asset::get()->get(file)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -836,12 +842,11 @@ void Resource::checkEvents() {
|
|||||||
// Carga los datos para el modo demostración (sin mostrar progreso)
|
// Carga los datos para el modo demostración (sin mostrar progreso)
|
||||||
void Resource::loadDemoDataQuiet() {
|
void Resource::loadDemoDataQuiet() {
|
||||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> DEMO FILES (quiet load)");
|
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "\n>> DEMO FILES (quiet load)");
|
||||||
|
auto list = Asset::get()->getListByType(Asset::Type::DEMODATA);
|
||||||
|
demos_.clear();
|
||||||
|
|
||||||
constexpr std::array<const char *, 2> DEMO_FILES = {"demo1.bin", "demo2.bin"};
|
for (const auto& l : list) {
|
||||||
|
demos_.emplace_back(loadDemoDataFromFile(l));
|
||||||
for (const auto &file : DEMO_FILES) {
|
|
||||||
demos_.emplace_back(loadDemoDataFromFile(Asset::get()->get(file)));
|
|
||||||
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "Demo file loaded: %s", file);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -217,6 +217,10 @@ void Screen::renderInfo() {
|
|||||||
// FPS
|
// FPS
|
||||||
const std::string FPS_TEXT = std::to_string(fps_.last_value) + " FPS";
|
const std::string FPS_TEXT = std::to_string(fps_.last_value) + " FPS";
|
||||||
debug_info_.text->writeDX(Text::COLOR | Text::STROKE, param.game.width - debug_info_.text->length(FPS_TEXT) - 2, 1 + debug_info_.text->getCharacterSize(), FPS_TEXT, 1, param.debug.color, 1, param.debug.color.DARKEN(150));
|
debug_info_.text->writeDX(Text::COLOR | Text::STROKE, param.game.width - debug_info_.text->length(FPS_TEXT) - 2, 1 + debug_info_.text->getCharacterSize(), FPS_TEXT, 1, param.debug.color, 1, param.debug.color.DARKEN(150));
|
||||||
|
#ifdef RECORDING
|
||||||
|
// RECORDING
|
||||||
|
debug_info_.text->writeDX(Text::COLOR | Text::STROKE, param.game.width - debug_info_.text->length("RECORDING"), 2*(1 + debug_info_.text->getCharacterSize()), "RECORDING", 1, param.debug.color, 1, param.debug.color.DARKEN(150));
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -2,12 +2,13 @@
|
|||||||
|
|
||||||
#include <SDL3/SDL.h> // Para SDL_GetTicks, SDL_SetRenderTarget, SDL_CreateTexture, SDL_Delay, SDL_DestroyTexture, SDL_EventType, SDL_GetRenderTarget, SDL_PollEvent, SDL_RenderTexture, SDL_SetTextureBlendMode, SDL_BLENDMODE_BLEND, SDL_Event, SDL_PixelFormat, SDL_Point, SDL_TextureAccess
|
#include <SDL3/SDL.h> // Para SDL_GetTicks, SDL_SetRenderTarget, SDL_CreateTexture, SDL_Delay, SDL_DestroyTexture, SDL_EventType, SDL_GetRenderTarget, SDL_PollEvent, SDL_RenderTexture, SDL_SetTextureBlendMode, SDL_BLENDMODE_BLEND, SDL_Event, SDL_PixelFormat, SDL_Point, SDL_TextureAccess
|
||||||
|
|
||||||
#include <algorithm> // Para find, clamp, find_if, min
|
#include <algorithm> // Para find, clamp, find_if, min, std::shuffle, std::iota
|
||||||
#include <array> // Para array
|
#include <array> // Para array
|
||||||
#include <cstdlib> // Para rand, size_t
|
#include <cstdlib> // Para rand, size_t
|
||||||
#include <functional> // Para function
|
#include <functional> // Para function
|
||||||
#include <iterator> // Para size
|
#include <iterator> // Para size
|
||||||
#include <memory> // Para shared_ptr, unique_ptr, __shared_ptr_access, allocator, make_unique, operator==, make_shared
|
#include <memory> // Para shared_ptr, unique_ptr, __shared_ptr_access, allocator, make_unique, operator==, make_shared
|
||||||
|
#include <random> // std::random_device, std::default_random_engine
|
||||||
#include <utility> // Para move
|
#include <utility> // Para move
|
||||||
|
|
||||||
#include "asset.h" // Para Asset
|
#include "asset.h" // Para Asset
|
||||||
@@ -48,7 +49,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
Game::Game(Player::Id player_id, int current_stage, bool demo)
|
Game::Game(Player::Id player_id, int current_stage, bool demo_enabled)
|
||||||
: renderer_(Screen::get()->getRenderer()),
|
: renderer_(Screen::get()->getRenderer()),
|
||||||
screen_(Screen::get()),
|
screen_(Screen::get()),
|
||||||
input_(Input::get()),
|
input_(Input::get()),
|
||||||
@@ -62,7 +63,7 @@ Game::Game(Player::Id player_id, int current_stage, bool demo)
|
|||||||
tabe_(std::make_unique<Tabe>()),
|
tabe_(std::make_unique<Tabe>()),
|
||||||
hit_(Hit(Resource::get()->getTexture("hit.png"))) {
|
hit_(Hit(Resource::get()->getTexture("hit.png"))) {
|
||||||
// Pasa variables
|
// Pasa variables
|
||||||
demo_.enabled = demo;
|
demo_.enabled = demo_enabled;
|
||||||
|
|
||||||
// Otras variables
|
// Otras variables
|
||||||
Section::name = Section::Name::GAME;
|
Section::name = Section::Name::GAME;
|
||||||
@@ -83,7 +84,9 @@ Game::Game(Player::Id player_id, int current_stage, bool demo)
|
|||||||
fade_in_->setPostDuration(0);
|
fade_in_->setPostDuration(0);
|
||||||
fade_in_->setType(Fade::Type::RANDOM_SQUARE2);
|
fade_in_->setType(Fade::Type::RANDOM_SQUARE2);
|
||||||
fade_in_->setMode(Fade::Mode::IN);
|
fade_in_->setMode(Fade::Mode::IN);
|
||||||
|
#ifndef RECORDING
|
||||||
fade_in_->activate();
|
fade_in_->activate();
|
||||||
|
#endif
|
||||||
|
|
||||||
fade_out_->setColor(param.fade.color);
|
fade_out_->setColor(param.fade.color);
|
||||||
fade_out_->setPostDuration(param.fade.post_duration_ms);
|
fade_out_->setPostDuration(param.fade.post_duration_ms);
|
||||||
@@ -109,6 +112,9 @@ Game::Game(Player::Id player_id, int current_stage, bool demo)
|
|||||||
pause_manager_->setServiceMenuPause(is_active);
|
pause_manager_->setServiceMenuPause(is_active);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
#ifdef RECORDING
|
||||||
|
setState(State::PLAYING);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
Game::~Game() {
|
Game::~Game() {
|
||||||
@@ -402,6 +408,7 @@ void Game::destroyAllItems() {
|
|||||||
|
|
||||||
// Comprueba la colisión entre el jugador y los globos activos
|
// Comprueba la colisión entre el jugador y los globos activos
|
||||||
auto Game::checkPlayerBalloonCollision(std::shared_ptr<Player>& player) -> std::shared_ptr<Balloon> {
|
auto Game::checkPlayerBalloonCollision(std::shared_ptr<Player>& player) -> std::shared_ptr<Balloon> {
|
||||||
|
#ifndef RECORDING
|
||||||
for (auto& balloon : balloon_manager_->getBalloons()) {
|
for (auto& balloon : balloon_manager_->getBalloons()) {
|
||||||
if (!balloon->isInvulnerable() && !balloon->isPowerBall()) {
|
if (!balloon->isInvulnerable() && !balloon->isPowerBall()) {
|
||||||
if (checkCollision(player->getCollider(), balloon->getCollider())) {
|
if (checkCollision(player->getCollider(), balloon->getCollider())) {
|
||||||
@@ -409,6 +416,7 @@ auto Game::checkPlayerBalloonCollision(std::shared_ptr<Player> &player) -> std::
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
return nullptr; // No se ha producido ninguna colisión
|
return nullptr; // No se ha producido ninguna colisión
|
||||||
}
|
}
|
||||||
@@ -909,9 +917,9 @@ void Game::update(float deltaTime) {
|
|||||||
screen_->update(deltaTime); // Actualiza el objeto screen
|
screen_->update(deltaTime); // Actualiza el objeto screen
|
||||||
Audio::update(); // Actualiza el objeto audio
|
Audio::update(); // Actualiza el objeto audio
|
||||||
|
|
||||||
updateDemo();
|
updateDemo(deltaTime);
|
||||||
#ifdef RECORDING
|
#ifdef RECORDING
|
||||||
updateRecording();
|
updateRecording(deltaTime);
|
||||||
#endif
|
#endif
|
||||||
updateGameStates(deltaTime);
|
updateGameStates(deltaTime);
|
||||||
fillCanvas();
|
fillCanvas();
|
||||||
@@ -1012,10 +1020,8 @@ void Game::run() {
|
|||||||
last_time_ = SDL_GetTicks();
|
last_time_ = SDL_GetTicks();
|
||||||
|
|
||||||
while (Section::name == Section::Name::GAME) {
|
while (Section::name == Section::Name::GAME) {
|
||||||
#ifndef RECORDING
|
|
||||||
checkInput();
|
|
||||||
#endif
|
|
||||||
const float delta_time = calculateDeltaTime();
|
const float delta_time = calculateDeltaTime();
|
||||||
|
checkInput();
|
||||||
update(delta_time);
|
update(delta_time);
|
||||||
handleEvents(); // Tiene que ir antes del render
|
handleEvents(); // Tiene que ir antes del render
|
||||||
render();
|
render();
|
||||||
@@ -1287,19 +1293,16 @@ void Game::demoHandlePassInput() {
|
|||||||
|
|
||||||
// Gestiona las entradas de los jugadores en el modo demo, incluyendo movimientos y disparos automáticos.
|
// Gestiona las entradas de los jugadores en el modo demo, incluyendo movimientos y disparos automáticos.
|
||||||
void Game::demoHandleInput() {
|
void Game::demoHandleInput() {
|
||||||
int index = 0;
|
|
||||||
for (const auto& player : players_) {
|
for (const auto& player : players_) {
|
||||||
if (player->isPlaying()) {
|
if (player->isPlaying()) {
|
||||||
// Maneja el input específico del jugador en modo demo.
|
demoHandlePlayerInput(player, player->getDemoFile()); // Maneja el input específico del jugador en modo demo.
|
||||||
demoHandlePlayerInput(player, index);
|
|
||||||
}
|
}
|
||||||
++index;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Procesa las entradas para un jugador específico durante el modo demo.
|
// Procesa las entradas para un jugador específico durante el modo demo.
|
||||||
void Game::demoHandlePlayerInput(const std::shared_ptr<Player>& player, int index) {
|
void Game::demoHandlePlayerInput(const std::shared_ptr<Player>& player, int index) {
|
||||||
const auto &demo_data = demo_.data.at(index).at(demo_.counter);
|
const auto& demo_data = demo_.data.at(index).at(demo_.index);
|
||||||
|
|
||||||
if (demo_data.left == 1) {
|
if (demo_data.left == 1) {
|
||||||
player->setInput(Input::Action::LEFT);
|
player->setInput(Input::Action::LEFT);
|
||||||
@@ -1514,21 +1517,42 @@ void Game::handleNameInput(const std::shared_ptr<Player> &player) {
|
|||||||
|
|
||||||
// Inicializa las variables para el modo DEMO
|
// Inicializa las variables para el modo DEMO
|
||||||
void Game::initDemo(Player::Id player_id) {
|
void Game::initDemo(Player::Id player_id) {
|
||||||
|
#ifdef RECORDING
|
||||||
|
// En modo grabación, inicializar vector vacío para almacenar teclas
|
||||||
|
demo_.data.emplace_back(); // Vector vacío para grabación
|
||||||
|
demo_.data.at(0).reserve(TOTAL_DEMO_DATA); // Reservar espacio para 2000 elementos
|
||||||
|
#endif
|
||||||
|
|
||||||
if (demo_.enabled) {
|
if (demo_.enabled) {
|
||||||
// Cambia el estado del juego
|
// Cambia el estado del juego
|
||||||
setState(State::PLAYING);
|
setState(State::PLAYING);
|
||||||
|
|
||||||
// Aleatoriza la asignación del fichero con los datos del modo demostracion
|
#ifndef RECORDING
|
||||||
const auto DEMO1 = rand() % 2;
|
// En modo juego: cargar todas las demos y asignar una diferente a cada jugador
|
||||||
const auto DEMO2 = (DEMO1 == 0) ? 1 : 0;
|
auto const NUM_DEMOS = Asset::get()->getListByType(Asset::Type::DEMODATA).size();
|
||||||
demo_.data.emplace_back(Resource::get()->getDemoData(DEMO1));
|
for (size_t num_demo = 0; num_demo < NUM_DEMOS; ++num_demo) {
|
||||||
demo_.data.emplace_back(Resource::get()->getDemoData(DEMO2));
|
demo_.data.emplace_back(Resource::get()->getDemoData(num_demo));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Crear índices mezclados para asignación aleatoria
|
||||||
|
std::vector<size_t> demo_indices(NUM_DEMOS);
|
||||||
|
std::iota(demo_indices.begin(), demo_indices.end(), 0);
|
||||||
|
std::random_device rd;
|
||||||
|
std::default_random_engine rng(rd());
|
||||||
|
std::shuffle(demo_indices.begin(), demo_indices.end(), rng);
|
||||||
|
|
||||||
|
// Asignar demos a jugadores (round-robin si hay más jugadores que demos)
|
||||||
|
for (size_t i = 0; i < players_.size(); ++i) {
|
||||||
|
size_t demo_index = demo_indices[i % NUM_DEMOS];
|
||||||
|
players_.at(i)->setDemoFile(demo_index);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Selecciona una pantalla al azar
|
// Selecciona una pantalla al azar
|
||||||
constexpr auto NUM_DEMOS = 3;
|
constexpr auto NUM_STAGES = 3;
|
||||||
const auto DEMO = rand() % NUM_DEMOS;
|
const auto STAGE = rand() % NUM_STAGES;
|
||||||
constexpr std::array<int, NUM_DEMOS> STAGES = {0, 3, 5};
|
constexpr std::array<int, NUM_STAGES> STAGES = {0, 3, 5};
|
||||||
stage_manager_->jumpToStage(STAGES.at(DEMO));
|
stage_manager_->jumpToStage(STAGES.at(STAGE));
|
||||||
|
|
||||||
// Activa o no al otro jugador
|
// Activa o no al otro jugador
|
||||||
if (rand() % 3 != 0) {
|
if (rand() % 3 != 0) {
|
||||||
@@ -1562,7 +1586,7 @@ void Game::initDemo(Player::Id player_id) {
|
|||||||
#else
|
#else
|
||||||
demo_.recording = false;
|
demo_.recording = false;
|
||||||
#endif
|
#endif
|
||||||
demo_.counter = 0;
|
demo_.index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa el marcador
|
// Inicializa el marcador
|
||||||
@@ -1617,7 +1641,11 @@ void Game::initPlayers(Player::Id player_id) {
|
|||||||
// Crea al jugador uno y lo pone en modo espera
|
// Crea al jugador uno y lo pone en modo espera
|
||||||
Player::Config config_player1{
|
Player::Config config_player1{
|
||||||
.id = Player::Id::PLAYER1,
|
.id = Player::Id::PLAYER1,
|
||||||
|
#ifdef RECORDING
|
||||||
|
.x = param.game.play_area.center_x - (Player::WIDTH / 2),
|
||||||
|
#else
|
||||||
.x = param.game.play_area.first_quarter_x - (Player::WIDTH / 2),
|
.x = param.game.play_area.first_quarter_x - (Player::WIDTH / 2),
|
||||||
|
#endif
|
||||||
.y = Y,
|
.y = Y,
|
||||||
.demo = demo_.enabled,
|
.demo = demo_.enabled,
|
||||||
.play_area = ¶m.game.play_area.rect,
|
.play_area = ¶m.game.play_area.rect,
|
||||||
@@ -1634,7 +1662,11 @@ void Game::initPlayers(Player::Id player_id) {
|
|||||||
player1->setName(Lang::getText("[SCOREBOARD] 1"));
|
player1->setName(Lang::getText("[SCOREBOARD] 1"));
|
||||||
player1->setGamepad(Options::gamepad_manager.getGamepad(Player::Id::PLAYER1).instance);
|
player1->setGamepad(Options::gamepad_manager.getGamepad(Player::Id::PLAYER1).instance);
|
||||||
player1->setUsesKeyboard(Player::Id::PLAYER1 == Options::keyboard.player_id);
|
player1->setUsesKeyboard(Player::Id::PLAYER1 == Options::keyboard.player_id);
|
||||||
|
#ifdef RECORDING
|
||||||
|
player1->setPlayingState(Player::State::PLAYING);
|
||||||
|
#else
|
||||||
player1->setPlayingState((player_id == Player::Id::BOTH_PLAYERS || player_id == Player::Id::PLAYER1) ? STATE : Player::State::WAITING);
|
player1->setPlayingState((player_id == Player::Id::BOTH_PLAYERS || player_id == Player::Id::PLAYER1) ? STATE : Player::State::WAITING);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Crea al jugador dos y lo pone en modo espera
|
// Crea al jugador dos y lo pone en modo espera
|
||||||
Player::Config config_player2{
|
Player::Config config_player2{
|
||||||
@@ -1692,7 +1724,7 @@ void Game::stopMusic() const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Actualiza las variables durante el modo demo
|
// Actualiza las variables durante el modo demo
|
||||||
void Game::updateDemo() {
|
void Game::updateDemo(float deltaTime) {
|
||||||
if (demo_.enabled) {
|
if (demo_.enabled) {
|
||||||
balloon_manager_->setCreationTimeEnabled(balloon_manager_->getNumBalloons() != 0);
|
balloon_manager_->setCreationTimeEnabled(balloon_manager_->getNumBalloons() != 0);
|
||||||
|
|
||||||
@@ -1700,16 +1732,12 @@ void Game::updateDemo() {
|
|||||||
fade_in_->update();
|
fade_in_->update();
|
||||||
fade_out_->update();
|
fade_out_->update();
|
||||||
|
|
||||||
// Incrementa el contador de la demo cada 1/60 segundos (16.67ms)
|
// Actualiza el contador de tiempo y el índice
|
||||||
static float demo_frame_timer = 0.0f;
|
demo_.elapsed_s += deltaTime;
|
||||||
demo_frame_timer += calculateDeltaTime();
|
demo_.index = static_cast<int>(demo_.elapsed_s * 60.0F);
|
||||||
if (demo_frame_timer >= 0.01667f && demo_.counter < TOTAL_DEMO_DATA) {
|
|
||||||
demo_.counter++;
|
|
||||||
demo_frame_timer -= 0.01667f; // Mantener precisión acumulada
|
|
||||||
}
|
|
||||||
|
|
||||||
// Activa el fundido antes de acabar con los datos de la demo
|
// Activa el fundido antes de acabar con los datos de la demo
|
||||||
if (demo_.counter == TOTAL_DEMO_DATA - 200) {
|
if (demo_.index == TOTAL_DEMO_DATA - 200) {
|
||||||
fade_out_->setType(Fade::Type::RANDOM_SQUARE2);
|
fade_out_->setType(Fade::Type::RANDOM_SQUARE2);
|
||||||
fade_out_->setPostDuration(param.fade.post_duration_ms);
|
fade_out_->setPostDuration(param.fade.post_duration_ms);
|
||||||
fade_out_->activate();
|
fade_out_->activate();
|
||||||
@@ -1725,22 +1753,28 @@ void Game::updateDemo() {
|
|||||||
|
|
||||||
#ifdef RECORDING
|
#ifdef RECORDING
|
||||||
// Actualiza las variables durante el modo de grabación
|
// Actualiza las variables durante el modo de grabación
|
||||||
void Game::updateRecording() {
|
void Game::updateRecording(float deltaTime) {
|
||||||
// Solo mira y guarda el input en cada update
|
// Actualiza el contador de tiempo y el índice
|
||||||
checkInput();
|
demo_.elapsed_s += deltaTime;
|
||||||
|
demo_.index = static_cast<int>(demo_.elapsed_s * 60.0F);
|
||||||
|
|
||||||
// Incrementa el contador de la demo cada 1/60 segundos (16.67ms)
|
if (demo_.index >= TOTAL_DEMO_DATA) {
|
||||||
static float recording_frame_timer = 0.0f;
|
Section::name = Section::Name::QUIT;
|
||||||
recording_frame_timer += calculateDeltaTime();
|
return;
|
||||||
if (recording_frame_timer >= 0.01667f && demo_.counter < TOTAL_DEMO_DATA) {
|
|
||||||
demo_.counter++;
|
|
||||||
recording_frame_timer -= 0.01667f; // Mantener precisión acumulada
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Si se ha llenado el vector con datos, sale del programa
|
// Almacenar las teclas del frame actual en el vector de grabación
|
||||||
else {
|
if (demo_.index < TOTAL_DEMO_DATA && demo_.data.size() > 0) {
|
||||||
section::name = section::Name::QUIT;
|
// Asegurar que el vector tenga el tamaño suficiente
|
||||||
return;
|
if (demo_.data.at(0).size() <= static_cast<size_t>(demo_.index)) {
|
||||||
|
demo_.data.at(0).resize(demo_.index + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Almacenar las teclas del frame actual
|
||||||
|
demo_.data.at(0).at(demo_.index) = demo_.keys;
|
||||||
|
|
||||||
|
// Resetear las teclas para el siguiente frame
|
||||||
|
demo_.keys = DemoKeys();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ class Game {
|
|||||||
static constexpr bool DEMO_ON = true; // Modo demo activado
|
static constexpr bool DEMO_ON = true; // Modo demo activado
|
||||||
|
|
||||||
// --- Constructor y destructor ---
|
// --- Constructor y destructor ---
|
||||||
Game(Player::Id player_id, int current_stage, bool demo); // Constructor principal
|
Game(Player::Id player_id, int current_stage, bool demo_enabled); // Constructor principal
|
||||||
~Game(); // Destructor
|
~Game(); // Destructor
|
||||||
|
|
||||||
// --- Bucle principal ---
|
// --- Bucle principal ---
|
||||||
@@ -325,7 +325,7 @@ class Game {
|
|||||||
|
|
||||||
// --- Modo demostración ---
|
// --- Modo demostración ---
|
||||||
void initDemo(Player::Id player_id); // Inicializa variables para el modo demostración
|
void initDemo(Player::Id player_id); // Inicializa variables para el modo demostración
|
||||||
void updateDemo(); // Actualiza lógica específica del modo demo
|
void updateDemo(float deltaTime); // Actualiza lógica específica del modo demo
|
||||||
|
|
||||||
// --- Recursos y renderizado ---
|
// --- Recursos y renderizado ---
|
||||||
void setResources(); // Asigna texturas y animaciones a los objetos
|
void setResources(); // Asigna texturas y animaciones a los objetos
|
||||||
@@ -346,7 +346,7 @@ class Game {
|
|||||||
|
|
||||||
// SISTEMA DE GRABACIÓN (CONDICIONAL)
|
// SISTEMA DE GRABACIÓN (CONDICIONAL)
|
||||||
#ifdef RECORDING
|
#ifdef RECORDING
|
||||||
void updateRecording(); // Actualiza variables durante modo de grabación
|
void updateRecording(float deltaTime); // Actualiza variables durante modo de grabación
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// --- Depuración (solo en modo DEBUG) ---
|
// --- Depuración (solo en modo DEBUG) ---
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ Texture::Texture(SDL_Renderer *renderer, std::string path)
|
|||||||
surface_ = loadSurface(path_);
|
surface_ = loadSurface(path_);
|
||||||
|
|
||||||
// Añade la propia paleta del fichero a la lista
|
// Añade la propia paleta del fichero a la lista
|
||||||
addPaletteFromGifFile(path_);
|
addPaletteFromGifFile(path_, true); // Usar modo silencioso
|
||||||
|
|
||||||
// Crea la textura, establece el BlendMode y copia la surface a la textura
|
// Crea la textura, establece el BlendMode y copia la surface a la textura
|
||||||
createBlank(width_, height_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING);
|
createBlank(width_, height_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING);
|
||||||
@@ -301,7 +301,7 @@ void Texture::setPaletteColor(int palette, int index, Uint32 color) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Carga una paleta desde un fichero
|
// Carga una paleta desde un fichero
|
||||||
auto Texture::loadPaletteFromFile(const std::string &file_path) -> Palette {
|
auto Texture::loadPaletteFromFile(const std::string &file_path, bool quiet) -> Palette {
|
||||||
Palette palette;
|
Palette palette;
|
||||||
|
|
||||||
std::vector<Uint8> buffer;
|
std::vector<Uint8> buffer;
|
||||||
@@ -329,7 +329,9 @@ auto Texture::loadPaletteFromFile(const std::string &file_path) -> Palette {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!quiet) {
|
||||||
printWithDots("Palette : ", getFileName(file_path), "[ LOADED ]");
|
printWithDots("Palette : ", getFileName(file_path), "[ LOADED ]");
|
||||||
|
}
|
||||||
|
|
||||||
// Usar la nueva función loadPalette, que devuelve un vector<uint32_t>
|
// Usar la nueva función loadPalette, que devuelve un vector<uint32_t>
|
||||||
GIF::Gif gif;
|
GIF::Gif gif;
|
||||||
@@ -349,14 +351,14 @@ auto Texture::loadPaletteFromFile(const std::string &file_path) -> Palette {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Añade una paleta a la lista
|
// Añade una paleta a la lista
|
||||||
void Texture::addPaletteFromGifFile(const std::string &path) {
|
void Texture::addPaletteFromGifFile(const std::string &path, bool quiet) {
|
||||||
palettes_.emplace_back(loadPaletteFromFile(path));
|
palettes_.emplace_back(loadPaletteFromFile(path, quiet));
|
||||||
setPaletteColor(palettes_.size() - 1, 0, 0x00000000);
|
setPaletteColor(palettes_.size() - 1, 0, 0x00000000);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Añade una paleta a la lista
|
// Añade una paleta a la lista
|
||||||
void Texture::addPaletteFromPalFile(const std::string &path) {
|
void Texture::addPaletteFromPalFile(const std::string &path) {
|
||||||
palettes_.emplace_back(readPalFile(path));
|
palettes_.emplace_back(readPalFile(path, true)); // Usar modo silencioso
|
||||||
setPaletteColor(palettes_.size() - 1, 0, 0x00000000);
|
setPaletteColor(palettes_.size() - 1, 0, 0x00000000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -372,7 +374,7 @@ void Texture::setPalette(size_t palette) {
|
|||||||
auto Texture::getRenderer() -> SDL_Renderer * { return renderer_; }
|
auto Texture::getRenderer() -> SDL_Renderer * { return renderer_; }
|
||||||
|
|
||||||
// Carga una paleta desde un archivo .pal
|
// Carga una paleta desde un archivo .pal
|
||||||
auto Texture::readPalFile(const std::string &file_path) -> Palette {
|
auto Texture::readPalFile(const std::string &file_path, bool quiet) -> Palette {
|
||||||
Palette palette{};
|
Palette palette{};
|
||||||
palette.fill(0); // Inicializar todo con 0 (transparente por defecto)
|
palette.fill(0); // Inicializar todo con 0 (transparente por defecto)
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ class Texture {
|
|||||||
void setAlpha(Uint8 alpha); // Establece el alpha para la modulación
|
void setAlpha(Uint8 alpha); // Establece el alpha para la modulación
|
||||||
|
|
||||||
// --- Paletas ---
|
// --- Paletas ---
|
||||||
void addPaletteFromGifFile(const std::string &path); // Añade una paleta a la lista
|
void addPaletteFromGifFile(const std::string &path, bool quiet = false); // Añade una paleta a la lista
|
||||||
void addPaletteFromPalFile(const std::string &path); // Añade una paleta a la lista
|
void addPaletteFromPalFile(const std::string &path); // Añade una paleta a la lista
|
||||||
void setPaletteColor(int palette, int index, Uint32 color); // Establece un color de la paleta
|
void setPaletteColor(int palette, int index, Uint32 color); // Establece un color de la paleta
|
||||||
void setPalette(size_t palette); // Cambia la paleta de la textura
|
void setPalette(size_t palette); // Cambia la paleta de la textura
|
||||||
@@ -76,8 +76,8 @@ class Texture {
|
|||||||
// --- Métodos internos ---
|
// --- Métodos internos ---
|
||||||
auto loadSurface(const std::string &file_path) -> std::shared_ptr<Surface>; // Crea una surface desde un fichero .gif
|
auto loadSurface(const std::string &file_path) -> std::shared_ptr<Surface>; // Crea una surface desde un fichero .gif
|
||||||
void flipSurface(); // Vuelca la surface en la textura
|
void flipSurface(); // Vuelca la surface en la textura
|
||||||
static auto loadPaletteFromFile(const std::string &file_path) -> Palette; // Carga una paleta desde un fichero
|
static auto loadPaletteFromFile(const std::string &file_path, bool quiet = false) -> Palette; // Carga una paleta desde un fichero
|
||||||
void unloadTexture(); // Libera la memoria de la textura
|
void unloadTexture(); // Libera la memoria de la textura
|
||||||
void unloadSurface(); // Libera la surface actual
|
void unloadSurface(); // Libera la surface actual
|
||||||
static auto readPalFile(const std::string &file_path) -> Palette; // Carga una paleta desde un archivo .pal
|
static auto readPalFile(const std::string &file_path, bool quiet = false) -> Palette; // Carga una paleta desde un archivo .pal
|
||||||
};
|
};
|
||||||
@@ -363,7 +363,7 @@ bool saveDemoFile(const std::string &file_path, const DemoData &dd) {
|
|||||||
if (file) {
|
if (file) {
|
||||||
// Guarda los datos
|
// Guarda los datos
|
||||||
for (const auto &data : dd) {
|
for (const auto &data : dd) {
|
||||||
if (SDL_RWwrite(file, &data, sizeof(DemoKeys), 1) != 1) {
|
if (SDL_WriteIO(file, &data, sizeof(DemoKeys)) != sizeof(DemoKeys)) {
|
||||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error al escribir el fichero %s", getFileName(file_path).c_str());
|
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Error al escribir el fichero %s", getFileName(file_path).c_str());
|
||||||
success = false;
|
success = false;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -53,20 +53,19 @@ struct DemoKeys {
|
|||||||
using DemoData = std::vector<DemoKeys>;
|
using DemoData = std::vector<DemoKeys>;
|
||||||
|
|
||||||
struct Demo {
|
struct Demo {
|
||||||
bool enabled; // Indica si está activo el modo demo
|
bool enabled = false; // Indica si está activo el modo demo
|
||||||
bool recording; // Indica si está activado el modo para grabar la demo
|
bool recording = false; // Indica si está activado el modo para grabar la demo
|
||||||
int counter; // Contador para el modo demo
|
float elapsed_s = 0.0F; // Segundos transcurridos de demo
|
||||||
|
int index = 0; // Contador para el modo demo
|
||||||
DemoKeys keys; // Variable con las pulsaciones de teclas del modo demo
|
DemoKeys keys; // Variable con las pulsaciones de teclas del modo demo
|
||||||
std::vector<DemoData> data; // Vector con diferentes sets de datos con los movimientos para la demo
|
std::vector<DemoData> data; // Vector con diferentes sets de datos con los movimientos para la demo
|
||||||
|
|
||||||
Demo()
|
Demo() = default;
|
||||||
: enabled(false),
|
|
||||||
recording(false),
|
|
||||||
counter(0) {}
|
|
||||||
Demo(bool e, bool r, int c, const DemoKeys& k, const std::vector<DemoData>& d)
|
Demo(bool e, bool r, int c, const DemoKeys& k, const std::vector<DemoData>& d)
|
||||||
: enabled(e),
|
: enabled(e),
|
||||||
recording(r),
|
recording(r),
|
||||||
counter(c),
|
index(c),
|
||||||
keys(k),
|
keys(k),
|
||||||
data(d) {}
|
data(d) {}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user