Revisados varios pequeños bugs

This commit is contained in:
2022-10-09 12:58:23 +02:00
parent d77757853d
commit 742ca02573
5 changed files with 225 additions and 142 deletions

View File

@@ -43,6 +43,8 @@ loop=0
frames=20,21,22,23
[/animation]
[animation]
name=sideshoot
speed=5
@@ -85,6 +87,52 @@ loop=0
frames=44,45,46,47
[/animation]
[animation]
name=walk_pwr
speed=3
loop=0
frames=0,1,2,3
[/animation]
[animation]
name=stand_pwr
speed=5
loop=0
frames=4,5,6,7
[/animation]
[animation]
name=walk_1C_pwr
speed=3
loop=0
frames=8,9,10,11
[/animation]
[animation]
name=stand_1C_pwr
speed=5
loop=0
frames=12,13,14,15
[/animation]
[animation]
name=walk_2C_pwr
speed=3
loop=0
frames=16,17,18,19
[/animation]
[animation]
name=stand_2C_pwr
speed=5
loop=0
frames=20,21,22,23
[/animation]
[animation]
name=sideshoot_pwr
speed=2

View File

@@ -89,7 +89,7 @@ frames=28,29,30,31
name=sideshoot_pwr
speed=2
loop=0
frames=16,17,18,19,20
frames=16,17,18,19
[/animation]
[animation]

View File

@@ -14,7 +14,7 @@ Game::Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *scr
// Pasa variables
this->demo.enabled = demo;
this->numPlayers = numPlayers;
this->currentStage = 9;//currentStage;
this->currentStage = currentStage;
lastStageReached = currentStage;
if (numPlayers == 1)
{ // Si solo juega un jugador, permite jugar tanto con teclado como con mando
@@ -307,9 +307,6 @@ void Game::init()
totalPowerToCompleteGame += stage[i].powerToComplete;
}
balloonsPopped = totalPowerToCompleteGame - 20;
stage[9].currentPower = stage[9].powerToComplete - 20;
// Modo demo
demo.recording = false;
demo.counter = 0;
@@ -1526,7 +1523,6 @@ void Game::updateHiScore()
{
// Si la puntuación actual es mayor que la máxima puntuación
for (auto player : players)
// for (int i = 0; i < numPlayers; i++)
if (player->getScore() > hiScore)
{
// Actualiza la máxima puntuación
@@ -1548,8 +1544,6 @@ void Game::updateHiScore()
// Transforma un valor numérico en una cadena de 6 cifras
std::string Game::updateScoreText(Uint32 num)
{
// return (std::to_string(num));
if ((num >= 0) && (num <= 9))
{
return ("000000" + std::to_string(num));
@@ -1781,8 +1775,7 @@ void Game::updateDeath()
// Renderiza el fade final cuando se acaba la partida
void Game::renderDeathFade(int counter)
// Counter debe ir de 0 a 150
{
{ // Counter debe ir de 0 a 150
SDL_SetRenderDrawColor(renderer, 0x27, 0x27, 0x36, 255);
if (counter < 150)
@@ -1790,15 +1783,19 @@ void Game::renderDeathFade(int counter)
// 192 / 6 = 32, 6 cuadrados de 32 pixeles
SDL_Rect rect[12];
Uint8 h = counter / 3;
for (int i = 0; i < 12; i++)
for (int i = 0; i < 12; ++i)
{
rect[i].x = 0;
rect[i].y = i * 16;
rect[i].w = GAME_WIDTH;
if (i == 0)
{
rect[i].h = h;
}
else
{
rect[i].h = std::max(rect[i - 1].h - 3, 0);
}
SDL_RenderFillRect(renderer, &rect[i]);
}
}
@@ -2741,10 +2738,7 @@ void Game::update()
checkBulletBalloonCollision();
// Comprueba el nivel de amenaza para ver si se han de crear nuevos enemigos
if (!gameCompleted)
{
updateMenace();
}
updateMenace();
// Actualiza la velocidad de los enemigos
updateBalloonSpeed();
@@ -2897,6 +2891,11 @@ void Game::render()
// Gestiona el nivel de amenaza
void Game::updateMenace()
{
if (gameCompleted)
{
return;
}
const float percent = stage[currentStage].currentPower / stage[currentStage].powerToComplete;
const Uint8 difference = stage[currentStage].maxMenace - stage[currentStage].minMenace;
@@ -3373,12 +3372,160 @@ void Game::runPausedGame()
}
}
// Actualiza los elementos de la pantalla de game over
void Game::updateGameOverScreen()
{
// Variables
static int postFade = 0;
// Comprueba los eventos que hay en la cola
while (SDL_PollEvent(eventHandler) != 0)
{
// Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT)
{
section.name = PROG_SECTION_QUIT;
break;
}
else if (eventHandler->type == SDL_KEYDOWN && eventHandler->key.repeat == 0)
{
if (gameCompleted)
{
postFade = 1;
fade->activateFade();
JA_PlaySound(itemPickUpSound);
}
}
}
// Calcula la lógica de los objetos
if (SDL_GetTicks() - ticks > ticksSpeed)
{
// Actualiza el contador de ticks
ticks = SDL_GetTicks();
// Actualiza la lógica del menu
gameOverMenu->update();
// Actualiza el fade
fade->update();
// Si ha terminado el fade, actua segun se haya operado
if (fade->hasEnded())
{
switch (postFade)
{
case 0: // YES
section.name = PROG_SECTION_GAME;
deleteAllVectorObjects();
init();
section.subsection = numPlayers == 1 ? GAME_SECTION_PLAY_1P : GAME_SECTION_PLAY_2P;
break;
case 1: // NO
section.name = PROG_SECTION_TITLE;
section.subsection = TITLE_SECTION_1;
break;
default:
break;
}
}
// Comprueba las entradas para el menu solo si no esta el juego completo
if (!gameCompleted)
{
gameOverMenu->checkInput();
// Comprueba si se ha seleccionado algún item del menú
switch (gameOverMenu->getItemSelected())
{
case 0: // YES
postFade = 0;
fade->activateFade();
break;
case 1: // NO
postFade = 1;
fade->activateFade();
break;
default:
break;
}
}
}
}
// Dibuja los elementos de la pantalla de game over
void Game::renderGameOverScreen()
{
// Prepara para empezar a dibujar en la textura de juego
screen->start();
// Limpia la pantalla
screen->clean(bgColor);
// Dibujo
if (!gameCompleted)
{ // Dibujo de haber perdido la partida
gameOverSprite->render();
}
else
{ // Dinujo de haber completado la partida
gameOverEndSprite->render();
}
// Dibuja los objetos
if (numPlayers == 1)
{
// Congratulations!!
if (gameCompleted)
{
text->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 8), lang->getText(50));
}
// Game Over
textBig->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 6), lang->getText(43));
// Your Score
text->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 3), lang->getText(44) + std::to_string(players.at(0)->getScore()));
}
else
{
// Congratulations!!
if (gameCompleted)
{
text->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 9), lang->getText(50));
}
// Game Over
textBig->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 7), lang->getText(43));
// Player1 Score
text->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 4), lang->getText(77) + std::to_string(players.at(0)->getScore()));
// Player2 Score
text->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 2), lang->getText(78) + std::to_string(players.at(1)->getScore()));
}
// Continue?
if (!gameCompleted)
{ // Solo dibuja el menu de continuar en el caso de no haber completado la partida
text->writeCentered(199, PLAY_AREA_CENTER_Y + BLOCK * 3, lang->getText(45));
gameOverMenu->render();
}
// Pinta el fade
fade->render();
// Vuelca el contenido del renderizador en pantalla
screen->blit();
}
// Bucle para la pantalla de game over
void Game::runGameOverScreen()
{
// Variables
int postFade = 0;
// Guarda los puntos
saveScoreFile();
@@ -3387,127 +3534,8 @@ void Game::runGameOverScreen()
while ((section.subsection == GAME_SECTION_GAMEOVER) && (section.name == PROG_SECTION_GAME))
{
// Comprueba los eventos que hay en la cola
while (SDL_PollEvent(eventHandler) != 0)
{
// Evento de salida de la aplicación
if (eventHandler->type == SDL_QUIT)
{
section.name = PROG_SECTION_QUIT;
break;
}
}
// Calcula la lógica de los objetos
if (SDL_GetTicks() - ticks > ticksSpeed)
{
// Actualiza el contador de ticks
ticks = SDL_GetTicks();
// Actualiza la lógica del menu
gameOverMenu->update();
fade->update();
if (fade->hasEnded())
{
switch (postFade)
{
case 0: // YES
if (!gameCompleted)
{ // Si el juego no se ha terminado, el menu actua normal
section.name = PROG_SECTION_GAME;
deleteAllVectorObjects();
init();
section.subsection = numPlayers == 1 ? GAME_SECTION_PLAY_1P : GAME_SECTION_PLAY_2P;
}
else
{ // Si ha completado el juego, siempre vuelve a la pantalla de titulo
section.name = PROG_SECTION_TITLE;
section.subsection = TITLE_SECTION_1;
}
break;
case 1: // NO
section.name = PROG_SECTION_TITLE;
section.subsection = TITLE_SECTION_1;
break;
default:
break;
}
break;
}
}
// Prepara para empezar a dibujar en la textura de juego
screen->start();
// Limpia la pantalla
screen->clean(bgColor);
// Dibujo
if (!gameCompleted)
{ // Dibujo de haber perdido la partida
gameOverSprite->render();
}
else
{ // Dinujo de haber completado la partida
gameOverEndSprite->render();
}
// Dibuja los objetos
if (numPlayers == 1)
{
// Game Over
textBig->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 6), lang->getText(43));
// Your Score
text->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 3), lang->getText(44) + std::to_string(players.at(0)->getScore()));
}
else
{
// Game Over
textBig->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 7), lang->getText(43));
// Player1 Score
text->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 4), lang->getText(77) + std::to_string(players.at(0)->getScore()));
// Player2 Score
text->writeCentered(PLAY_AREA_CENTER_X, PLAY_AREA_CENTER_Y - (BLOCK * 2), lang->getText(78) + std::to_string(players.at(1)->getScore()));
}
// Continue?
if (!gameCompleted)
{ // Solo dibuja el menu de continuar en el caso de no haber completado la partida
text->writeCentered(199, PLAY_AREA_CENTER_Y + BLOCK * 3, lang->getText(45));
gameOverMenu->render();
}
// Pinta el fade
fade->render();
// Vuelca el contenido del renderizador en pantalla
screen->blit();
// Comprueba las entradas para el menu
gameOverMenu->checkInput();
// Comprueba si se ha seleccionado algún item del menú
switch (gameOverMenu->getItemSelected())
{
case 0: // YES
postFade = 0;
fade->activateFade();
break;
case 1: // NO
postFade = 1;
fade->activateFade();
break;
default:
break;
}
updateGameOverScreen();
renderGameOverScreen();
}
}
@@ -3554,7 +3582,7 @@ void Game::initPaths()
const int centerPoint = PLAY_AREA_CENTER_Y - (BLOCK * 2);
const int distance = (PLAY_AREA_BOTTOM) - (PLAY_AREA_CENTER_Y - 16);
for (int i = 0; i < STAGE_COUNTER; i++)
for (int i = 0; i < STAGE_COUNTER; ++i)
{
if (i < firstPart)
{
@@ -3584,7 +3612,7 @@ void Game::initPaths()
const float distance1 = finish1 - start1;
const float distance2 = finish2 - start2;
for (int i = 0; i < STAGE_COUNTER; i++)
for (int i = 0; i < STAGE_COUNTER; ++i)
{
if (i < firstPart)
{
@@ -3592,10 +3620,12 @@ void Game::initPaths()
getReadyBitmapPath[i] *= distance1;
getReadyBitmapPath[i] -= size;
}
else if (i < secondPart)
{
getReadyBitmapPath[i] = (int)finish1;
}
else
{
getReadyBitmapPath[i] = sin[(int)((i - 150) * 1.8f)];

View File

@@ -467,6 +467,12 @@ private:
// Bucle para el menu de pausa del juego
void runPausedGame();
// Actualiza los elementos de la pantalla de game over
void updateGameOverScreen();
// Dibuja los elementos de la pantalla de game over
void renderGameOverScreen();
// Bucle para la pantalla de game over
void runGameOverScreen();

View File

@@ -236,7 +236,6 @@ void Player::setAnimation()
}
const std::string aPowerUp = powerUp ? "_pwr" : "";
//const std::string aPowerUp = "";
const std::string aWalking = statusWalking == PLAYER_STATUS_WALKING_STOP ? "stand" : "walk";
const std::string aFiring = statusFiring == PLAYER_STATUS_FIRING_UP ? "centershoot" : "sideshoot";