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
#define CONST_H
#define RECORDING
// Tamaño de bloque
#define BLOCK 8
#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
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
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<demoKeys_t> *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<demoKeys_t> *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<demoKeys_t> *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<demoKeys_t> *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

View File

@@ -232,7 +232,7 @@ private:
bool loadScoreFile();
// 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
bool saveScoreFile();