From eb9eaec61dae4d9bfa3ac02cd88e473d09b60e44 Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Tue, 13 Aug 2024 11:29:13 +0200 Subject: [PATCH] =?UTF-8?q?arreglos=20en=20la=20powerball:=20=20-=20quan?= =?UTF-8?q?=20apareix=20al=20centro,=20pot=20anar=20cap=20a=20l'esquerra?= =?UTF-8?q?=20o=20cap=20a=20la=20dreta=20=20-=20ara=20apareix=20a=20la=20a?= =?UTF-8?q?ltura=20que=20li=20toca=20als=20globos=20grans=20=20-=20tarda?= =?UTF-8?q?=20en=20generarse=20igual=20que=20la=20resta=20de=20globos=20?= =?UTF-8?q?=20-=20rebota=20igual=20que=20els=20globos=20grans=20(com=20fei?= =?UTF-8?q?a=20abans=20de=20canviar=20les=20f=C3=ADsiques=20dels=20globos?= =?UTF-8?q?=20grans)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/balloon.cpp | 4 +-- source/game.cpp | 83 +++++++++++++++++++++++++++++++--------------- 2 files changed, 59 insertions(+), 28 deletions(-) diff --git a/source/balloon.cpp b/source/balloon.cpp index 303f0b4..43eb80d 100644 --- a/source/balloon.cpp +++ b/source/balloon.cpp @@ -199,8 +199,8 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c this->velX = velx; velY = 0; maxVelY = 3.0f; - gravity = 0.10f; - defaultVelY = 4.95f; + gravity = param->balloon4.grav; + defaultVelY = param->balloon4.vel; // Puntos que da el globo al ser destruido score = 0; diff --git a/source/game.cpp b/source/game.cpp index 48414a8..3825039 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -882,7 +882,9 @@ void Game::deployEnemyFormation() // Evita repetir la ultima formación enemiga desplegada if (set == lastEnemyDeploy) + { ++set %= 10; + } lastEnemyDeploy = set; @@ -1087,17 +1089,21 @@ int Game::createBalloon(float x, int y, int kind, float velx, float speed, int c // Crea una PowerBall void Game::createPowerBall() { - const int posY = PLAY_AREA_TOP; + const int values = 6; + const int posY = PLAY_AREA_TOP - BLOCK; const int left = PLAY_AREA_LEFT; const int center = PLAY_AREA_CENTER_X - (BALLOON_WIDTH_4 / 2); const int right = PLAY_AREA_RIGHT - BALLOON_WIDTH_4; - const int luck = rand() % 3; - const int x[3] = {left, center, right}; - const float vx[3] = {BALLOON_VELX_POSITIVE, BALLOON_VELX_POSITIVE, BALLOON_VELX_NEGATIVE}; + const float vpos = BALLOON_VELX_POSITIVE; + const float vneg = BALLOON_VELX_NEGATIVE; - Balloon *b = new Balloon(x[luck], posY, POWER_BALL, vx[luck], enemySpeed, 100, balloonTextures[4], balloonAnimations[4], param); + const int luck = rand() % values; + const int x[values] = {left, left, center, center, right, right}; + const float vx[values] = {vpos, vpos, vpos, vneg, vneg, vneg}; + + Balloon *b = new Balloon(x[luck], posY, POWER_BALL, vx[luck], enemySpeed, 300, balloonTextures[4], balloonAnimations[4], param); balloons.push_back(b); powerBallEnabled = true; @@ -1907,11 +1913,6 @@ void Game::update() // Actualiza el contador de ticks ticks = SDL_GetTicks(); -#ifdef DEBUG - if (counter == 0) - createPowerBall(); -#endif - // Actualiza el contador de juego counter++; @@ -2639,15 +2640,6 @@ bool Game::allPlayersAreDead() // Comprueba los eventos que hay en cola void Game::checkEvents() { -#ifdef DEBUG - const Uint8 *keyStates = SDL_GetKeyboardState(nullptr); - - if (keyStates[SDL_SCANCODE_H] != 0) - { - createItemScoreSprite(param->gameWidth / 2, param->gameWidth / 2, n1000Sprite); - } -#endif - while (SDL_PollEvent(eventHandler) != 0) { // Evento de salida de la aplicación @@ -2659,24 +2651,63 @@ void Game::checkEvents() else if (eventHandler->type == SDL_WINDOWEVENT) { - if (eventHandler->window.event == SDL_WINDOWEVENT_FOCUS_LOST) + switch (eventHandler->window.event) { + case SDL_WINDOWEVENT_FOCUS_LOST: if (!demo.enabled) { pause(true); } - } + break; - if (eventHandler->window.event == SDL_WINDOWEVENT_FOCUS_GAINED) - { + case SDL_WINDOWEVENT_FOCUS_GAINED: pause(false); - } + break; - if (eventHandler->window.event == SDL_WINDOWEVENT_SIZE_CHANGED) - { + case SDL_WINDOWEVENT_SIZE_CHANGED: reloadTextures(); + break; + + default: + break; } } + +#ifdef DEBUG + else if (eventHandler->type == SDL_KEYDOWN) + { + switch (eventHandler->key.keysym.sym) + { + case SDLK_h: + createItemScoreSprite(param->gameWidth / 2, param->gameWidth / 2, n1000Sprite); + break; + + case SDLK_1: + createPowerBall(); + break; + + case SDLK_2: + { + const int set = 0; + const stage_t stage = enemyFormations->getStage(0); + const int numEnemies = stage.enemyPool->set[set]->numberOfEnemies; + for (int i = 0; i < numEnemies; ++i) + { + createBalloon(stage.enemyPool->set[set]->init[i].x, + stage.enemyPool->set[set]->init[i].y, + stage.enemyPool->set[set]->init[i].kind, + stage.enemyPool->set[set]->init[i].velX, + enemySpeed, + stage.enemyPool->set[set]->init[i].creationCounter); + } + } + break; + + default: + break; + } + } +#endif } }