Arreglado el modo demo
Grabada una nueva demo
This commit is contained in:
4
Makefile
4
Makefile
@@ -130,6 +130,10 @@ windows:
|
||||
$(CXX) $(SOURCES) $(CXXFLAGS) -Wl,-subsystem,windows $(LDFLAGS) -o "$(TARGET_FILE).exe"
|
||||
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:
|
||||
@echo off
|
||||
|
||||
BIN
data/config/demo - copia.bin
Normal file
BIN
data/config/demo - copia.bin
Normal file
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
@@ -136,7 +136,7 @@ void Director::initInput()
|
||||
// Mando - Otros
|
||||
input->bindGameControllerButton(input_accept, SDL_CONTROLLER_BUTTON_START);
|
||||
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);
|
||||
|
||||
// Pone valores por defecto a las opciones de control
|
||||
@@ -758,7 +758,7 @@ void Director::runTitle()
|
||||
// Ejecuta la seccion de juego donde se juega
|
||||
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->run();
|
||||
delete game;
|
||||
|
||||
140
source/game.cpp
140
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()
|
||||
@@ -1519,6 +1527,8 @@ void Game::updateHiScore()
|
||||
void Game::updatePlayers()
|
||||
{
|
||||
for (auto player : players)
|
||||
{
|
||||
if (player->isEnabled())
|
||||
{
|
||||
player->update();
|
||||
|
||||
@@ -1527,14 +1537,12 @@ void Game::updatePlayers()
|
||||
{
|
||||
if (player->isAlive())
|
||||
{
|
||||
killPlayer(player);
|
||||
|
||||
if (demo.enabled)
|
||||
{
|
||||
section->name = SECTION_PROG_HI_SCORE_TABLE;
|
||||
}
|
||||
else
|
||||
{
|
||||
killPlayer(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1542,15 +1550,19 @@ void Game::updatePlayers()
|
||||
checkPlayerItemCollision(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Dibuja a los jugadores
|
||||
void Game::renderPlayers()
|
||||
{
|
||||
for (auto player : players)
|
||||
{
|
||||
if (player->isEnabled())
|
||||
{
|
||||
player->render();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza las variables de la fase
|
||||
void Game::updateStage()
|
||||
@@ -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.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();
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
|
||||
// Contadores
|
||||
#define STAGE_COUNTER 200
|
||||
#define SHAKE_COUNTER 10
|
||||
#define HELP_COUNTER 1000
|
||||
#define GAME_COMPLETED_START_FADE 500
|
||||
#define GAME_COMPLETED_END 700
|
||||
@@ -237,9 +236,10 @@ private:
|
||||
|
||||
// Guarda el fichero de puntos
|
||||
bool saveScoreFile();
|
||||
|
||||
#ifdef RECORDING
|
||||
// Guarda el fichero de datos para la demo
|
||||
bool saveDemoFile();
|
||||
#endif
|
||||
|
||||
// Inicializa las formaciones enemigas
|
||||
void initEnemyFormations();
|
||||
@@ -407,7 +407,7 @@ private:
|
||||
void updateBackground();
|
||||
|
||||
// Gestiona la entrada durante el juego
|
||||
void checkGameInput();
|
||||
void checkInput();
|
||||
|
||||
// Pinta diferentes mensajes en la pantalla
|
||||
void renderMessages();
|
||||
|
||||
@@ -175,11 +175,6 @@ void Player::move()
|
||||
// Pinta el jugador en pantalla
|
||||
void Player::render()
|
||||
{
|
||||
if (!enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (isAlive())
|
||||
{
|
||||
if (invulnerable)
|
||||
@@ -337,11 +332,6 @@ void Player::updateCooldown()
|
||||
// Actualiza al jugador a su posicion, animación y controla los contadores
|
||||
void Player::update()
|
||||
{
|
||||
if (!enabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
move();
|
||||
setAnimation();
|
||||
shiftColliders();
|
||||
@@ -620,6 +610,7 @@ void Player::setPlayerTextures(std::vector<Texture *> texture)
|
||||
void Player::enable(bool value)
|
||||
{
|
||||
enabled = value;
|
||||
init();
|
||||
}
|
||||
|
||||
// Obtiene el valor de la variable
|
||||
|
||||
@@ -239,12 +239,6 @@ void Title::checkInput()
|
||||
postFade = index;
|
||||
}
|
||||
|
||||
//else if (input->checkInput(input_start, REPEAT_FALSE))
|
||||
//{
|
||||
// fade->activate();
|
||||
// postFade = 0;
|
||||
//}
|
||||
|
||||
// Comprueba el input para el resto de objetos
|
||||
screen->checkInput();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user