Arreglado el modo demo

Grabada una nueva demo
This commit is contained in:
2024-07-05 20:40:08 +02:00
parent dc09c189e9
commit f73eab7a77
8 changed files with 109 additions and 82 deletions

View File

@@ -130,6 +130,10 @@ windows:
$(CXX) $(SOURCES) $(CXXFLAGS) -Wl,-subsystem,windows $(LDFLAGS) -o "$(TARGET_FILE).exe" $(CXX) $(SOURCES) $(CXXFLAGS) -Wl,-subsystem,windows $(LDFLAGS) -o "$(TARGET_FILE).exe"
strip -s -R .comment -R .gnu.version "$(TARGET_FILE).exe" --strip-unneeded strip -s -R .comment -R .gnu.version "$(TARGET_FILE).exe" --strip-unneeded
windows_rec:
@echo off
$(CXX) $(SOURCES) -D RECORDING $(CXXFLAGS) -Wl,-subsystem,windows $(LDFLAGS) -o "$(TARGET_FILE)_rec.exe"
windows_debug: windows_debug:
@echo off @echo off

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

View File

@@ -136,7 +136,7 @@ void Director::initInput()
// Mando - Otros // Mando - Otros
input->bindGameControllerButton(input_accept, SDL_CONTROLLER_BUTTON_START); input->bindGameControllerButton(input_accept, SDL_CONTROLLER_BUTTON_START);
input->bindGameControllerButton(input_cancel, SDL_CONTROLLER_BUTTON_A); input->bindGameControllerButton(input_cancel, SDL_CONTROLLER_BUTTON_A);
input->bindGameControllerButton(input_pause, SDL_CONTROLLER_BUTTON_START); input->bindGameControllerButton(input_pause, SDL_CONTROLLER_BUTTON_B);
input->bindGameControllerButton(input_exit, SDL_CONTROLLER_BUTTON_BACK); input->bindGameControllerButton(input_exit, SDL_CONTROLLER_BUTTON_BACK);
// Pone valores por defecto a las opciones de control // Pone valores por defecto a las opciones de control
@@ -758,7 +758,7 @@ void Director::runTitle()
// Ejecuta la seccion de juego donde se juega // Ejecuta la seccion de juego donde se juega
void Director::runGame() void Director::runGame()
{ {
const int playerID = section->subsection == SUBSECTION_GAME_PLAY_1P ? 0 : 1; const int playerID = section->subsection == SUBSECTION_GAME_PLAY_1P ? 1 : 2;
game = new Game(playerID, 0, renderer, screen, asset, lang, input, false, param, options, section, getMusic(musics, "playing.ogg")); game = new Game(playerID, 0, renderer, screen, asset, lang, input, false, param, options, section, getMusic(musics, "playing.ogg"));
game->run(); game->run();
delete game; delete game;

View File

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

View File

@@ -30,7 +30,6 @@
// Contadores // Contadores
#define STAGE_COUNTER 200 #define STAGE_COUNTER 200
#define SHAKE_COUNTER 10
#define HELP_COUNTER 1000 #define HELP_COUNTER 1000
#define GAME_COMPLETED_START_FADE 500 #define GAME_COMPLETED_START_FADE 500
#define GAME_COMPLETED_END 700 #define GAME_COMPLETED_END 700
@@ -237,9 +236,10 @@ private:
// Guarda el fichero de puntos // Guarda el fichero de puntos
bool saveScoreFile(); bool saveScoreFile();
#ifdef RECORDING
// Guarda el fichero de datos para la demo // Guarda el fichero de datos para la demo
bool saveDemoFile(); bool saveDemoFile();
#endif
// Inicializa las formaciones enemigas // Inicializa las formaciones enemigas
void initEnemyFormations(); void initEnemyFormations();
@@ -407,7 +407,7 @@ private:
void updateBackground(); void updateBackground();
// Gestiona la entrada durante el juego // Gestiona la entrada durante el juego
void checkGameInput(); void checkInput();
// Pinta diferentes mensajes en la pantalla // Pinta diferentes mensajes en la pantalla
void renderMessages(); void renderMessages();

View File

@@ -175,11 +175,6 @@ void Player::move()
// Pinta el jugador en pantalla // Pinta el jugador en pantalla
void Player::render() void Player::render()
{ {
if (!enabled)
{
return;
}
if (isAlive()) if (isAlive())
{ {
if (invulnerable) if (invulnerable)
@@ -337,11 +332,6 @@ void Player::updateCooldown()
// Actualiza al jugador a su posicion, animación y controla los contadores // Actualiza al jugador a su posicion, animación y controla los contadores
void Player::update() void Player::update()
{ {
if (!enabled)
{
return;
}
move(); move();
setAnimation(); setAnimation();
shiftColliders(); shiftColliders();
@@ -620,6 +610,7 @@ void Player::setPlayerTextures(std::vector<Texture *> texture)
void Player::enable(bool value) void Player::enable(bool value)
{ {
enabled = value; enabled = value;
init();
} }
// Obtiene el valor de la variable // Obtiene el valor de la variable

View File

@@ -239,12 +239,6 @@ void Title::checkInput()
postFade = index; postFade = index;
} }
//else if (input->checkInput(input_start, REPEAT_FALSE))
//{
// fade->activate();
// postFade = 0;
//}
// Comprueba el input para el resto de objetos // Comprueba el input para el resto de objetos
screen->checkInput(); screen->checkInput();
} }