repensada la forma d'asignar fitxers de demo als jugadors
refets els fitxers de demo i afegit un tercer fitxer
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -1292,13 +1293,10 @@ 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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1530,18 +1528,31 @@ void Game::initDemo(Player::Id player_id) {
|
|||||||
setState(State::PLAYING);
|
setState(State::PLAYING);
|
||||||
|
|
||||||
#ifndef RECORDING
|
#ifndef RECORDING
|
||||||
// Solo en modo reproducción: aleatoriza la asignación del fichero con los datos del modo demostracion
|
// En modo juego: cargar todas las demos y asignar una diferente a cada jugador
|
||||||
const auto DEMO1 = rand() % 2;
|
auto const NUM_DEMOS = Asset::get()->getListByType(Asset::Type::DEMODATA).size();
|
||||||
const auto DEMO2 = (DEMO1 == 0) ? 1 : 0;
|
for (size_t num_demo = 0; num_demo < NUM_DEMOS; ++num_demo) {
|
||||||
demo_.data.emplace_back(Resource::get()->getDemoData(DEMO1));
|
demo_.data.emplace_back(Resource::get()->getDemoData(num_demo));
|
||||||
demo_.data.emplace_back(Resource::get()->getDemoData(DEMO2));
|
}
|
||||||
|
|
||||||
|
// 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
|
#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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user