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:
@@ -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 <algorithm> // Para find, clamp, find_if, min
|
||||
#include <algorithm> // Para find, clamp, find_if, min, std::shuffle, std::iota
|
||||
#include <array> // Para array
|
||||
#include <cstdlib> // Para rand, size_t
|
||||
#include <functional> // Para function
|
||||
#include <iterator> // Para size
|
||||
#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 "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.
|
||||
void Game::demoHandleInput() {
|
||||
int index = 0;
|
||||
for (const auto& player : players_) {
|
||||
if (player->isPlaying()) {
|
||||
// Maneja el input específico del jugador en modo demo.
|
||||
demoHandlePlayerInput(player, index);
|
||||
demoHandlePlayerInput(player, player->getDemoFile()); // Maneja el input específico del jugador en modo demo.
|
||||
}
|
||||
++index;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1530,18 +1528,31 @@ void Game::initDemo(Player::Id player_id) {
|
||||
setState(State::PLAYING);
|
||||
|
||||
#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));
|
||||
// En modo juego: cargar todas las demos y asignar una diferente a cada jugador
|
||||
auto const NUM_DEMOS = Asset::get()->getListByType(Asset::Type::DEMODATA).size();
|
||||
for (size_t num_demo = 0; num_demo < NUM_DEMOS; ++num_demo) {
|
||||
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
|
||||
constexpr auto NUM_DEMOS = 3;
|
||||
const auto DEMO = rand() % NUM_DEMOS;
|
||||
constexpr std::array<int, NUM_DEMOS> STAGES = {0, 3, 5};
|
||||
stage_manager_->jumpToStage(STAGES.at(DEMO));
|
||||
constexpr auto NUM_STAGES = 3;
|
||||
const auto STAGE = rand() % NUM_STAGES;
|
||||
constexpr std::array<int, NUM_STAGES> STAGES = {0, 3, 5};
|
||||
stage_manager_->jumpToStage(STAGES.at(STAGE));
|
||||
|
||||
// Activa o no al otro jugador
|
||||
if (rand() % 3 != 0) {
|
||||
|
||||
Reference in New Issue
Block a user