diff --git a/source/balloon.cpp b/source/balloon.cpp index 3fd0126..7928a43 100644 --- a/source/balloon.cpp +++ b/source/balloon.cpp @@ -12,12 +12,20 @@ Balloon::Balloon(float x, float y, Uint8 kind, float vel_x, float speed, Uint16 pos_x_(x), pos_y_(y), vel_x_(vel_x), + being_created_(creation_timer > 0), + blinking_(false), + enabled_(true), + invulnerable_(creation_timer > 0), + stopped_(true), + visible_(true), creation_counter_(creation_timer), creation_counter_ini_(creation_timer), + stopped_counter_(0), kind_(kind), + counter_(0), + travel_y_(1.0f), speed_(speed) { - enabled_ = true; switch (kind_) { @@ -243,21 +251,6 @@ Balloon::Balloon(float x, float y, Uint8 kind, float vel_x, float speed, Uint16 // Alinea el circulo de colisión con el objeto updateColliders(); - - // Inicializa variables - stopped_ = true; - stopped_counter_ = 0; - blinking_ = false; - visible_ = true; - invulnerable_ = true; - being_created_ = true; - - // Actualiza valores - being_created_ = creation_counter_ == 0 ? false : true; - invulnerable_ = being_created_ == false ? false : true; - - counter_ = 0; - travel_y_ = 1.0f; } // Centra el globo en la posición X diff --git a/source/balloon_formations.cpp b/source/balloon_formations.cpp new file mode 100644 index 0000000..0c22096 --- /dev/null +++ b/source/balloon_formations.cpp @@ -0,0 +1,719 @@ +#include "balloon_formations.h" +#include "balloon.h" // for BALLOON_VELX_NEGATIVE, BALLOON_VELX_POSITIVE +#include "param.h" // for param +#include "utils.h" // for ParamGame, Param, Zone, BLOCK + +// Constructor +BalloonFormations::BalloonFormations() +{ + initBalloonFormations(); + initBalloonFormationPools(); + initGameStages(); +} + +// Inicializa las formaciones enemigas +void BalloonFormations::initBalloonFormations() +{ + constexpr int y4 = -BLOCK; + const int x4_0 = param.game.play_area.rect.x; + const int x4_100 = param.game.play_area.rect.w - BALLOON_WIDTH_4; + + constexpr int y3 = -BLOCK; + const int x3_0 = param.game.play_area.rect.x; + const int x3_100 = param.game.play_area.rect.w - BALLOON_WIDTH_3; + + constexpr int y2 = -BLOCK; + const int x2_0 = param.game.play_area.rect.x; + const int x2_100 = param.game.play_area.rect.w - BALLOON_WIDTH_2; + + constexpr int y1 = -BLOCK; + const int x1_0 = param.game.play_area.rect.x; + const int x1_50 = param.game.play_area.center_x - (BALLOON_WIDTH_1 / 2); + const int x1_100 = param.game.play_area.rect.w - BALLOON_WIDTH_1; + + // Inicializa a cero las variables + for (int i = 0; i < NUMBER_OF_BALLOON_FORMATIONS; i++) + { + balloon_formation_[i].number_of_balloons = 0; + for (int j = 0; j < MAX_NUMBER_OF_BALLOONS_IN_A_FORMATION; j++) + { + balloon_formation_[i].init[j].x = 0; + balloon_formation_[i].init[j].y = 0; + balloon_formation_[i].init[j].vel_x = 0; + balloon_formation_[i].init[j].kind = 0; + balloon_formation_[i].init[j].creation_counter = 0; + } + } + + const int creation_time = 300; + int inc_x = 0; + int inc_time = 0; + int j = 0; + + // #00 - Dos enemigos BALLOON4 uno a cada extremo + j = 0; + balloon_formation_[j].number_of_balloons = 2; + inc_x = x4_100; + inc_time = 0; + for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) + { + balloon_formation_[j].init[i].x = x4_0 + (i * inc_x); + balloon_formation_[j].init[i].y = y4; + balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE * (((i % 2) * 2) - 1); + balloon_formation_[j].init[i].kind = BALLOON_4; + balloon_formation_[j].init[i].creation_counter = creation_time + (inc_time * i); + } + + // #01 - Dos enemigos BALLOON4 uno a cada cuarto. Ambos van hacia el centro + j = 1; + balloon_formation_[j].number_of_balloons = 2; + inc_x = param.game.play_area.center_x; + inc_time = 0; + for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) + { + balloon_formation_[j].init[i].x = param.game.play_area.first_quarter_x - (BALLOON_WIDTH_4 / 2) + (i * inc_x); + balloon_formation_[j].init[i].y = y4; + balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE * (((i % 2) * 2) - 1); + balloon_formation_[j].init[i].kind = BALLOON_4; + balloon_formation_[j].init[i].creation_counter = creation_time + (inc_time * i); + } + + // #02 - Cuatro enemigos BALLOON2 uno detras del otro. A la izquierda y hacia el centro + j = 2; + balloon_formation_[j].number_of_balloons = 4; + inc_x = BALLOON_WIDTH_2 + 1; + inc_time = 10; + for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) + { + balloon_formation_[j].init[i].x = x2_0 + (i * inc_x); + balloon_formation_[j].init[i].y = y2; + balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE; + balloon_formation_[j].init[i].kind = BALLOON_2; + balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i); + } + + // #03 - Cuatro enemigos BALLOON2 uno detras del otro. A la derecha y hacia el centro + j = 3; + balloon_formation_[j].number_of_balloons = 4; + inc_x = BALLOON_WIDTH_2 + 1; + inc_time = 10; + for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) + { + balloon_formation_[j].init[i].x = x2_100 - (i * inc_x); + balloon_formation_[j].init[i].y = y2; + balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE; + balloon_formation_[j].init[i].kind = BALLOON_2; + balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i); + } + + // #04 - Tres enemigos BALLOON3. 0, 25, 50. Hacia la derecha + j = 4; + balloon_formation_[j].number_of_balloons = 3; + inc_x = BALLOON_WIDTH_3 * 2; + inc_time = 10; + for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) + { + balloon_formation_[j].init[i].x = x3_0 + (i * inc_x); + balloon_formation_[j].init[i].y = y3; + balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE; + balloon_formation_[j].init[i].kind = BALLOON_3; + balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i); + } + + // #05 - Tres enemigos BALLOON3. 50, 75, 100. Hacia la izquierda + j = 5; + balloon_formation_[j].number_of_balloons = 3; + inc_x = BALLOON_WIDTH_3 * 2; + inc_time = 10; + for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) + { + balloon_formation_[j].init[i].x = x3_100 - (i * inc_x); + balloon_formation_[j].init[i].y = y3; + balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE; + balloon_formation_[j].init[i].kind = BALLOON_3; + balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i); + } + + // #06 - Tres enemigos BALLOON3. 0, 0, 0. Hacia la derecha + j = 6; + balloon_formation_[j].number_of_balloons = 3; + inc_x = BALLOON_WIDTH_3 + 1; + inc_time = 10; + for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) + { + balloon_formation_[j].init[i].x = x3_0 + (i * inc_x); + balloon_formation_[j].init[i].y = y3; + balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE; + balloon_formation_[j].init[i].kind = BALLOON_3; + balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i); + } + + // #07 - Tres enemigos BALLOON3. 100, 100, 100. Hacia la izquierda + j = 7; + balloon_formation_[j].number_of_balloons = 3; + inc_x = BALLOON_WIDTH_3 + 1; + inc_time = 10; + for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) + { + balloon_formation_[j].init[i].x = x3_100 - (i * inc_x); + balloon_formation_[j].init[i].y = y3; + balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE; + balloon_formation_[j].init[i].kind = BALLOON_3; + balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i); + } + + // #08 - Seis enemigos BALLOON1. 0, 0, 0, 0, 0, 0. Hacia la derecha + j = 8; + balloon_formation_[j].number_of_balloons = 6; + inc_x = BALLOON_WIDTH_1 + 1; + inc_time = 10; + for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) + { + balloon_formation_[j].init[i].x = x1_0 + (i * inc_x); + balloon_formation_[j].init[i].y = y1; + balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE; + balloon_formation_[j].init[i].kind = BALLOON_1; + balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i); + } + + // #09 - Seis enemigos BALLOON1. 100, 100, 100, 100, 100, 100. Hacia la izquierda + j = 9; + balloon_formation_[j].number_of_balloons = 6; + inc_x = BALLOON_WIDTH_1 + 1; + inc_time = 10; + for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) + { + balloon_formation_[j].init[i].x = x1_100 - (i * inc_x); + balloon_formation_[j].init[i].y = y1; + balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE; + balloon_formation_[j].init[i].kind = BALLOON_1; + balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i); + } + + // #10 - Tres enemigos BALLOON4 seguidos desde la izquierda + j = 10; + balloon_formation_[j].number_of_balloons = 3; + inc_x = BALLOON_WIDTH_4 + 1; + inc_time = 15; + for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) + { + balloon_formation_[j].init[i].x = x4_0 + (i * inc_x); + balloon_formation_[j].init[i].y = y4; + balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE; + balloon_formation_[j].init[i].kind = BALLOON_4; + balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i); + } + + // #11 - Tres enemigos BALLOON4 seguidos desde la derecha + j = 11; + balloon_formation_[j].number_of_balloons = 3; + inc_x = BALLOON_WIDTH_4 + 1; + inc_time = 15; + for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) + { + balloon_formation_[j].init[i].x = x4_100 - (i * inc_x); + balloon_formation_[j].init[i].y = y4; + balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE; + balloon_formation_[j].init[i].kind = BALLOON_4; + balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i); + } + + // #12 - Seis enemigos BALLOON2 uno detras del otro. A la izquierda y hacia el centro + j = 12; + balloon_formation_[j].number_of_balloons = 6; + inc_x = BALLOON_WIDTH_2 + 1; + inc_time = 10; + for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) + { + balloon_formation_[j].init[i].x = x2_0 + (i * inc_x); + balloon_formation_[j].init[i].y = y2; + balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE; + balloon_formation_[j].init[i].kind = BALLOON_2; + balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i); + } + + // #13 - Seis enemigos BALLOON2 uno detras del otro. A la derecha y hacia el centro + j = 13; + balloon_formation_[j].number_of_balloons = 6; + inc_x = BALLOON_WIDTH_2 + 1; + inc_time = 10; + for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) + { + balloon_formation_[j].init[i].x = x2_100 - (i * inc_x); + balloon_formation_[j].init[i].y = y2; + balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE; + balloon_formation_[j].init[i].kind = BALLOON_2; + balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i); + } + + // #14 - Cinco enemigos BALLOON3. Hacia la derecha. Separados + j = 14; + balloon_formation_[j].number_of_balloons = 5; + inc_x = BALLOON_WIDTH_3 * 2; + inc_time = 10; + for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) + { + balloon_formation_[j].init[i].x = x3_0 + (i * inc_x); + balloon_formation_[j].init[i].y = y3; + balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE; + balloon_formation_[j].init[i].kind = BALLOON_3; + balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i); + } + + // #15 - Cinco enemigos BALLOON3. Hacia la izquierda. Separados + j = 15; + balloon_formation_[j].number_of_balloons = 5; + inc_x = BALLOON_WIDTH_3 * 2; + inc_time = 10; + for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) + { + balloon_formation_[j].init[i].x = x3_100 - (i * inc_x); + balloon_formation_[j].init[i].y = y3; + balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE; + balloon_formation_[j].init[i].kind = BALLOON_3; + balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i); + } + + // #16 - Cinco enemigos BALLOON3. Hacia la derecha. Juntos + j = 16; + balloon_formation_[j].number_of_balloons = 5; + inc_x = BALLOON_WIDTH_3 + 1; + inc_time = 10; + for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) + { + balloon_formation_[j].init[i].x = x3_0 + (i * inc_x); + balloon_formation_[j].init[i].y = y3; + balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE; + balloon_formation_[j].init[i].kind = BALLOON_3; + balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i); + } + + // #17 - Cinco enemigos BALLOON3. Hacia la izquierda. Juntos + j = 17; + balloon_formation_[j].number_of_balloons = 5; + inc_x = BALLOON_WIDTH_3 + 1; + inc_time = 10; + for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) + { + balloon_formation_[j].init[i].x = x3_100 - (i * inc_x); + balloon_formation_[j].init[i].y = y3; + balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE; + balloon_formation_[j].init[i].kind = BALLOON_3; + balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i); + } + + // #18 - Doce enemigos BALLOON1. Hacia la derecha. Juntos + j = 18; + balloon_formation_[j].number_of_balloons = 12; + inc_x = BALLOON_WIDTH_1 + 1; + inc_time = 10; + for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) + { + balloon_formation_[j].init[i].x = x1_0 + (i * inc_x); + balloon_formation_[j].init[i].y = y1; + balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE; + balloon_formation_[j].init[i].kind = BALLOON_1; + balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i); + } + + // #19 - Doce enemigos BALLOON1. Hacia la izquierda. Juntos + j = 19; + balloon_formation_[j].number_of_balloons = 12; + inc_x = BALLOON_WIDTH_1 + 1; + inc_time = 10; + for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) + { + balloon_formation_[j].init[i].x = x1_100 - (i * inc_x); + balloon_formation_[j].init[i].y = y1; + balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE; + balloon_formation_[j].init[i].kind = BALLOON_1; + balloon_formation_[j].init[i].creation_counter = creation_time - (inc_time * i); + } + + // #20 - Dos enemigos BALLOON4 seguidos desde la izquierda/derecha. Simetricos + j = 20; + balloon_formation_[j].number_of_balloons = 4; + inc_x = BALLOON_WIDTH_4 + 1; + inc_time = 0; + for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) + { + const int half = balloon_formation_[j].number_of_balloons / 2; + if (i < half) + { + balloon_formation_[j].init[i].x = x4_0 + (i * inc_x); + balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE; + } + else + { + balloon_formation_[j].init[i].x = x4_100 - ((i - half) * inc_x); + balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE; + } + balloon_formation_[j].init[i].y = y4; + balloon_formation_[j].init[i].kind = BALLOON_4; + balloon_formation_[j].init[i].creation_counter = creation_time + (inc_time * i); + } + + // #21 - Diez enemigos BALLOON2 uno detras del otro. Izquierda/derecha. Simetricos + j = 21; + balloon_formation_[j].number_of_balloons = 10; + inc_x = BALLOON_WIDTH_2 + 1; + inc_time = 3; + for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) + { + const int half = balloon_formation_[j].number_of_balloons / 2; + if (i < half) + { + balloon_formation_[j].init[i].x = x2_0 + (i * inc_x); + balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE; + balloon_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * i); + } + else + { + balloon_formation_[j].init[i].x = x2_100 - ((i - half) * inc_x); + balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE; + balloon_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * (i - half)); + } + balloon_formation_[j].init[i].y = y2; + balloon_formation_[j].init[i].kind = BALLOON_2; + } + + // #22 - Diez enemigos BALLOON3. Hacia la derecha/izquierda. Separados. Simetricos + j = 22; + balloon_formation_[j].number_of_balloons = 10; + inc_x = BALLOON_WIDTH_3 * 2; + inc_time = 10; + for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) + { + const int half = balloon_formation_[j].number_of_balloons / 2; + if (i < half) + { + balloon_formation_[j].init[i].x = x3_0 + (i * inc_x); + balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE; + balloon_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * i); + } + else + { + balloon_formation_[j].init[i].x = x3_100 - ((i - half) * inc_x); + balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE; + balloon_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * (i - half)); + } + balloon_formation_[j].init[i].y = y3; + balloon_formation_[j].init[i].kind = BALLOON_3; + } + + // #23 - Diez enemigos BALLOON3. Hacia la derecha. Juntos. Simetricos + j = 23; + balloon_formation_[j].number_of_balloons = 10; + inc_x = BALLOON_WIDTH_3 + 1; + inc_time = 10; + for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) + { + const int half = balloon_formation_[j].number_of_balloons / 2; + if (i < half) + { + balloon_formation_[j].init[i].x = x3_0 + (i * inc_x); + balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE; + balloon_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * i); + } + else + { + balloon_formation_[j].init[i].x = x3_100 - ((i - half) * inc_x); + balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE; + balloon_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * (i - half)); + } + balloon_formation_[j].init[i].y = y3; + balloon_formation_[j].init[i].kind = BALLOON_3; + } + + // #24 - Treinta enemigos BALLOON1. Del centro hacia los extremos. Juntos. Simetricos + j = 24; + balloon_formation_[j].number_of_balloons = 30; + inc_x = 0; + inc_time = 5; + for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) + { + const int half = balloon_formation_[j].number_of_balloons / 2; + if (i < half) + { + balloon_formation_[j].init[i].x = x1_50; + balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE; + balloon_formation_[j].init[i].creation_counter = (creation_time) + (inc_time * i); + } + else + { + balloon_formation_[j].init[i].x = x1_50; + balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE; + balloon_formation_[j].init[i].creation_counter = (creation_time) + (inc_time * (i - half)); + } + balloon_formation_[j].init[i].y = y1; + balloon_formation_[j].init[i].kind = BALLOON_1; + } + + // #25 - Treinta enemigos BALLOON1. Del centro hacia adentro. Juntos. Simetricos + j = 25; + balloon_formation_[j].number_of_balloons = 30; + inc_time = 5; + for (int i = 0; i < balloon_formation_[j].number_of_balloons; i++) + { + const int half = balloon_formation_[j].number_of_balloons / 2; + if (i < half) + { + balloon_formation_[j].init[i].x = x1_50 + 20; + balloon_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE; + balloon_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * i); + } + else + { + balloon_formation_[j].init[i].x = x1_50 - 20; + balloon_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE; + balloon_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * (i - half)); + } + balloon_formation_[j].init[i].y = y1; + balloon_formation_[j].init[i].kind = BALLOON_1; + } + + // Crea las mismas formaciones pero con hexagonos a partir de la posición 50 del vector + for (int k = 0; k < j + 1; k++) + { + balloon_formation_[k + 50].number_of_balloons = balloon_formation_[k].number_of_balloons; + for (int i = 0; i < balloon_formation_[k + 50].number_of_balloons; i++) + { + balloon_formation_[k + 50].init[i].x = balloon_formation_[k].init[i].x; + balloon_formation_[k + 50].init[i].y = balloon_formation_[k].init[i].y; + balloon_formation_[k + 50].init[i].vel_x = balloon_formation_[k].init[i].vel_x; + balloon_formation_[k + 50].init[i].creation_counter = balloon_formation_[k].init[i].creation_counter; + balloon_formation_[k + 50].init[i].kind = balloon_formation_[k].init[i].kind + 4; + } + } + + // TEST + balloon_formation_[99].number_of_balloons = 4; + + balloon_formation_[99].init[0].x = 10; + balloon_formation_[99].init[0].y = y1; + balloon_formation_[99].init[0].vel_x = 0; + balloon_formation_[99].init[0].kind = BALLOON_1; + balloon_formation_[99].init[0].creation_counter = 200; + + balloon_formation_[99].init[1].x = 50; + balloon_formation_[99].init[1].y = y1; + balloon_formation_[99].init[1].vel_x = 0; + balloon_formation_[99].init[1].kind = BALLOON_2; + balloon_formation_[99].init[1].creation_counter = 200; + + balloon_formation_[99].init[2].x = 90; + balloon_formation_[99].init[2].y = y1; + balloon_formation_[99].init[2].vel_x = 0; + balloon_formation_[99].init[2].kind = BALLOON_3; + balloon_formation_[99].init[2].creation_counter = 200; + + balloon_formation_[99].init[3].x = 140; + balloon_formation_[99].init[3].y = y1; + balloon_formation_[99].init[3].vel_x = 0; + balloon_formation_[99].init[3].kind = BALLOON_4; + balloon_formation_[99].init[3].creation_counter = 200; +} + +// Inicializa los conjuntos de formaciones +void BalloonFormations::initBalloonFormationPools() +{ + // EnemyPool #0 + balloon_formation_pool_[0].set[0] = &balloon_formation_[0]; + balloon_formation_pool_[0].set[1] = &balloon_formation_[1]; + balloon_formation_pool_[0].set[2] = &balloon_formation_[2]; + balloon_formation_pool_[0].set[3] = &balloon_formation_[3]; + balloon_formation_pool_[0].set[4] = &balloon_formation_[4]; + balloon_formation_pool_[0].set[5] = &balloon_formation_[5]; + balloon_formation_pool_[0].set[6] = &balloon_formation_[6]; + balloon_formation_pool_[0].set[7] = &balloon_formation_[7]; + balloon_formation_pool_[0].set[8] = &balloon_formation_[8]; + balloon_formation_pool_[0].set[9] = &balloon_formation_[9]; + + // EnemyPool #1 + balloon_formation_pool_[1].set[0] = &balloon_formation_[10]; + balloon_formation_pool_[1].set[1] = &balloon_formation_[11]; + balloon_formation_pool_[1].set[2] = &balloon_formation_[12]; + balloon_formation_pool_[1].set[3] = &balloon_formation_[13]; + balloon_formation_pool_[1].set[4] = &balloon_formation_[14]; + balloon_formation_pool_[1].set[5] = &balloon_formation_[15]; + balloon_formation_pool_[1].set[6] = &balloon_formation_[16]; + balloon_formation_pool_[1].set[7] = &balloon_formation_[17]; + balloon_formation_pool_[1].set[8] = &balloon_formation_[18]; + balloon_formation_pool_[1].set[9] = &balloon_formation_[19]; + + // EnemyPool #2 + balloon_formation_pool_[2].set[0] = &balloon_formation_[0]; + balloon_formation_pool_[2].set[1] = &balloon_formation_[1]; + balloon_formation_pool_[2].set[2] = &balloon_formation_[2]; + balloon_formation_pool_[2].set[3] = &balloon_formation_[3]; + balloon_formation_pool_[2].set[4] = &balloon_formation_[4]; + balloon_formation_pool_[2].set[5] = &balloon_formation_[55]; + balloon_formation_pool_[2].set[6] = &balloon_formation_[56]; + balloon_formation_pool_[2].set[7] = &balloon_formation_[57]; + balloon_formation_pool_[2].set[8] = &balloon_formation_[58]; + balloon_formation_pool_[2].set[9] = &balloon_formation_[59]; + + // EnemyPool #3 + balloon_formation_pool_[3].set[0] = &balloon_formation_[50]; + balloon_formation_pool_[3].set[1] = &balloon_formation_[51]; + balloon_formation_pool_[3].set[2] = &balloon_formation_[52]; + balloon_formation_pool_[3].set[3] = &balloon_formation_[53]; + balloon_formation_pool_[3].set[4] = &balloon_formation_[54]; + balloon_formation_pool_[3].set[5] = &balloon_formation_[5]; + balloon_formation_pool_[3].set[6] = &balloon_formation_[6]; + balloon_formation_pool_[3].set[7] = &balloon_formation_[7]; + balloon_formation_pool_[3].set[8] = &balloon_formation_[8]; + balloon_formation_pool_[3].set[9] = &balloon_formation_[9]; + + // EnemyPool #4 + balloon_formation_pool_[4].set[0] = &balloon_formation_[60]; + balloon_formation_pool_[4].set[1] = &balloon_formation_[61]; + balloon_formation_pool_[4].set[2] = &balloon_formation_[62]; + balloon_formation_pool_[4].set[3] = &balloon_formation_[63]; + balloon_formation_pool_[4].set[4] = &balloon_formation_[64]; + balloon_formation_pool_[4].set[5] = &balloon_formation_[65]; + balloon_formation_pool_[4].set[6] = &balloon_formation_[66]; + balloon_formation_pool_[4].set[7] = &balloon_formation_[67]; + balloon_formation_pool_[4].set[8] = &balloon_formation_[68]; + balloon_formation_pool_[4].set[9] = &balloon_formation_[69]; + + // EnemyPool #5 + balloon_formation_pool_[5].set[0] = &balloon_formation_[10]; + balloon_formation_pool_[5].set[1] = &balloon_formation_[61]; + balloon_formation_pool_[5].set[2] = &balloon_formation_[12]; + balloon_formation_pool_[5].set[3] = &balloon_formation_[63]; + balloon_formation_pool_[5].set[4] = &balloon_formation_[14]; + balloon_formation_pool_[5].set[5] = &balloon_formation_[65]; + balloon_formation_pool_[5].set[6] = &balloon_formation_[16]; + balloon_formation_pool_[5].set[7] = &balloon_formation_[67]; + balloon_formation_pool_[5].set[8] = &balloon_formation_[18]; + balloon_formation_pool_[5].set[9] = &balloon_formation_[69]; + + // EnemyPool #6 + balloon_formation_pool_[6].set[0] = &balloon_formation_[60]; + balloon_formation_pool_[6].set[1] = &balloon_formation_[11]; + balloon_formation_pool_[6].set[2] = &balloon_formation_[62]; + balloon_formation_pool_[6].set[3] = &balloon_formation_[13]; + balloon_formation_pool_[6].set[4] = &balloon_formation_[64]; + balloon_formation_pool_[6].set[5] = &balloon_formation_[15]; + balloon_formation_pool_[6].set[6] = &balloon_formation_[66]; + balloon_formation_pool_[6].set[7] = &balloon_formation_[17]; + balloon_formation_pool_[6].set[8] = &balloon_formation_[68]; + balloon_formation_pool_[6].set[9] = &balloon_formation_[19]; + + // EnemyPool #7 + balloon_formation_pool_[7].set[0] = &balloon_formation_[20]; + balloon_formation_pool_[7].set[1] = &balloon_formation_[21]; + balloon_formation_pool_[7].set[2] = &balloon_formation_[22]; + balloon_formation_pool_[7].set[3] = &balloon_formation_[23]; + balloon_formation_pool_[7].set[4] = &balloon_formation_[24]; + balloon_formation_pool_[7].set[5] = &balloon_formation_[65]; + balloon_formation_pool_[7].set[6] = &balloon_formation_[66]; + balloon_formation_pool_[7].set[7] = &balloon_formation_[67]; + balloon_formation_pool_[7].set[8] = &balloon_formation_[68]; + balloon_formation_pool_[7].set[9] = &balloon_formation_[69]; + + // EnemyPool #8 + balloon_formation_pool_[8].set[0] = &balloon_formation_[70]; + balloon_formation_pool_[8].set[1] = &balloon_formation_[71]; + balloon_formation_pool_[8].set[2] = &balloon_formation_[72]; + balloon_formation_pool_[8].set[3] = &balloon_formation_[73]; + balloon_formation_pool_[8].set[4] = &balloon_formation_[74]; + balloon_formation_pool_[8].set[5] = &balloon_formation_[15]; + balloon_formation_pool_[8].set[6] = &balloon_formation_[16]; + balloon_formation_pool_[8].set[7] = &balloon_formation_[17]; + balloon_formation_pool_[8].set[8] = &balloon_formation_[18]; + balloon_formation_pool_[8].set[9] = &balloon_formation_[19]; + + // EnemyPool #9 + balloon_formation_pool_[9].set[0] = &balloon_formation_[20]; + balloon_formation_pool_[9].set[1] = &balloon_formation_[21]; + balloon_formation_pool_[9].set[2] = &balloon_formation_[22]; + balloon_formation_pool_[9].set[3] = &balloon_formation_[23]; + balloon_formation_pool_[9].set[4] = &balloon_formation_[24]; + balloon_formation_pool_[9].set[5] = &balloon_formation_[70]; + balloon_formation_pool_[9].set[6] = &balloon_formation_[71]; + balloon_formation_pool_[9].set[7] = &balloon_formation_[72]; + balloon_formation_pool_[9].set[8] = &balloon_formation_[73]; + balloon_formation_pool_[9].set[9] = &balloon_formation_[74]; +} + +// Inicializa las fases del juego +void BalloonFormations::initGameStages() +{ + // STAGE 1 + stage_[0].number = 1; + stage_[0].power_to_complete = 200; + stage_[0].min_menace = 7 + (4 * 1); + stage_[0].max_menace = 7 + (4 * 3); + stage_[0].balloon_pool = &balloon_formation_pool_[0]; + + // STAGE 2 + stage_[1].number = 2; + stage_[1].power_to_complete = 300; + stage_[1].min_menace = 7 + (4 * 2); + stage_[1].max_menace = 7 + (4 * 4); + stage_[1].balloon_pool = &balloon_formation_pool_[1]; + + // STAGE 3 + stage_[2].number = 3; + stage_[2].power_to_complete = 600; + stage_[2].min_menace = 7 + (4 * 3); + stage_[2].max_menace = 7 + (4 * 5); + stage_[2].balloon_pool = &balloon_formation_pool_[2]; + + // STAGE 4 + stage_[3].number = 4; + stage_[3].power_to_complete = 600; + stage_[3].min_menace = 7 + (4 * 3); + stage_[3].max_menace = 7 + (4 * 5); + stage_[3].balloon_pool = &balloon_formation_pool_[3]; + + // STAGE 5 + stage_[4].number = 5; + stage_[4].power_to_complete = 600; + stage_[4].min_menace = 7 + (4 * 4); + stage_[4].max_menace = 7 + (4 * 6); + stage_[4].balloon_pool = &balloon_formation_pool_[4]; + + // STAGE 6 + stage_[5].number = 6; + stage_[5].power_to_complete = 600; + stage_[5].min_menace = 7 + (4 * 4); + stage_[5].max_menace = 7 + (4 * 6); + stage_[5].balloon_pool = &balloon_formation_pool_[5]; + + // STAGE 7 + stage_[6].number = 7; + stage_[6].power_to_complete = 650; + stage_[6].min_menace = 7 + (4 * 5); + stage_[6].max_menace = 7 + (4 * 7); + stage_[6].balloon_pool = &balloon_formation_pool_[6]; + + // STAGE 8 + stage_[7].number = 8; + stage_[7].power_to_complete = 750; + stage_[7].min_menace = 7 + (4 * 5); + stage_[7].max_menace = 7 + (4 * 7); + stage_[7].balloon_pool = &balloon_formation_pool_[7]; + + // STAGE 9 + stage_[8].number = 9; + stage_[8].power_to_complete = 850; + stage_[8].min_menace = 7 + (4 * 6); + stage_[8].max_menace = 7 + (4 * 8); + stage_[8].balloon_pool = &balloon_formation_pool_[8]; + + // STAGE 10 + stage_[9].number = 10; + stage_[9].power_to_complete = 950; + stage_[9].min_menace = 7 + (4 * 7); + stage_[9].max_menace = 7 + (4 * 10); + stage_[9].balloon_pool = &balloon_formation_pool_[9]; +} + +// Devuelve una fase +Stage BalloonFormations::getStage(int index) const +{ + return stage_[index]; +} \ No newline at end of file diff --git a/source/balloon_formations.h b/source/balloon_formations.h new file mode 100644 index 0000000..dac04d0 --- /dev/null +++ b/source/balloon_formations.h @@ -0,0 +1,63 @@ +#pragma once + +constexpr int NUMBER_OF_BALLOON_FORMATIONS = 100; +constexpr int MAX_NUMBER_OF_BALLOONS_IN_A_FORMATION = 50; + +// Estructuras +struct BalloonFormationParams +{ + int x; // Posición en el eje X donde crear al enemigo + int y; // Posición en el eje Y donde crear al enemigo + float vel_x; // Velocidad inicial en el eje X + int kind; // Tipo de enemigo + int creation_counter; // Temporizador para la creación del enemigo +}; + +struct BalloonFormationUnit // Contiene la información de una formación enemiga +{ + int number_of_balloons; // Cantidad de enemigos que forman la formación + BalloonFormationParams init[MAX_NUMBER_OF_BALLOONS_IN_A_FORMATION]; // Vector con todas las inicializaciones de los enemigos de la formación +}; + +struct BalloonFormationPool +{ + BalloonFormationUnit *set[10]; // Conjunto de formaciones de globos +}; + +struct Stage // Contiene todas las variables relacionadas con una fase +{ + BalloonFormationPool *balloon_pool; // El conjunto de formaciones de globos de la fase + int power_to_complete; // Cantidad de poder que se necesita para completar la fase + int max_menace; // Umbral máximo de amenaza de la fase + int min_menace; // Umbral mínimo de amenaza de la fase + int number; // Número de fase +}; + +// Clase BalloonFormations, para gestionar las formaciones de globos +class BalloonFormations +{ +private: + // Variables + Stage stage_[10]; // Variable con los datos de cada pantalla + BalloonFormationUnit balloon_formation_[NUMBER_OF_BALLOON_FORMATIONS]; // Vector con todas las formaciones enemigas + BalloonFormationPool balloon_formation_pool_[10]; // Variable con los diferentes conjuntos de formaciones enemigas + + // Inicializa las formaciones enemigas + void initBalloonFormations(); + + // Inicializa los conjuntos de formaciones + void initBalloonFormationPools(); + + // Inicializa las fases del juego + void initGameStages(); + +public: + // Constructor + BalloonFormations(); + + // Destructor + ~BalloonFormations() = default; + + // Devuelve una fase + Stage getStage(int index) const; +}; \ No newline at end of file diff --git a/source/enemy_formations.cpp b/source/enemy_formations.cpp deleted file mode 100644 index f8297dd..0000000 --- a/source/enemy_formations.cpp +++ /dev/null @@ -1,719 +0,0 @@ -#include "enemy_formations.h" -#include "balloon.h" // for BALLOON_VELX_NEGATIVE, BALLOON_VELX_POSITIVE -#include "param.h" // for param -#include "utils.h" // for ParamGame, Param, Zone, BLOCK - -// Constructor -EnemyFormations::EnemyFormations() -{ - initEnemyFormations(); - initEnemyPools(); - initGameStages(); -} - -// Inicializa las formaciones enemigas -void EnemyFormations::initEnemyFormations() -{ - constexpr int y4 = -BLOCK; - const int x4_0 = param.game.play_area.rect.x; - const int x4_100 = param.game.play_area.rect.w - BALLOON_WIDTH_4; - - constexpr int y3 = -BLOCK; - const int x3_0 = param.game.play_area.rect.x; - const int x3_100 = param.game.play_area.rect.w - BALLOON_WIDTH_3; - - constexpr int y2 = -BLOCK; - const int x2_0 = param.game.play_area.rect.x; - const int x2_100 = param.game.play_area.rect.w - BALLOON_WIDTH_2; - - constexpr int y1 = -BLOCK; - const int x1_0 = param.game.play_area.rect.x; - const int x1_50 = param.game.play_area.center_x - (BALLOON_WIDTH_1 / 2); - const int x1_100 = param.game.play_area.rect.w - BALLOON_WIDTH_1; - - // Inicializa a cero las variables - for (int i = 0; i < NUMBER_OF_ENEMY_FORMATIONS; i++) - { - enemy_formation_[i].number_of_enemies = 0; - for (int j = 0; j < MAX_NUMBER_OF_ENEMIES_IN_A_FORMATION; j++) - { - enemy_formation_[i].init[j].x = 0; - enemy_formation_[i].init[j].y = 0; - enemy_formation_[i].init[j].vel_x = 0; - enemy_formation_[i].init[j].kind = 0; - enemy_formation_[i].init[j].creation_counter = 0; - } - } - - const int creation_time = 300; - int inc_x = 0; - int inc_time = 0; - int j = 0; - - // #00 - Dos enemigos BALLOON4 uno a cada extremo - j = 0; - enemy_formation_[j].number_of_enemies = 2; - inc_x = x4_100; - inc_time = 0; - for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++) - { - enemy_formation_[j].init[i].x = x4_0 + (i * inc_x); - enemy_formation_[j].init[i].y = y4; - enemy_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE * (((i % 2) * 2) - 1); - enemy_formation_[j].init[i].kind = BALLOON_4; - enemy_formation_[j].init[i].creation_counter = creation_time + (inc_time * i); - } - - // #01 - Dos enemigos BALLOON4 uno a cada cuarto. Ambos van hacia el centro - j = 1; - enemy_formation_[j].number_of_enemies = 2; - inc_x = param.game.play_area.center_x; - inc_time = 0; - for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++) - { - enemy_formation_[j].init[i].x = param.game.play_area.first_quarter_x - (BALLOON_WIDTH_4 / 2) + (i * inc_x); - enemy_formation_[j].init[i].y = y4; - enemy_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE * (((i % 2) * 2) - 1); - enemy_formation_[j].init[i].kind = BALLOON_4; - enemy_formation_[j].init[i].creation_counter = creation_time + (inc_time * i); - } - - // #02 - Cuatro enemigos BALLOON2 uno detras del otro. A la izquierda y hacia el centro - j = 2; - enemy_formation_[j].number_of_enemies = 4; - inc_x = BALLOON_WIDTH_2 + 1; - inc_time = 10; - for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++) - { - enemy_formation_[j].init[i].x = x2_0 + (i * inc_x); - enemy_formation_[j].init[i].y = y2; - enemy_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE; - enemy_formation_[j].init[i].kind = BALLOON_2; - enemy_formation_[j].init[i].creation_counter = creation_time - (inc_time * i); - } - - // #03 - Cuatro enemigos BALLOON2 uno detras del otro. A la derecha y hacia el centro - j = 3; - enemy_formation_[j].number_of_enemies = 4; - inc_x = BALLOON_WIDTH_2 + 1; - inc_time = 10; - for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++) - { - enemy_formation_[j].init[i].x = x2_100 - (i * inc_x); - enemy_formation_[j].init[i].y = y2; - enemy_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE; - enemy_formation_[j].init[i].kind = BALLOON_2; - enemy_formation_[j].init[i].creation_counter = creation_time - (inc_time * i); - } - - // #04 - Tres enemigos BALLOON3. 0, 25, 50. Hacia la derecha - j = 4; - enemy_formation_[j].number_of_enemies = 3; - inc_x = BALLOON_WIDTH_3 * 2; - inc_time = 10; - for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++) - { - enemy_formation_[j].init[i].x = x3_0 + (i * inc_x); - enemy_formation_[j].init[i].y = y3; - enemy_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE; - enemy_formation_[j].init[i].kind = BALLOON_3; - enemy_formation_[j].init[i].creation_counter = creation_time - (inc_time * i); - } - - // #05 - Tres enemigos BALLOON3. 50, 75, 100. Hacia la izquierda - j = 5; - enemy_formation_[j].number_of_enemies = 3; - inc_x = BALLOON_WIDTH_3 * 2; - inc_time = 10; - for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++) - { - enemy_formation_[j].init[i].x = x3_100 - (i * inc_x); - enemy_formation_[j].init[i].y = y3; - enemy_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE; - enemy_formation_[j].init[i].kind = BALLOON_3; - enemy_formation_[j].init[i].creation_counter = creation_time - (inc_time * i); - } - - // #06 - Tres enemigos BALLOON3. 0, 0, 0. Hacia la derecha - j = 6; - enemy_formation_[j].number_of_enemies = 3; - inc_x = BALLOON_WIDTH_3 + 1; - inc_time = 10; - for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++) - { - enemy_formation_[j].init[i].x = x3_0 + (i * inc_x); - enemy_formation_[j].init[i].y = y3; - enemy_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE; - enemy_formation_[j].init[i].kind = BALLOON_3; - enemy_formation_[j].init[i].creation_counter = creation_time - (inc_time * i); - } - - // #07 - Tres enemigos BALLOON3. 100, 100, 100. Hacia la izquierda - j = 7; - enemy_formation_[j].number_of_enemies = 3; - inc_x = BALLOON_WIDTH_3 + 1; - inc_time = 10; - for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++) - { - enemy_formation_[j].init[i].x = x3_100 - (i * inc_x); - enemy_formation_[j].init[i].y = y3; - enemy_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE; - enemy_formation_[j].init[i].kind = BALLOON_3; - enemy_formation_[j].init[i].creation_counter = creation_time - (inc_time * i); - } - - // #08 - Seis enemigos BALLOON1. 0, 0, 0, 0, 0, 0. Hacia la derecha - j = 8; - enemy_formation_[j].number_of_enemies = 6; - inc_x = BALLOON_WIDTH_1 + 1; - inc_time = 10; - for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++) - { - enemy_formation_[j].init[i].x = x1_0 + (i * inc_x); - enemy_formation_[j].init[i].y = y1; - enemy_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE; - enemy_formation_[j].init[i].kind = BALLOON_1; - enemy_formation_[j].init[i].creation_counter = creation_time - (inc_time * i); - } - - // #09 - Seis enemigos BALLOON1. 100, 100, 100, 100, 100, 100. Hacia la izquierda - j = 9; - enemy_formation_[j].number_of_enemies = 6; - inc_x = BALLOON_WIDTH_1 + 1; - inc_time = 10; - for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++) - { - enemy_formation_[j].init[i].x = x1_100 - (i * inc_x); - enemy_formation_[j].init[i].y = y1; - enemy_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE; - enemy_formation_[j].init[i].kind = BALLOON_1; - enemy_formation_[j].init[i].creation_counter = creation_time - (inc_time * i); - } - - // #10 - Tres enemigos BALLOON4 seguidos desde la izquierda - j = 10; - enemy_formation_[j].number_of_enemies = 3; - inc_x = BALLOON_WIDTH_4 + 1; - inc_time = 15; - for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++) - { - enemy_formation_[j].init[i].x = x4_0 + (i * inc_x); - enemy_formation_[j].init[i].y = y4; - enemy_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE; - enemy_formation_[j].init[i].kind = BALLOON_4; - enemy_formation_[j].init[i].creation_counter = creation_time - (inc_time * i); - } - - // #11 - Tres enemigos BALLOON4 seguidos desde la derecha - j = 11; - enemy_formation_[j].number_of_enemies = 3; - inc_x = BALLOON_WIDTH_4 + 1; - inc_time = 15; - for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++) - { - enemy_formation_[j].init[i].x = x4_100 - (i * inc_x); - enemy_formation_[j].init[i].y = y4; - enemy_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE; - enemy_formation_[j].init[i].kind = BALLOON_4; - enemy_formation_[j].init[i].creation_counter = creation_time - (inc_time * i); - } - - // #12 - Seis enemigos BALLOON2 uno detras del otro. A la izquierda y hacia el centro - j = 12; - enemy_formation_[j].number_of_enemies = 6; - inc_x = BALLOON_WIDTH_2 + 1; - inc_time = 10; - for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++) - { - enemy_formation_[j].init[i].x = x2_0 + (i * inc_x); - enemy_formation_[j].init[i].y = y2; - enemy_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE; - enemy_formation_[j].init[i].kind = BALLOON_2; - enemy_formation_[j].init[i].creation_counter = creation_time - (inc_time * i); - } - - // #13 - Seis enemigos BALLOON2 uno detras del otro. A la derecha y hacia el centro - j = 13; - enemy_formation_[j].number_of_enemies = 6; - inc_x = BALLOON_WIDTH_2 + 1; - inc_time = 10; - for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++) - { - enemy_formation_[j].init[i].x = x2_100 - (i * inc_x); - enemy_formation_[j].init[i].y = y2; - enemy_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE; - enemy_formation_[j].init[i].kind = BALLOON_2; - enemy_formation_[j].init[i].creation_counter = creation_time - (inc_time * i); - } - - // #14 - Cinco enemigos BALLOON3. Hacia la derecha. Separados - j = 14; - enemy_formation_[j].number_of_enemies = 5; - inc_x = BALLOON_WIDTH_3 * 2; - inc_time = 10; - for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++) - { - enemy_formation_[j].init[i].x = x3_0 + (i * inc_x); - enemy_formation_[j].init[i].y = y3; - enemy_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE; - enemy_formation_[j].init[i].kind = BALLOON_3; - enemy_formation_[j].init[i].creation_counter = creation_time - (inc_time * i); - } - - // #15 - Cinco enemigos BALLOON3. Hacia la izquierda. Separados - j = 15; - enemy_formation_[j].number_of_enemies = 5; - inc_x = BALLOON_WIDTH_3 * 2; - inc_time = 10; - for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++) - { - enemy_formation_[j].init[i].x = x3_100 - (i * inc_x); - enemy_formation_[j].init[i].y = y3; - enemy_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE; - enemy_formation_[j].init[i].kind = BALLOON_3; - enemy_formation_[j].init[i].creation_counter = creation_time - (inc_time * i); - } - - // #16 - Cinco enemigos BALLOON3. Hacia la derecha. Juntos - j = 16; - enemy_formation_[j].number_of_enemies = 5; - inc_x = BALLOON_WIDTH_3 + 1; - inc_time = 10; - for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++) - { - enemy_formation_[j].init[i].x = x3_0 + (i * inc_x); - enemy_formation_[j].init[i].y = y3; - enemy_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE; - enemy_formation_[j].init[i].kind = BALLOON_3; - enemy_formation_[j].init[i].creation_counter = creation_time - (inc_time * i); - } - - // #17 - Cinco enemigos BALLOON3. Hacia la izquierda. Juntos - j = 17; - enemy_formation_[j].number_of_enemies = 5; - inc_x = BALLOON_WIDTH_3 + 1; - inc_time = 10; - for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++) - { - enemy_formation_[j].init[i].x = x3_100 - (i * inc_x); - enemy_formation_[j].init[i].y = y3; - enemy_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE; - enemy_formation_[j].init[i].kind = BALLOON_3; - enemy_formation_[j].init[i].creation_counter = creation_time - (inc_time * i); - } - - // #18 - Doce enemigos BALLOON1. Hacia la derecha. Juntos - j = 18; - enemy_formation_[j].number_of_enemies = 12; - inc_x = BALLOON_WIDTH_1 + 1; - inc_time = 10; - for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++) - { - enemy_formation_[j].init[i].x = x1_0 + (i * inc_x); - enemy_formation_[j].init[i].y = y1; - enemy_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE; - enemy_formation_[j].init[i].kind = BALLOON_1; - enemy_formation_[j].init[i].creation_counter = creation_time - (inc_time * i); - } - - // #19 - Doce enemigos BALLOON1. Hacia la izquierda. Juntos - j = 19; - enemy_formation_[j].number_of_enemies = 12; - inc_x = BALLOON_WIDTH_1 + 1; - inc_time = 10; - for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++) - { - enemy_formation_[j].init[i].x = x1_100 - (i * inc_x); - enemy_formation_[j].init[i].y = y1; - enemy_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE; - enemy_formation_[j].init[i].kind = BALLOON_1; - enemy_formation_[j].init[i].creation_counter = creation_time - (inc_time * i); - } - - // #20 - Dos enemigos BALLOON4 seguidos desde la izquierda/derecha. Simetricos - j = 20; - enemy_formation_[j].number_of_enemies = 4; - inc_x = BALLOON_WIDTH_4 + 1; - inc_time = 0; - for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++) - { - const int half = enemy_formation_[j].number_of_enemies / 2; - if (i < half) - { - enemy_formation_[j].init[i].x = x4_0 + (i * inc_x); - enemy_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE; - } - else - { - enemy_formation_[j].init[i].x = x4_100 - ((i - half) * inc_x); - enemy_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE; - } - enemy_formation_[j].init[i].y = y4; - enemy_formation_[j].init[i].kind = BALLOON_4; - enemy_formation_[j].init[i].creation_counter = creation_time + (inc_time * i); - } - - // #21 - Diez enemigos BALLOON2 uno detras del otro. Izquierda/derecha. Simetricos - j = 21; - enemy_formation_[j].number_of_enemies = 10; - inc_x = BALLOON_WIDTH_2 + 1; - inc_time = 3; - for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++) - { - const int half = enemy_formation_[j].number_of_enemies / 2; - if (i < half) - { - enemy_formation_[j].init[i].x = x2_0 + (i * inc_x); - enemy_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE; - enemy_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * i); - } - else - { - enemy_formation_[j].init[i].x = x2_100 - ((i - half) * inc_x); - enemy_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE; - enemy_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * (i - half)); - } - enemy_formation_[j].init[i].y = y2; - enemy_formation_[j].init[i].kind = BALLOON_2; - } - - // #22 - Diez enemigos BALLOON3. Hacia la derecha/izquierda. Separados. Simetricos - j = 22; - enemy_formation_[j].number_of_enemies = 10; - inc_x = BALLOON_WIDTH_3 * 2; - inc_time = 10; - for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++) - { - const int half = enemy_formation_[j].number_of_enemies / 2; - if (i < half) - { - enemy_formation_[j].init[i].x = x3_0 + (i * inc_x); - enemy_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE; - enemy_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * i); - } - else - { - enemy_formation_[j].init[i].x = x3_100 - ((i - half) * inc_x); - enemy_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE; - enemy_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * (i - half)); - } - enemy_formation_[j].init[i].y = y3; - enemy_formation_[j].init[i].kind = BALLOON_3; - } - - // #23 - Diez enemigos BALLOON3. Hacia la derecha. Juntos. Simetricos - j = 23; - enemy_formation_[j].number_of_enemies = 10; - inc_x = BALLOON_WIDTH_3 + 1; - inc_time = 10; - for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++) - { - const int half = enemy_formation_[j].number_of_enemies / 2; - if (i < half) - { - enemy_formation_[j].init[i].x = x3_0 + (i * inc_x); - enemy_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE; - enemy_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * i); - } - else - { - enemy_formation_[j].init[i].x = x3_100 - ((i - half) * inc_x); - enemy_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE; - enemy_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * (i - half)); - } - enemy_formation_[j].init[i].y = y3; - enemy_formation_[j].init[i].kind = BALLOON_3; - } - - // #24 - Treinta enemigos BALLOON1. Del centro hacia los extremos. Juntos. Simetricos - j = 24; - enemy_formation_[j].number_of_enemies = 30; - inc_x = 0; - inc_time = 5; - for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++) - { - const int half = enemy_formation_[j].number_of_enemies / 2; - if (i < half) - { - enemy_formation_[j].init[i].x = x1_50; - enemy_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE; - enemy_formation_[j].init[i].creation_counter = (creation_time) + (inc_time * i); - } - else - { - enemy_formation_[j].init[i].x = x1_50; - enemy_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE; - enemy_formation_[j].init[i].creation_counter = (creation_time) + (inc_time * (i - half)); - } - enemy_formation_[j].init[i].y = y1; - enemy_formation_[j].init[i].kind = BALLOON_1; - } - - // #25 - Treinta enemigos BALLOON1. Del centro hacia adentro. Juntos. Simetricos - j = 25; - enemy_formation_[j].number_of_enemies = 30; - inc_time = 5; - for (int i = 0; i < enemy_formation_[j].number_of_enemies; i++) - { - const int half = enemy_formation_[j].number_of_enemies / 2; - if (i < half) - { - enemy_formation_[j].init[i].x = x1_50 + 20; - enemy_formation_[j].init[i].vel_x = BALLOON_VELX_NEGATIVE; - enemy_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * i); - } - else - { - enemy_formation_[j].init[i].x = x1_50 - 20; - enemy_formation_[j].init[i].vel_x = BALLOON_VELX_POSITIVE; - enemy_formation_[j].init[i].creation_counter = (creation_time) - (inc_time * (i - half)); - } - enemy_formation_[j].init[i].y = y1; - enemy_formation_[j].init[i].kind = BALLOON_1; - } - - // Crea las mismas formaciones pero con hexagonos a partir de la posición 50 del vector - for (int k = 0; k < j + 1; k++) - { - enemy_formation_[k + 50].number_of_enemies = enemy_formation_[k].number_of_enemies; - for (int i = 0; i < enemy_formation_[k + 50].number_of_enemies; i++) - { - enemy_formation_[k + 50].init[i].x = enemy_formation_[k].init[i].x; - enemy_formation_[k + 50].init[i].y = enemy_formation_[k].init[i].y; - enemy_formation_[k + 50].init[i].vel_x = enemy_formation_[k].init[i].vel_x; - enemy_formation_[k + 50].init[i].creation_counter = enemy_formation_[k].init[i].creation_counter; - enemy_formation_[k + 50].init[i].kind = enemy_formation_[k].init[i].kind + 4; - } - } - - // TEST - enemy_formation_[99].number_of_enemies = 4; - - enemy_formation_[99].init[0].x = 10; - enemy_formation_[99].init[0].y = y1; - enemy_formation_[99].init[0].vel_x = 0; - enemy_formation_[99].init[0].kind = BALLOON_1; - enemy_formation_[99].init[0].creation_counter = 200; - - enemy_formation_[99].init[1].x = 50; - enemy_formation_[99].init[1].y = y1; - enemy_formation_[99].init[1].vel_x = 0; - enemy_formation_[99].init[1].kind = BALLOON_2; - enemy_formation_[99].init[1].creation_counter = 200; - - enemy_formation_[99].init[2].x = 90; - enemy_formation_[99].init[2].y = y1; - enemy_formation_[99].init[2].vel_x = 0; - enemy_formation_[99].init[2].kind = BALLOON_3; - enemy_formation_[99].init[2].creation_counter = 200; - - enemy_formation_[99].init[3].x = 140; - enemy_formation_[99].init[3].y = y1; - enemy_formation_[99].init[3].vel_x = 0; - enemy_formation_[99].init[3].kind = BALLOON_4; - enemy_formation_[99].init[3].creation_counter = 200; -} - -// Inicializa los conjuntos de formaciones -void EnemyFormations::initEnemyPools() -{ - // EnemyPool #0 - enemy_pool_[0].set[0] = &enemy_formation_[0]; - enemy_pool_[0].set[1] = &enemy_formation_[1]; - enemy_pool_[0].set[2] = &enemy_formation_[2]; - enemy_pool_[0].set[3] = &enemy_formation_[3]; - enemy_pool_[0].set[4] = &enemy_formation_[4]; - enemy_pool_[0].set[5] = &enemy_formation_[5]; - enemy_pool_[0].set[6] = &enemy_formation_[6]; - enemy_pool_[0].set[7] = &enemy_formation_[7]; - enemy_pool_[0].set[8] = &enemy_formation_[8]; - enemy_pool_[0].set[9] = &enemy_formation_[9]; - - // EnemyPool #1 - enemy_pool_[1].set[0] = &enemy_formation_[10]; - enemy_pool_[1].set[1] = &enemy_formation_[11]; - enemy_pool_[1].set[2] = &enemy_formation_[12]; - enemy_pool_[1].set[3] = &enemy_formation_[13]; - enemy_pool_[1].set[4] = &enemy_formation_[14]; - enemy_pool_[1].set[5] = &enemy_formation_[15]; - enemy_pool_[1].set[6] = &enemy_formation_[16]; - enemy_pool_[1].set[7] = &enemy_formation_[17]; - enemy_pool_[1].set[8] = &enemy_formation_[18]; - enemy_pool_[1].set[9] = &enemy_formation_[19]; - - // EnemyPool #2 - enemy_pool_[2].set[0] = &enemy_formation_[0]; - enemy_pool_[2].set[1] = &enemy_formation_[1]; - enemy_pool_[2].set[2] = &enemy_formation_[2]; - enemy_pool_[2].set[3] = &enemy_formation_[3]; - enemy_pool_[2].set[4] = &enemy_formation_[4]; - enemy_pool_[2].set[5] = &enemy_formation_[55]; - enemy_pool_[2].set[6] = &enemy_formation_[56]; - enemy_pool_[2].set[7] = &enemy_formation_[57]; - enemy_pool_[2].set[8] = &enemy_formation_[58]; - enemy_pool_[2].set[9] = &enemy_formation_[59]; - - // EnemyPool #3 - enemy_pool_[3].set[0] = &enemy_formation_[50]; - enemy_pool_[3].set[1] = &enemy_formation_[51]; - enemy_pool_[3].set[2] = &enemy_formation_[52]; - enemy_pool_[3].set[3] = &enemy_formation_[53]; - enemy_pool_[3].set[4] = &enemy_formation_[54]; - enemy_pool_[3].set[5] = &enemy_formation_[5]; - enemy_pool_[3].set[6] = &enemy_formation_[6]; - enemy_pool_[3].set[7] = &enemy_formation_[7]; - enemy_pool_[3].set[8] = &enemy_formation_[8]; - enemy_pool_[3].set[9] = &enemy_formation_[9]; - - // EnemyPool #4 - enemy_pool_[4].set[0] = &enemy_formation_[60]; - enemy_pool_[4].set[1] = &enemy_formation_[61]; - enemy_pool_[4].set[2] = &enemy_formation_[62]; - enemy_pool_[4].set[3] = &enemy_formation_[63]; - enemy_pool_[4].set[4] = &enemy_formation_[64]; - enemy_pool_[4].set[5] = &enemy_formation_[65]; - enemy_pool_[4].set[6] = &enemy_formation_[66]; - enemy_pool_[4].set[7] = &enemy_formation_[67]; - enemy_pool_[4].set[8] = &enemy_formation_[68]; - enemy_pool_[4].set[9] = &enemy_formation_[69]; - - // EnemyPool #5 - enemy_pool_[5].set[0] = &enemy_formation_[10]; - enemy_pool_[5].set[1] = &enemy_formation_[61]; - enemy_pool_[5].set[2] = &enemy_formation_[12]; - enemy_pool_[5].set[3] = &enemy_formation_[63]; - enemy_pool_[5].set[4] = &enemy_formation_[14]; - enemy_pool_[5].set[5] = &enemy_formation_[65]; - enemy_pool_[5].set[6] = &enemy_formation_[16]; - enemy_pool_[5].set[7] = &enemy_formation_[67]; - enemy_pool_[5].set[8] = &enemy_formation_[18]; - enemy_pool_[5].set[9] = &enemy_formation_[69]; - - // EnemyPool #6 - enemy_pool_[6].set[0] = &enemy_formation_[60]; - enemy_pool_[6].set[1] = &enemy_formation_[11]; - enemy_pool_[6].set[2] = &enemy_formation_[62]; - enemy_pool_[6].set[3] = &enemy_formation_[13]; - enemy_pool_[6].set[4] = &enemy_formation_[64]; - enemy_pool_[6].set[5] = &enemy_formation_[15]; - enemy_pool_[6].set[6] = &enemy_formation_[66]; - enemy_pool_[6].set[7] = &enemy_formation_[17]; - enemy_pool_[6].set[8] = &enemy_formation_[68]; - enemy_pool_[6].set[9] = &enemy_formation_[19]; - - // EnemyPool #7 - enemy_pool_[7].set[0] = &enemy_formation_[20]; - enemy_pool_[7].set[1] = &enemy_formation_[21]; - enemy_pool_[7].set[2] = &enemy_formation_[22]; - enemy_pool_[7].set[3] = &enemy_formation_[23]; - enemy_pool_[7].set[4] = &enemy_formation_[24]; - enemy_pool_[7].set[5] = &enemy_formation_[65]; - enemy_pool_[7].set[6] = &enemy_formation_[66]; - enemy_pool_[7].set[7] = &enemy_formation_[67]; - enemy_pool_[7].set[8] = &enemy_formation_[68]; - enemy_pool_[7].set[9] = &enemy_formation_[69]; - - // EnemyPool #8 - enemy_pool_[8].set[0] = &enemy_formation_[70]; - enemy_pool_[8].set[1] = &enemy_formation_[71]; - enemy_pool_[8].set[2] = &enemy_formation_[72]; - enemy_pool_[8].set[3] = &enemy_formation_[73]; - enemy_pool_[8].set[4] = &enemy_formation_[74]; - enemy_pool_[8].set[5] = &enemy_formation_[15]; - enemy_pool_[8].set[6] = &enemy_formation_[16]; - enemy_pool_[8].set[7] = &enemy_formation_[17]; - enemy_pool_[8].set[8] = &enemy_formation_[18]; - enemy_pool_[8].set[9] = &enemy_formation_[19]; - - // EnemyPool #9 - enemy_pool_[9].set[0] = &enemy_formation_[20]; - enemy_pool_[9].set[1] = &enemy_formation_[21]; - enemy_pool_[9].set[2] = &enemy_formation_[22]; - enemy_pool_[9].set[3] = &enemy_formation_[23]; - enemy_pool_[9].set[4] = &enemy_formation_[24]; - enemy_pool_[9].set[5] = &enemy_formation_[70]; - enemy_pool_[9].set[6] = &enemy_formation_[71]; - enemy_pool_[9].set[7] = &enemy_formation_[72]; - enemy_pool_[9].set[8] = &enemy_formation_[73]; - enemy_pool_[9].set[9] = &enemy_formation_[74]; -} - -// Inicializa las fases del juego -void EnemyFormations::initGameStages() -{ - // STAGE 1 - stage_[0].number = 1; - stage_[0].power_to_complete = 200; - stage_[0].min_menace = 7 + (4 * 1); - stage_[0].max_menace = 7 + (4 * 3); - stage_[0].enemy_pool = &enemy_pool_[0]; - - // STAGE 2 - stage_[1].number = 2; - stage_[1].power_to_complete = 300; - stage_[1].min_menace = 7 + (4 * 2); - stage_[1].max_menace = 7 + (4 * 4); - stage_[1].enemy_pool = &enemy_pool_[1]; - - // STAGE 3 - stage_[2].number = 3; - stage_[2].power_to_complete = 600; - stage_[2].min_menace = 7 + (4 * 3); - stage_[2].max_menace = 7 + (4 * 5); - stage_[2].enemy_pool = &enemy_pool_[2]; - - // STAGE 4 - stage_[3].number = 4; - stage_[3].power_to_complete = 600; - stage_[3].min_menace = 7 + (4 * 3); - stage_[3].max_menace = 7 + (4 * 5); - stage_[3].enemy_pool = &enemy_pool_[3]; - - // STAGE 5 - stage_[4].number = 5; - stage_[4].power_to_complete = 600; - stage_[4].min_menace = 7 + (4 * 4); - stage_[4].max_menace = 7 + (4 * 6); - stage_[4].enemy_pool = &enemy_pool_[4]; - - // STAGE 6 - stage_[5].number = 6; - stage_[5].power_to_complete = 600; - stage_[5].min_menace = 7 + (4 * 4); - stage_[5].max_menace = 7 + (4 * 6); - stage_[5].enemy_pool = &enemy_pool_[5]; - - // STAGE 7 - stage_[6].number = 7; - stage_[6].power_to_complete = 650; - stage_[6].min_menace = 7 + (4 * 5); - stage_[6].max_menace = 7 + (4 * 7); - stage_[6].enemy_pool = &enemy_pool_[6]; - - // STAGE 8 - stage_[7].number = 8; - stage_[7].power_to_complete = 750; - stage_[7].min_menace = 7 + (4 * 5); - stage_[7].max_menace = 7 + (4 * 7); - stage_[7].enemy_pool = &enemy_pool_[7]; - - // STAGE 9 - stage_[8].number = 9; - stage_[8].power_to_complete = 850; - stage_[8].min_menace = 7 + (4 * 6); - stage_[8].max_menace = 7 + (4 * 8); - stage_[8].enemy_pool = &enemy_pool_[8]; - - // STAGE 10 - stage_[9].number = 10; - stage_[9].power_to_complete = 950; - stage_[9].min_menace = 7 + (4 * 7); - stage_[9].max_menace = 7 + (4 * 10); - stage_[9].enemy_pool = &enemy_pool_[9]; -} - -// Devuelve una fase -Stage EnemyFormations::getStage(int index) const -{ - return stage_[index]; -} \ No newline at end of file diff --git a/source/enemy_formations.h b/source/enemy_formations.h deleted file mode 100644 index 5d8c4a1..0000000 --- a/source/enemy_formations.h +++ /dev/null @@ -1,63 +0,0 @@ -#pragma once - -constexpr int NUMBER_OF_ENEMY_FORMATIONS = 100; -constexpr int MAX_NUMBER_OF_ENEMIES_IN_A_FORMATION = 50; - -// Estructuras -struct EnemyFormationInit -{ - int x; // Posición en el eje X donde crear al enemigo - int y; // Posición en el eje Y donde crear al enemigo - float vel_x; // Velocidad inicial en el eje X - int kind; // Tipo de enemigo - int creation_counter; // Temporizador para la creación del enemigo -}; - -struct EnemyFormationUnit // Contiene la información de una formación enemiga -{ - int number_of_enemies; // Cantidad de enemigos que forman la formación - EnemyFormationInit init[MAX_NUMBER_OF_ENEMIES_IN_A_FORMATION]; // Vector con todas las inicializaciones de los enemigos de la formación -}; - -struct EnemyFormationPool -{ - EnemyFormationUnit *set[10]; // Conjunto de formaciones enemigas -}; - -struct Stage // Contiene todas las variables relacionadas con una fase -{ - EnemyFormationPool *enemy_pool; // El conjunto de formaciones enemigas de la fase - int power_to_complete; // Cantidad de poder que se necesita para completar la fase - int max_menace; // Umbral máximo de amenaza de la fase - int min_menace; // Umbral mínimo de amenaza de la fase - int number; // Número de fase -}; - -// Clase EnemyFormations, para gestionar las formaciones enemigas -class EnemyFormations -{ -private: - // Variables - Stage stage_[10]; // Variable con los datos de cada pantalla - EnemyFormationUnit enemy_formation_[NUMBER_OF_ENEMY_FORMATIONS]; // Vector con todas las formaciones enemigas - EnemyFormationPool enemy_pool_[10]; // Variable con los diferentes conjuntos de formaciones enemigas - - // Inicializa las formaciones enemigas - void initEnemyFormations(); - - // Inicializa los conjuntos de formaciones - void initEnemyPools(); - - // Inicializa las fases del juego - void initGameStages(); - -public: - // Constructor - EnemyFormations(); - - // Destructor - ~EnemyFormations() = default; - - // Devuelve una fase - Stage getStage(int index) const; -}; \ No newline at end of file diff --git a/source/game.cpp b/source/game.cpp index 484b312..23250b1 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -13,7 +13,7 @@ #include "background.h" // for Background #include "balloon.h" // for Balloon, BALLOON_SPEED_1, BALLOON_... #include "bullet.h" // for Bullet, BulletType::LEFT, BulletType::RIGHT -#include "enemy_formations.h" // for Stage, EnemyFormations, enemyIni... +#include "balloon_formations.h" // for Stage, EnemyFormations, enemyIni... #include "explosions.h" // for Explosions #include "fade.h" // for Fade, FadeType::RANDOM_SQUARE, FADE_VEN... #include "global_inputs.h" // for globalInputs::check @@ -56,7 +56,7 @@ Game::Game(int player_id, int current_stage, bool demo, JA_Music_t *music) background_ = std::make_unique(renderer_); explosions_ = std::make_unique(); - enemy_formations_ = std::make_unique(); + balloon_formations_ = std::make_unique(); // Carga los recursos loadMedia(); @@ -146,7 +146,7 @@ void Game::init(int player_id) { case GameDifficulty::EASY: { - default_enemy_speed_ = BALLOON_SPEED_1; + default_balloon_speed_ = BALLOON_SPEED_1; difficulty_score_multiplier_ = 0.5f; difficulty_color_ = difficulty_easy_color; scoreboard_->setColor(difficulty_color_); @@ -155,7 +155,7 @@ void Game::init(int player_id) case GameDifficulty::NORMAL: { - default_enemy_speed_ = BALLOON_SPEED_1; + default_balloon_speed_ = BALLOON_SPEED_1; difficulty_score_multiplier_ = 1.0f; difficulty_color_ = difficulty_normal_color; scoreboard_->setColor(scoreboard_color); @@ -164,7 +164,7 @@ void Game::init(int player_id) case GameDifficulty::HARD: { - default_enemy_speed_ = BALLOON_SPEED_5; + default_balloon_speed_ = BALLOON_SPEED_5; difficulty_score_multiplier_ = 1.5f; difficulty_color_ = difficulty_hard_color; scoreboard_->setColor(difficulty_color_); @@ -177,7 +177,7 @@ void Game::init(int player_id) // Variables para el marcador scoreboard_->setPos({param.scoreboard.x, param.scoreboard.y, param.scoreboard.w, param.scoreboard.h}); - for (auto &player : players_) + for (const auto &player : players_) { scoreboard_->setName(player->getScoreBoardPanel(), player->getName()); if (player->isWaiting()) @@ -204,9 +204,9 @@ void Game::init(int player_id) time_stopped_ = false; time_stopped_counter_ = 0; counter_ = 0; - last_enemy_deploy_ = 0; - enemy_deploy_counter_ = 0; - balloon_speed_ = default_enemy_speed_; + last_ballon_deploy_ = 0; + balloon_deploy_counter_ = 0; + balloon_speed_ = default_balloon_speed_; helper_.need_coffee = false; helper_.need_coffee_machine = false; helper_.need_power_ball = false; @@ -237,7 +237,7 @@ void Game::init(int player_id) // Actualiza el numero de globos explotados según la fase de la demo for (int i = 0; i < current_stage_; ++i) { - balloons_popped_ += enemy_formations_->getStage(i).power_to_complete; + balloons_popped_ += balloon_formations_->getStage(i).power_to_complete; } // Activa o no al otro jugador @@ -273,7 +273,7 @@ void Game::init(int player_id) total_power_to_complete_game_ = 0; for (int i = 0; i < 10; ++i) { - total_power_to_complete_game_ += enemy_formations_->getStage(i).power_to_complete; + total_power_to_complete_game_ += balloon_formations_->getStage(i).power_to_complete; } // Modo grabar demo @@ -598,12 +598,13 @@ void Game::unloadMedia() } // Carga el fichero de datos para la demo -bool Game::loadDemoFile(std::string file_path, DemoKeys (*data_file)[TOTAL_DEMO_DATA]) +bool Game::loadDemoFile(const std::string &file_path, DemoKeys (*data_file)[TOTAL_DEMO_DATA]) { // Indicador de éxito en la carga auto success = true; +#ifdef VERBOSE const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1); - +#endif auto file = SDL_RWFromFile(file_path.c_str(), "r+b"); if (!file) { // El fichero no existe @@ -671,10 +672,12 @@ bool Game::loadDemoFile(std::string file_path, DemoKeys (*data_file)[TOTAL_DEMO_ #ifdef RECORDING // Guarda el fichero de datos para la demo -bool Game::saveDemoFile(std::string file_path) +bool Game::saveDemoFile(const std::string &file_path) { auto success = true; +#ifdef VERBOSE const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1); +#endif // VERBOSE auto file = SDL_RWFromFile(file_path.c_str(), "w+b"); if (file) @@ -707,7 +710,7 @@ bool Game::saveDemoFile(std::string file_path) void Game::deployEnemyFormation() { // Solo despliega una formación enemiga si ha pasado cierto tiempo desde la última - if (enemy_deploy_counter_ == 0) + if (balloon_deploy_counter_ == 0) { // En este punto se decide entre crear una powerball o una formación enemiga @@ -717,7 +720,7 @@ void Game::deployEnemyFormation() createPowerBall(); // Da un poco de margen para que se creen mas enemigos - enemy_deploy_counter_ = 300; + balloon_deploy_counter_ = 300; } else { @@ -728,26 +731,26 @@ void Game::deployEnemyFormation() auto set = rand() % 10; // Evita repetir la ultima formación enemiga desplegada - if (set == last_enemy_deploy_) + if (set == last_ballon_deploy_) { ++set %= 10; } - last_enemy_deploy_ = set; + last_ballon_deploy_ = set; - const Stage stage = enemy_formations_->getStage(current_stage_); - const auto numEnemies = stage.enemy_pool->set[set]->number_of_enemies; + const Stage stage = balloon_formations_->getStage(current_stage_); + const auto numEnemies = stage.balloon_pool->set[set]->number_of_balloons; for (int i = 0; i < numEnemies; ++i) { - createBalloon(stage.enemy_pool->set[set]->init[i].x, - stage.enemy_pool->set[set]->init[i].y, - stage.enemy_pool->set[set]->init[i].kind, - stage.enemy_pool->set[set]->init[i].vel_x, + createBalloon(stage.balloon_pool->set[set]->init[i].x, + stage.balloon_pool->set[set]->init[i].y, + stage.balloon_pool->set[set]->init[i].kind, + stage.balloon_pool->set[set]->init[i].vel_x, balloon_speed_, - stage.enemy_pool->set[set]->init[i].creation_counter); + stage.balloon_pool->set[set]->init[i].creation_counter); } - enemy_deploy_counter_ = 300; + balloon_deploy_counter_ = 300; } } } @@ -762,7 +765,7 @@ void Game::increaseStageCurrentPower(int power) void Game::updateHiScore() { // Si la puntuación actual es mayor que la máxima puntuación - for (auto &player : players_) + for (const auto &player : players_) { if (player->getScore() > hi_score_.score) { @@ -826,7 +829,7 @@ void Game::renderPlayers() // Comprueba si hay cambio de fase y actualiza las variables void Game::updateStage() { - if (current_power_ >= enemy_formations_->getStage(current_stage_).power_to_complete) + if (current_power_ >= balloon_formations_->getStage(current_stage_).power_to_complete) { // Cambio de fase current_stage_++; @@ -851,7 +854,7 @@ void Game::updateStage() } JA_PlaySound(stage_change_sound_); stage_bitmap_counter_ = 0; - balloon_speed_ = default_enemy_speed_; + balloon_speed_ = default_balloon_speed_; setBalloonSpeed(balloon_speed_); screen_->flash(flash_color, 5); screen_->shake(); @@ -970,7 +973,7 @@ void Game::setBalloonSpeed(float speed) // Actualiza la velocidad de los globos en funcion del poder acumulado de la fase void Game::updateBalloonSpeed() { - const float percent = (float)current_power_ / (float)enemy_formations_->getStage(current_stage_).power_to_complete; + const float percent = (float)current_power_ / (float)balloon_formations_->getStage(current_stage_).power_to_complete; float old_balloon_speed = balloon_speed_; // Comprueba si se ha de modificar la velocidad de los globos @@ -1013,7 +1016,7 @@ void Game::popBalloon(std::shared_ptr balloon) { destroyAllBalloons(); power_ball_enabled_ = false; - enemy_deploy_counter_ = 20; + balloon_deploy_counter_ = 20; } else { @@ -1103,20 +1106,6 @@ void Game::destroyBalloon(std::shared_ptr &balloon) evaluateAndSetMenace(); } -// Explosiona todos los globos -void Game::popAllBalloons() -{ - for (auto &balloon : balloons_) - { - if (balloon->canBePopped()) - { - popBalloon(balloon); - } - } - - JA_PlaySound(balloon_sound_); -} - // Destruye todos los globos void Game::destroyAllBalloons() { @@ -1128,7 +1117,7 @@ void Game::destroyAllBalloons() } } - enemy_deploy_counter_ = 300; + balloon_deploy_counter_ = 300; JA_PlaySound(power_ball_sound_); screen_->flash(flash_color, 5); screen_->shake(); @@ -1160,22 +1149,6 @@ void Game::startAllBalloons() } } -// Obtiene el número de globos activos -int Game::countBalloons() -{ - auto num = 0; - - for (auto &balloon : balloons_) - { - if (balloon->isEnabled()) - { - num++; - } - } - - return num; -} - // Vacia del vector de globos los globos que ya no sirven void Game::freeBalloons() { @@ -1674,9 +1647,9 @@ void Game::updateTimeStoppedCounter() // Actualiza la variable enemyDeployCounter void Game::updateEnemyDeployCounter() { - if (enemy_deploy_counter_ > 0) + if (balloon_deploy_counter_ > 0) { - enemy_deploy_counter_--; + balloon_deploy_counter_--; } } @@ -1888,7 +1861,7 @@ void Game::updateMenace() return; } - const auto stage = enemy_formations_->getStage(current_stage_); + const auto stage = balloon_formations_->getStage(current_stage_); const float percent = current_power_ / stage.power_to_complete; const int difference = stage.max_menace - stage.min_menace; @@ -2195,7 +2168,7 @@ void Game::renderMessages() // STAGE NUMBER if (stage_bitmap_counter_ < STAGE_COUNTER) { - const auto stage_number = enemy_formations_->getStage(current_stage_).number; + const auto stage_number = balloon_formations_->getStage(current_stage_).number; std::string text = ""; if (stage_number == 10) @@ -2315,22 +2288,19 @@ void Game::initPaths() const auto center_point = param.game.play_area.center_y - (BLOCK * 2); const auto distance = (param.game.play_area.rect.h) - (param.game.play_area.center_y - 16); - for (int i = 0; i < STAGE_COUNTER; ++i) + for (int i = 0; i < first_part; ++i) { - if (i < first_part) - { - stage_bitmap_path_[i] = (sin[(int)((i * 1.8f) + 90)] * (distance) + center_point); - } + stage_bitmap_path_[i] = (sin[(int)((i * 1.8f) + 90)] * (distance) + center_point); + } - else if (i < second_part) - { - stage_bitmap_path_[i] = (int)center_point; - } + for (int i = first_part; i < second_part; ++i) + { + stage_bitmap_path_[i] = (int)center_point; + } - else - { - stage_bitmap_path_[i] = (sin[(int)(((i - 149) * 1.8f) + 90)] * (center_point + 17) - 17); - } + for (int i = second_part; i < STAGE_COUNTER; ++i) + { + stage_bitmap_path_[i] = (sin[(int)(((i - 149) * 1.8f) + 90)] * (center_point + 17) - 17); } // Letrero de GetReady @@ -2338,33 +2308,28 @@ void Game::initPaths() const float start1 = param.game.play_area.rect.x - size; const float finish1 = param.game.play_area.center_x - (size / 2); - - const float start2 = finish1; const float finish2 = param.game.play_area.rect.w; const float distance1 = finish1 - start1; - const float distance2 = finish2 - start2; + const float distance2 = finish2 - finish1; - for (int i = 0; i < STAGE_COUNTER; ++i) + for (int i = 0; i < first_part; ++i) { - if (i < first_part) - { - get_ready_bitmap_path_[i] = sin[(int)(i * 1.8f)]; - get_ready_bitmap_path_[i] *= distance1; - get_ready_bitmap_path_[i] -= size; - } + get_ready_bitmap_path_[i] = sin[(int)(i * 1.8f)]; + get_ready_bitmap_path_[i] *= distance1; + get_ready_bitmap_path_[i] -= size; + } - else if (i < second_part) - { - get_ready_bitmap_path_[i] = (int)finish1; - } + for (int i = first_part; i < second_part; ++i) + { + get_ready_bitmap_path_[i] = (int)finish1; + } - else if (i < STAGE_COUNTER) - { - get_ready_bitmap_path_[i] = sin[(int)((i - second_part) * 1.8f)]; - get_ready_bitmap_path_[i] *= distance2; - get_ready_bitmap_path_[i] += finish1; - } + for (int i = second_part; i < STAGE_COUNTER; ++i) + { + get_ready_bitmap_path_[i] = sin[(int)((i - second_part) * 1.8f)]; + get_ready_bitmap_path_[i] *= distance2; + get_ready_bitmap_path_[i] += finish1; } } @@ -2496,16 +2461,16 @@ void Game::checkEvents() case SDLK_2: { const auto set = 0; - const auto stage = enemy_formations_->getStage(0); - const auto numEnemies = stage.enemy_pool->set[set]->number_of_enemies; + const auto stage = balloon_formations_->getStage(0); + const auto numEnemies = stage.balloon_pool->set[set]->number_of_balloons; for (int i = 0; i < numEnemies; ++i) { - createBalloon(stage.enemy_pool->set[set]->init[i].x, - stage.enemy_pool->set[set]->init[i].y, - stage.enemy_pool->set[set]->init[i].kind, - stage.enemy_pool->set[set]->init[i].vel_x, + createBalloon(stage.balloon_pool->set[set]->init[i].x, + stage.balloon_pool->set[set]->init[i].y, + stage.balloon_pool->set[set]->init[i].kind, + stage.balloon_pool->set[set]->init[i].vel_x, balloon_speed_, - stage.enemy_pool->set[set]->init[i].creation_counter); + stage.balloon_pool->set[set]->init[i].creation_counter); } } break; @@ -2608,8 +2573,8 @@ void Game::updateScoreboard() } // Resto de marcador - scoreboard_->setStage(enemy_formations_->getStage(current_stage_).number); - scoreboard_->setPower((float)current_power_ / (float)enemy_formations_->getStage(current_stage_).power_to_complete); + scoreboard_->setStage(balloon_formations_->getStage(current_stage_).number); + scoreboard_->setPower((float)current_power_ / (float)balloon_formations_->getStage(current_stage_).power_to_complete); scoreboard_->setHiScore(hi_score_.score); scoreboard_->setHiScoreName(hi_score_.name); diff --git a/source/game.h b/source/game.h index 7d3812a..b314066 100644 --- a/source/game.h +++ b/source/game.h @@ -8,21 +8,21 @@ #include "section.h" // for SectionOptions #include "utils.h" // for DemoKeys, Color, HiScoreEntry #include -#include "asset.h" // lines 11-11 -#include "background.h" // lines 12-12 -#include "balloon.h" // lines 13-13 -#include "bullet.h" // lines 14-14 -#include "enemy_formations.h" // lines 15-15 -#include "explosions.h" // lines 16-16 -#include "fade.h" // lines 17-17 -#include "input.h" // lines 18-18 -#include "item.h" // lines 19-19 -#include "player.h" // lines 20-20 -#include "scoreboard.h" // lines 21-21 -#include "screen.h" // lines 22-22 -#include "smart_sprite.h" // lines 23-23 -#include "text.h" // lines 24-24 -#include "texture.h" // lines 24-24 +#include "asset.h" // lines 11-11 +#include "background.h" // lines 12-12 +#include "balloon.h" // lines 13-13 +#include "bullet.h" // lines 14-14 +#include "balloon_formations.h" // lines 15-15 +#include "explosions.h" // lines 16-16 +#include "fade.h" // lines 17-17 +#include "input.h" // lines 18-18 +#include "item.h" // lines 19-19 +#include "player.h" // lines 20-20 +#include "scoreboard.h" // lines 21-21 +#include "screen.h" // lines 22-22 +#include "smart_sprite.h" // lines 23-23 +#include "text.h" // lines 24-24 +#include "texture.h" // lines 24-24 enum class BulletType; struct JA_Music_t; // lines 26-26 struct JA_Sound_t; // lines 27-27 @@ -114,9 +114,9 @@ private: Input *input_; // Manejador de entrada Scoreboard *scoreboard_; // Objeto para dibujar el marcador - std::unique_ptr background_; // Objeto para dibujar el fondo del juego - std::unique_ptr explosions_; // Objeto para dibujar explosiones - std::unique_ptr enemy_formations_; // Objeto para gestionar las oleadas enemigas + std::unique_ptr background_; // Objeto para dibujar el fondo del juego + std::unique_ptr explosions_; // Objeto para dibujar explosiones + std::unique_ptr balloon_formations_; // Objeto para gestionar las oleadas enemigas SDL_Texture *canvas_; // Textura para dibujar la zona de juego @@ -186,10 +186,10 @@ private: int time_stopped_counter_; // Temporizador para llevar la cuenta del tiempo detenido int counter_; // Contador para el juego int balloons_popped_; // Lleva la cuenta de los globos explotados - int last_enemy_deploy_; // Guarda cual ha sido la última formación desplegada para no repetir; - int enemy_deploy_counter_; // Cuando se lanza una formación, se le da un valor y no sale otra hasta que llegue a cero + int last_ballon_deploy_; // Guarda cual ha sido la última formación desplegada para no repetir; + int balloon_deploy_counter_; // Cuando se lanza una formación, se le da un valor y no sale otra hasta que llegue a cero float balloon_speed_; // Velocidad a la que se mueven los enemigos - float default_enemy_speed_; // Velocidad base de los enemigos, sin incrementar + float default_balloon_speed_; // Velocidad base de los enemigos, sin incrementar Helper helper_; // Variable para gestionar las ayudas bool power_ball_enabled_; // Indica si hay una powerball ya activa int power_ball_counter_; // Contador de formaciones enemigas entre la aparicion de una PowerBall y otra @@ -227,10 +227,10 @@ private: void unloadMedia(); // Carga el fichero de datos para la demo - bool loadDemoFile(std::string file_path, DemoKeys (*data_file)[TOTAL_DEMO_DATA]); + bool loadDemoFile(const std::string &file_path, DemoKeys (*data_file)[TOTAL_DEMO_DATA]); #ifdef RECORDING // Guarda el fichero de datos para la demo - bool saveDemoFile(std::string file_path); + bool saveDemoFile(const std::string &file_path); #endif // Crea una formación de enemigos void deployEnemyFormation(); @@ -277,9 +277,6 @@ private: // Explosiona un globo. Lo destruye void destroyBalloon(std::shared_ptr &balloon); - // Explosiona todos los globos - void popAllBalloons(); - // Destruye todos los globos void destroyAllBalloons(); @@ -289,9 +286,6 @@ private: // Pone en marcha todos los globos void startAllBalloons(); - // Obtiene el número de globos activos - int countBalloons(); - // Vacia el vector de globos void freeBalloons(); diff --git a/source/game_logo.cpp b/source/game_logo.cpp index dc84c06..a66a5cb 100644 --- a/source/game_logo.cpp +++ b/source/game_logo.cpp @@ -13,25 +13,24 @@ // Constructor GameLogo::GameLogo(int x, int y) - : x_(x), y_(y) + : dust_texture_(std::make_shared(Screen::get()->getRenderer(), Asset::get()->get("title_dust.png"))), + coffee_texture_(std::make_shared(Screen::get()->getRenderer(), Asset::get()->get("title_coffee.png"))), + crisis_texture_(std::make_shared(Screen::get()->getRenderer(), Asset::get()->get("title_crisis.png"))), + arcade_edition_texture_(std::make_shared(Screen::get()->getRenderer(), Asset::get()->get("title_arcade_edition.png"))), + + dust_left_sprite_(std::make_unique(dust_texture_, Asset::get()->get("title_dust.ani"))), + dust_right_sprite_(std::make_unique(dust_texture_, Asset::get()->get("title_dust.ani"))), + + coffee_sprite_(std::make_unique(coffee_texture_)), + crisis_sprite_(std::make_unique(crisis_texture_)), + + arcade_edition_sprite_(std::make_unique((param.game.width - arcade_edition_texture_->getWidth()) / 2, param.title.arcade_edition_position, arcade_edition_texture_->getWidth(), arcade_edition_texture_->getHeight(), arcade_edition_texture_)), + + crash_sound_(JA_LoadSound(Asset::get()->get("title.wav").c_str())), + + x_(x), + y_(y) { - // Crea los objetos - dust_texture_ = std::make_shared(Screen::get()->getRenderer(), Asset::get()->get("title_dust.png")); - coffee_texture_ = std::make_shared(Screen::get()->getRenderer(), Asset::get()->get("title_coffee.png")); - crisis_texture_ = std::make_shared(Screen::get()->getRenderer(), Asset::get()->get("title_crisis.png")); - arcade_edition_texture_ = std::make_shared(Screen::get()->getRenderer(), Asset::get()->get("title_arcade_edition.png")); - - coffee_sprite_ = std::make_unique(coffee_texture_); - crisis_sprite_ = std::make_unique(crisis_texture_); - - arcade_edition_sprite_ = std::make_unique((param.game.width - arcade_edition_texture_->getWidth()) / 2, param.title.arcade_edition_position, arcade_edition_texture_->getWidth(), arcade_edition_texture_->getHeight(), arcade_edition_texture_); - - dust_left_sprite_ = std::make_unique(dust_texture_, Asset::get()->get("title_dust.ani")); - dust_right_sprite_ = std::make_unique(dust_texture_, Asset::get()->get("title_dust.ani")); - - // Sonidos - crash_sound_ = JA_LoadSound(Asset::get()->get("title.wav").c_str()); - // Inicializa las variables init(); } diff --git a/source/game_logo.h b/source/game_logo.h index 8f4062c..878db66 100644 --- a/source/game_logo.h +++ b/source/game_logo.h @@ -13,13 +13,31 @@ struct JA_Sound_t; class GameLogo { private: + enum class Status + { + DISABLED, + MOVING, + SHAKING, + FINISHED, + }; + + struct Shake + { + 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 + }; + // Objetos y punteros - std::shared_ptr dust_texture_; // Textura con los graficos del polvo - std::shared_ptr coffee_texture_; // Textura con los graficos de la palabra "COFFEE" - std::shared_ptr crisis_texture_; // Textura con los graficos de la plabra "CRISIS" + std::shared_ptr dust_texture_; // Textura con los graficos del polvo + std::shared_ptr coffee_texture_; // Textura con los graficos de la palabra "COFFEE" + std::shared_ptr crisis_texture_; // Textura con los graficos de la plabra "CRISIS" std::shared_ptr arcade_edition_texture_; // Textura con los graficos de "Arcade Edition" - std::unique_ptr dust_left_sprite_; // Sprite con la el polvo que aparece al colisionar el texto de la pantalla de titulo + std::unique_ptr dust_left_sprite_; // Sprite con la el polvo que aparece al colisionar el texto de la pantalla de titulo std::unique_ptr dust_right_sprite_; // Sprite con la el polvo que aparece al colisionar el texto de la pantalla de titulo std::unique_ptr coffee_sprite_; // Sprite con la palabra "COFFEE" para la pantalla de titulo @@ -33,23 +51,8 @@ private: int x_; // Posición donde dibujar el logo int y_; // Posición donde dibujar el logo - enum class Status - { - DISABLED, - MOVING, - SHAKING, - FINISHED, - } status_; // Estado en el que se encuentra la clase - - struct Shake - { - 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_; // Estructura para generar el efecto de agitación + Status status_; // Estado en el que se encuentra la clase + Shake shake_; // Estructura para generar el efecto de agitación // Inicializa las variables void init(); diff --git a/source/input.cpp b/source/input.cpp index 2d74762..3b64b61 100644 --- a/source/input.cpp +++ b/source/input.cpp @@ -9,7 +9,7 @@ Input *Input::input_ = nullptr; // [SINGLETON] Crearemos el objeto input con esta función estática -void Input::init(std::string game_controller_db_path) +void Input::init(const std::string &game_controller_db_path) { Input::input_ = new Input(game_controller_db_path); } @@ -27,12 +27,10 @@ Input *Input::get() } // Constructor -Input::Input(std::string game_controller_db_path) - : game_controller_db_path_(game_controller_db_path) +Input::Input(const std::string &game_controller_db_path) + : game_controller_db_path_(game_controller_db_path), + enabled_(true) { - // Inicializa variables - enabled_ = true; - // Busca si hay mandos conectados discoverGameControllers(); @@ -434,12 +432,11 @@ bool Input::discoverGameControllers() for (int i = 0; i < num_gamepads_; i++) { // Abre el mando y lo añade a la lista - SDL_GameController *pad = SDL_GameControllerOpen(i); + auto pad = SDL_GameControllerOpen(i); if (SDL_GameControllerGetAttached(pad) == 1) { connected_controllers_.push_back(pad); - const std::string separator(" #"); - std::string name = SDL_GameControllerNameForIndex(i); + const std::string name = SDL_GameControllerNameForIndex(i); #ifdef VERBOSE { std::cout << name << std::endl; @@ -528,7 +525,7 @@ SDL_GameControllerButton Input::getControllerBinding(int controller_index, Input } // Obtiene el indice a partir del nombre del mando -int Input::getIndexByName(std::string name) const +int Input::getIndexByName(const std::string &name) const { for (int i = 0; i < num_gamepads_; ++i) { @@ -572,7 +569,7 @@ std::string Input::to_string(InputType input) const } // Convierte un std::string a InputType -InputType Input::to_inputs_e(std::string name) const +InputType Input::to_inputs_e(const std::string &name) const { if (name == "input_fire_left") { @@ -602,16 +599,6 @@ InputType Input::to_inputs_e(std::string name) const return InputType::NONE; } -// Activa todos los inputs. Sirve para evitar inputs sin repeticiones pero que ya vienen pulsados cuando checkInput no estaba monitorizando -/*void Input::allActive(int controller_index) -{ - for (int i = 0; i < (int)button_inputs_.size(); ++i) - { - controller_bindings_[controller_index][i].active = true; - } -} -*/ - // Comprueba el eje del mando bool Input::checkAxisInput(InputType input, int controller_index) const { diff --git a/source/input.h b/source/input.h index f60659b..66d604e 100644 --- a/source/input.h +++ b/source/input.h @@ -91,14 +91,14 @@ private: bool checkAxisInput(InputType input, int controller_index = 0) const; // Constructor - Input(std::string game_controller_db_path); + explicit Input(const std::string &game_controller_db_path); // Destructor ~Input() = default; public: // [SINGLETON] Crearemos el objeto screen con esta función estática - static void init(std::string game_controller_db_path); + static void init(const std::string &game_controller_db_path); // [SINGLETON] Destruiremos el objeto screen con esta función estática static void destroy(); @@ -150,11 +150,8 @@ public: std::string to_string(InputType input) const; // Convierte un std::string a InputType - InputType to_inputs_e(std::string name) const; + InputType to_inputs_e(const std::string &name) const; // Obtiene el indice a partir del nombre del mando - int getIndexByName(std::string name) const; - - // Activa todos los inputs. Sirve para evitar inputs sin repeticiones pero que ya vienen pulsados cuando checkInput no estaba monitorizando - //void allActive(int index); + int getIndexByName(const std::string &name) const; }; \ No newline at end of file diff --git a/source/intro.cpp b/source/intro.cpp index fe8631c..f35f784 100644 --- a/source/intro.cpp +++ b/source/intro.cpp @@ -408,12 +408,12 @@ void Intro::render() Screen::get()->clean(bg_color); // Dibuja los objetos - for (auto &bitmap : bitmaps_) + for (const auto &bitmap : bitmaps_) { bitmap->render(); } - for (auto &text : texts_) + for (const auto &text : texts_) { text->render(); } diff --git a/source/item.cpp b/source/item.cpp index a7be78d..a86c2a1 100644 --- a/source/item.cpp +++ b/source/item.cpp @@ -6,15 +6,14 @@ class Texture; // Constructor Item::Item(int kind, float x, float y, SDL_Rect *play_area, std::shared_ptr texture, std::vector *animation) - : kind_(kind), play_area_(play_area) + : sprite_(std::make_unique(texture, "", animation)), + accel_x_(0.0f), + floor_collision_(false), + kind_(kind), + enabled_(true), + play_area_(play_area), + time_to_live_(600) { - sprite_ = std::make_unique(texture, "", animation); - - enabled_ = true; - time_to_live_ = 600; - accel_x_ = 0.0f; - floor_collision_ = false; - if (kind == ITEM_COFFEE_MACHINE) { width_ = 28; diff --git a/source/manage_hiscore_table.cpp b/source/manage_hiscore_table.cpp index 4c2bdf5..5b8e4d8 100644 --- a/source/manage_hiscore_table.cpp +++ b/source/manage_hiscore_table.cpp @@ -50,25 +50,25 @@ void ManageHiScoreTable::sort() { struct { - bool operator()(HiScoreEntry a, HiScoreEntry b) const { return a.score > b.score; } + bool operator()(HiScoreEntry &a, HiScoreEntry &b) const { return a.score > b.score; } } custom_less; std::sort(table_->begin(), table_->end(), custom_less); } // Carga la tabla con los datos de un fichero -bool ManageHiScoreTable::loadFromFile(std::string file_path) +bool ManageHiScoreTable::loadFromFile(const std::string &file_path) { clear(); auto success = true; - const std::string filename = file_path.substr(file_path.find_last_of("\\/") + 1); auto file = SDL_RWFromFile(file_path.c_str(), "r+b"); if (file) { #ifdef VERBOSE - std::cout << "Reading file: " << filename.c_str() << std::endl; + const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1); + std::cout << "Reading file: " << file_name.c_str() << std::endl; #endif for (int i = 0; i < (int)table_->size(); ++i) { @@ -86,7 +86,7 @@ bool ManageHiScoreTable::loadFromFile(std::string file_path) break; } - char *name = (char *)malloc(nameSize + 1); + char *name = static_cast(malloc(nameSize + 1)); if (SDL_RWread(file, name, sizeof(char) * nameSize, 1) == 0) { success = false; @@ -113,10 +113,12 @@ bool ManageHiScoreTable::loadFromFile(std::string file_path) } // Guarda la tabla en un fichero -bool ManageHiScoreTable::saveToFile(std::string file_path) +bool ManageHiScoreTable::saveToFile(const std::string &file_path) { +#ifdef VERBOSE + const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1); +#endif auto success = true; - const std::string fileName = file_path.substr(file_path.find_last_of("\\/") + 1); auto file = SDL_RWFromFile(file_path.c_str(), "w+b"); if (file) @@ -131,7 +133,7 @@ bool ManageHiScoreTable::saveToFile(std::string file_path) } #ifdef VERBOSE - std::cout << "Writing file: " << fileName.c_str() << std::endl; + std::cout << "Writing file: " << file_name.c_str() << std::endl; #endif // Cierra el fichero SDL_RWclose(file); @@ -139,7 +141,7 @@ bool ManageHiScoreTable::saveToFile(std::string file_path) else { #ifdef VERBOSE - std::cout << "Error: Unable to save " << fileName.c_str() << " file! " << SDL_GetError() << std::endl; + std::cout << "Error: Unable to save " << file_name.c_str() << " file! " << SDL_GetError() << std::endl; #endif } return success; diff --git a/source/manage_hiscore_table.h b/source/manage_hiscore_table.h index 7ae1b0f..b75720f 100644 --- a/source/manage_hiscore_table.h +++ b/source/manage_hiscore_table.h @@ -36,8 +36,8 @@ public: void add(HiScoreEntry entry); // Carga la tabla con los datos de un fichero - bool loadFromFile(std::string file_path); + bool loadFromFile(const std::string &file_path); // Guarda la tabla en un fichero - bool saveToFile(std::string file_path); + bool saveToFile(const std::string &file_path); }; \ No newline at end of file diff --git a/source/moving_sprite.cpp b/source/moving_sprite.cpp index 8715e9b..eca665e 100644 --- a/source/moving_sprite.cpp +++ b/source/moving_sprite.cpp @@ -9,12 +9,12 @@ MovingSprite::MovingSprite(float x, float y, int w, int h, float vx, float vy, f vx_(vx), vy_(vy), ax_(ax), - ay_(ay) + ay_(ay), + zoom_w_(1), + zoom_h_(1), + counter_(0), + flip_(SDL_FLIP_NONE) { - // Establece el zoom W,H del sprite - zoom_w_ = 1; - zoom_h_ = 1; - // Establece los valores de rotacion rotate_.enabled = false; rotate_.speed = 0; @@ -22,14 +22,7 @@ MovingSprite::MovingSprite(float x, float y, int w, int h, float vx, float vy, f rotate_.amount = 0.0f; rotate_.center = nullptr; - // Contador interno - counter_ = 0; - - // Establece el rectangulo de donde coger la imagen sprite_clip_ = (SDL_Rect){0, 0, w, h}; - - // Establece el tipo de volteado - flip_ = SDL_FLIP_NONE; }; MovingSprite::MovingSprite(std::shared_ptr texture) diff --git a/source/notify.cpp b/source/notify.cpp index ecbbdb7..f5c7ab9 100644 --- a/source/notify.cpp +++ b/source/notify.cpp @@ -11,21 +11,18 @@ // Constructor Notify::Notify(SDL_Renderer *renderer, std::string iconFile, std::string bitmapFile, std::string textFile, std::string soundFile) - : renderer(renderer) + : renderer(renderer), + text(std::make_unique(bitmapFile, textFile, renderer)), + bgColor(param.notification.color), + waitTime(150), + stack(false), + sound(JA_LoadSound(soundFile.c_str())) { // Inicializa variables - bgColor = param.notification.color; - waitTime = 150; - stack = false; - hasIcons = iconFile == "" ? false : true; + hasIcons = !iconFile.empty(); // Crea objetos - if (hasIcons) - { - iconTexture = std::make_unique(renderer, iconFile); - } - text = std::make_unique(bitmapFile, textFile, renderer); - sound = JA_LoadSound(soundFile.c_str()); + iconTexture = hasIcons ? std::make_unique(renderer, iconFile) : nullptr; } // Destructor diff --git a/source/notify.h b/source/notify.h index bd0a344..c6c6187 100644 --- a/source/notify.h +++ b/source/notify.h @@ -65,9 +65,9 @@ private: Color bgColor; // Color de fondo de las notificaciones int waitTime; // Tiempo que se ve la notificación std::vector notifications; // La lista de notificaciones activas - JA_Sound_t *sound; // Sonido a reproducir cuando suena la notificación bool stack; // Indica si las notificaciones se apilan bool hasIcons; // Indica si el notificador tiene textura para iconos + JA_Sound_t *sound; // Sonido a reproducir cuando suena la notificación // Elimina las notificaciones finalizadas void clearFinishedNotifications(); diff --git a/source/options.cpp b/source/options.cpp index 0063a20..dc258be 100644 --- a/source/options.cpp +++ b/source/options.cpp @@ -13,7 +13,7 @@ Options options; // Declaraciones -bool setOptions(std::string var, std::string value); +bool setOptions(std::string var, const std::string &value); // Inicializa las opciones del programa void initOptions() @@ -86,7 +86,9 @@ bool loadOptionsFile(std::string file_path) bool success = true; // Variables para manejar el fichero +#ifdef VERBOSE const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1); +#endif std::ifstream file(file_path); // Si el fichero se puede abrir @@ -150,7 +152,9 @@ bool loadOptionsFile(std::string file_path) // Guarda el fichero de configuración bool saveOptionsFile(std::string file_path) { +#ifdef VERBOSE const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1); +#endif std::ofstream file(file_path); if (!file.good()) @@ -240,10 +244,10 @@ bool saveOptionsFile(std::string file_path) } // Asigna variables a partir de dos cadenas -bool setOptions(std::string var, std::string value) +bool setOptions(std::string var, const std::string &value) { // Indicador de éxito en la asignación - bool success = true; + auto success = true; // Opciones de video if (var == "video.mode") diff --git a/source/param.cpp b/source/param.cpp index ffa0480..6d850ee 100644 --- a/source/param.cpp +++ b/source/param.cpp @@ -6,7 +6,7 @@ Param param; // Asigna variables a partir de dos cadenas -bool setParams(std::string var, std::string value); +bool setParams(const std::string &var, const std::string &value); // Calcula variables a partir de otras variables void precalculateZones(); @@ -55,13 +55,13 @@ void initParam() } // Establece valores para los parametros a partir de un fichero de texto -void loadParamsFromFile(std::string filePath) +void loadParamsFromFile(std::string file_path) { // Pone valores por defecto a las variables initParam(); // Variables para manejar el fichero - std::ifstream file(filePath); + std::ifstream file(file_path); std::string line; std::string param1; std::string param2; @@ -70,15 +70,15 @@ void loadParamsFromFile(std::string filePath) if (file.good()) { #ifdef VERBOSE - const std::string filename = filePath.substr(filePath.find_last_of("\\/") + 1); - std::cout << "Reading file: " << filename << std::endl; + const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1); + std::cout << "Reading file: " << file_name << std::endl; #endif // Procesa cada linea del fichero while (std::getline(file, line)) { // Reinicia variables - param1 = ""; - param2 = ""; + param1.clear(); + param2.clear(); // Elimina los comentarios line = line.substr(0, line.find("#")); @@ -145,17 +145,17 @@ void loadParamsFromFile(std::string filePath) } #ifdef VERBOSE else - std::cout << "Failed to load file: " << filePath << std::endl; + std::cout << "Failed to load file: " << file_path << std::endl; #endif precalculateZones(); } // Asigna variables a partir de dos cadenas -bool setParams(std::string var, std::string value) +bool setParams(const std::string &var, const std::string &value) { // Indicador de éxito en la asignación - bool success = true; + auto success = true; // GAME if (var == "game.width") diff --git a/source/screen.cpp b/source/screen.cpp index 87c6f1a..926c8cc 100644 --- a/source/screen.cpp +++ b/source/screen.cpp @@ -76,7 +76,7 @@ Screen::Screen(SDL_Window *window, SDL_Renderer *renderer) info_resolution_ = std::to_string(DM.w) + " X " + std::to_string(DM.h) + " AT " + std::to_string(DM.refresh_rate) + " HZ"; // Crea los objetos - notify_ = std::make_unique(renderer_, "", Asset::get()->get("8bithud.png"), Asset::get()->get("8bithud.txt"), Asset::get()->get("notify_.wav")); + notify_ = std::make_unique(renderer_, "", Asset::get()->get("8bithud.png"), Asset::get()->get("8bithud.txt"), Asset::get()->get("notify.wav")); // Define el color del borde para el modo de pantalla completa border_color_ = {0x00, 0x00, 0x00}; diff --git a/source/utils.h b/source/utils.h index e0dc351..a1fac60 100644 --- a/source/utils.h +++ b/source/utils.h @@ -23,7 +23,7 @@ enum class GameDifficulty }; // Tamaño de bloque -#define BLOCK 8 +constexpr int BLOCK = 8; // Estructura para definir un circulo struct Circle