corregit: el mode demo ja funciona correctament
This commit is contained in:
@@ -140,6 +140,9 @@ target_compile_options(${PROJECT_NAME} PRIVATE $<$<CONFIG:RELEASE>:-Os -ffunctio
|
||||
# Definir _DEBUG en modo 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
|
||||
if(WIN32)
|
||||
|
||||
@@ -40,7 +40,7 @@ scoreboard.skip_countdown_value 8 # Valor para saltar la cuenta atrás (
|
||||
|
||||
# --- TITLE ---
|
||||
title.press_start_position 180 # Posición Y del texto "Press Start"
|
||||
title.title_duration 14 # Duración de la pantalla de título (segundos)
|
||||
title.title_duration 1 # Duración de la pantalla de título (segundos)
|
||||
title.arcade_edition_position 123 # Posición Y del subtítulo "Arcade Edition"
|
||||
title.title_c_c_position 80 # Posición Y del título principal
|
||||
title.bg_color 41526F # Color de fondo en la sección titulo
|
||||
|
||||
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 |
@@ -42,7 +42,7 @@ Director::Director(int argc, std::span<char *> argv) {
|
||||
Section::name = Section::Name::GAME;
|
||||
Section::options = Section::Options::GAME_PLAY_1P;
|
||||
#elif _DEBUG
|
||||
Section::name = Section::Name::GAME;
|
||||
Section::name = Section::Name::TITLE;
|
||||
Section::options = Section::Options::GAME_PLAY_1P;
|
||||
#else // NORMAL GAME
|
||||
Section::name = Section::Name::LOGO;
|
||||
|
||||
@@ -217,6 +217,10 @@ void Screen::renderInfo() {
|
||||
// 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));
|
||||
#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
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
#endif
|
||||
|
||||
// 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()),
|
||||
screen_(Screen::get()),
|
||||
input_(Input::get()),
|
||||
@@ -62,7 +62,7 @@ Game::Game(Player::Id player_id, int current_stage, bool demo)
|
||||
tabe_(std::make_unique<Tabe>()),
|
||||
hit_(Hit(Resource::get()->getTexture("hit.png"))) {
|
||||
// Pasa variables
|
||||
demo_.enabled = demo;
|
||||
demo_.enabled = demo_enabled;
|
||||
|
||||
// Otras variables
|
||||
Section::name = Section::Name::GAME;
|
||||
@@ -83,7 +83,9 @@ Game::Game(Player::Id player_id, int current_stage, bool demo)
|
||||
fade_in_->setPostDuration(0);
|
||||
fade_in_->setType(Fade::Type::RANDOM_SQUARE2);
|
||||
fade_in_->setMode(Fade::Mode::IN);
|
||||
#ifndef RECORDING
|
||||
fade_in_->activate();
|
||||
#endif
|
||||
|
||||
fade_out_->setColor(param.fade.color);
|
||||
fade_out_->setPostDuration(param.fade.post_duration_ms);
|
||||
@@ -109,6 +111,9 @@ Game::Game(Player::Id player_id, int current_stage, bool demo)
|
||||
pause_manager_->setServiceMenuPause(is_active);
|
||||
}
|
||||
});
|
||||
#ifdef RECORDING
|
||||
setState(State::PLAYING);
|
||||
#endif
|
||||
}
|
||||
|
||||
Game::~Game() {
|
||||
@@ -402,6 +407,7 @@ void Game::destroyAllItems() {
|
||||
|
||||
// Comprueba la colisión entre el jugador y los globos activos
|
||||
auto Game::checkPlayerBalloonCollision(std::shared_ptr<Player>& player) -> std::shared_ptr<Balloon> {
|
||||
#ifndef RECORDING
|
||||
for (auto& balloon : balloon_manager_->getBalloons()) {
|
||||
if (!balloon->isInvulnerable() && !balloon->isPowerBall()) {
|
||||
if (checkCollision(player->getCollider(), balloon->getCollider())) {
|
||||
@@ -409,6 +415,7 @@ auto Game::checkPlayerBalloonCollision(std::shared_ptr<Player> &player) -> std::
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return nullptr; // No se ha producido ninguna colisión
|
||||
}
|
||||
@@ -909,9 +916,9 @@ void Game::update(float deltaTime) {
|
||||
screen_->update(deltaTime); // Actualiza el objeto screen
|
||||
Audio::update(); // Actualiza el objeto audio
|
||||
|
||||
updateDemo();
|
||||
updateDemo(deltaTime);
|
||||
#ifdef RECORDING
|
||||
updateRecording();
|
||||
updateRecording(deltaTime);
|
||||
#endif
|
||||
updateGameStates(deltaTime);
|
||||
fillCanvas();
|
||||
@@ -1012,10 +1019,8 @@ void Game::run() {
|
||||
last_time_ = SDL_GetTicks();
|
||||
|
||||
while (Section::name == Section::Name::GAME) {
|
||||
#ifndef RECORDING
|
||||
checkInput();
|
||||
#endif
|
||||
const float delta_time = calculateDeltaTime();
|
||||
checkInput();
|
||||
update(delta_time);
|
||||
handleEvents(); // Tiene que ir antes del render
|
||||
render();
|
||||
@@ -1299,7 +1304,7 @@ void Game::demoHandleInput() {
|
||||
|
||||
// Procesa las entradas para un jugador específico durante el modo demo.
|
||||
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) {
|
||||
player->setInput(Input::Action::LEFT);
|
||||
@@ -1514,15 +1519,23 @@ void Game::handleNameInput(const std::shared_ptr<Player> &player) {
|
||||
|
||||
// Inicializa las variables para el modo DEMO
|
||||
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) {
|
||||
// Cambia el estado del juego
|
||||
setState(State::PLAYING);
|
||||
|
||||
// Aleatoriza la asignación del fichero con los datos del modo demostracion
|
||||
#ifndef RECORDING
|
||||
// Solo en modo reproducción: aleatoriza la asignación del fichero con los datos del modo demostracion
|
||||
const auto DEMO1 = rand() % 2;
|
||||
const auto DEMO2 = (DEMO1 == 0) ? 1 : 0;
|
||||
demo_.data.emplace_back(Resource::get()->getDemoData(DEMO1));
|
||||
demo_.data.emplace_back(Resource::get()->getDemoData(DEMO2));
|
||||
#endif
|
||||
|
||||
// Selecciona una pantalla al azar
|
||||
constexpr auto NUM_DEMOS = 3;
|
||||
@@ -1562,7 +1575,7 @@ void Game::initDemo(Player::Id player_id) {
|
||||
#else
|
||||
demo_.recording = false;
|
||||
#endif
|
||||
demo_.counter = 0;
|
||||
demo_.index = 0;
|
||||
}
|
||||
|
||||
// Inicializa el marcador
|
||||
@@ -1617,7 +1630,11 @@ void Game::initPlayers(Player::Id player_id) {
|
||||
// Crea al jugador uno y lo pone en modo espera
|
||||
Player::Config config_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),
|
||||
#endif
|
||||
.y = Y,
|
||||
.demo = demo_.enabled,
|
||||
.play_area = ¶m.game.play_area.rect,
|
||||
@@ -1634,7 +1651,11 @@ void Game::initPlayers(Player::Id player_id) {
|
||||
player1->setName(Lang::getText("[SCOREBOARD] 1"));
|
||||
player1->setGamepad(Options::gamepad_manager.getGamepad(Player::Id::PLAYER1).instance);
|
||||
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);
|
||||
#endif
|
||||
|
||||
// Crea al jugador dos y lo pone en modo espera
|
||||
Player::Config config_player2{
|
||||
@@ -1692,7 +1713,7 @@ void Game::stopMusic() const {
|
||||
}
|
||||
|
||||
// Actualiza las variables durante el modo demo
|
||||
void Game::updateDemo() {
|
||||
void Game::updateDemo(float deltaTime) {
|
||||
if (demo_.enabled) {
|
||||
balloon_manager_->setCreationTimeEnabled(balloon_manager_->getNumBalloons() != 0);
|
||||
|
||||
@@ -1700,16 +1721,12 @@ void Game::updateDemo() {
|
||||
fade_in_->update();
|
||||
fade_out_->update();
|
||||
|
||||
// Incrementa el contador de la demo cada 1/60 segundos (16.67ms)
|
||||
static float demo_frame_timer = 0.0f;
|
||||
demo_frame_timer += calculateDeltaTime();
|
||||
if (demo_frame_timer >= 0.01667f && demo_.counter < TOTAL_DEMO_DATA) {
|
||||
demo_.counter++;
|
||||
demo_frame_timer -= 0.01667f; // Mantener precisión acumulada
|
||||
}
|
||||
// Actualiza el contador de tiempo y el índice
|
||||
demo_.elapsed_s += deltaTime;
|
||||
demo_.index = static_cast<int>(demo_.elapsed_s * 60.0F);
|
||||
|
||||
// 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_->setPostDuration(param.fade.post_duration_ms);
|
||||
fade_out_->activate();
|
||||
@@ -1725,22 +1742,28 @@ void Game::updateDemo() {
|
||||
|
||||
#ifdef RECORDING
|
||||
// Actualiza las variables durante el modo de grabación
|
||||
void Game::updateRecording() {
|
||||
// Solo mira y guarda el input en cada update
|
||||
checkInput();
|
||||
void Game::updateRecording(float deltaTime) {
|
||||
// Actualiza el contador de tiempo y el índice
|
||||
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)
|
||||
static float recording_frame_timer = 0.0f;
|
||||
recording_frame_timer += calculateDeltaTime();
|
||||
if (recording_frame_timer >= 0.01667f && demo_.counter < TOTAL_DEMO_DATA) {
|
||||
demo_.counter++;
|
||||
recording_frame_timer -= 0.01667f; // Mantener precisión acumulada
|
||||
if (demo_.index >= TOTAL_DEMO_DATA) {
|
||||
Section::name = Section::Name::QUIT;
|
||||
return;
|
||||
}
|
||||
|
||||
// Si se ha llenado el vector con datos, sale del programa
|
||||
else {
|
||||
section::name = section::Name::QUIT;
|
||||
return;
|
||||
// Almacenar las teclas del frame actual en el vector de grabación
|
||||
if (demo_.index < TOTAL_DEMO_DATA && demo_.data.size() > 0) {
|
||||
// Asegurar que el vector tenga el tamaño suficiente
|
||||
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
|
||||
|
||||
@@ -56,7 +56,7 @@ class Game {
|
||||
static constexpr bool DEMO_ON = true; // Modo demo activado
|
||||
|
||||
// --- 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
|
||||
|
||||
// --- Bucle principal ---
|
||||
@@ -325,7 +325,7 @@ class Game {
|
||||
|
||||
// --- 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 ---
|
||||
void setResources(); // Asigna texturas y animaciones a los objetos
|
||||
@@ -346,7 +346,7 @@ class Game {
|
||||
|
||||
// SISTEMA DE GRABACIÓN (CONDICIONAL)
|
||||
#ifdef RECORDING
|
||||
void updateRecording(); // Actualiza variables durante modo de grabación
|
||||
void updateRecording(float deltaTime); // Actualiza variables durante modo de grabación
|
||||
#endif
|
||||
|
||||
// --- Depuración (solo en modo DEBUG) ---
|
||||
|
||||
@@ -363,7 +363,7 @@ bool saveDemoFile(const std::string &file_path, const DemoData &dd) {
|
||||
if (file) {
|
||||
// Guarda los datos
|
||||
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());
|
||||
success = false;
|
||||
break;
|
||||
|
||||
@@ -53,20 +53,19 @@ struct DemoKeys {
|
||||
using DemoData = std::vector<DemoKeys>;
|
||||
|
||||
struct Demo {
|
||||
bool enabled; // Indica si está activo el modo demo
|
||||
bool recording; // Indica si está activado el modo para grabar la demo
|
||||
int counter; // Contador para el modo demo
|
||||
bool enabled = false; // Indica si está activo el modo demo
|
||||
bool recording = false; // Indica si está activado el modo para grabar la 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
|
||||
std::vector<DemoData> data; // Vector con diferentes sets de datos con los movimientos para la demo
|
||||
|
||||
Demo()
|
||||
: enabled(false),
|
||||
recording(false),
|
||||
counter(0) {}
|
||||
Demo() = default;
|
||||
|
||||
Demo(bool e, bool r, int c, const DemoKeys& k, const std::vector<DemoData>& d)
|
||||
: enabled(e),
|
||||
recording(r),
|
||||
counter(c),
|
||||
index(c),
|
||||
keys(k),
|
||||
data(d) {}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user