Resueltos los dos últimos problemas

This commit is contained in:
2022-10-03 17:14:33 +02:00
parent 99b61c4b2d
commit 95d6396dfa
7 changed files with 204 additions and 129 deletions

2
.gitignore vendored
View File

@@ -1,5 +1,5 @@
.vscode .vscode
*.DS_Store *.DS_Store
bin bin
data/config.bin data/config.txt
data/score.bin data/score.bin

View File

@@ -225,7 +225,7 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
// Valores para el efecto de rebote // Valores para el efecto de rebote
mBouncing.enabled = false; mBouncing.enabled = false;
mBouncing.counter = 0; mBouncing.counter = 0;
mBouncing.speed = 0; mBouncing.speed = 2;
mBouncing.zoomW = 1.0f; mBouncing.zoomW = 1.0f;
mBouncing.zoomH = 1.0f; mBouncing.zoomH = 1.0f;
mBouncing.despX = 0.0f; mBouncing.despX = 0.0f;
@@ -252,18 +252,12 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c
mStoppedCounter = 0; mStoppedCounter = 0;
mBlinking = false; mBlinking = false;
mVisible = true; mVisible = true;
mInvulnerable = false; mInvulnerable = true;
mBeingCreated = true; mBeingCreated = true;
mCreationCounter = creationtimer; mCreationCounter = creationtimer;
mCreationCounterIni = creationtimer; mCreationCounterIni = creationtimer;
mPopping = false; mPopping = false;
mBouncing.enabled = false;
mBouncing.counter = 0;
mBouncing.speed = 2;
mBouncing.zoomW = 1;
mBouncing.zoomH = 1;
mBouncing.despX = 0;
mBouncing.despY = 0;
mCounter = 0; mCounter = 0;
mTravelY = 1.0f; mTravelY = 1.0f;
mSpeed = speed; mSpeed = speed;
@@ -571,6 +565,20 @@ void Balloon::updateState()
// Establece la animación correspondiente al estado // Establece la animación correspondiente al estado
void Balloon::updateAnimation() void Balloon::updateAnimation()
{ {
std::string creatingAnimation = "blue";
std::string normalAnimation = "orange";
if (mKind == POWER_BALL)
{
creatingAnimation = "powerball";
normalAnimation = "powerball";
}
else if (getClass() == HEXAGON_CLASS)
{
creatingAnimation = "red";
normalAnimation = "green";
}
// Establece el frame de animación // Establece el frame de animación
if (isPopping()) if (isPopping())
{ {
@@ -578,11 +586,11 @@ void Balloon::updateAnimation()
} }
else if (isBeingCreated()) else if (isBeingCreated())
{ {
mSprite->setCurrentAnimation("blue"); mSprite->setCurrentAnimation(creatingAnimation);
} }
else else
{ {
mSprite->setCurrentAnimation("orange"); mSprite->setCurrentAnimation(normalAnimation);
} }
mSprite->animate(); mSprite->animate();

View File

@@ -2462,6 +2462,22 @@ void Game::createItemScoreSprite(int x, int y, SmartSprite *sprite)
ss->setEnabledCounter(100); ss->setEnabledCounter(100);
} }
// Vacia el vector de smartsprites
void Game::freeSmartSprites()
{
if (smartSprites.empty() == false)
{
for (int i = smartSprites.size() - 1; i >= 0; --i)
{
if (smartSprites.at(i)->hasFinished())
{
delete smartSprites.at(i);
smartSprites.erase(smartSprites.begin() + i);
}
}
}
}
// Dibuja el efecto de flash // Dibuja el efecto de flash
void Game::renderFlashEffect() void Game::renderFlashEffect()
{ {
@@ -2662,9 +2678,21 @@ void Game::updateEnemyDeployCounter()
} }
} }
// Actualiza el campo de juego // Actualiza el juego
void Game::updatePlayField() void Game::update()
{ {
// Comprueba los eventos que hay en cola
checkEventHandler();
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
if (SDL_GetTicks() - mTicks > mTicksSpeed)
{
// Actualiza el contador de ticks
mTicks = SDL_GetTicks();
// Actualiza el contador de juego
mCounter++;
// Comprueba el teclado/mando // Comprueba el teclado/mando
checkGameInput(); checkGameInput();
@@ -2719,6 +2747,8 @@ void Game::updatePlayField()
freeBullets(); freeBullets();
freeBalloons(); freeBalloons();
freeItems(); freeItems();
freeSmartSprites();
}
} }
// Actualiza el fondo // Actualiza el fondo
@@ -2788,9 +2818,16 @@ void Game::renderBackground()
mSpriteGrass->render(); mSpriteGrass->render();
} }
// Dibuja el campo de juego // Dibuja el juego
void Game::renderPlayField() void Game::render()
{ {
// Prepara para empezar a dibujar en la textura de juego
mScreen->start();
// Limpia la pantalla
mScreen->clean(bgColor);
// Dibuja los objetos
renderBackground(); renderBackground();
renderBalloons(); renderBalloons();
renderBullets(); renderBullets();
@@ -2817,6 +2854,12 @@ void Game::renderPlayField()
renderFlashEffect(); renderFlashEffect();
mText->write(0, 0, std::to_string(balloons.size())); mText->write(0, 0, std::to_string(balloons.size()));
// Pinta la informacion de debug
renderDebugInfo();
// Vuelca el contenido del renderizador en pantalla
mScreen->blit();
} }
// Gestiona el nivel de amenaza // Gestiona el nivel de amenaza
@@ -3193,44 +3236,11 @@ section_t Game::run()
} }
} }
// Comprueba que la diferencia de ticks sea mayor a la velocidad del juego
if (SDL_GetTicks() - mTicks > mTicksSpeed)
{
// Actualiza el contador de ticks
mTicks = SDL_GetTicks();
// Actualiza el contador de juego
mCounter++;
// Comprueba los eventos que hay en la cola
while (SDL_PollEvent(mEventHandler) != 0)
{
// Evento de salida de la aplicación
if (mEventHandler->type == SDL_QUIT)
{
mSection.name = PROG_SECTION_QUIT;
break;
}
}
// Actualiza la lógica del juego // Actualiza la lógica del juego
updatePlayField(); update();
}
// Prepara para empezar a dibujar en la textura de juego
mScreen->start();
// Limpia la pantalla
mScreen->clean(bgColor);
// Dibuja los objetos // Dibuja los objetos
renderPlayField(); render();
// Pinta la informacion de debug
renderDebugInfo();
// Vuelca el contenido del renderizador en pantalla
mScreen->blit();
} }
} }
@@ -3246,15 +3256,7 @@ void Game::runPausedGame()
while ((mSection.subsection == GAME_SECTION_PAUSE) && (mSection.name == PROG_SECTION_GAME)) while ((mSection.subsection == GAME_SECTION_PAUSE) && (mSection.name == PROG_SECTION_GAME))
{ {
// Comprueba los eventos que hay en la cola // Comprueba los eventos que hay en la cola
while (SDL_PollEvent(mEventHandler) != 0) checkEventHandler();
{
// Evento de salida de la aplicación
if (mEventHandler->type == SDL_QUIT)
{
mSection.name = PROG_SECTION_QUIT;
break;
}
}
// Calcula la lógica de los objetos // Calcula la lógica de los objetos
if (SDL_GetTicks() - mTicks > mTicksSpeed) if (SDL_GetTicks() - mTicks > mTicksSpeed)
@@ -3281,7 +3283,37 @@ void Game::runPausedGame()
mScreen->clean(bgColor); mScreen->clean(bgColor);
// Pinta el escenario // Pinta el escenario
renderPlayField(); {
renderBackground();
renderBalloons();
renderBullets();
renderMessages();
renderItems();
renderSmartSprites();
renderScoreBoard();
for (auto player : players)
{
player->render();
}
if ((mDeathCounter <= 150) && !players.at(0)->isAlive())
{
renderDeathFade(150 - mDeathCounter);
}
if ((mGameCompleted) && (mGameCompletedCounter >= 300))
{
renderDeathFade(mGameCompletedCounter - 300);
}
renderFlashEffect();
mText->write(0, 0, std::to_string(balloons.size()));
// Pinta la informacion de debug
renderDebugInfo();
}
mMenuPause->render(); mMenuPause->render();
mFade->render(); mFade->render();
@@ -3600,3 +3632,29 @@ bool Game::allPlayersAreDead()
return success; return success;
} }
// Comprueba los eventos que hay en cola
void Game::checkEventHandler()
{
while (SDL_PollEvent(mEventHandler) != 0)
{
// Evento de salida de la aplicación
if (mEventHandler->type == SDL_QUIT)
{
mSection.name = PROG_SECTION_QUIT;
break;
}
else if (mEventHandler->type == SDL_KEYDOWN && mEventHandler->key.repeat == 0)
{
switch (mEventHandler->key.keysym.scancode)
{
case SDL_SCANCODE_P:
createPowerBall();
break;
default:
break;
}
}
}
}

View File

@@ -239,6 +239,15 @@ private:
demo_t mDemo; // Variable con todas las variables relacionadas con el modo demo demo_t mDemo; // Variable con todas las variables relacionadas con el modo demo
debug_t mDebug; // Variable con las opciones de debug debug_t mDebug; // Variable con las opciones de debug
// Actualiza el juego
void update();
// Dibuja el juego
void render();
// Comprueba los eventos que hay en cola
void checkEventHandler();
// Inicializa el vector con los valores del seno // Inicializa el vector con los valores del seno
void initSin(); void initSin();
@@ -392,6 +401,9 @@ private:
// Crea un objeto SmartSprite // Crea un objeto SmartSprite
void createItemScoreSprite(int x, int y, SmartSprite *sprite); void createItemScoreSprite(int x, int y, SmartSprite *sprite);
// Vacia el vector de smartsprites
void freeSmartSprites();
// Dibuja el efecto de flash // Dibuja el efecto de flash
void renderFlashEffect(); void renderFlashEffect();
@@ -443,17 +455,12 @@ private:
// Gestiona el nivel de amenaza // Gestiona el nivel de amenaza
void updateMenace(); void updateMenace();
// Actualiza el campo de juego
void updatePlayField();
// Actualiza el fondo // Actualiza el fondo
void updateBackground(); void updateBackground();
// Dibuja el fondo // Dibuja el fondo
void renderBackground(); void renderBackground();
// Dibuja el campo de juego
void renderPlayField();
// Gestiona la entrada durante el juego // Gestiona la entrada durante el juego
void checkGameInput(); void checkGameInput();

View File

@@ -149,7 +149,7 @@ void LTexture::setAlpha(Uint8 alpha)
// Renderiza la textura en un punto específico // Renderiza la textura en un punto específico
void LTexture::render(SDL_Renderer *renderer, int x, int y, SDL_Rect *clip, float zoomW, float zoomH, double angle, SDL_Point *center, SDL_RendererFlip flip) void LTexture::render(SDL_Renderer *renderer, int x, int y, SDL_Rect *clip, float zoomW, float zoomH, double angle, SDL_Point *center, SDL_RendererFlip flip)
{ {
// Establece el destini de renderizado en la pantalla // Establece el destino de renderizado en la pantalla
SDL_Rect renderQuad = {x, y, width, height}; SDL_Rect renderQuad = {x, y, width, height};
// Obtiene las dimesiones del clip de renderizado // Obtiene las dimesiones del clip de renderizado

View File

@@ -45,7 +45,7 @@ MovingSprite::MovingSprite(float x, float y, int w, int h, float velx, float vel
spriteClip = {0, 0, w, h}; spriteClip = {0, 0, w, h};
// Establece el centro de rotación // Establece el centro de rotación
center = {0, 0}; center = nullptr;
// Establece el tipo de volteado // Establece el tipo de volteado
currentFlip = SDL_FLIP_NONE; currentFlip = SDL_FLIP_NONE;
@@ -73,7 +73,7 @@ void MovingSprite::clear()
angle = 0.0; // Angulo para dibujarlo angle = 0.0; // Angulo para dibujarlo
rotateEnabled = false; // Indica si ha de rotar rotateEnabled = false; // Indica si ha de rotar
center = {0, 0}; // Centro de rotación center = nullptr; // Centro de rotación
rotateSpeed = 0; // Velocidad de giro rotateSpeed = 0; // Velocidad de giro
rotateAmount = 0.0; // Cantidad de grados a girar en cada iteración rotateAmount = 0.0; // Cantidad de grados a girar en cada iteración
counter = 0; // Contador interno counter = 0; // Contador interno
@@ -101,7 +101,9 @@ void MovingSprite::move()
void MovingSprite::render() void MovingSprite::render()
{ {
if (enabled) if (enabled)
texture->render(renderer, (int)x, (int)y, &spriteClip, zoomW, zoomH, angle, &center, currentFlip); {
texture->render(renderer, (int)x, (int)y, &spriteClip, zoomW, zoomH, angle, center, currentFlip);
}
} }
// Obtiene el valor de la variable // Obtiene el valor de la variable

View File

@@ -30,7 +30,7 @@ protected:
int rotateSpeed; // Velocidad de giro int rotateSpeed; // Velocidad de giro
double rotateAmount; // Cantidad de grados a girar en cada iteración double rotateAmount; // Cantidad de grados a girar en cada iteración
int counter; // Contador interno int counter; // Contador interno
SDL_Point center; // Centro de rotación SDL_Point *center; // Centro de rotación
SDL_RendererFlip currentFlip; // Indica como se voltea el sprite SDL_RendererFlip currentFlip; // Indica como se voltea el sprite
public: public: