From 55638e2997158e580908f4bf50291ad5bfab6d58 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Fri, 12 Jul 2024 13:02:22 +0200 Subject: [PATCH] el modo demo ya funciona con las tres combinaciones de jugadores y con diferentes ficheros de demo --- data/config/demo1.bin | Bin 12000 -> 12000 bytes source/const.h | 2 -- source/game.cpp | 70 +++++++++++++++++------------------------- source/game.h | 2 +- 4 files changed, 29 insertions(+), 45 deletions(-) diff --git a/data/config/demo1.bin b/data/config/demo1.bin index d886e4add6a15e6e8a927a1e861e013024fe3adb..d17b069d53221949f1104e33c295dd5f496c45ea 100644 GIT binary patch literal 12000 zcmeHJZF|EY2u%O~pB|V*5m9+b>e^->`dH++Z)OM z1r{4XDp%XFnE4^Vcp?5>qPj2#N?lk@@524O!tT*dtG?+4o>%Rjz{{moy6NmD{SNE= z9F`hqI`7+If7a(t4acBSLJIt&scDp_9AU%N*zW3!6;@5k#7m~RH*xz+J0^mVMoTZk z6C*Q?V2NaleBRdQV2kk)+XC2Z757l_habh42CU~ww6Vpnb5pQKx*K&CPfgvRm zI!<&|9QhG!YQ)JK!Xl@aH-Jr)PF@eTQ0W${RCRwhjPz=4^jjdE< zGC1V3YdsO|tq{Q?tC#n|!qC+2d3~M{r0F?F7{OxiGi}oxn{Ka#$ns!~(*o0M(;@k* zu(OR^^q=8o;3Y0%H~Z@1JF*XBgiYlJCE;ptJC<`3Rw3wf9(ifzaLeVkVXvC{=aia@ zBCR{-5Ad0{^)AW$-JlMxMH{&StKsH)uHfZ0H8udRMy{9>!M550)lgllkc8Sx5(&L% zQit$Ka+=I{Jr7Ro=fz6Anh_1!{f<7;vzZn)YIG?$J{3W4{BBjga7~l literal 12000 zcmd^Bi*}?i2%Y)=pDrYNBm@wMnW*jAc5TAtKET=ie7+z2y8F*@eK)s=2D2ttVf~A9 zM};JAEBG&|i;n1tSf59=%8HVMMz+Ggd%nsyj;h;S=Ww9RS=oPRt-|(7R-ODH0dYJy zvh3JKus|#Fj`Vb5vvxJf=wzVh3$fy4jrfdu=S;;8POLaPI26y7wQbC$u|SEWS>jb# z6r9yOgavS#_X*g}T>i6SWJFV=vL-kpdH{>D<9F_7vy;I#`T2s@AQ!bb9ZSi`bCVT0 zcO(yPO~cmZ04!#>H;709dj6-)5)w5`Sw?vFf!t>v+78{A%5JrxvTB>Uj>!QPs7N*T&jvm0RKc72L^SeZaJy>@7J~c}WdH zHqI}@wq0=&8s)ZBwm1t6NE=*k`RM^JDywK<6Ig5SGDunDET(R%R8u8Uf7#Zq1>CWyfd+X-$n?C diff --git a/source/const.h b/source/const.h index 5d9c0f0..f16010a 100644 --- a/source/const.h +++ b/source/const.h @@ -6,8 +6,6 @@ #ifndef CONST_H #define CONST_H -#define RECORDING - // Tamaño de bloque #define BLOCK 8 #define HALF_BLOCK BLOCK / 2 diff --git a/source/game.cpp b/source/game.cpp index 1f5464b..025665e 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -34,23 +34,13 @@ Game::Game(int playerID, int currentStage, SDL_Renderer *renderer, Screen *scree // Inicializa los vectores con los datos para la demo if (demo) { - std::vector tmp; - this->demo.dataFile.clear(); - this->demo.dataFile.push_back(tmp); - this->demo.dataFile.push_back(tmp); - // Aleatoriza la asignación del fichero const int index1 = rand() % 2; const int index2 = (index1 + 1) % 2; - loadDemoFile(asset->get("demo1.bin"), &this->demo.dataFile.at(index1)); - loadDemoFile(asset->get("demo2.bin"), &this->demo.dataFile.at(index2)); + loadDemoFile(asset->get("demo1.bin"), &this->demo.dataFile[index1]); + loadDemoFile(asset->get("demo2.bin"), &this->demo.dataFile[index2]); } -#ifdef RECORDING - // Prepara el vector para recoger los datos - //this->demo.dataFile[0].clear(); -#endif - // Establece la máxima puntuación desde fichero o desde las puntuaciones online setHiScore(); @@ -277,7 +267,7 @@ void Game::init(int playerID) } // Activa o no al otro jugador - // if (rand() % 3 == 0) + if (rand() % 3 == 0) { const int otherPlayer = playerID == 1 ? 2 : 1; players[otherPlayer - 1]->enable(true); @@ -628,7 +618,7 @@ bool Game::loadScoreFile() } // Carga el fichero de datos para la demo -bool Game::loadDemoFile(std::string f, std::vector *dataFile) +bool Game::loadDemoFile(std::string f, demoKeys_t (*dataFile)[TOTAL_DEMO_DATA]) { // Indicador de éxito en la carga bool success = true; @@ -655,7 +645,6 @@ bool Game::loadDemoFile(std::string f, std::vector *dataFile) } // Inicializas los datos y los guarda en el fichero - dataFile->clear(); for (int i = 0; i < TOTAL_DEMO_DATA; ++i) { demoKeys_t tmp; @@ -665,7 +654,7 @@ bool Game::loadDemoFile(std::string f, std::vector *dataFile) tmp.fire = 0; tmp.fireLeft = 0; tmp.fireRight = 0; - dataFile->push_back(tmp); + (*dataFile)[i] = tmp; SDL_RWwrite(file, &tmp, sizeof(demoKeys_t), 1); } @@ -690,15 +679,12 @@ bool Game::loadDemoFile(std::string f, std::vector *dataFile) std::cout << "Reading file " << filename.c_str() << std::endl; } - // Inicializa el destino - dataFile->clear(); - // Lee todos los datos del fichero y los deja en el destino for (int i = 0; i < TOTAL_DEMO_DATA; ++i) { demoKeys_t tmp; SDL_RWread(file, &tmp, sizeof(demoKeys_t), 1); - dataFile->push_back(tmp); + (*dataFile)[i] = tmp; } // Cierra el fichero @@ -749,31 +735,31 @@ bool Game::saveDemoFile() const std::string p = asset->get("demo1.bin"); const std::string filename = p.substr(p.find_last_of("\\/") + 1); - SDL_RWops *file = SDL_RWFromFile(p.c_str(), "w+b"); - if (file != nullptr) + SDL_RWops *file = SDL_RWFromFile(p.c_str(), "w+b"); + if (file != nullptr) + { + // Guardamos los datos + for (int i = 0; i < TOTAL_DEMO_DATA; ++i) { - // Guardamos los datos - for (int i = 0; i < TOTAL_DEMO_DATA; ++i) - { - SDL_RWwrite(file, &demo.dataFile[0][i], sizeof(demoKeys_t), 1); - } - - if (options->console) - { - std::cout << "Writing file " << filename.c_str() << std::endl; - } - - // Cerramos el fichero - SDL_RWclose(file); + SDL_RWwrite(file, &demo.dataFile[0][i], sizeof(demoKeys_t), 1); } - else + + if (options->console) { - if (options->console) - { - std::cout << "Error: Unable to save " << filename.c_str() << " file! " << SDL_GetError() << std::endl; - } + std::cout << "Writing file " << filename.c_str() << std::endl; } - + + // Cerramos el fichero + SDL_RWclose(file); + } + else + { + if (options->console) + { + std::cout << "Error: Unable to save " << filename.c_str() << " file! " << SDL_GetError() << std::endl; + } + } + return success; } #endif @@ -2793,9 +2779,9 @@ void Game::checkInput() // Modo Demo activo if (demo.enabled) { + int i = 0; for (auto player : players) { - int i = 0; if (player->isAlive() && player->isEnabled()) { // Comprueba direcciones diff --git a/source/game.h b/source/game.h index 0066374..8d7bf4f 100644 --- a/source/game.h +++ b/source/game.h @@ -232,7 +232,7 @@ private: bool loadScoreFile(); // Carga el fichero de datos para la demo - bool loadDemoFile(std::string fileName, std::vector *dataFile); + bool loadDemoFile(std::string fileName, demoKeys_t (*dataFile)[TOTAL_DEMO_DATA]); // Guarda el fichero de puntos bool saveScoreFile();