shakeScreen ya no detiene la ejecución del programa
This commit is contained in:
@@ -5,18 +5,30 @@
|
|||||||
// Constructor
|
// Constructor
|
||||||
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options_t *options)
|
Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options_t *options)
|
||||||
{
|
{
|
||||||
// Inicializa variables
|
// Copia punteros
|
||||||
this->window = window;
|
this->window = window;
|
||||||
this->renderer = renderer;
|
this->renderer = renderer;
|
||||||
this->options = options;
|
this->options = options;
|
||||||
this->asset = asset;
|
this->asset = asset;
|
||||||
|
|
||||||
|
// Inicializa variables
|
||||||
|
windowWidth = 0;
|
||||||
|
windowHeight = 0;
|
||||||
gameCanvasWidth = options->video.gameWidth;
|
gameCanvasWidth = options->video.gameWidth;
|
||||||
gameCanvasHeight = options->video.gameHeight;
|
gameCanvasHeight = options->video.gameHeight;
|
||||||
borderWidth = options->video.border.width * 2;
|
borderWidth = options->video.border.width * 2;
|
||||||
borderHeight = options->video.border.height * 2;
|
borderHeight = options->video.border.height * 2;
|
||||||
notificationLogicalWidth = gameCanvasWidth;
|
dest = {0, 0, 0, 0};
|
||||||
notificationLogicalHeight = gameCanvasHeight;
|
borderColor = {0, 0, 0};
|
||||||
|
fade = 0;
|
||||||
|
fadeCounter = 0;
|
||||||
|
fadeLenght = 0;
|
||||||
|
shake.desp = 1;
|
||||||
|
shake.delay = 3;
|
||||||
|
shake.counter = 0;
|
||||||
|
shake.lenght = 8;
|
||||||
|
shake.remaining = 0;
|
||||||
|
shake.origin = 0;
|
||||||
|
|
||||||
iniFade();
|
iniFade();
|
||||||
|
|
||||||
@@ -28,9 +40,6 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options
|
|||||||
|
|
||||||
// Establece el modo de video
|
// Establece el modo de video
|
||||||
setVideoMode(options->video.mode);
|
setVideoMode(options->video.mode);
|
||||||
|
|
||||||
// Inicializa variables
|
|
||||||
notifyActive = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor
|
||||||
@@ -82,7 +91,7 @@ void Screen::setVideoMode(int videoMode)
|
|||||||
SDL_ShowCursor(SDL_ENABLE);
|
SDL_ShowCursor(SDL_ENABLE);
|
||||||
|
|
||||||
// Esconde la ventana
|
// Esconde la ventana
|
||||||
//SDL_HideWindow(window);
|
// SDL_HideWindow(window);
|
||||||
|
|
||||||
if (options->video.border.enabled)
|
if (options->video.border.enabled)
|
||||||
{
|
{
|
||||||
@@ -246,23 +255,6 @@ bool Screen::fadeEnded()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Activa el spectrum fade
|
|
||||||
void Screen::setspectrumFade()
|
|
||||||
{
|
|
||||||
spectrumFade = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Comprueba si ha terminado el spectrum fade
|
|
||||||
bool Screen::spectrumFadeEnded()
|
|
||||||
{
|
|
||||||
if (spectrumFade || spectrumFadeCounter > 0)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inicializa las variables para el fade
|
// Inicializa las variables para el fade
|
||||||
void Screen::iniFade()
|
void Screen::iniFade()
|
||||||
{
|
{
|
||||||
@@ -312,4 +304,41 @@ void Screen::updateFX()
|
|||||||
void Screen::renderFX()
|
void Screen::renderFX()
|
||||||
{
|
{
|
||||||
renderFade();
|
renderFade();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza la lógica de la clase
|
||||||
|
void Screen::update()
|
||||||
|
{
|
||||||
|
updateShake();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Agita la pantalla
|
||||||
|
void Screen::startShake()
|
||||||
|
{
|
||||||
|
shake.remaining = shake.lenght;
|
||||||
|
shake.counter = shake.delay;
|
||||||
|
shake.origin = dest.x;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Actualiza la logica para agitar la pantalla
|
||||||
|
void Screen::updateShake()
|
||||||
|
{
|
||||||
|
if (shake.remaining > 0)
|
||||||
|
{
|
||||||
|
if (shake.counter > 0)
|
||||||
|
{
|
||||||
|
shake.counter--;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
shake.counter = shake.delay;
|
||||||
|
const int desp = shake.remaining % 2 == 0 ? shake.desp * (-1) : shake.desp;
|
||||||
|
dest.x = shake.origin + desp;
|
||||||
|
shake.remaining--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dest.x = shake.origin;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -23,26 +23,29 @@ private:
|
|||||||
options_t *options; // Variable con todas las opciones del programa
|
options_t *options; // Variable con todas las opciones del programa
|
||||||
|
|
||||||
// Variables
|
// Variables
|
||||||
int windowWidth; // Ancho de la pantalla o ventana
|
int windowWidth; // Ancho de la pantalla o ventana
|
||||||
int windowHeight; // Alto de la pantalla o ventana
|
int windowHeight; // Alto de la pantalla o ventana
|
||||||
int gameCanvasWidth; // Resolución interna del juego. Es el ancho de la textura donde se dibuja el juego
|
int gameCanvasWidth; // Resolución interna del juego. Es el ancho de la textura donde se dibuja el juego
|
||||||
int gameCanvasHeight; // Resolución interna del juego. Es el alto de la textura donde se dibuja el juego
|
int gameCanvasHeight; // Resolución interna del juego. Es el alto de la textura donde se dibuja el juego
|
||||||
int borderWidth; // Anchura del borde
|
int borderWidth; // Anchura del borde
|
||||||
int borderHeight; // Anltura del borde
|
int borderHeight; // Anltura del borde
|
||||||
SDL_Rect dest; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana
|
SDL_Rect dest; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana
|
||||||
color_t borderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla
|
color_t borderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla
|
||||||
bool notifyActive; // Indica si hay notificaciones activas
|
|
||||||
int notificationLogicalWidth; // Ancho lógico de las notificaciones en relación al tamaño de pantalla
|
|
||||||
int notificationLogicalHeight; // Alto lógico de las notificaciones en relación al tamaño de pantalla
|
|
||||||
|
|
||||||
// Variables - Efectos
|
// Variables - Efectos
|
||||||
bool fade; // Indica si esta activo el efecto de fade
|
bool fade; // Indica si esta activo el efecto de fade
|
||||||
int fadeCounter; // Temporizador para el efecto de fade
|
int fadeCounter; // Temporizador para el efecto de fade
|
||||||
int fadeLenght; // Duración del fade
|
int fadeLenght; // Duración del fade
|
||||||
bool spectrumFade; // Indica si esta activo el efecto de fade spectrum
|
|
||||||
int spectrumFadeCounter; // Temporizador para el efecto de fade spectrum
|
struct shake_t
|
||||||
int spectrumFadeLenght; // Duración del fade spectrum
|
{
|
||||||
std::vector<color_t> spectrumColor; // Colores para el fade spectrum
|
int desp; // Pixels de desplazamiento para agitar la pantalla en el eje x
|
||||||
|
int delay; // Retraso entre cada desplazamiento de la pantalla al agitarse
|
||||||
|
int counter; // Contador para el retraso
|
||||||
|
int lenght; // Cantidad de desplazamientos a realizar
|
||||||
|
int remaining; // Cantidad de desplazamientos pendientes a realizar
|
||||||
|
int origin; // Valor inicial de la pantalla para dejarla igual tras el desplazamiento
|
||||||
|
} shake;
|
||||||
|
|
||||||
// Inicializa las variables para el fade
|
// Inicializa las variables para el fade
|
||||||
void iniFade();
|
void iniFade();
|
||||||
@@ -53,6 +56,15 @@ private:
|
|||||||
// Dibuja el fade
|
// Dibuja el fade
|
||||||
void renderFade();
|
void renderFade();
|
||||||
|
|
||||||
|
// Actualiza los efectos
|
||||||
|
void updateFX();
|
||||||
|
|
||||||
|
// Dibuja los efectos
|
||||||
|
void renderFX();
|
||||||
|
|
||||||
|
// Actualiza la logica para agitar la pantalla
|
||||||
|
void updateShake();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options_t *options);
|
Screen(SDL_Window *window, SDL_Renderer *renderer, Asset *asset, options_t *options);
|
||||||
@@ -60,6 +72,9 @@ public:
|
|||||||
// Destructor
|
// Destructor
|
||||||
~Screen();
|
~Screen();
|
||||||
|
|
||||||
|
// Actualiza la lógica de la clase
|
||||||
|
void update();
|
||||||
|
|
||||||
// Limpia la pantalla
|
// Limpia la pantalla
|
||||||
void clean(color_t color = {0x00, 0x00, 0x00});
|
void clean(color_t color = {0x00, 0x00, 0x00});
|
||||||
|
|
||||||
@@ -106,17 +121,8 @@ public:
|
|||||||
// Comprueba si ha terminado el fade
|
// Comprueba si ha terminado el fade
|
||||||
bool fadeEnded();
|
bool fadeEnded();
|
||||||
|
|
||||||
// Activa el spectrum fade
|
// Agita la pantalla
|
||||||
void setspectrumFade();
|
void startShake();
|
||||||
|
|
||||||
// Comprueba si ha terminado el spectrum fade
|
|
||||||
bool spectrumFadeEnded();
|
|
||||||
|
|
||||||
// Actualiza los efectos
|
|
||||||
void updateFX();
|
|
||||||
|
|
||||||
// Dibuja los efectos
|
|
||||||
void renderFX();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -215,7 +215,7 @@ void Game::init()
|
|||||||
players.push_back(player2);
|
players.push_back(player2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inicializa las variables
|
// Variables relacionadas con la dificultad
|
||||||
switch (difficulty)
|
switch (difficulty)
|
||||||
{
|
{
|
||||||
case DIFFICULTY_EASY:
|
case DIFFICULTY_EASY:
|
||||||
@@ -246,18 +246,18 @@ void Game::init()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Marcador
|
// Variables para el marcador
|
||||||
scoreboard->setPos({10, 10, 256-20, 32});
|
scoreboard->setPos({0, 160, 256, 32});
|
||||||
if (difficulty == DIFFICULTY_NORMAL)
|
if (difficulty == DIFFICULTY_NORMAL)
|
||||||
{
|
{
|
||||||
scoreboard->setColor({46, 63, 71});
|
scoreboard->setColor({46, 63, 71});
|
||||||
scoreboard->setColor({255, 63, 71});
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
scoreboard->setColor(difficultyColor);
|
scoreboard->setColor(difficultyColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Resto de variables
|
||||||
gameCompleted = false;
|
gameCompleted = false;
|
||||||
gameCompletedCounter = 0;
|
gameCompletedCounter = 0;
|
||||||
section->name = SECTION_PROG_GAME;
|
section->name = SECTION_PROG_GAME;
|
||||||
@@ -2545,7 +2545,6 @@ void Game::killPlayer(Player *player)
|
|||||||
stopAllBalloons(10);
|
stopAllBalloons(10);
|
||||||
JA_PlaySound(playerCollisionSound);
|
JA_PlaySound(playerCollisionSound);
|
||||||
shakeScreen();
|
shakeScreen();
|
||||||
SDL_Delay(500);
|
|
||||||
JA_PlaySound(coffeeOutSound);
|
JA_PlaySound(coffeeOutSound);
|
||||||
player->setAlive(false);
|
player->setAlive(false);
|
||||||
if (allPlayersAreDead())
|
if (allPlayersAreDead())
|
||||||
@@ -2641,6 +2640,9 @@ void Game::update()
|
|||||||
// Actualiza el contador de juego
|
// Actualiza el contador de juego
|
||||||
counter++;
|
counter++;
|
||||||
|
|
||||||
|
// Actualiza el objeto screen
|
||||||
|
screen->update();
|
||||||
|
|
||||||
// Comprueba el teclado/mando
|
// Comprueba el teclado/mando
|
||||||
checkGameInput();
|
checkGameInput();
|
||||||
|
|
||||||
@@ -2798,6 +2800,14 @@ void Game::renderBackground()
|
|||||||
grassSprite->render();
|
grassSprite->render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Dibuja la linea que separa la zona ade juego del marcador
|
||||||
|
void Game::renderSeparator()
|
||||||
|
{
|
||||||
|
// Dibuja la linea que separa el marcador de la zona de juego
|
||||||
|
SDL_SetRenderDrawColor(renderer, 13, 26, 43, 255);
|
||||||
|
SDL_RenderDrawLine(renderer, 0, 160, 255, 160);
|
||||||
|
}
|
||||||
|
|
||||||
// Dibuja el juego
|
// Dibuja el juego
|
||||||
void Game::render()
|
void Game::render()
|
||||||
{
|
{
|
||||||
@@ -2815,6 +2825,7 @@ void Game::render()
|
|||||||
renderItems();
|
renderItems();
|
||||||
renderSmartSprites();
|
renderSmartSprites();
|
||||||
scoreboard->render();
|
scoreboard->render();
|
||||||
|
renderSeparator();
|
||||||
renderPlayers();
|
renderPlayers();
|
||||||
|
|
||||||
if ((deathCounter <= 150) && !players[0]->isAlive())
|
if ((deathCounter <= 150) && !players[0]->isAlive())
|
||||||
@@ -3149,41 +3160,7 @@ void Game::disableTimeStopItem()
|
|||||||
// Agita la pantalla
|
// Agita la pantalla
|
||||||
void Game::shakeScreen()
|
void Game::shakeScreen()
|
||||||
{
|
{
|
||||||
const int v[] = {-1, 1, -1, 1, -1, 1, -1, 0};
|
screen->startShake();
|
||||||
for (int n = 0; n < 8; ++n)
|
|
||||||
{
|
|
||||||
// Prepara para empezar a dibujar en la textura de juego
|
|
||||||
screen->start();
|
|
||||||
|
|
||||||
// Limpia la pantalla
|
|
||||||
screen->clean(bgColor);
|
|
||||||
|
|
||||||
// Dibuja los objetos
|
|
||||||
buildingsSprite->setPosX(0);
|
|
||||||
buildingsSprite->setWidth(1);
|
|
||||||
buildingsSprite->setSpriteClip(0, 0, 1, 160);
|
|
||||||
renderBackground();
|
|
||||||
|
|
||||||
buildingsSprite->setPosX(255);
|
|
||||||
buildingsSprite->setSpriteClip(255, 0, 1, 160);
|
|
||||||
buildingsSprite->render();
|
|
||||||
|
|
||||||
buildingsSprite->setPosX(v[n]);
|
|
||||||
buildingsSprite->setWidth(256);
|
|
||||||
buildingsSprite->setSpriteClip(0, 0, 256, 160);
|
|
||||||
buildingsSprite->render();
|
|
||||||
|
|
||||||
grassSprite->render();
|
|
||||||
renderBalloons();
|
|
||||||
renderBullets();
|
|
||||||
renderItems();
|
|
||||||
renderPlayers();
|
|
||||||
scoreboard->render();
|
|
||||||
|
|
||||||
// Vuelca el contenido del renderizador en pantalla
|
|
||||||
screen->blit();
|
|
||||||
SDL_Delay(50);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bucle para el juego
|
// Bucle para el juego
|
||||||
|
|||||||
@@ -508,6 +508,9 @@ private:
|
|||||||
// Actualiza el marcador
|
// Actualiza el marcador
|
||||||
void updateScoreboard();
|
void updateScoreboard();
|
||||||
|
|
||||||
|
// Dibuja la linea que separa la zona ade juego del marcador
|
||||||
|
void renderSeparator();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, Input *input, bool demo, options_t *options, section_t *section);
|
Game(int numPlayers, int currentStage, SDL_Renderer *renderer, Screen *screen, Asset *asset, Lang *lang, Input *input, bool demo, options_t *options, section_t *section);
|
||||||
|
|||||||
@@ -372,7 +372,7 @@ void Player::setAlive(bool value)
|
|||||||
{
|
{
|
||||||
alive = value;
|
alive = value;
|
||||||
|
|
||||||
if (!value)
|
if (!alive)
|
||||||
{
|
{
|
||||||
deathSprite->setPosX(headSprite->getRect().x);
|
deathSprite->setPosX(headSprite->getRect().x);
|
||||||
deathSprite->setPosY(headSprite->getRect().y);
|
deathSprite->setPosY(headSprite->getRect().y);
|
||||||
|
|||||||
@@ -216,10 +216,6 @@ void Scoreboard::fillBackgroundTexture()
|
|||||||
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 255);
|
SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 255);
|
||||||
SDL_RenderFillRect(renderer, nullptr);
|
SDL_RenderFillRect(renderer, nullptr);
|
||||||
|
|
||||||
// Dibuja la linea que separa el marcador de la zona de juego
|
|
||||||
// SDL_SetRenderDrawColor(renderer, 13, 26, 43, 255);
|
|
||||||
// SDL_RenderDrawLine(renderer, 0, 160, 255, 160);
|
|
||||||
|
|
||||||
// PLAYER1 - SCORE
|
// PLAYER1 - SCORE
|
||||||
textScoreBoard->writeCentered(offsetScoreP1Label.x, offsetScoreP1Label.y, lang->getText(53));
|
textScoreBoard->writeCentered(offsetScoreP1Label.x, offsetScoreP1Label.y, lang->getText(53));
|
||||||
textScoreBoard->writeCentered(offsetScoreP1.x, offsetScoreP1.y, updateScoreText(score1));
|
textScoreBoard->writeCentered(offsetScoreP1.x, offsetScoreP1.y, updateScoreText(score1));
|
||||||
|
|||||||
Reference in New Issue
Block a user