el modo demo ya funciona con las tres combinaciones de jugadores y con diferentes ficheros de demo

This commit is contained in:
2024-07-12 13:02:22 +02:00
parent 49d8232187
commit 55638e2997
4 changed files with 29 additions and 45 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

View File

@@ -6,8 +6,6 @@
#ifndef CONST_H #ifndef CONST_H
#define CONST_H #define CONST_H
#define RECORDING
// Tamaño de bloque // Tamaño de bloque
#define BLOCK 8 #define BLOCK 8
#define HALF_BLOCK BLOCK / 2 #define HALF_BLOCK BLOCK / 2

View File

@@ -34,23 +34,13 @@ Game::Game(int playerID, int currentStage, SDL_Renderer *renderer, Screen *scree
// Inicializa los vectores con los datos para la demo // Inicializa los vectores con los datos para la demo
if (demo) if (demo)
{ {
std::vector<demoKeys_t> tmp;
this->demo.dataFile.clear();
this->demo.dataFile.push_back(tmp);
this->demo.dataFile.push_back(tmp);
// Aleatoriza la asignación del fichero // Aleatoriza la asignación del fichero
const int index1 = rand() % 2; const int index1 = rand() % 2;
const int index2 = (index1 + 1) % 2; const int index2 = (index1 + 1) % 2;
loadDemoFile(asset->get("demo1.bin"), &this->demo.dataFile.at(index1)); loadDemoFile(asset->get("demo1.bin"), &this->demo.dataFile[index1]);
loadDemoFile(asset->get("demo2.bin"), &this->demo.dataFile.at(index2)); 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 // Establece la máxima puntuación desde fichero o desde las puntuaciones online
setHiScore(); setHiScore();
@@ -277,7 +267,7 @@ void Game::init(int playerID)
} }
// Activa o no al otro jugador // Activa o no al otro jugador
// if (rand() % 3 == 0) if (rand() % 3 == 0)
{ {
const int otherPlayer = playerID == 1 ? 2 : 1; const int otherPlayer = playerID == 1 ? 2 : 1;
players[otherPlayer - 1]->enable(true); players[otherPlayer - 1]->enable(true);
@@ -628,7 +618,7 @@ bool Game::loadScoreFile()
} }
// Carga el fichero de datos para la demo // Carga el fichero de datos para la demo
bool Game::loadDemoFile(std::string f, std::vector<demoKeys_t> *dataFile) bool Game::loadDemoFile(std::string f, demoKeys_t (*dataFile)[TOTAL_DEMO_DATA])
{ {
// Indicador de éxito en la carga // Indicador de éxito en la carga
bool success = true; bool success = true;
@@ -655,7 +645,6 @@ bool Game::loadDemoFile(std::string f, std::vector<demoKeys_t> *dataFile)
} }
// Inicializas los datos y los guarda en el fichero // Inicializas los datos y los guarda en el fichero
dataFile->clear();
for (int i = 0; i < TOTAL_DEMO_DATA; ++i) for (int i = 0; i < TOTAL_DEMO_DATA; ++i)
{ {
demoKeys_t tmp; demoKeys_t tmp;
@@ -665,7 +654,7 @@ bool Game::loadDemoFile(std::string f, std::vector<demoKeys_t> *dataFile)
tmp.fire = 0; tmp.fire = 0;
tmp.fireLeft = 0; tmp.fireLeft = 0;
tmp.fireRight = 0; tmp.fireRight = 0;
dataFile->push_back(tmp); (*dataFile)[i] = tmp;
SDL_RWwrite(file, &tmp, sizeof(demoKeys_t), 1); SDL_RWwrite(file, &tmp, sizeof(demoKeys_t), 1);
} }
@@ -690,15 +679,12 @@ bool Game::loadDemoFile(std::string f, std::vector<demoKeys_t> *dataFile)
std::cout << "Reading file " << filename.c_str() << std::endl; 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 // Lee todos los datos del fichero y los deja en el destino
for (int i = 0; i < TOTAL_DEMO_DATA; ++i) for (int i = 0; i < TOTAL_DEMO_DATA; ++i)
{ {
demoKeys_t tmp; demoKeys_t tmp;
SDL_RWread(file, &tmp, sizeof(demoKeys_t), 1); SDL_RWread(file, &tmp, sizeof(demoKeys_t), 1);
dataFile->push_back(tmp); (*dataFile)[i] = tmp;
} }
// Cierra el fichero // Cierra el fichero
@@ -2793,9 +2779,9 @@ void Game::checkInput()
// Modo Demo activo // Modo Demo activo
if (demo.enabled) if (demo.enabled)
{ {
int i = 0;
for (auto player : players) for (auto player : players)
{ {
int i = 0;
if (player->isAlive() && player->isEnabled()) if (player->isAlive() && player->isEnabled())
{ {
// Comprueba direcciones // Comprueba direcciones

View File

@@ -232,7 +232,7 @@ private:
bool loadScoreFile(); bool loadScoreFile();
// Carga el fichero de datos para la demo // Carga el fichero de datos para la demo
bool loadDemoFile(std::string fileName, std::vector<demoKeys_t> *dataFile); bool loadDemoFile(std::string fileName, demoKeys_t (*dataFile)[TOTAL_DEMO_DATA]);
// Guarda el fichero de puntos // Guarda el fichero de puntos
bool saveScoreFile(); bool saveScoreFile();