Arreglado el modo demo
Grabada una nueva demo
This commit is contained in:
160
source/game.cpp
160
source/game.cpp
@@ -54,7 +54,9 @@ Game::Game(int playerID, int currentStage, SDL_Renderer *renderer, Screen *scree
|
||||
Game::~Game()
|
||||
{
|
||||
saveScoreFile();
|
||||
#ifdef RECORDING
|
||||
saveDemoFile();
|
||||
#endif
|
||||
|
||||
// Elimina todos los objetos contenidos en vectores
|
||||
deleteAllVectorObjects();
|
||||
@@ -176,7 +178,8 @@ void Game::init(int playerID)
|
||||
Player *player2 = new Player((PLAY_AREA_CENTER_FIRST_QUARTER_X * ((1 * 2) + 1)) - 11, PLAY_AREA_BOTTOM - 24, renderer, playerTextures[1], playerAnimations);
|
||||
players.push_back(player2);
|
||||
|
||||
players[playerID]->enable(true);
|
||||
// playerID es player 1 o player 2
|
||||
players[playerID - 1]->enable(true);
|
||||
|
||||
// Variables relacionadas con la dificultad
|
||||
switch (difficulty)
|
||||
@@ -275,6 +278,9 @@ void Game::init(int playerID)
|
||||
|
||||
// Modo demo
|
||||
demo.recording = false;
|
||||
#ifdef RECORDING
|
||||
demo.recording = true;
|
||||
#endif
|
||||
demo.counter = 0;
|
||||
|
||||
// Inicializa el objeto para el fundido
|
||||
@@ -686,6 +692,7 @@ bool Game::saveScoreFile()
|
||||
return success;
|
||||
}
|
||||
|
||||
#ifdef RECORDING
|
||||
// Guarda el fichero de datos para la demo
|
||||
bool Game::saveDemoFile()
|
||||
{
|
||||
@@ -721,6 +728,7 @@ bool Game::saveDemoFile()
|
||||
}
|
||||
return success;
|
||||
}
|
||||
#endif
|
||||
|
||||
// Inicializa las formaciones enemigas
|
||||
void Game::initEnemyFormations()
|
||||
@@ -1520,26 +1528,27 @@ void Game::updatePlayers()
|
||||
{
|
||||
for (auto player : players)
|
||||
{
|
||||
player->update();
|
||||
|
||||
// Comprueba la colisión entre el jugador y los globos
|
||||
if (checkPlayerBalloonCollision(player))
|
||||
if (player->isEnabled())
|
||||
{
|
||||
if (player->isAlive())
|
||||
player->update();
|
||||
|
||||
// Comprueba la colisión entre el jugador y los globos
|
||||
if (checkPlayerBalloonCollision(player))
|
||||
{
|
||||
if (demo.enabled)
|
||||
{
|
||||
section->name = SECTION_PROG_HI_SCORE_TABLE;
|
||||
}
|
||||
else
|
||||
if (player->isAlive())
|
||||
{
|
||||
killPlayer(player);
|
||||
|
||||
if (demo.enabled)
|
||||
{
|
||||
section->name = SECTION_PROG_HI_SCORE_TABLE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba las colisiones entre el jugador y los items
|
||||
checkPlayerItemCollision(player);
|
||||
// Comprueba las colisiones entre el jugador y los items
|
||||
checkPlayerItemCollision(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1548,7 +1557,10 @@ void Game::renderPlayers()
|
||||
{
|
||||
for (auto player : players)
|
||||
{
|
||||
player->render();
|
||||
if (player->isEnabled())
|
||||
{
|
||||
player->render();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2390,6 +2402,11 @@ void Game::renderSmartSprites()
|
||||
// Acciones a realizar cuando el jugador muere
|
||||
void Game::killPlayer(Player *player)
|
||||
{
|
||||
if (!player->isEnabled())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!player->isInvulnerable())
|
||||
{
|
||||
if (player->hasExtraHit())
|
||||
@@ -2505,6 +2522,30 @@ void Game::update()
|
||||
// Actualiza el contador de juego
|
||||
counter++;
|
||||
|
||||
// Incrementa el contador de la demo
|
||||
if (demo.counter < TOTAL_DEMO_DATA)
|
||||
{
|
||||
demo.counter++;
|
||||
}
|
||||
else
|
||||
{
|
||||
section->name = SECTION_PROG_HI_SCORE_TABLE;
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef RECORDING
|
||||
checkInput();
|
||||
|
||||
if (demo.recording)
|
||||
{
|
||||
if (demo.counter >= TOTAL_DEMO_DATA)
|
||||
{
|
||||
section->name = SECTION_PROG_QUIT;
|
||||
return;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Comprueba si la música ha de estar sonando
|
||||
checkMusicStatus();
|
||||
|
||||
@@ -2677,19 +2718,13 @@ void Game::updateMenace()
|
||||
}
|
||||
|
||||
// Gestiona la entrada durante el juego
|
||||
void Game::checkGameInput()
|
||||
void Game::checkInput()
|
||||
{
|
||||
demo.keys.left = 0;
|
||||
demo.keys.right = 0;
|
||||
demo.keys.noInput = 0;
|
||||
demo.keys.fire = 0;
|
||||
demo.keys.fireLeft = 0;
|
||||
demo.keys.fireRight = 0;
|
||||
|
||||
// Comprueba las teclas que afectan al programa (solo para el primer jugador)
|
||||
if (input->checkInput(input_exit, REPEAT_FALSE))
|
||||
{
|
||||
section->name = SECTION_PROG_QUIT;
|
||||
return;
|
||||
}
|
||||
|
||||
else if (input->checkInput(input_pause, REPEAT_FALSE))
|
||||
@@ -2701,21 +2736,23 @@ void Game::checkGameInput()
|
||||
if (demo.enabled)
|
||||
{
|
||||
const int index = 0;
|
||||
// Comprueba direcciones
|
||||
if (demo.dataFile[demo.counter].left == 1)
|
||||
{
|
||||
players[index]->setInput(input_left);
|
||||
}
|
||||
|
||||
if (demo.dataFile[demo.counter].right == 1)
|
||||
else if (demo.dataFile[demo.counter].right == 1)
|
||||
{
|
||||
players[index]->setInput(input_right);
|
||||
}
|
||||
|
||||
if (demo.dataFile[demo.counter].noInput == 1)
|
||||
else if (demo.dataFile[demo.counter].noInput == 1)
|
||||
{
|
||||
players[index]->setInput(input_null);
|
||||
}
|
||||
|
||||
// Comprueba botones
|
||||
if (demo.dataFile[demo.counter].fire == 1)
|
||||
{
|
||||
if (players[index]->canFire())
|
||||
@@ -2726,7 +2763,7 @@ void Game::checkGameInput()
|
||||
}
|
||||
}
|
||||
|
||||
if (demo.dataFile[demo.counter].fireLeft == 1)
|
||||
else if (demo.dataFile[demo.counter].fireLeft == 1)
|
||||
{
|
||||
if (players[index]->canFire())
|
||||
{
|
||||
@@ -2736,7 +2773,7 @@ void Game::checkGameInput()
|
||||
}
|
||||
}
|
||||
|
||||
if (demo.dataFile[demo.counter].fireRight == 1)
|
||||
else if (demo.dataFile[demo.counter].fireRight == 1)
|
||||
{
|
||||
if (players[index]->canFire())
|
||||
{
|
||||
@@ -2746,40 +2783,37 @@ void Game::checkGameInput()
|
||||
}
|
||||
}
|
||||
|
||||
// Si pulsamos la tecla de salir, se acaba el programa
|
||||
if (input->checkInput(input_exit))
|
||||
{
|
||||
section->name = SECTION_PROG_QUIT;
|
||||
}
|
||||
// Si se pulsa cualquier tecla, se sale del modo demo
|
||||
else if (input->checkAnyInput())
|
||||
if (input->checkAnyButtonPressed())
|
||||
{
|
||||
section->name = SECTION_PROG_TITLE;
|
||||
}
|
||||
|
||||
// Incrementa el contador de la demo
|
||||
if (demo.counter < TOTAL_DEMO_DATA)
|
||||
{
|
||||
demo.counter++;
|
||||
}
|
||||
else
|
||||
{
|
||||
section->name = SECTION_PROG_HI_SCORE_TABLE;
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Modo Demo no activo
|
||||
else
|
||||
{
|
||||
#ifdef RECORDING
|
||||
// Resetea el teclado
|
||||
demo.keys.left = 0;
|
||||
demo.keys.right = 0;
|
||||
demo.keys.noInput = 0;
|
||||
demo.keys.fire = 0;
|
||||
demo.keys.fireLeft = 0;
|
||||
demo.keys.fireRight = 0;
|
||||
#endif
|
||||
int i = 0;
|
||||
for (auto player : players)
|
||||
{
|
||||
if (player->isAlive())
|
||||
if (player->isAlive() && player->isEnabled())
|
||||
{
|
||||
// Input a la izquierda
|
||||
if (input->checkInput(input_left, REPEAT_TRUE, options->game.input[i].deviceType, options->game.input[i].id))
|
||||
{
|
||||
player->setInput(input_left);
|
||||
#ifdef RECORDING
|
||||
demo.keys.left = 1;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2787,13 +2821,17 @@ void Game::checkGameInput()
|
||||
if (input->checkInput(input_right, REPEAT_TRUE, options->game.input[i].deviceType, options->game.input[i].id))
|
||||
{
|
||||
player->setInput(input_right);
|
||||
#ifdef RECORDING
|
||||
demo.keys.right = 1;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
// Ninguno de los dos inputs anteriores
|
||||
player->setInput(input_null);
|
||||
#ifdef RECORDING
|
||||
demo.keys.noInput = 1;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
// Comprueba el input de disparar al centro
|
||||
@@ -2807,13 +2845,14 @@ void Game::checkGameInput()
|
||||
|
||||
// Reproduce el sonido de disparo
|
||||
JA_PlaySound(bulletSound);
|
||||
|
||||
#ifdef RECORDING
|
||||
demo.keys.fire = 1;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba el input de disparar a la izquierda
|
||||
if (input->checkInput(input_fire_left, REPEAT_TRUE, options->game.input[i].deviceType, options->game.input[i].id))
|
||||
else if (input->checkInput(input_fire_left, REPEAT_TRUE, options->game.input[i].deviceType, options->game.input[i].id))
|
||||
{
|
||||
if (player->canFire())
|
||||
{
|
||||
@@ -2823,13 +2862,14 @@ void Game::checkGameInput()
|
||||
|
||||
// Reproduce el sonido de disparo
|
||||
JA_PlaySound(bulletSound);
|
||||
|
||||
#ifdef RECORDING
|
||||
demo.keys.fireLeft = 1;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba el input de disparar a la derecha
|
||||
if (input->checkInput(input_fire_right, REPEAT_TRUE, options->game.input[i].deviceType, options->game.input[i].id))
|
||||
else if (input->checkInput(input_fire_right, REPEAT_TRUE, options->game.input[i].deviceType, options->game.input[i].id))
|
||||
{
|
||||
if (player->canFire())
|
||||
{
|
||||
@@ -2839,31 +2879,27 @@ void Game::checkGameInput()
|
||||
|
||||
// Reproduce el sonido de disparo
|
||||
JA_PlaySound(bulletSound);
|
||||
|
||||
#ifdef RECORDING
|
||||
demo.keys.fireRight = 1;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (demo.counter < TOTAL_DEMO_DATA)
|
||||
#ifdef RECORDING
|
||||
if (demo.recording)
|
||||
{
|
||||
if (demo.recording)
|
||||
if (demo.counter < TOTAL_DEMO_DATA)
|
||||
{
|
||||
demo.dataFile[demo.counter] = demo.keys;
|
||||
}
|
||||
demo.counter++;
|
||||
}
|
||||
else if (demo.recording)
|
||||
{
|
||||
section->name = SECTION_PROG_QUIT;
|
||||
}
|
||||
|
||||
#endif
|
||||
i++;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (input->checkInput(input_accept, REPEAT_TRUE, options->game.input[i].deviceType, options->game.input[i].id))
|
||||
if (input->checkInput(input_start, REPEAT_TRUE, options->game.input[i].deviceType, options->game.input[i].id))
|
||||
{
|
||||
player->init();
|
||||
player->enable(true);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
@@ -2990,7 +3026,9 @@ void Game::run()
|
||||
{
|
||||
while (section->name == SECTION_PROG_GAME)
|
||||
{
|
||||
checkGameInput();
|
||||
#ifndef RECORDING
|
||||
checkInput();
|
||||
#endif
|
||||
update();
|
||||
checkEvents(); // Tiene que ir antes del render
|
||||
render();
|
||||
|
||||
Reference in New Issue
Block a user