diff --git a/data/config/param_320x240.txt b/data/config/param_320x240.txt index 73ee3c3..c2356cc 100644 --- a/data/config/param_320x240.txt +++ b/data/config/param_320x240.txt @@ -1,19 +1,19 @@ ## GAME -game.itemSize 20 -game.width 320 -game.height 240 -game.playArea.rect.x 0 -game.playArea.rect.y 0 -game.playArea.rect.w 320 -game.playArea.rect.h 200 +game.item_size 20 +game.width 320 +game.height 240 +game.play_area.rect.x 0 +game.play_area.rect.y 0 +game.play_area.rect.w 320 +game.play_area.rect.h 200 ## FADE -fade.numSquaresWidth 160 -fade.numSquaresHeight 120 -fade.randomSquaresDelay 1 -fade.randomSquaresMult 500 -fade.postDuration 80 -fade.venetianSize 16 +fade.num_squares_width 160 +fade.num_squares_height 120 +fade.random_squares_delay 1 +fade.random_squares_mult 500 +fade.post_duration 80 +fade.venetian_size 16 ## SCOREBOARD scoreboard.x 0 @@ -22,23 +22,23 @@ scoreboard.w 320 scoreboard.h 40 ## TITLE -title.pressStartPosition 170 -title.titleDuration 800 -title.arcadeEditionPosition 123 -title.titleCCPosition 80 +title.press_start_position 170 +title.title_duration 800 +title.arcade_edition_position 123 +title.title_c_c_position 80 ## BACKGROUND -background.attenuateColor.r 255 -background.attenuateColor.g 255 -background.attenuateColor.b 255 -background.attenuateAlpha 0 +background.attenuate_color.r 255 +background.attenuate_color.g 255 +background.attenuate_color.b 255 +background.attenuate_alpha 0 ## BALLOONS -balloon1.vel 2.75f -balloon1.grav 0.09f -balloon2.vel 3.70f -balloon2.grav 0.10f -balloon3.vel 4.70f -balloon3.grav 0.10f -balloon4.vel 5.45f -balloon4.grav 0.10f \ No newline at end of file +balloon_1.vel 2.75f +balloon_1.grav 0.09f +balloon_2.vel 3.70f +balloon_2.grav 0.10f +balloon_3.vel 4.70f +balloon_3.grav 0.10f +balloon_4.vel 5.45f +balloon_4.grav 0.10f \ No newline at end of file diff --git a/data/config/param_320x256.txt b/data/config/param_320x256.txt index b348a53..1fd79e5 100644 --- a/data/config/param_320x256.txt +++ b/data/config/param_320x256.txt @@ -1,19 +1,19 @@ ## GAME -game.itemSize 20 -game.width 320 -game.height 256 -game.playArea.rect.x 0 -game.playArea.rect.y 0 -game.playArea.rect.w 320 -game.playArea.rect.h 216 +game.item_size 20 +game.width 320 +game.height 256 +game.play_area.rect.x 0 +game.play_area.rect.y 0 +game.play_area.rect.w 320 +game.play_area.rect.h 216 ## FADE -fade.numSquaresWidth 160 -fade.numSquaresHeight 128 -fade.randomSquaresDelay 1 -fade.randomSquaresMult 500 -fade.postDuration 80 -fade.venetianSize 16 +fade.num_squares_width 160 +fade.num_squares_height 128 +fade.random_squares_delay 1 +fade.random_squares_mult 500 +fade.post_duration 80 +fade.venetian_size 16 ## SCOREBOARD scoreboard.x 0 @@ -22,23 +22,23 @@ scoreboard.w 320 scoreboard.h 40 ## TITLE -title.pressStartPosition 180 -title.titleDuration 800 -title.arcadeEditionPosition 123 -title.titleCCPosition 80 +title.press_start_position 180 +title.title_duration 800 +title.arcade_edition_position 123 +title.title_c_c_position 80 ## BACKGROUND -background.attenuateColor.r 255 -background.attenuateColor.g 255 -background.attenuateColor.b 255 -background.attenuateAlpha 0 +background.attenuate_color.r 255 +background.attenuate_color.g 255 +background.attenuate_color.b 255 +background.attenuate_alpha 0 ## BALLOONS -balloon1.vel 2.75f -balloon1.grav 0.09f -balloon2.vel 3.70f -balloon2.grav 0.10f -balloon3.vel 4.70f -balloon3.grav 0.10f -balloon4.vel 5.45f -balloon4.grav 0.10f \ No newline at end of file +balloon_1.vel 2.75f +balloon_1.grav 0.09f +balloon_2.vel 3.70f +balloon_2.grav 0.10f +balloon_3.vel 4.70f +balloon_3.grav 0.10f +balloon_4.vel 5.45f +balloon_4.grav 0.10f \ No newline at end of file diff --git a/data/gfx/balloon/balloon1.ani b/data/gfx/balloon/balloon1.ani index eff7c0a..aa701fe 100644 --- a/data/gfx/balloon/balloon1.ani +++ b/data/gfx/balloon/balloon1.ani @@ -1,5 +1,5 @@ -frameWidth=10 -frameHeight=10 +frame_width=10 +frame_height=10 [animation] name=orange diff --git a/data/gfx/balloon/balloon2.ani b/data/gfx/balloon/balloon2.ani index 1cc7ad2..57cd439 100644 --- a/data/gfx/balloon/balloon2.ani +++ b/data/gfx/balloon/balloon2.ani @@ -1,5 +1,5 @@ -frameWidth=16 -frameHeight=16 +frame_width=16 +frame_height=16 [animation] name=orange diff --git a/data/gfx/balloon/balloon3.ani b/data/gfx/balloon/balloon3.ani index f2366a5..9085bde 100644 --- a/data/gfx/balloon/balloon3.ani +++ b/data/gfx/balloon/balloon3.ani @@ -1,5 +1,5 @@ -frameWidth=26 -frameHeight=26 +frame_width=26 +frame_height=26 [animation] name=orange diff --git a/data/gfx/balloon/balloon4.ani b/data/gfx/balloon/balloon4.ani index 353635e..32220b3 100644 --- a/data/gfx/balloon/balloon4.ani +++ b/data/gfx/balloon/balloon4.ani @@ -1,5 +1,5 @@ -frameWidth=48 -frameHeight=48 +frame_width=48 +frame_height=48 [animation] name=orange diff --git a/data/gfx/balloon/explosion1.ani b/data/gfx/balloon/explosion1.ani index 30cb568..7206e11 100644 --- a/data/gfx/balloon/explosion1.ani +++ b/data/gfx/balloon/explosion1.ani @@ -1,5 +1,5 @@ -frameWidth=10 -frameHeight=10 +frame_width=10 +frame_height=10 [animation] name=default diff --git a/data/gfx/balloon/explosion2.ani b/data/gfx/balloon/explosion2.ani index fa783f0..e62469e 100644 --- a/data/gfx/balloon/explosion2.ani +++ b/data/gfx/balloon/explosion2.ani @@ -1,5 +1,5 @@ -frameWidth=16 -frameHeight=16 +frame_width=16 +frame_height=16 [animation] name=default diff --git a/data/gfx/balloon/explosion3.ani b/data/gfx/balloon/explosion3.ani index 957e88d..feb66e3 100644 --- a/data/gfx/balloon/explosion3.ani +++ b/data/gfx/balloon/explosion3.ani @@ -1,5 +1,5 @@ -frameWidth=26 -frameHeight=26 +frame_width=26 +frame_height=26 [animation] name=default diff --git a/data/gfx/balloon/explosion4.ani b/data/gfx/balloon/explosion4.ani index db5758f..dc06f55 100644 --- a/data/gfx/balloon/explosion4.ani +++ b/data/gfx/balloon/explosion4.ani @@ -1,5 +1,5 @@ -frameWidth=46 -frameHeight=46 +frame_width=46 +frame_height=46 [animation] name=default diff --git a/data/gfx/balloon/powerball.ani b/data/gfx/balloon/powerball.ani index d5559ad..1efbeb5 100644 --- a/data/gfx/balloon/powerball.ani +++ b/data/gfx/balloon/powerball.ani @@ -1,5 +1,5 @@ -frameWidth=46 -frameHeight=46 +frame_width=46 +frame_height=46 [animation] name=powerball diff --git a/data/gfx/item/item_clock.ani b/data/gfx/item/item_clock.ani index 67ae07a..3922815 100644 --- a/data/gfx/item/item_clock.ani +++ b/data/gfx/item/item_clock.ani @@ -1,5 +1,5 @@ -frameWidth=20 -frameHeight=20 +frame_width=20 +frame_height=20 [animation] name=default diff --git a/data/gfx/item/item_coffee.ani b/data/gfx/item/item_coffee.ani index 67ae07a..3922815 100644 --- a/data/gfx/item/item_coffee.ani +++ b/data/gfx/item/item_coffee.ani @@ -1,5 +1,5 @@ -frameWidth=20 -frameHeight=20 +frame_width=20 +frame_height=20 [animation] name=default diff --git a/data/gfx/item/item_coffee_machine.ani b/data/gfx/item/item_coffee_machine.ani index 15e1965..6659918 100644 --- a/data/gfx/item/item_coffee_machine.ani +++ b/data/gfx/item/item_coffee_machine.ani @@ -1,5 +1,5 @@ -frameWidth=28 -frameHeight=37 +frame_width=28 +frame_height=37 [animation] name=default diff --git a/data/gfx/item/item_points1_disk.ani b/data/gfx/item/item_points1_disk.ani index 67ae07a..3922815 100644 --- a/data/gfx/item/item_points1_disk.ani +++ b/data/gfx/item/item_points1_disk.ani @@ -1,5 +1,5 @@ -frameWidth=20 -frameHeight=20 +frame_width=20 +frame_height=20 [animation] name=default diff --git a/data/gfx/item/item_points2_gavina.ani b/data/gfx/item/item_points2_gavina.ani index 67ae07a..3922815 100644 --- a/data/gfx/item/item_points2_gavina.ani +++ b/data/gfx/item/item_points2_gavina.ani @@ -1,5 +1,5 @@ -frameWidth=20 -frameHeight=20 +frame_width=20 +frame_height=20 [animation] name=default diff --git a/data/gfx/item/item_points3_pacmar.ani b/data/gfx/item/item_points3_pacmar.ani index 67ae07a..3922815 100644 --- a/data/gfx/item/item_points3_pacmar.ani +++ b/data/gfx/item/item_points3_pacmar.ani @@ -1,5 +1,5 @@ -frameWidth=20 -frameHeight=20 +frame_width=20 +frame_height=20 [animation] name=default diff --git a/data/gfx/player/player.ani b/data/gfx/player/player.ani index d8640ad..9fff605 100644 --- a/data/gfx/player/player.ani +++ b/data/gfx/player/player.ani @@ -1,5 +1,5 @@ -frameWidth=30 -frameHeight=30 +frame_width=30 +frame_height=30 [animation] name=walk diff --git a/data/gfx/player/player_power.ani b/data/gfx/player/player_power.ani index 0377089..cae83ad 100644 --- a/data/gfx/player/player_power.ani +++ b/data/gfx/player/player_power.ani @@ -1,5 +1,5 @@ -frameWidth=39 -frameHeight=44 +frame_width=39 +frame_height=44 [animation] name=default diff --git a/data/gfx/title/title_dust.ani b/data/gfx/title/title_dust.ani index 9e655a4..bbc3a58 100644 --- a/data/gfx/title/title_dust.ani +++ b/data/gfx/title/title_dust.ani @@ -1,5 +1,5 @@ -frameWidth=16 -frameHeight=16 +frame_width=16 +frame_height=16 [animation] name=default diff --git a/source/animated_sprite.cpp b/source/animated_sprite.cpp index d671202..c7b0c05 100644 --- a/source/animated_sprite.cpp +++ b/source/animated_sprite.cpp @@ -5,18 +5,18 @@ #include "texture.h" // for Texture // Carga la animación desde un fichero -animatedSprite_t loadAnimationFromFile(std::shared_ptr texture, std::string filePath) +AnimatedFile loadAnimationFromFile(std::shared_ptr texture, std::string file_path) { // Inicializa variables - animatedSprite_t as; - as.texture = texture; - auto framesPerRow = 0; - auto frameWidth = 0; - auto frameHeight = 0; - auto maxTiles = 0; + AnimatedFile af; + af.texture = texture; + auto frames_per_row = 0; + auto frame_width = 0; + auto frame_height = 0; + auto max_tiles = 0; - const std::string filename = filePath.substr(filePath.find_last_of("\\/") + 1); - std::ifstream file(filePath); + const std::string file_name = file_path.substr(file_path.find_last_of("\\/") + 1); + std::ifstream file(file_path); std::string line; // El fichero se puede abrir @@ -24,7 +24,7 @@ animatedSprite_t loadAnimationFromFile(std::shared_ptr texture, std::st { // Procesa el fichero linea a linea #ifdef VERBOSE - std::cout << "Animation loaded: " << filename << std::endl; + std::cout << "Animation loaded: " << file_name << std::endl; #endif while (std::getline(file, line)) { @@ -33,7 +33,7 @@ animatedSprite_t loadAnimationFromFile(std::shared_ptr texture, std::st { Animation buffer; buffer.counter = 0; - buffer.currentFrame = 0; + buffer.current_frame = 0; buffer.completed = false; do @@ -66,13 +66,13 @@ animatedSprite_t loadAnimationFromFile(std::shared_ptr texture, std::st // Se introducen los valores separados por comas en un vector std::stringstream ss(line.substr(pos + 1, line.length())); std::string tmp; - SDL_Rect rect = {0, 0, frameWidth, frameHeight}; + SDL_Rect rect = {0, 0, frame_width, frame_height}; while (getline(ss, tmp, ',')) { // Comprueba que el tile no sea mayor que el maximo indice permitido - const auto numTile = std::stoi(tmp) > maxTiles ? 0 : std::stoi(tmp); - rect.x = (numTile % framesPerRow) * frameWidth; - rect.y = (numTile / framesPerRow) * frameHeight; + const auto num_tile = std::stoi(tmp) > max_tiles ? 0 : std::stoi(tmp); + rect.x = (num_tile % frames_per_row) * frame_width; + rect.y = (num_tile / frames_per_row) * frame_height; buffer.frames.push_back(rect); } } @@ -80,14 +80,14 @@ animatedSprite_t loadAnimationFromFile(std::shared_ptr texture, std::st else { #ifdef VERBOSE - std::cout << "Warning: file " << filename.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl; + std::cout << "Warning: file " << file_name.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl; #endif } } } while (line != "[/animation]"); // Añade la animación al vector de animaciones - as.animations.push_back(buffer); + af.animations.push_back(buffer); } // En caso contrario se parsea el fichero para buscar las variables y los valores @@ -99,39 +99,39 @@ animatedSprite_t loadAnimationFromFile(std::shared_ptr texture, std::st // Procesa las dos subcadenas if (pos != (int)line.npos) { - if (line.substr(0, pos) == "framesPerRow") + if (line.substr(0, pos) == "frames_per_row") { - framesPerRow = std::stoi(line.substr(pos + 1, line.length())); + frames_per_row = std::stoi(line.substr(pos + 1, line.length())); } - else if (line.substr(0, pos) == "frameWidth") + else if (line.substr(0, pos) == "frame_width") { - frameWidth = std::stoi(line.substr(pos + 1, line.length())); + frame_width = std::stoi(line.substr(pos + 1, line.length())); } - else if (line.substr(0, pos) == "frameHeight") + else if (line.substr(0, pos) == "frame_height") { - frameHeight = std::stoi(line.substr(pos + 1, line.length())); + frame_height = std::stoi(line.substr(pos + 1, line.length())); } else { #ifdef VERBOSE - std::cout << "Warning: file " << filename.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl; + std::cout << "Warning: file " << file_name.c_str() << "\n, unknown parameter \"" << line.substr(0, pos).c_str() << "\"" << std::endl; #endif } // Normaliza valores - if (framesPerRow == 0 && frameWidth > 0) + if (frames_per_row == 0 && frame_width > 0) { - framesPerRow = texture->getWidth() / frameWidth; + frames_per_row = texture->getWidth() / frame_width; } - if (maxTiles == 0 && frameWidth > 0 && frameHeight > 0) + if (max_tiles == 0 && frame_width > 0 && frame_height > 0) { - const auto w = texture->getWidth() / frameWidth; - const auto h = texture->getHeight() / frameHeight; - maxTiles = w * h; + const auto w = texture->getWidth() / frame_width; + const auto h = texture->getHeight() / frame_height; + max_tiles = w * h; } } } @@ -144,11 +144,11 @@ animatedSprite_t loadAnimationFromFile(std::shared_ptr texture, std::st else { #ifdef VERBOSE - std::cout << "Warning: Unable to open " << filename.c_str() << " file" << std::endl; + std::cout << "Warning: Unable to open " << file_name.c_str() << " file" << std::endl; #endif } - return as; + return af; } // Constructor @@ -160,7 +160,7 @@ AnimatedSprite::AnimatedSprite(std::shared_ptr texture, std::string fil // Carga las animaciones if (file != "") { - animatedSprite_t as = loadAnimationFromFile(texture, file); + AnimatedFile as = loadAnimationFromFile(texture, file); // Copia los datos de las animaciones for (auto animation : as.animations) @@ -175,17 +175,17 @@ AnimatedSprite::AnimatedSprite(std::shared_ptr texture, std::string fil } // Inicializa variables - currentAnimation_ = 0; + current_animation_ = 0; } // Constructor -AnimatedSprite::AnimatedSprite(animatedSprite_t *animation) +AnimatedSprite::AnimatedSprite(AnimatedFile *animation) { // Copia los punteros setTexture(animation->texture); // Inicializa variables - currentAnimation_ = 0; + current_animation_ = 0; // Copia los datos de las animaciones for (auto a : animation->animations) @@ -222,61 +222,61 @@ int AnimatedSprite::getIndex(std::string name) // Calcula el frame correspondiente a la animación void AnimatedSprite::animate() { - if (!enabled_ || animations_[currentAnimation_].speed == 0) + if (!enabled_ || animations_[current_animation_].speed == 0) { return; } // Calcula el frame actual a partir del contador - animations_[currentAnimation_].currentFrame = animations_[currentAnimation_].counter / animations_[currentAnimation_].speed; + animations_[current_animation_].current_frame = animations_[current_animation_].counter / animations_[current_animation_].speed; // Si alcanza el final de la animación, reinicia el contador de la animación // en función de la variable loop y coloca el nuevo frame - if (animations_[currentAnimation_].currentFrame >= (int)animations_[currentAnimation_].frames.size()) + if (animations_[current_animation_].current_frame >= (int)animations_[current_animation_].frames.size()) { - if (animations_[currentAnimation_].loop == -1) + if (animations_[current_animation_].loop == -1) { // Si no hay loop, deja el último frame - animations_[currentAnimation_].currentFrame = animations_[currentAnimation_].frames.size(); - animations_[currentAnimation_].completed = true; + animations_[current_animation_].current_frame = animations_[current_animation_].frames.size(); + animations_[current_animation_].completed = true; } else { // Si hay loop, vuelve al frame indicado - animations_[currentAnimation_].counter = 0; - animations_[currentAnimation_].currentFrame = animations_[currentAnimation_].loop; + animations_[current_animation_].counter = 0; + animations_[current_animation_].current_frame = animations_[current_animation_].loop; } } // En caso contrario else { // Escoge el frame correspondiente de la animación - setSpriteClip(animations_[currentAnimation_].frames[animations_[currentAnimation_].currentFrame]); + setSpriteClip(animations_[current_animation_].frames[animations_[current_animation_].current_frame]); // Incrementa el contador de la animacion - animations_[currentAnimation_].counter++; + animations_[current_animation_].counter++; } } // Obtiene el número de frames de la animación actual int AnimatedSprite::getNumFrames() { - return (int)animations_[currentAnimation_].frames.size(); + return (int)animations_[current_animation_].frames.size(); } // Establece el frame actual de la animación void AnimatedSprite::setCurrentFrame(int num) { // Descarta valores fuera de rango - if (num >= (int)animations_[currentAnimation_].frames.size()) + if (num >= (int)animations_[current_animation_].frames.size()) { num = 0; } // Cambia el valor de la variable - animations_[currentAnimation_].currentFrame = num; - animations_[currentAnimation_].counter = 0; + animations_[current_animation_].current_frame = num; + animations_[current_animation_].counter = 0; // Escoge el frame correspondiente de la animación - setSpriteClip(animations_[currentAnimation_].frames[animations_[currentAnimation_].currentFrame]); + setSpriteClip(animations_[current_animation_].frames[animations_[current_animation_].current_frame]); } // Establece el valor del contador @@ -324,7 +324,7 @@ void AnimatedSprite::setAnimationCompleted(int index, bool value) // Comprueba si ha terminado la animación bool AnimatedSprite::animationIsCompleted() { - return animations_[currentAnimation_].completed; + return animations_[current_animation_].completed; } // Devuelve el rectangulo de una animación y frame concreto @@ -343,10 +343,10 @@ SDL_Rect AnimatedSprite::getAnimationClip(int indexA, Uint8 indexF) bool AnimatedSprite::loadFromVector(std::vector *source) { // Inicializa variables - auto framesPerRow = 0; - auto frameWidth = 0; - auto frameHeight = 0; - auto maxTiles = 0; + auto frames_per_row = 0; + auto frame_width = 0; + auto frame_height = 0; + auto max_tiles = 0; // Indicador de éxito en el proceso auto success = true; @@ -364,7 +364,7 @@ bool AnimatedSprite::loadFromVector(std::vector *source) { Animation buffer; buffer.counter = 0; - buffer.currentFrame = 0; + buffer.current_frame = 0; buffer.completed = false; do @@ -399,13 +399,13 @@ bool AnimatedSprite::loadFromVector(std::vector *source) // Se introducen los valores separados por comas en un vector std::stringstream ss(line.substr(pos + 1, line.length())); std::string tmp; - SDL_Rect rect = {0, 0, frameWidth, frameHeight}; + SDL_Rect rect = {0, 0, frame_width, frame_height}; while (getline(ss, tmp, ',')) { // Comprueba que el tile no sea mayor que el maximo indice permitido - const int numTile = std::stoi(tmp) > maxTiles ? 0 : std::stoi(tmp); - rect.x = (numTile % framesPerRow) * frameWidth; - rect.y = (numTile / framesPerRow) * frameHeight; + const int num_tile = std::stoi(tmp) > max_tiles ? 0 : std::stoi(tmp); + rect.x = (num_tile % frames_per_row) * frame_width; + rect.y = (num_tile / frames_per_row) * frame_height; buffer.frames.push_back(rect); } } @@ -433,19 +433,19 @@ bool AnimatedSprite::loadFromVector(std::vector *source) // Procesa las dos subcadenas if (pos != (int)line.npos) { - if (line.substr(0, pos) == "framesPerRow") + if (line.substr(0, pos) == "frames_per_row") { - framesPerRow = std::stoi(line.substr(pos + 1, line.length())); + frames_per_row = std::stoi(line.substr(pos + 1, line.length())); } - else if (line.substr(0, pos) == "frameWidth") + else if (line.substr(0, pos) == "frame_width") { - frameWidth = std::stoi(line.substr(pos + 1, line.length())); + frame_width = std::stoi(line.substr(pos + 1, line.length())); } - else if (line.substr(0, pos) == "frameHeight") + else if (line.substr(0, pos) == "frame_height") { - frameHeight = std::stoi(line.substr(pos + 1, line.length())); + frame_height = std::stoi(line.substr(pos + 1, line.length())); } else @@ -457,16 +457,16 @@ bool AnimatedSprite::loadFromVector(std::vector *source) } // Normaliza valores - if (framesPerRow == 0 && frameWidth > 0) + if (frames_per_row == 0 && frame_width > 0) { - framesPerRow = texture_->getWidth() / frameWidth; + frames_per_row = texture_->getWidth() / frame_width; } - if (maxTiles == 0 && frameWidth > 0 && frameHeight > 0) + if (max_tiles == 0 && frame_width > 0 && frame_height > 0) { - const int w = texture_->getWidth() / frameWidth; - const int h = texture_->getHeight() / frameHeight; - maxTiles = w * h; + const int w = texture_->getWidth() / frame_width; + const int h = texture_->getHeight() / frame_height; + max_tiles = w * h; } } } @@ -476,7 +476,7 @@ bool AnimatedSprite::loadFromVector(std::vector *source) } // Pone un valor por defecto - setRect({0, 0, frameWidth, frameHeight}); + setRect({0, 0, frame_width, frame_height}); return success; } @@ -484,26 +484,26 @@ bool AnimatedSprite::loadFromVector(std::vector *source) // Establece la animacion actual void AnimatedSprite::setCurrentAnimation(std::string name) { - const auto newAnimation = getIndex(name); - if (currentAnimation_ != newAnimation) + const auto new_animation = getIndex(name); + if (current_animation_ != new_animation) { - currentAnimation_ = newAnimation; - animations_[currentAnimation_].currentFrame = 0; - animations_[currentAnimation_].counter = 0; - animations_[currentAnimation_].completed = false; + current_animation_ = new_animation; + animations_[current_animation_].current_frame = 0; + animations_[current_animation_].counter = 0; + animations_[current_animation_].completed = false; } } // Establece la animacion actual void AnimatedSprite::setCurrentAnimation(int index) { - const auto newAnimation = index; - if (currentAnimation_ != newAnimation) + const auto new_animation = index; + if (current_animation_ != new_animation) { - currentAnimation_ = newAnimation; - animations_[currentAnimation_].currentFrame = 0; - animations_[currentAnimation_].counter = 0; - animations_[currentAnimation_].completed = false; + current_animation_ = new_animation; + animations_[current_animation_].current_frame = 0; + animations_[current_animation_].counter = 0; + animations_[current_animation_].completed = false; } } @@ -535,7 +535,7 @@ void AnimatedSprite::setAnimationCounter(int value) // Reinicia la animación void AnimatedSprite::resetAnimation() { - animations_[currentAnimation_].currentFrame = 0; - animations_[currentAnimation_].counter = 0; - animations_[currentAnimation_].completed = false; + animations_[current_animation_].current_frame = 0; + animations_[current_animation_].counter = 0; + animations_[current_animation_].completed = false; } \ No newline at end of file diff --git a/source/animated_sprite.h b/source/animated_sprite.h index aef5b50..7f03ca3 100644 --- a/source/animated_sprite.h +++ b/source/animated_sprite.h @@ -15,30 +15,30 @@ struct Animation int speed; // Velocidad de la animación int loop; // Indica a que frame vuelve la animación al terminar. -1 para que no vuelva bool completed; // Indica si ha finalizado la animación - int currentFrame; // Frame actual + int current_frame; // Frame actual int counter; // Contador para las animaciones }; -struct animatedSprite_t +struct AnimatedFile { std::vector animations; // Vector con las diferentes animaciones std::shared_ptr texture; // Textura con los graficos para el sprite }; // Carga la animación desde un fichero -animatedSprite_t loadAnimationFromFile(std::shared_ptr texture, std::string filePath); +AnimatedFile loadAnimationFromFile(std::shared_ptr texture, std::string filePath); class AnimatedSprite : public MovingSprite { private: // Variables std::vector animations_; // Vector con las diferentes animaciones - int currentAnimation_; // Animacion activa + int current_animation_; // Animacion activa public: // Constructor AnimatedSprite(std::shared_ptr texture = nullptr, std::string file = "", std::vector *buffer = nullptr); - AnimatedSprite(animatedSprite_t *animation); + AnimatedSprite(AnimatedFile *animation); // Destructor ~AnimatedSprite(); diff --git a/source/asset.cpp b/source/asset.cpp index f9b0042..c6c61e1 100644 --- a/source/asset.cpp +++ b/source/asset.cpp @@ -1,16 +1,16 @@ #include "asset.h" -#include // for SDL_RWFromFile, SDL_RWclose, SDL_RWops -#include // for SDL_max -#include // for size_t -#include // for basic_ostream, operator<<, cout, endl +#include // for SDL_RWFromFile, SDL_RWclose, SDL_RWops +#include // for SDL_max +#include // for size_t +#include // for basic_ostream, operator<<, cout, endl // [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado Asset *Asset::asset = nullptr; // [SINGLETON] Crearemos el objeto asset con esta función estática -void Asset::init(std::string executablePath) +void Asset::init(std::string executable_path) { - Asset::asset = new Asset(executablePath); + Asset::asset = new Asset(executable_path); } // [SINGLETON] Destruiremos el objeto asset con esta función estática @@ -26,37 +26,32 @@ Asset *Asset::get() } // Constructor -Asset::Asset(std::string executablePath) +Asset::Asset(std::string executable_path) { - this->executablePath = executablePath.substr(0, executablePath.find_last_of("\\/")); - longestName = 0; -#ifdef VERBOSE - verbose = true; -#else - verbose = false; -#endif + executable_path_ = executable_path.substr(0, executable_path.find_last_of("\\/")); + longest_name_ = 0; } // Añade un elemento a la lista -void Asset::add(std::string file, enum assetType type, bool required, bool absolute) +void Asset::add(std::string file, AssetType type, bool required, bool absolute) { - item_t temp; - temp.file = absolute ? file : executablePath + file; - temp.type = type; - temp.required = required; - fileList.push_back(temp); + AssetItem ai; + ai.file = absolute ? file : executable_path_ + file; + ai.type = type; + ai.required = required; + file_list_.push_back(ai); - const std::string filename = file.substr(file.find_last_of("\\/") + 1); - longestName = SDL_max(longestName, filename.size()); + const std::string file_name = file.substr(file.find_last_of("\\/") + 1); + longest_name_ = SDL_max(longest_name_, file_name.size()); } // Devuelve el fichero de un elemento de la lista a partir de una cadena -std::string Asset::get(std::string text) +std::string Asset::get(std::string text) const { - for (auto f : fileList) + for (auto f : file_list_) { - const size_t lastIndex = f.file.find_last_of("/") + 1; - const std::string file = f.file.substr(lastIndex, std::string::npos); + const size_t last_index = f.file.find_last_of("/") + 1; + const std::string file = f.file.substr(last_index, std::string::npos); if (file == text) { @@ -64,35 +59,33 @@ std::string Asset::get(std::string text) } } - if (verbose) - { - std::cout << "Warning: file " << text.c_str() << " not found" << std::endl; - } +#ifdef VERBOSE + std::cout << "Warning: file " << text.c_str() << " not found" << std::endl; +#endif return ""; } // Comprueba que existen todos los elementos -bool Asset::check() +bool Asset::check() const { bool success = true; - if (verbose) - { - std::cout << "\n** Checking files" << std::endl; +#ifdef VERBOSE + std::cout << "\n** Checking files" << std::endl; - std::cout << "Executable path is: " << executablePath << std::endl; - std::cout << "Sample filepath: " << fileList.back().file << std::endl; - } + std::cout << "Executable path is: " << executable_path_ << std::endl; + std::cout << "Sample filepath: " << file_list_.back().file << std::endl; +#endif // Comprueba la lista de ficheros clasificandolos por tipo - for (int type = 0; type < t_maxAssetType; ++type) + for (int type = 0; type < static_cast(AssetType::MAX_ASSET_TYPE); ++type) { // Comprueba si hay ficheros de ese tipo bool any = false; - for (auto f : fileList) + for (auto f : file_list_) { - if ((f.required) && (f.type == type)) + if (f.required && f.type == static_cast(type)) { any = true; } @@ -101,14 +94,13 @@ bool Asset::check() // Si hay ficheros de ese tipo, comprueba si existen if (any) { - if (verbose) - { - std::cout << "\n>> " << getTypeName(type).c_str() << " FILES" << std::endl; - } +#ifdef VERBOSE + std::cout << "\n>> " << getTypeName(type).c_str() << " FILES" << std::endl; +#endif - for (auto f : fileList) + for (auto f : file_list_) { - if ((f.required) && (f.type == type)) + if (f.required && f.type == static_cast(type)) { success &= checkFile(f.file); } @@ -116,32 +108,22 @@ bool Asset::check() } } - // Resultado - if (verbose) - { - if (success) - { - std::cout << "\n** All files OK.\n" - << std::endl; - } - else - { - std::cout << "\n** A file is missing. Exiting.\n" - << std::endl; - } - } +// Resultado +#ifdef VERBOSE + std::cout << (success ? "\n** All files OK.\n" : "\n** A file is missing. Exiting.\n") << std::endl; +#endif return success; } // Comprueba que existe un fichero -bool Asset::checkFile(std::string path) +bool Asset::checkFile(std::string path) const { bool success = false; std::string result = "ERROR"; // Comprueba si existe el fichero - const std::string filename = path.substr(path.find_last_of("\\/") + 1); + const std::string file_name = path.substr(path.find_last_of("\\/") + 1); SDL_RWops *file = SDL_RWFromFile(path.c_str(), "rb"); if (file != nullptr) @@ -151,57 +133,56 @@ bool Asset::checkFile(std::string path) SDL_RWclose(file); } - if (verbose) - { - std::cout.setf(std::ios::left, std::ios::adjustfield); - std::cout << "Checking file: "; - std::cout.width(longestName + 2); - std::cout.fill('.'); - std::cout << filename + " "; - std::cout << " [" + result + "]" << std::endl; - } +#ifdef VERBOSE + std::cout.setf(std::ios::left, std::ios::adjustfield); + std::cout << "Checking file: "; + std::cout.width(longest_name_ + 2); + std::cout.fill('.'); + std::cout << file_name + " "; + std::cout << " [" + result + "]" << std::endl; +#endif return success; } // Devuelve el nombre del tipo de recurso -std::string Asset::getTypeName(int type) +std::string Asset::getTypeName(int type) const { switch (type) { - case t_bitmap: + case static_cast(AssetType::BITMAP): return "BITMAP"; break; - case t_music: + case static_cast(AssetType::MUSIC): return "MUSIC"; break; - case t_sound: + case static_cast(AssetType::SOUND): return "SOUND"; break; - case t_font: + case static_cast(AssetType::FONT): return "FONT"; break; - case t_lang: + case static_cast(AssetType::LANG): return "LANG"; break; - case t_data: + case static_cast(AssetType::DATA): return "DATA"; break; - case t_animation: + case static_cast(AssetType::ANIMATION): return "ANIMATION"; break; - case t_palette: + case static_cast(AssetType::PALETTE): return "PALETTE"; break; - case t_item: + case static_cast(AssetType::ITEM): return "ITEM"; break; @@ -211,18 +192,12 @@ std::string Asset::getTypeName(int type) } } -// Establece si ha de mostrar texto por pantalla -void Asset::setVerbose(bool value) -{ - verbose = value; -} - // Devuelve la lista de recursos de un tipo -std::vector Asset::getListByType(assetType type) +std::vector Asset::getListByType(AssetType type) const { std::vector list; - for (auto f : fileList) + for (auto f : file_list_) { if (f.type == type) { diff --git a/source/asset.h b/source/asset.h index c2bfb21..c79c956 100644 --- a/source/asset.h +++ b/source/asset.h @@ -3,18 +3,18 @@ #include // for string, basic_string #include // for vector -enum assetType +enum class AssetType { - t_bitmap, - t_music, - t_sound, - t_font, - t_lang, - t_data, - t_animation, - t_palette, - t_item, - t_maxAssetType + BITMAP, + MUSIC, + SOUND, + FONT, + LANG, + DATA, + ANIMATION, + PALETTE, + ITEM, + MAX_ASSET_TYPE, }; // Clase Asset @@ -25,25 +25,24 @@ private: static Asset *asset; // Estructura para definir un item - struct item_t + struct AssetItem { std::string file; // Ruta del fichero desde la raiz del directorio - enum assetType type; // Indica el tipo de recurso + enum AssetType type; // Indica el tipo de recurso bool required; // Indica si es un fichero que debe de existir // bool absolute; // Indica si la ruta que se ha proporcionado es una ruta absoluta }; // Variables - int longestName; // Contiene la longitud del nombre de fichero mas largo - std::vector fileList; // Listado con todas las rutas a los ficheros - std::string executablePath; // Ruta al ejecutable - bool verbose; // Indica si ha de mostrar información por pantalla + int longest_name_; // Contiene la longitud del nombre de fichero mas largo + std::vector file_list_; // Listado con todas las rutas a los ficheros + std::string executable_path_; // Ruta al ejecutable // Comprueba que existe un fichero - bool checkFile(std::string executablePath); + bool checkFile(std::string executable_path) const; // Devuelve el nombre del tipo de recurso - std::string getTypeName(int type); + std::string getTypeName(int type) const; // Constructor Asset(std::string path); @@ -62,17 +61,14 @@ public: static Asset *get(); // Añade un elemento a la lista - void add(std::string file, enum assetType type, bool required = true, bool absolute = false); + void add(std::string file, AssetType type, bool required = true, bool absolute = false); // Devuelve un elemento de la lista a partir de una cadena - std::string get(std::string text); + std::string get(std::string text) const; // Comprueba que existen todos los elementos - bool check(); - - // Establece si ha de mostrar texto por pantalla - void setVerbose(bool value); + bool check() const; // Devuelve la lista de recursos de un tipo - std::vector getListByType(assetType type); + std::vector getListByType(AssetType type) const; }; \ No newline at end of file diff --git a/source/background.cpp b/source/background.cpp index 769a64f..f54bc9a 100644 --- a/source/background.cpp +++ b/source/background.cpp @@ -1,108 +1,108 @@ #include "background.h" -#include // for SDL_BLENDMODE_BLEND -#include // for SDL_PIXELFORMAT_RGBA8888 -#include // for max, min -#include // for basic_string -#include "asset.h" // for Asset -#include "param.h" // for param +#include // for SDL_BLENDMODE_BLEND +#include // for SDL_PIXELFORMAT_RGBA8888 +#include // for max, min +#include // for basic_string +#include "asset.h" // for Asset +#include "param.h" // for param // Constructor Background::Background(SDL_Renderer *renderer) -: renderer(renderer) + : renderer_(renderer) { // Carga las texturas - buildingsTexture = std::make_shared(renderer, Asset::get()->get("game_buildings.png")); - topCloudsTexture = std::make_shared(renderer, Asset::get()->get("game_clouds1.png")); - bottomCloudsTexture = std::make_shared(renderer, Asset::get()->get("game_clouds2.png")); - grassTexture = std::make_shared(renderer, Asset::get()->get("game_grass.png")); - gradientsTexture = std::make_shared(renderer, Asset::get()->get("game_sky_colors.png")); + buildings_texture_ = std::make_shared(renderer, Asset::get()->get("game_buildings.png")); + top_clouds_texture_ = std::make_shared(renderer, Asset::get()->get("game_clouds1.png")); + bottom_clouds_texture_ = std::make_shared(renderer, Asset::get()->get("game_clouds2.png")); + grass_texture_ = std::make_shared(renderer, Asset::get()->get("game_grass.png")); + gradients_texture_ = std::make_shared(renderer, Asset::get()->get("game_sky_colors.png")); // Inicializa variables - gradientNumber = 0; - alpha = 0; - cloudsSpeed = 0; - transition = 0; - counter = 0; + gradient_number_ = 0; + alpha_ = 0; + clouds_speed_ = 0; + transition_ = 0; + counter_ = 0; - rect = {0, 0, gradientsTexture->getWidth() / 2, gradientsTexture->getHeight() / 2}; - srcRect = {0, 0, 320, 240}; - dstRect = {0, 0, 320, 240}; + rect_ = {0, 0, gradients_texture_->getWidth() / 2, gradients_texture_->getHeight() / 2}; + src_rect_ = {0, 0, 320, 240}; + dst_rect_ = {0, 0, 320, 240}; - base = rect.h; - color = {param.background.attenuateColor.r, param.background.attenuateColor.g, param.background.attenuateColor.b}; - alphaColorText = alphaColorTextTemp = param.background.attenuateAlpha; + base_ = rect_.h; + color_ = {param.background.attenuateColor.r, param.background.attenuateColor.g, param.background.attenuateColor.b}; + alpha_color_text_ = alpha_color_text_temp_ = param.background.attenuateAlpha; - gradientRect[0] = {0, 0, rect.w, rect.h}; - gradientRect[1] = {rect.w, 0, rect.w, rect.h}; - gradientRect[2] = {0, rect.h, rect.w, rect.h}; - gradientRect[3] = {rect.w, rect.h, rect.w, rect.h}; + gradient_rect_[0] = {0, 0, rect_.w, rect_.h}; + gradient_rect_[1] = {rect_.w, 0, rect_.w, rect_.h}; + gradient_rect_[2] = {0, rect_.h, rect_.w, rect_.h}; + gradient_rect_[3] = {rect_.w, rect_.h, rect_.w, rect_.h}; - const int topCloudsTextureHeight = topCloudsTexture->getHeight() / 4; - const int bottomCloudsTextureHeight = bottomCloudsTexture->getHeight() / 4; + const int top_clouds_texture_height = top_clouds_texture_->getHeight() / 4; + const int bottom_clouds_texture_height = bottom_clouds_texture_->getHeight() / 4; for (int i = 0; i < 4; ++i) { - topCloudsRect[i] = {0, i * topCloudsTextureHeight, topCloudsTexture->getWidth(), topCloudsTextureHeight}; - bottomCloudsRect[i] = {0, i * bottomCloudsTextureHeight, bottomCloudsTexture->getWidth(), bottomCloudsTextureHeight}; + top_clouds_rect_[i] = {0, i * top_clouds_texture_height, top_clouds_texture_->getWidth(), top_clouds_texture_height}; + bottom_clouds_rect_[i] = {0, i * bottom_clouds_texture_height, bottom_clouds_texture_->getWidth(), bottom_clouds_texture_height}; } // Crea los sprites - const int topClouds_y = base - 165; - const int bottomClouds_y = base - 101; - const float topCloudsSpeed = 0.1f; - const float bottomCloudsSpeed = 0.05f; - topCloudsSprite_A = std::make_unique(0, topClouds_y, rect.w, topCloudsTexture->getHeight(), -topCloudsSpeed, 0.0f, 0.0f, 0.0f, topCloudsTexture); - topCloudsSprite_B = std::make_unique(rect.w, topClouds_y, rect.w, topCloudsTexture->getHeight(), -topCloudsSpeed, 0.0f, 0.0f, 0.0f, topCloudsTexture); + const int top_clouds_y = base_ - 165; + const int bottom_clouds_y = base_ - 101; + constexpr float top_clouds_speed = 0.1f; + constexpr float bottom_clouds_speed = 0.05f; + top_clouds_sprite_a_ = std::make_unique(0, top_clouds_y, rect_.w, top_clouds_texture_->getHeight(), -top_clouds_speed, 0.0f, 0.0f, 0.0f, top_clouds_texture_); + top_clouds_sprite_b_ = std::make_unique(rect_.w, top_clouds_y, rect_.w, top_clouds_texture_->getHeight(), -top_clouds_speed, 0.0f, 0.0f, 0.0f, top_clouds_texture_); - bottomCloudsSprite_A = std::make_unique(0, bottomClouds_y, rect.w, bottomCloudsTexture->getHeight(), -bottomCloudsSpeed, 0.0f, 0.0f, 0.0f, bottomCloudsTexture); - bottomCloudsSprite_B = std::make_unique(rect.w, bottomClouds_y, rect.w, bottomCloudsTexture->getHeight(), -bottomCloudsSpeed, 0.0f, 0.0f, 0.0f, bottomCloudsTexture); + bottom_clouds_sprite_a_ = std::make_unique(0, bottom_clouds_y, rect_.w, bottom_clouds_texture_->getHeight(), -bottom_clouds_speed, 0.0f, 0.0f, 0.0f, bottom_clouds_texture_); + bottom_clouds_sprite_b_ = std::make_unique(rect_.w, bottom_clouds_y, rect_.w, bottom_clouds_texture_->getHeight(), -bottom_clouds_speed, 0.0f, 0.0f, 0.0f, bottom_clouds_texture_); - buildingsSprite = std::make_unique(0, 0, buildingsTexture->getWidth(), buildingsTexture->getHeight(), buildingsTexture); - gradientSprite = std::make_unique(0, 0, rect.w, rect.h, gradientsTexture); - grassSprite = std::make_unique(0, 0, grassTexture->getWidth(), grassTexture->getHeight() / 2, grassTexture); + buildings_sprite_ = std::make_unique(0, 0, buildings_texture_->getWidth(), buildings_texture_->getHeight(), buildings_texture_); + gradient_sprite_ = std::make_unique(0, 0, rect_.w, rect_.h, gradients_texture_); + grass_sprite_ = std::make_unique(0, 0, grass_texture_->getWidth(), grass_texture_->getHeight() / 2, grass_texture_); // Inicializa objetos - topCloudsSprite_A->setSpriteClip(0, 0, topCloudsTexture->getWidth(), topCloudsTexture->getHeight()); - topCloudsSprite_B->setSpriteClip(0, 0, topCloudsTexture->getWidth(), topCloudsTexture->getHeight()); - bottomCloudsSprite_A->setSpriteClip(0, 0, bottomCloudsTexture->getWidth(), bottomCloudsTexture->getHeight()); - bottomCloudsSprite_B->setSpriteClip(0, 0, bottomCloudsTexture->getWidth(), bottomCloudsTexture->getHeight()); - buildingsSprite->setPosY(base - buildingsSprite->getHeight()); - grassSprite->setPosY(base - grassSprite->getHeight()); + top_clouds_sprite_a_->setSpriteClip(0, 0, top_clouds_texture_->getWidth(), top_clouds_texture_->getHeight()); + top_clouds_sprite_b_->setSpriteClip(0, 0, top_clouds_texture_->getWidth(), top_clouds_texture_->getHeight()); + bottom_clouds_sprite_a_->setSpriteClip(0, 0, bottom_clouds_texture_->getWidth(), bottom_clouds_texture_->getHeight()); + bottom_clouds_sprite_b_->setSpriteClip(0, 0, bottom_clouds_texture_->getWidth(), bottom_clouds_texture_->getHeight()); + buildings_sprite_->setPosY(base_ - buildings_sprite_->getHeight()); + grass_sprite_->setPosY(base_ - grass_sprite_->getHeight()); // Crea la textura para componer el fondo - canvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, rect.w, rect.h); - SDL_SetTextureBlendMode(canvas, SDL_BLENDMODE_BLEND); + canvas_ = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, rect_.w, rect_.h); + SDL_SetTextureBlendMode(canvas_, SDL_BLENDMODE_BLEND); // Crea la textura para atenuar el fondo - colorTexture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, rect.w, rect.h); - SDL_SetTextureBlendMode(colorTexture, SDL_BLENDMODE_BLEND); - setColor(color); - SDL_SetTextureAlphaMod(colorTexture, alphaColorText); + color_texture_ = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, rect_.w, rect_.h); + SDL_SetTextureBlendMode(color_texture_, SDL_BLENDMODE_BLEND); + setColor(color_); + SDL_SetTextureAlphaMod(color_texture_, alpha_color_text_); } // Destructor Background::~Background() { - SDL_DestroyTexture(canvas); - SDL_DestroyTexture(colorTexture); + SDL_DestroyTexture(canvas_); + SDL_DestroyTexture(color_texture_); } // Actualiza la lógica del objeto void Background::update() { - // Actualiza el valor de alpha + // Actualiza el valor de alpha_ updateAlphaColorText(); // Actualiza las nubes updateClouds(); // Calcula el frame de la hierba - grassSprite->setSpriteClip(0, (10 * (counter / 20 % 2)), 320, 10); + grass_sprite_->setSpriteClip(0, (10 * (counter_ / 20 % 2)), 320, 10); - // Calcula el valor de alpha - alpha = std::max((255 - (int)(255 * transition)), 0); + // Calcula el valor de alpha_ + alpha_ = std::max((255 - (int)(255 * transition_)), 0); // Incrementa el contador - counter++; + counter_++; fillCanvas(); } @@ -111,58 +111,58 @@ void Background::update() void Background::renderGradient() { // Dibuja el gradiente 2 - gradientsTexture->setAlpha(255); - gradientSprite->setSpriteClip(gradientRect[(gradientNumber + 1) % 4]); - gradientSprite->render(); + gradients_texture_->setAlpha(255); + gradient_sprite_->setSpriteClip(gradient_rect_[(gradient_number_ + 1) % 4]); + gradient_sprite_->render(); // Dibuja el gradiente 1 con una opacidad cada vez menor - gradientsTexture->setAlpha(alpha); - gradientSprite->setSpriteClip(gradientRect[gradientNumber]); - gradientSprite->render(); + gradients_texture_->setAlpha(alpha_); + gradient_sprite_->setSpriteClip(gradient_rect_[gradient_number_]); + gradient_sprite_->render(); } // Dibuja las nubes de arriba void Background::renderTopClouds() { // Dibuja el primer conjunto de nubes - topCloudsTexture->setAlpha(255); - topCloudsSprite_A->setSpriteClip(topCloudsRect[(gradientNumber + 1) % 4]); - topCloudsSprite_A->render(); - topCloudsSprite_B->setSpriteClip(topCloudsRect[(gradientNumber + 1) % 4]); - topCloudsSprite_B->render(); + top_clouds_texture_->setAlpha(255); + top_clouds_sprite_a_->setSpriteClip(top_clouds_rect_[(gradient_number_ + 1) % 4]); + top_clouds_sprite_a_->render(); + top_clouds_sprite_b_->setSpriteClip(top_clouds_rect_[(gradient_number_ + 1) % 4]); + top_clouds_sprite_b_->render(); // Dibuja el segundo conjunto de nubes - topCloudsTexture->setAlpha(alpha); - topCloudsSprite_A->setSpriteClip(topCloudsRect[gradientNumber]); - topCloudsSprite_A->render(); - topCloudsSprite_B->setSpriteClip(topCloudsRect[gradientNumber]); - topCloudsSprite_B->render(); + top_clouds_texture_->setAlpha(alpha_); + top_clouds_sprite_a_->setSpriteClip(top_clouds_rect_[gradient_number_]); + top_clouds_sprite_a_->render(); + top_clouds_sprite_b_->setSpriteClip(top_clouds_rect_[gradient_number_]); + top_clouds_sprite_b_->render(); } // Dibuja las nubes de abajo void Background::renderBottomClouds() { // Dibuja el primer conjunto de nubes - bottomCloudsTexture->setAlpha(255); - bottomCloudsSprite_A->setSpriteClip(bottomCloudsRect[(gradientNumber + 1) % 4]); - bottomCloudsSprite_A->render(); - bottomCloudsSprite_B->setSpriteClip(bottomCloudsRect[(gradientNumber + 1) % 4]); - bottomCloudsSprite_B->render(); + bottom_clouds_texture_->setAlpha(255); + bottom_clouds_sprite_a_->setSpriteClip(bottom_clouds_rect_[(gradient_number_ + 1) % 4]); + bottom_clouds_sprite_a_->render(); + bottom_clouds_sprite_b_->setSpriteClip(bottom_clouds_rect_[(gradient_number_ + 1) % 4]); + bottom_clouds_sprite_b_->render(); // Dibuja el segundo conjunto de nubes - bottomCloudsTexture->setAlpha(alpha); - bottomCloudsSprite_A->setSpriteClip(bottomCloudsRect[gradientNumber]); - bottomCloudsSprite_A->render(); - bottomCloudsSprite_B->setSpriteClip(bottomCloudsRect[gradientNumber]); - bottomCloudsSprite_B->render(); + bottom_clouds_texture_->setAlpha(alpha_); + bottom_clouds_sprite_a_->setSpriteClip(bottom_clouds_rect_[gradient_number_]); + bottom_clouds_sprite_a_->render(); + bottom_clouds_sprite_b_->setSpriteClip(bottom_clouds_rect_[gradient_number_]); + bottom_clouds_sprite_b_->render(); } // Compone todos los elementos del fondo en la textura void Background::fillCanvas() { // Cambia el destino del renderizador - SDL_Texture *temp = SDL_GetRenderTarget(renderer); - SDL_SetRenderTarget(renderer, canvas); + auto temp = SDL_GetRenderTarget(renderer_); + SDL_SetRenderTarget(renderer_, canvas_); // Dibuja el gradiente de fondo renderGradient(); @@ -174,45 +174,45 @@ void Background::fillCanvas() renderBottomClouds(); // Dibuja los edificios - buildingsSprite->render(); + buildings_sprite_->render(); // Dibuja la hierba - grassSprite->render(); + grass_sprite_->render(); // Deja el renderizador apuntando donde estaba - SDL_SetRenderTarget(renderer, temp); + SDL_SetRenderTarget(renderer_, temp); } // Dibuja el objeto void Background::render() { // Fondo - SDL_RenderCopy(renderer, canvas, &srcRect, &dstRect); + SDL_RenderCopy(renderer_, canvas_, &src_rect_, &dst_rect_); // Atenuación - SDL_RenderCopy(renderer, colorTexture, &srcRect, &dstRect); + SDL_RenderCopy(renderer_, color_texture_, &src_rect_, &dst_rect_); } // Vuelve a cargar las texturas void Background::reloadTextures() { - buildingsTexture->reLoad(); - topCloudsTexture->reLoad(); - bottomCloudsTexture->reLoad(); - grassTexture->reLoad(); - gradientsTexture->reLoad(); + buildings_texture_->reLoad(); + top_clouds_texture_->reLoad(); + bottom_clouds_texture_->reLoad(); + grass_texture_->reLoad(); + gradients_texture_->reLoad(); } // Ajusta el valor de la variable void Background::setCloudsSpeed(float value) { - cloudsSpeed = value; + clouds_speed_ = value; } // Ajusta el valor de la variable void Background::setGradientNumber(int value) { - gradientNumber = value % 4; + gradient_number_ = value % 4; } // Ajusta el valor de la variable @@ -220,73 +220,73 @@ void Background::setTransition(float value) { value = std::min(value, 1.0f); value = std::max(value, 0.0f); - transition = value; + transition_ = value; } // Establece la posición del objeto void Background::setPos(SDL_Rect pos) { - this->dstRect = pos; + dst_rect_ = pos; // Si cambian las medidas del destino, hay que cambiar las del origen para evitar deformar la imagen - this->srcRect.x = 0; - this->srcRect.y = rect.h - pos.h; - this->srcRect.w = pos.w; - this->srcRect.h = pos.h; + src_rect_.x = 0; + src_rect_.y = rect_.h - pos.h; + src_rect_.w = pos.w; + src_rect_.h = pos.h; } // Ajusta el valor de la variable void Background::setSrcRect(SDL_Rect value) { - srcRect = value; + src_rect_ = value; } // Ajusta el valor de la variable void Background::setDstRect(SDL_Rect value) { - dstRect = value; + dst_rect_ = value; } -// Establece el color de atenuación -void Background::setColor(color_t color) +// Establece el color_ de atenuación +void Background::setColor(Color color) { - this->color = color; + color_ = color; // Colorea la textura - SDL_Texture *temp = SDL_GetRenderTarget(renderer); - SDL_SetRenderTarget(renderer, colorTexture); + auto temp = SDL_GetRenderTarget(renderer_); + SDL_SetRenderTarget(renderer_, color_texture_); - SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 255); - SDL_RenderClear(renderer); + SDL_SetRenderDrawColor(renderer_, color_.r, color_.g, color_.b, 255); + SDL_RenderClear(renderer_); - SDL_SetRenderTarget(renderer, temp); + SDL_SetRenderTarget(renderer_, temp); } // Establece la transparencia de la atenuación void Background::setAlpha(int alpha) { // Evita que se asignen valores fuera de rango - alpha = std::min(alpha, 255); - alpha = std::max(alpha, 0); + alpha_ = std::min(alpha, 255); + alpha_ = std::max(alpha, 0); // Guarda el valor actual - alphaColorTextTemp = alphaColorText; + alpha_color_text_temp_ = alpha_color_text_; // Establece el nuevo valor - alphaColorText = alpha; + alpha_color_text_ = alpha_; } -// Actualiza el valor de alpha +// Actualiza el valor de alpha_ void Background::updateAlphaColorText() { - if (alphaColorText == alphaColorTextTemp) + if (alpha_color_text_ == alpha_color_text_temp_) { return; } else { - alphaColorText > alphaColorTextTemp ? alphaColorTextTemp++ : alphaColorTextTemp--; - SDL_SetTextureAlphaMod(colorTexture, alphaColorTextTemp); + alpha_color_text_ > alpha_color_text_temp_ ? ++alpha_color_text_temp_ : --alpha_color_text_temp_; + SDL_SetTextureAlphaMod(color_texture_, alpha_color_text_temp_); } } @@ -294,35 +294,35 @@ void Background::updateAlphaColorText() void Background::updateClouds() { // Aplica la velocidad calculada a las nubes - topCloudsSprite_A->setVelX(cloudsSpeed); - topCloudsSprite_B->setVelX(cloudsSpeed); - bottomCloudsSprite_A->setVelX(cloudsSpeed / 2); - bottomCloudsSprite_B->setVelX(cloudsSpeed / 2); + top_clouds_sprite_a_->setVelX(clouds_speed_); + top_clouds_sprite_b_->setVelX(clouds_speed_); + bottom_clouds_sprite_a_->setVelX(clouds_speed_ / 2); + bottom_clouds_sprite_b_->setVelX(clouds_speed_ / 2); // Mueve las nubes - topCloudsSprite_A->move(); - topCloudsSprite_B->move(); - bottomCloudsSprite_A->move(); - bottomCloudsSprite_B->move(); + top_clouds_sprite_a_->move(); + top_clouds_sprite_b_->move(); + bottom_clouds_sprite_a_->move(); + bottom_clouds_sprite_b_->move(); // Calcula el offset de las nubes - if (topCloudsSprite_A->getPosX() < -topCloudsSprite_A->getWidth()) + if (top_clouds_sprite_a_->getPosX() < -top_clouds_sprite_a_->getWidth()) { - topCloudsSprite_A->setPosX(topCloudsSprite_A->getWidth()); + top_clouds_sprite_a_->setPosX(top_clouds_sprite_a_->getWidth()); } - if (topCloudsSprite_B->getPosX() < -topCloudsSprite_B->getWidth()) + if (top_clouds_sprite_b_->getPosX() < -top_clouds_sprite_b_->getWidth()) { - topCloudsSprite_B->setPosX(topCloudsSprite_B->getWidth()); + top_clouds_sprite_b_->setPosX(top_clouds_sprite_b_->getWidth()); } - if (bottomCloudsSprite_A->getPosX() < -bottomCloudsSprite_A->getWidth()) + if (bottom_clouds_sprite_a_->getPosX() < -bottom_clouds_sprite_a_->getWidth()) { - bottomCloudsSprite_A->setPosX(bottomCloudsSprite_A->getWidth()); + bottom_clouds_sprite_a_->setPosX(bottom_clouds_sprite_a_->getWidth()); } - if (bottomCloudsSprite_B->getPosX() < -bottomCloudsSprite_B->getWidth()) + if (bottom_clouds_sprite_b_->getPosX() < -bottom_clouds_sprite_b_->getWidth()) { - bottomCloudsSprite_B->setPosX(bottomCloudsSprite_B->getWidth()); + bottom_clouds_sprite_b_->setPosX(bottom_clouds_sprite_b_->getWidth()); } } \ No newline at end of file diff --git a/source/background.h b/source/background.h index 4b09e65..2658dbd 100644 --- a/source/background.h +++ b/source/background.h @@ -1,8 +1,8 @@ #pragma once -#include // for SDL_Rect -#include // for SDL_Renderer, SDL_Texture -#include "utils.h" // for color_t +#include // for SDL_Rect +#include // for SDL_Renderer, SDL_Texture +#include "utils.h" // for Color #include "moving_sprite.h" #include "sprite.h" #include "texture.h" @@ -38,7 +38,7 @@ - setDstRecr(SDL_Rect value) Rectangulo de destino donde se mostrará el rectángulo antrior. Automaticamente modifica srcRect para coincidor en tamaño con el destino. - - setColor(color_t color) + - setColor(Color color) Establece el color de la textura de superposición - setAlpha(int alpha) @@ -50,42 +50,42 @@ class Background { private: // Objetos y punteros - SDL_Renderer *renderer; // El renderizador de la ventana + SDL_Renderer *renderer_; // El renderizador de la ventana - std::shared_ptr buildingsTexture; // Textura con los edificios de fondo - std::shared_ptr topCloudsTexture; // Textura con las nubes de fondo - std::shared_ptr bottomCloudsTexture; // Textura con las nubes de fondo - std::shared_ptr grassTexture; // Textura con la hierba del suelo - std::shared_ptr gradientsTexture; // Textura con los diferentes colores de fondo del juego + std::shared_ptr buildings_texture_; // Textura con los edificios de fondo + std::shared_ptr top_clouds_texture_; // Textura con las nubes de fondo + std::shared_ptr bottom_clouds_texture_; // Textura con las nubes de fondo + std::shared_ptr grass_texture_; // Textura con la hierba del suelo + std::shared_ptr gradients_texture_; // Textura con los diferentes colores de fondo del juego - std::unique_ptr topCloudsSprite_A; // Sprite para las nubes superiores - std::unique_ptr topCloudsSprite_B; // Sprite para las nubes superiores - std::unique_ptr bottomCloudsSprite_A; // Sprite para las nubes inferiores - std::unique_ptr bottomCloudsSprite_B; // Sprite para las nubes inferiores + std::unique_ptr top_clouds_sprite_a_; // Sprite para las nubes superiores + std::unique_ptr top_clouds_sprite_b_; // Sprite para las nubes superiores + std::unique_ptr bottom_clouds_sprite_a_; // Sprite para las nubes inferiores + std::unique_ptr bottom_clouds_sprite_b_; // Sprite para las nubes inferiores - std::unique_ptr buildingsSprite; // Sprite con los edificios de fondo - std::unique_ptr gradientSprite; // Sprite con los graficos del degradado de color de fondo - std::unique_ptr grassSprite; // Sprite para la hierba + std::unique_ptr buildings_sprite_; // Sprite con los edificios de fondo + std::unique_ptr gradient_sprite_; // Sprite con los graficos del degradado de color de fondo + std::unique_ptr grass_sprite_; // Sprite para la hierba - SDL_Texture *canvas; // Textura para componer el fondo - SDL_Texture *colorTexture; // Textura para atenuar el fondo + SDL_Texture *canvas_; // Textura para componer el fondo + SDL_Texture *color_texture_; // Textura para atenuar el fondo // Variables - SDL_Rect gradientRect[4]; // Vector con las coordenadas de los 4 degradados para el cielo - SDL_Rect topCloudsRect[4]; // Vector con las coordenadas de los 4 nubes de arriba - SDL_Rect bottomCloudsRect[4]; // Vector con las coordenadas de los 4 nubes de abajo - int gradientNumber; // Indica el número de degradado de fondo que se va a dibujar - int alpha; // Transparencia entre los dos degradados - float cloudsSpeed; // Velocidad a la que se desplazan las nubes - float transition; // Nivel de transición del fondo 0..1 - int counter; // Contador interno - SDL_Rect rect; // Tamaño del objeto fondo - SDL_Rect srcRect; // Parte del objeto fondo que se va a dibujará en pantalla - SDL_Rect dstRect; // Posición donde dibujar la parte del objeto fondo que se dibujará en pantalla - int base; // Linea de fondo coincidente con el area inferior de la zona de juego - color_t color; // Color para atenuar el fondo - int alphaColorText; // Alpha para atenuar el fondo - int alphaColorTextTemp; // Valor temporal para hacer la transición de alpha + SDL_Rect gradient_rect_[4]; // Vector con las coordenadas de los 4 degradados para el cielo + SDL_Rect top_clouds_rect_[4]; // Vector con las coordenadas de los 4 nubes de arriba + SDL_Rect bottom_clouds_rect_[4]; // Vector con las coordenadas de los 4 nubes de abajo + int gradient_number_; // Indica el número de degradado de fondo que se va a dibujar + int alpha_; // Transparencia entre los dos degradados + float clouds_speed_; // Velocidad a la que se desplazan las nubes + float transition_; // Nivel de transición del fondo 0..1 + int counter_; // Contador interno + SDL_Rect rect_; // Tamaño del objeto fondo + SDL_Rect src_rect_; // Parte del objeto fondo que se va a dibujará en pantalla + SDL_Rect dst_rect_; // Posición donde dibujar la parte del objeto fondo que se dibujará en pantalla + int base_; // Linea de fondo coincidente con el area inferior de la zona de juego + Color color_; // Color para atenuar el fondo + int alpha_color_text_; // Alpha para atenuar el fondo + int alpha_color_text_temp_; // Valor temporal para hacer la transición de alpha // Dibuja el gradiente de fondo void renderGradient(); @@ -140,7 +140,7 @@ public: void setDstRect(SDL_Rect value); // Establece el color de atenuación - void setColor(color_t color); + void setColor(Color color); // Establece la transparencia de la atenuación void setAlpha(int alpha); diff --git a/source/balloon.cpp b/source/balloon.cpp index 0aebf3e..7997b53 100644 --- a/source/balloon.cpp +++ b/source/balloon.cpp @@ -7,216 +7,215 @@ #include "texture.h" // for Texture // Constructor -Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, std::shared_ptr texture, std::vector *animation) - : kind(kind), speed(speed) +Balloon::Balloon(float x, float y, Uint8 kind, float vel_x, float speed, Uint16 creation_timer, std::shared_ptr texture, std::vector *animation) + : kind_(kind), speed_(speed) { - sprite = std::make_unique(texture, "", animation); - //disable(); + sprite_ = std::make_unique(texture, "", animation); - enabled = true; + enabled_ = true; - switch (kind) + switch (kind_) { case BALLOON_1: // Alto y ancho del objeto - width = BALLOON_WIDTH_1; - height = BALLOON_WIDTH_1; - size = BALLOON_SIZE_1; - power = 1; + width_ = BALLOON_WIDTH_1; + height_ = BALLOON_WIDTH_1; + size_ = BALLOON_SIZE_1; + power_ = 1; // Inicializa los valores de velocidad y gravedad - this->velX = velx; - velY = 0; - maxVelY = 3.0f; - gravity = param.balloon1.grav; - defaultVelY = param.balloon1.vel; + vel_x_ = vel_x; + vel_y_ = 0; + max_vel_y_ = 3.0f; + gravity_ = param.balloon1.grav; + default_vel_y_ = param.balloon1.vel; // Puntos que da el globo al ser destruido - score = BALLOON_SCORE_1; + score_ = BALLOON_SCORE_1; // Amenaza que genera el globo - menace = 1; + menace_ = 1; break; case BALLOON_2: // Alto y ancho del objeto - width = BALLOON_WIDTH_2; - height = BALLOON_WIDTH_2; - size = BALLOON_SIZE_2; - power = 3; + width_ = BALLOON_WIDTH_2; + height_ = BALLOON_WIDTH_2; + size_ = BALLOON_SIZE_2; + power_ = 3; // Inicializa los valores de velocidad y gravedad - this->velX = velx; - velY = 0; - maxVelY = 3.0f; - gravity = param.balloon2.grav; - defaultVelY = param.balloon2.vel; + vel_x_ = vel_x; + vel_y_ = 0; + max_vel_y_ = 3.0f; + gravity_ = param.balloon2.grav; + default_vel_y_ = param.balloon2.vel; // Puntos que da el globo al ser destruido - score = BALLOON_SCORE_2; + score_ = BALLOON_SCORE_2; // Amenaza que genera el globo - menace = 2; + menace_ = 2; break; case BALLOON_3: // Alto y ancho del objeto - width = BALLOON_WIDTH_3; - height = BALLOON_WIDTH_3; - size = BALLOON_SIZE_3; - power = 7; + width_ = BALLOON_WIDTH_3; + height_ = BALLOON_WIDTH_3; + size_ = BALLOON_SIZE_3; + power_ = 7; // Inicializa los valores de velocidad y gravedad - this->velX = velx; - velY = 0; - maxVelY = 3.0f; - gravity = param.balloon3.grav; - defaultVelY = param.balloon3.vel; + vel_x_ = vel_x; + vel_y_ = 0; + max_vel_y_ = 3.0f; + gravity_ = param.balloon3.grav; + default_vel_y_ = param.balloon3.vel; // Puntos que da el globo al ser destruido - score = BALLOON_SCORE_3; + score_ = BALLOON_SCORE_3; // Amenaza que genera el globo - menace = 4; + menace_ = 4; break; case BALLOON_4: // Alto y ancho del objeto - width = BALLOON_WIDTH_4; - height = BALLOON_WIDTH_4; - size = BALLOON_SIZE_4; - power = 15; + width_ = BALLOON_WIDTH_4; + height_ = BALLOON_WIDTH_4; + size_ = BALLOON_SIZE_4; + power_ = 15; // Inicializa los valores de velocidad y gravedad - this->velX = velx; - velY = 0; - maxVelY = 3.0f; - gravity = param.balloon4.grav; - defaultVelY = param.balloon4.vel; + vel_x_ = vel_x; + vel_y_ = 0; + max_vel_y_ = 3.0f; + gravity_ = param.balloon4.grav; + default_vel_y_ = param.balloon4.vel; // Puntos que da el globo al ser destruido - score = BALLOON_SCORE_4; + score_ = BALLOON_SCORE_4; // Amenaza que genera el globo - menace = 8; + menace_ = 8; break; case HEXAGON_1: // Alto y ancho del objeto - width = BALLOON_WIDTH_1; - height = BALLOON_WIDTH_1; - size = BALLOON_SIZE_1; - power = 1; + width_ = BALLOON_WIDTH_1; + height_ = BALLOON_WIDTH_1; + size_ = BALLOON_SIZE_1; + power_ = 1; // Inicializa los valores de velocidad y gravedad - this->velX = velx; - velY = abs(velx) * 2; - maxVelY = abs(velx) * 2; - gravity = 0.00f; - defaultVelY = abs(velx) * 2; + vel_x_ = vel_x; + vel_y_ = abs(vel_x) * 2; + max_vel_y_ = abs(vel_x) * 2; + gravity_ = 0.00f; + default_vel_y_ = abs(vel_x) * 2; // Puntos que da el globo al ser destruido - score = BALLOON_SCORE_1; + score_ = BALLOON_SCORE_1; // Amenaza que genera el globo - menace = 1; + menace_ = 1; break; case HEXAGON_2: // Alto y ancho del objeto - width = BALLOON_WIDTH_2; - height = BALLOON_WIDTH_2; - size = BALLOON_SIZE_2; - power = 3; + width_ = BALLOON_WIDTH_2; + height_ = BALLOON_WIDTH_2; + size_ = BALLOON_SIZE_2; + power_ = 3; // Inicializa los valores de velocidad y gravedad - this->velX = velx; - velY = abs(velx) * 2; - maxVelY = abs(velx) * 2; - gravity = 0.00f; - defaultVelY = abs(velx) * 2; + vel_x_ = vel_x; + vel_y_ = abs(vel_x) * 2; + max_vel_y_ = abs(vel_x) * 2; + gravity_ = 0.00f; + default_vel_y_ = abs(vel_x) * 2; // Puntos que da el globo al ser destruido - score = BALLOON_SCORE_2; + score_ = BALLOON_SCORE_2; // Amenaza que genera el globo - menace = 2; + menace_ = 2; break; case HEXAGON_3: // Alto y ancho del objeto - width = BALLOON_WIDTH_3; - height = BALLOON_WIDTH_3; - size = BALLOON_SIZE_3; - power = 7; + width_ = BALLOON_WIDTH_3; + height_ = BALLOON_WIDTH_3; + size_ = BALLOON_SIZE_3; + power_ = 7; // Inicializa los valores de velocidad y gravedad - this->velX = velx; - velY = abs(velx) * 2; - maxVelY = abs(velx) * 2; - gravity = 0.00f; - defaultVelY = abs(velx) * 2; + vel_x_ = vel_x; + vel_y_ = abs(vel_x) * 2; + max_vel_y_ = abs(vel_x) * 2; + gravity_ = 0.00f; + default_vel_y_ = abs(vel_x) * 2; // Puntos que da el globo al ser destruido - score = BALLOON_SCORE_3; + score_ = BALLOON_SCORE_3; // Amenaza que genera el globo - menace = 4; + menace_ = 4; break; case HEXAGON_4: // Alto y ancho del objeto - width = BALLOON_WIDTH_4; - height = BALLOON_WIDTH_4; - size = BALLOON_SIZE_4; - power = 15; + width_ = BALLOON_WIDTH_4; + height_ = BALLOON_WIDTH_4; + size_ = BALLOON_SIZE_4; + power_ = 15; // Inicializa los valores de velocidad y gravedad - this->velX = velx; - velY = abs(velx) * 2; - maxVelY = abs(velx) * 2; - gravity = 0.00f; - defaultVelY = abs(velx) * 2; + vel_x_ = vel_x; + vel_y_ = abs(vel_x) * 2; + max_vel_y_ = abs(vel_x) * 2; + gravity_ = 0.00f; + default_vel_y_ = abs(vel_x) * 2; // Puntos que da el globo al ser destruido - score = BALLOON_SCORE_4; + score_ = BALLOON_SCORE_4; // Amenaza que genera el globo - menace = 8; + menace_ = 8; break; case POWER_BALL: // Alto y ancho del objeto - width = BALLOON_WIDTH_4; - height = BALLOON_WIDTH_4; - size = 4; - power = 0; + width_ = BALLOON_WIDTH_4; + height_ = BALLOON_WIDTH_4; + size_ = 4; + power_ = 0; // Inicializa los valores de velocidad y gravedad - this->velX = velx; - velY = 0; - maxVelY = 3.0f; - gravity = param.balloon4.grav; - defaultVelY = param.balloon4.vel; + vel_x_ = vel_x; + vel_y_ = 0; + max_vel_y_ = 3.0f; + gravity_ = param.balloon4.grav; + default_vel_y_ = param.balloon4.vel; // Puntos que da el globo al ser destruido - score = 0; + score_ = 0; // Amenaza que genera el globo - menace = 0; + menace_ = 0; - // Añade rotación al sprite - sprite->setRotate(false); - sprite->setRotateSpeed(0); - velX > 0.0f ? sprite->setRotateAmount(2.0) : sprite->setRotateAmount(-2.0); + // Añade rotación al sprite_ + sprite_->setRotate(false); + sprite_->setRotateSpeed(0); + vel_x_ > 0.0f ? sprite_->setRotateAmount(2.0) : sprite_->setRotateAmount(-2.0); break; @@ -225,69 +224,69 @@ Balloon::Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 c } // Posición inicial - posX = x; - posY = y; + pos_x_ = x; + pos_y_ = y; // Valores para el efecto de rebote - bouncing.enabled = false; - bouncing.counter = 0; - bouncing.speed = 2; - bouncing.zoomW = 1.0f; - bouncing.zoomH = 1.0f; - bouncing.despX = 0.0f; - bouncing.despY = 0.0f; - bouncing.w = {1.10f, 1.05f, 1.00f, 0.95f, 0.90f, 0.95f, 1.00f, 1.02f, 1.05f, 1.02f}; - bouncing.h = {0.90f, 0.95f, 1.00f, 1.05f, 1.10f, 1.05f, 1.00f, 0.98f, 0.95f, 0.98f}; + bouncing_.enabled = false; + bouncing_.counter = 0; + bouncing_.speed = 2; + bouncing_.zoomW = 1.0f; + bouncing_.zoomH = 1.0f; + bouncing_.despX = 0.0f; + bouncing_.despY = 0.0f; + bouncing_.w = {1.10f, 1.05f, 1.00f, 0.95f, 0.90f, 0.95f, 1.00f, 1.02f, 1.05f, 1.02f}; + bouncing_.h = {0.90f, 0.95f, 1.00f, 1.05f, 1.10f, 1.05f, 1.00f, 0.98f, 0.95f, 0.98f}; - // Alto y ancho del sprite - sprite->setWidth(width); - sprite->setHeight(height); + // Alto y ancho del sprite_ + sprite_->setWidth(width_); + sprite_->setHeight(height_); - // Posición X,Y del sprite - sprite->setPosX((int)posX); - sprite->setPosY((int)posY); + // Posición X,Y del sprite_ + sprite_->setPosX((int)pos_x_); + sprite_->setPosY((int)pos_y_); // Tamaño del circulo de colisión - collider.r = width / 2; + collider_.r = width_ / 2; // Alinea el circulo de colisión con el objeto updateColliders(); // Inicializa variables - stopped = true; - stoppedCounter = 0; - blinking = false; - visible = true; - invulnerable = true; - beingCreated = true; - creationCounter = creationtimer; - creationCounterIni = creationtimer; + stopped_ = true; + stopped_counter_ = 0; + blinking_ = false; + visible_ = true; + invulnerable_ = true; + being_created_ = true; + creation_counter_ = creation_timer; + creation_counter_ini_ = creation_timer; // Actualiza valores - beingCreated = creationCounter == 0 ? false : true; - invulnerable = beingCreated == false ? false : true; + being_created_ = creation_counter_ == 0 ? false : true; + invulnerable_ = being_created_ == false ? false : true; - counter = 0; - travelY = 1.0f; + counter_ = 0; + travel_y_ = 1.0f; } // Centra el globo en la posición X void Balloon::allignTo(int x) { - posX = float(x - (width / 2)); + pos_x_ = float(x - (width_ / 2)); - if (posX < param.game.playArea.rect.x) + if (pos_x_ < param.game.play_area.rect.x) { - posX = param.game.playArea.rect.x + 1; + pos_x_ = param.game.play_area.rect.x + 1; } - else if ((posX + width) > param.game.playArea.rect.w) + else if ((pos_x_ + width_) > param.game.play_area.rect.w) { - posX = float(param.game.playArea.rect.w - width - 1); + pos_x_ = float(param.game.play_area.rect.w - width_ - 1); } - // Posición X,Y del sprite - sprite->setPosX(getPosX()); - sprite->setPosY(getPosY()); + // Posición X,Y del sprite_ + sprite_->setPosX(getPosX()); + sprite_->setPosY(getPosY()); // Alinea el circulo de colisión con el objeto updateColliders(); @@ -296,35 +295,35 @@ void Balloon::allignTo(int x) // Pinta el globo en la pantalla void Balloon::render() { - if (visible && enabled) + if (visible_ && enabled_) { - if (bouncing.enabled) + if (bouncing_.enabled) { - if (kind != POWER_BALL) + if (kind_ != POWER_BALL) { // Aplica desplazamiento para el zoom - sprite->setPosX(getPosX() + bouncing.despX); - sprite->setPosY(getPosY() + bouncing.despY); - sprite->render(); - sprite->setPosX(getPosX() - bouncing.despX); - sprite->setPosY(getPosY() - bouncing.despY); + sprite_->setPosX(getPosX() + bouncing_.despX); + sprite_->setPosY(getPosY() + bouncing_.despY); + sprite_->render(); + sprite_->setPosX(getPosX() - bouncing_.despX); + sprite_->setPosY(getPosY() - bouncing_.despY); } } else if (isBeingCreated()) { // Aplica alpha blending - sprite->getTexture()->setAlpha(255 - (int)((float)creationCounter * (255.0f / (float)creationCounterIni))); - sprite->render(); - sprite->getTexture()->setAlpha(255); + sprite_->getTexture()->setAlpha(255 - (int)((float)creation_counter_ * (255.0f / (float)creation_counter_ini_))); + sprite_->render(); + sprite_->getTexture()->setAlpha(255); } else { - sprite->render(); + sprite_->render(); } - if (kind == POWER_BALL && !isBeingCreated()) + if (kind_ == POWER_BALL && !isBeingCreated()) { - auto sp = std::make_unique(sprite->getRect(), sprite->getTexture()); + auto sp = std::make_unique(sprite_->getRect(), sprite_->getTexture()); sp->setSpriteClip(BALLOON_WIDTH_4, 0, BALLOON_WIDTH_4, BALLOON_WIDTH_4); sp->render(); } @@ -338,57 +337,57 @@ void Balloon::move() if (!isStopped()) { // Lo mueve a izquierda o derecha - posX += (velX * speed); + pos_x_ += (vel_x_ * speed_); // Si queda fuera de pantalla, corregimos su posición y cambiamos su sentido - if ((posX < param.game.playArea.rect.x) || (posX + width > param.game.playArea.rect.w)) + if ((pos_x_ < param.game.play_area.rect.x) || (pos_x_ + width_ > param.game.play_area.rect.w)) { // Corrige posición - posX -= (velX * speed); + pos_x_ -= (vel_x_ * speed_); // Invierte sentido - velX = -velX; + vel_x_ = -vel_x_; // Invierte la rotación - sprite->switchRotate(); + sprite_->switchRotate(); // Activa el efecto de rebote - if (kind != POWER_BALL) + if (kind_ != POWER_BALL) { bounceStart(); } } // Mueve el globo hacia arriba o hacia abajo - posY += (velY * speed); + pos_y_ += (vel_y_ * speed_); // Si se sale por arriba - if (posY < param.game.playArea.rect.y) + if (pos_y_ < param.game.play_area.rect.y) { // Corrige - posY = param.game.playArea.rect.y; + pos_y_ = param.game.play_area.rect.y; // Invierte sentido - velY = -velY; + vel_y_ = -vel_y_; // Activa el efecto de rebote - if (kind != POWER_BALL) + if (kind_ != POWER_BALL) { bounceStart(); } } // Si el globo se sale por la parte inferior - if (posY + height > param.game.playArea.rect.h) + if (pos_y_ + height_ > param.game.play_area.rect.h) { // Corrige - posY = param.game.playArea.rect.h - height; + pos_y_ = param.game.play_area.rect.h - height_; // Invierte colocando una velocidad por defecto - velY = -defaultVelY; + vel_y_ = -default_vel_y_; // Activa el efecto de rebote - if (kind != POWER_BALL) + if (kind_ != POWER_BALL) { bounceStart(); } @@ -404,61 +403,61 @@ void Balloon::move() */ // Incrementa la variable que calcula la distancia acumulada en Y - travelY += speed; + travel_y_ += speed_; // Si la distancia acumulada en Y es igual a la velocidad, se aplica la gravedad - if (travelY >= 1.0f) + if (travel_y_ >= 1.0f) { // Quita el excedente - travelY -= 1.0f; + travel_y_ -= 1.0f; // Aplica la gravedad al objeto sin pasarse de una velocidad máxima - velY += gravity; + vel_y_ += gravity_; // Al parecer esta asignación se quedó sin hacer y ahora el juego no funciona // correctamente si se aplica, así que se deja sin efecto - // velY = std::min(velY, maxVelY); + // vel_y_ = std::min(vel_y_, max_vel_y_); } - // Actualiza la posición del sprite - sprite->setPosX(getPosX()); - sprite->setPosY(getPosY()); + // Actualiza la posición del sprite_ + sprite_->setPosX(getPosX()); + sprite_->setPosY(getPosY()); } } // Deshabilita el globo y pone a cero todos los valores void Balloon::disable() { - beingCreated = false; - blinking = false; - collider.r = 0; - collider.x = 0; - collider.y = 0; - counter = 0; - creationCounter = 0; - creationCounterIni = 0; - defaultVelY = 0.0f; - enabled = false; - gravity = 0.0f; - height = 0; - invulnerable = false; - kind = 0; - maxVelY = 0.0f; - menace = 0; - posX = 0.0f; - posY = 0.0f; - power = 0; - score = 0; - size = 0; - speed = 0; - stopped = false; - stoppedCounter = 0; - travelY = 0; - velX = 0.0f; - velY = 0.0f; - visible = false; - width = 0; - sprite->clear(); + being_created_ = false; + blinking_ = false; + collider_.r = 0; + collider_.x = 0; + collider_.y = 0; + counter_ = 0; + creation_counter_ = 0; + creation_counter_ini_ = 0; + default_vel_y_ = 0.0f; + enabled_ = false; + gravity_ = 0.0f; + height_ = 0; + invulnerable_ = false; + kind_ = 0; + max_vel_y_ = 0.0f; + menace_ = 0; + pos_x_ = 0.0f; + pos_y_ = 0.0f; + power_ = 0; + score_ = 0; + size_ = 0; + speed_ = 0; + stopped_ = false; + stopped_counter_ = 0; + travel_y_ = 0; + vel_x_ = 0.0f; + vel_y_ = 0.0f; + visible_ = false; + width_ = 0; + sprite_->clear(); } // Explosiona el globo @@ -470,15 +469,15 @@ void Balloon::pop() // Actualiza al globo a su posicion, animación y controla los contadores void Balloon::update() { - if (enabled) + if (enabled_) { - sprite->MovingSprite::update(); + sprite_->MovingSprite::update(); move(); updateAnimation(); updateColliders(); updateState(); updateBounce(); - counter++; + counter_++; } } @@ -493,31 +492,31 @@ void Balloon::updateState() setInvulnerable(true); // Todavia tiene tiempo en el contador - if (creationCounter > 0) + if (creation_counter_ > 0) { // Desplaza lentamente el globo hacia abajo y hacia un lado - if (creationCounter % 10 == 0) + if (creation_counter_ % 10 == 0) { - posY++; - posX += velX; + pos_y_++; + pos_x_ += vel_x_; // Comprueba no se salga por los laterales - if ((posX < param.game.playArea.rect.x) || (posX > (param.game.playArea.rect.w - width))) + if ((pos_x_ < param.game.play_area.rect.x) || (pos_x_ > (param.game.play_area.rect.w - width_))) { // Corrige y cambia el sentido de la velocidad - posX -= velX; - velX = -velX; + pos_x_ -= vel_x_; + vel_x_ = -vel_x_; } - // Actualiza la posición del sprite - sprite->setPosX(getPosX()); - sprite->setPosY(getPosY()); + // Actualiza la posición del sprite_ + sprite_->setPosX(getPosX()); + sprite_->setPosY(getPosY()); // Actualiza la posición del circulo de colisión updateColliders(); } - creationCounter--; + creation_counter_--; } // El contador ha llegado a cero else @@ -526,9 +525,9 @@ void Balloon::updateState() setStop(false); setVisible(true); setInvulnerable(false); - if (kind == POWER_BALL) + if (kind_ == POWER_BALL) { - sprite->setRotate(true); + sprite_->setRotate(true); } } } @@ -536,15 +535,15 @@ void Balloon::updateState() else if (isStopped()) { // Si es una powerball deja de rodar - if (kind == POWER_BALL) + if (kind_ == POWER_BALL) { - sprite->setRotate(false); + sprite_->setRotate(false); } // Reduce el contador - if (stoppedCounter > 0) + if (stopped_counter_ > 0) { - stoppedCounter--; + stopped_counter_--; } // Si el contador ha llegado a cero else @@ -552,9 +551,9 @@ void Balloon::updateState() setStop(false); // Si es una powerball vuelve a rodar - if (kind == POWER_BALL) + if (kind_ == POWER_BALL) { - sprite->setRotate(true); + sprite_->setRotate(true); } } } @@ -563,102 +562,102 @@ void Balloon::updateState() // Establece la animación correspondiente al estado void Balloon::updateAnimation() { - std::string creatingAnimation = "blue"; - std::string normalAnimation = "orange"; + std::string creating_animation = "blue"; + std::string normal_animation = "orange"; - if (kind == POWER_BALL) + if (kind_ == POWER_BALL) { - creatingAnimation = "powerball"; - normalAnimation = "powerball"; + creating_animation = "powerball"; + normal_animation = "powerball"; } else if (getClass() == HEXAGON_CLASS) { - creatingAnimation = "red"; - normalAnimation = "green"; + creating_animation = "red"; + normal_animation = "green"; } // Establece el frame de animación if (isBeingCreated()) { - sprite->setCurrentAnimation(creatingAnimation); + sprite_->setCurrentAnimation(creating_animation); } else { - sprite->setCurrentAnimation(normalAnimation); + sprite_->setCurrentAnimation(normal_animation); } - sprite->animate(); + sprite_->animate(); } // Comprueba si el globo está habilitado bool Balloon::isEnabled() const { - return enabled; + return enabled_; } // Obtiene del valor de la variable float Balloon::getPosX() const { - return posX; + return pos_x_; } // Obtiene del valor de la variable float Balloon::getPosY() const { - return posY; + return pos_y_; } // Obtiene del valor de la variable float Balloon::getVelY() const { - return velY; + return vel_y_; } // Obtiene del valor de la variable int Balloon::getWidth() const { - return width; + return width_; } // Obtiene del valor de la variable int Balloon::getHeight() const { - return height; + return height_; } // Establece el valor de la variable -void Balloon::setVelY(float velY) +void Balloon::setVelY(float vel_y_) { - this->velY = velY; + this->vel_y_ = vel_y_; } // Establece el valor de la variable -void Balloon::setSpeed(float speed) +void Balloon::setSpeed(float speed_) { - this->speed = speed; + this->speed_ = speed_; } // Obtiene del valor de la variable int Balloon::getKind() const { - return kind; + return kind_; } // Obtiene del valor de la variable Uint8 Balloon::getSize() const { - return size; + return size_; } // Obtiene la clase a la que pertenece el globo Uint8 Balloon::getClass() const { - if ((kind >= BALLOON_1) && (kind <= BALLOON_4)) + if ((kind_ >= BALLOON_1) && (kind_ <= BALLOON_4)) { return BALLOON_CLASS; } - else if ((kind >= HEXAGON_1) && (kind <= HEXAGON_4)) + else if ((kind_ >= HEXAGON_1) && (kind_ <= HEXAGON_4)) { return HEXAGON_CLASS; } @@ -669,148 +668,141 @@ Uint8 Balloon::getClass() const // Establece el valor de la variable void Balloon::setStop(bool state) { - stopped = state; + stopped_ = state; } // Obtiene del valor de la variable bool Balloon::isStopped() const { - return stopped; + return stopped_; } // Establece el valor de la variable void Balloon::setBlink(bool value) { - blinking = value; + blinking_ = value; } // Obtiene del valor de la variable bool Balloon::isBlinking() const { - return blinking; + return blinking_; } // Establece el valor de la variable void Balloon::setVisible(bool value) { - visible = value; + visible_ = value; } // Obtiene del valor de la variable bool Balloon::isVisible() const { - return visible; + return visible_; } // Establece el valor de la variable void Balloon::setInvulnerable(bool value) { - invulnerable = value; + invulnerable_ = value; } // Obtiene del valor de la variable bool Balloon::isInvulnerable() const { - return invulnerable; + return invulnerable_; } // Establece el valor de la variable void Balloon::setBeingCreated(bool value) { - beingCreated = value; + being_created_ = value; } // Obtiene del valor de la variable bool Balloon::isBeingCreated() const { - return beingCreated; + return being_created_; } // Establece el valor de la variable void Balloon::setStoppedTimer(Uint16 time) { - stoppedCounter = time; + stopped_counter_ = time; } // Obtiene del valor de la variable Uint16 Balloon::getStoppedTimer() const { - return stoppedCounter; + return stopped_counter_; } // Obtiene del valor de la variable Uint16 Balloon::getScore() const { - return score; + return score_; } // Obtiene el circulo de colisión -circle_t &Balloon::getCollider() +Circle &Balloon::getCollider() { - return collider; + return collider_; } // Alinea el circulo de colisión con la posición del objeto globo void Balloon::updateColliders() { - collider.x = Uint16(posX + collider.r); - collider.y = posY + collider.r; + collider_.x = Uint16(pos_x_ + collider_.r); + collider_.y = pos_y_ + collider_.r; } // Obtiene le valor de la variable Uint8 Balloon::getMenace() const { - if (isEnabled()) - { - return menace; - } - else - { - return 0; - } + return isEnabled() ? menace_ : 0; } // Obtiene le valor de la variable Uint8 Balloon::getPower() const { - return power; + return power_; } void Balloon::bounceStart() { - bouncing.enabled = true; - bouncing.zoomW = 1; - bouncing.zoomH = 1; - sprite->setZoomW(bouncing.zoomW); - sprite->setZoomH(bouncing.zoomH); - bouncing.despX = 0; - bouncing.despY = 0; + bouncing_.enabled = true; + bouncing_.zoomW = 1; + bouncing_.zoomH = 1; + sprite_->setZoomW(bouncing_.zoomW); + sprite_->setZoomH(bouncing_.zoomH); + bouncing_.despX = 0; + bouncing_.despY = 0; } void Balloon::bounceStop() { - bouncing.enabled = false; - bouncing.counter = 0; - bouncing.zoomW = 1.0f; - bouncing.zoomH = 1.0f; - sprite->setZoomW(bouncing.zoomW); - sprite->setZoomH(bouncing.zoomH); - bouncing.despX = 0.0f; - bouncing.despY = 0.0f; + bouncing_.enabled = false; + bouncing_.counter = 0; + bouncing_.zoomW = 1.0f; + bouncing_.zoomH = 1.0f; + sprite_->setZoomW(bouncing_.zoomW); + sprite_->setZoomH(bouncing_.zoomH); + bouncing_.despX = 0.0f; + bouncing_.despY = 0.0f; } void Balloon::updateBounce() { - if (bouncing.enabled) + if (bouncing_.enabled) { - bouncing.zoomW = bouncing.w[bouncing.counter / bouncing.speed]; - bouncing.zoomH = bouncing.h[bouncing.counter / bouncing.speed]; - sprite->setZoomW(bouncing.zoomW); - sprite->setZoomH(bouncing.zoomH); - bouncing.despX = (sprite->getSpriteClip().w - (sprite->getSpriteClip().w * bouncing.zoomW)); - bouncing.despY = (sprite->getSpriteClip().h - (sprite->getSpriteClip().h * bouncing.zoomH)); - bouncing.counter++; - if ((bouncing.counter / bouncing.speed) > (MAX_BOUNCE - 1)) + bouncing_.zoomW = bouncing_.w[bouncing_.counter / bouncing_.speed]; + bouncing_.zoomH = bouncing_.h[bouncing_.counter / bouncing_.speed]; + sprite_->setZoomW(bouncing_.zoomW); + sprite_->setZoomH(bouncing_.zoomH); + bouncing_.despX = (sprite_->getSpriteClip().w - (sprite_->getSpriteClip().w * bouncing_.zoomW)); + bouncing_.despY = (sprite_->getSpriteClip().h - (sprite_->getSpriteClip().h * bouncing_.zoomH)); + ++bouncing_.counter; + if ((bouncing_.counter / bouncing_.speed) > (MAX_BOUNCE - 1)) { bounceStop(); } diff --git a/source/balloon.h b/source/balloon.h index 315e8ca..9fc7389 100644 --- a/source/balloon.h +++ b/source/balloon.h @@ -1,71 +1,71 @@ #pragma once -#include // for Uint8, Uint16, Uint32 -#include // for string -#include // for vector +#include // for Uint8, Uint16, Uint32 +#include // for string +#include // for vector #include -#include "utils.h" // for circle_t +#include "utils.h" // for Circle #include "animated_sprite.h" #include "texture.h" // Cantidad de elementos del vector con los valores de la deformación del globo al rebotar -constexpr int MAX_BOUNCE = 10; +constexpr int MAX_BOUNCE = 10; // Tipos de globo -constexpr int BALLOON_1 = 1; -constexpr int BALLOON_2 = 2; -constexpr int BALLOON_3 = 3; -constexpr int BALLOON_4 = 4; -constexpr int HEXAGON_1 = 5; -constexpr int HEXAGON_2 = 6; -constexpr int HEXAGON_3 = 7; -constexpr int HEXAGON_4 = 8; -constexpr int POWER_BALL = 9; +constexpr int BALLOON_1 = 1; +constexpr int BALLOON_2 = 2; +constexpr int BALLOON_3 = 3; +constexpr int BALLOON_4 = 4; +constexpr int HEXAGON_1 = 5; +constexpr int HEXAGON_2 = 6; +constexpr int HEXAGON_3 = 7; +constexpr int HEXAGON_4 = 8; +constexpr int POWER_BALL = 9; // Puntos de globo -constexpr int BALLOON_SCORE_1 = 50; -constexpr int BALLOON_SCORE_2 = 100; -constexpr int BALLOON_SCORE_3 = 200; -constexpr int BALLOON_SCORE_4 = 400; +constexpr int BALLOON_SCORE_1 = 50; +constexpr int BALLOON_SCORE_2 = 100; +constexpr int BALLOON_SCORE_3 = 200; +constexpr int BALLOON_SCORE_4 = 400; // Tamaños de globo -constexpr int BALLOON_SIZE_1 = 1; -constexpr int BALLOON_SIZE_2 = 2; -constexpr int BALLOON_SIZE_3 = 3; -constexpr int BALLOON_SIZE_4 = 4; +constexpr int BALLOON_SIZE_1 = 1; +constexpr int BALLOON_SIZE_2 = 2; +constexpr int BALLOON_SIZE_3 = 3; +constexpr int BALLOON_SIZE_4 = 4; // Clases de globo -constexpr int BALLOON_CLASS = 0; -constexpr int HEXAGON_CLASS = 1; +constexpr int BALLOON_CLASS = 0; +constexpr int HEXAGON_CLASS = 1; // Velocidad del globo -constexpr float BALLOON_VELX_POSITIVE = 0.7f; -constexpr float BALLOON_VELX_NEGATIVE = -0.7f; +constexpr float BALLOON_VELX_POSITIVE = 0.7f; +constexpr float BALLOON_VELX_NEGATIVE = -0.7f; // Indice para las animaciones de los globos -constexpr int BALLOON_MOVING_ANIMATION = 0; -constexpr int BALLOON_POP_ANIMATION = 1; -constexpr int BALLOON_BORN_ANIMATION = 2; +constexpr int BALLOON_MOVING_ANIMATION = 0; +constexpr int BALLOON_POP_ANIMATION = 1; +constexpr int BALLOON_BORN_ANIMATION = 2; // Cantidad posible de globos -constexpr int MAX_BALLOONS = 100; +constexpr int MAX_BALLOONS = 100; // Velocidades a las que se mueven los globos -constexpr float BALLOON_SPEED_1 = 0.60f; -constexpr float BALLOON_SPEED_2 = 0.70f; -constexpr float BALLOON_SPEED_3 = 0.80f; -constexpr float BALLOON_SPEED_4 = 0.90f; -constexpr float BALLOON_SPEED_5 = 1.00f; +constexpr float BALLOON_SPEED_1 = 0.60f; +constexpr float BALLOON_SPEED_2 = 0.70f; +constexpr float BALLOON_SPEED_3 = 0.80f; +constexpr float BALLOON_SPEED_4 = 0.90f; +constexpr float BALLOON_SPEED_5 = 1.00f; // Tamaño de los globos -constexpr int BALLOON_WIDTH_1 = 10; -constexpr int BALLOON_WIDTH_2 = 16; -constexpr int BALLOON_WIDTH_3 = 26; -constexpr int BALLOON_WIDTH_4 = 46; +constexpr int BALLOON_WIDTH_1 = 10; +constexpr int BALLOON_WIDTH_2 = 16; +constexpr int BALLOON_WIDTH_3 = 26; +constexpr int BALLOON_WIDTH_4 = 46; // PowerBall -constexpr int POWERBALL_SCREENPOWER_MINIMUM = 10; -constexpr int POWERBALL_COUNTER = 8; +constexpr int POWERBALL_SCREENPOWER_MINIMUM = 10; +constexpr int POWERBALL_COUNTER = 8; // Clase Balloon class Balloon @@ -86,37 +86,37 @@ private: }; // Objetos y punteros - std::unique_ptr sprite; // Sprite del objeto globo + std::unique_ptr sprite_; // Sprite del objeto globo // Variables - float posX; // Posición en el eje X - float posY; // Posición en el eje Y - Uint8 width; // Ancho - Uint8 height; // Alto - float velX; // Velocidad en el eje X. Cantidad de pixeles a desplazarse - float velY; // Velocidad en el eje Y. Cantidad de pixeles a desplazarse - float gravity; // Aceleración en el eje Y. Modifica la velocidad - float defaultVelY; // Velocidad inicial que tienen al rebotar contra el suelo - float maxVelY; // Máxima velocidad que puede alcanzar el objeto en el eje Y - bool beingCreated; // Indica si el globo se está creando - bool blinking; // Indica si el globo está intermitente - bool enabled; // Indica si el globo esta activo - bool invulnerable; // Indica si el globo es invulnerable - bool stopped; // Indica si el globo está parado - bool visible; // Indica si el globo es visible - circle_t collider; // Circulo de colisión del objeto - Uint16 creationCounter; // Temporizador para controlar el estado "creandose" - Uint16 creationCounterIni; // Valor inicial para el temporizador para controlar el estado "creandose" - Uint16 score; // Puntos que da el globo al ser destruido - Uint16 stoppedCounter; // Contador para controlar el estado "parado" - Uint8 kind; // Tipo de globo - Uint8 menace; // Cantidad de amenaza que genera el globo - Uint32 counter; // Contador interno - float travelY; // Distancia que ha de recorrer el globo en el eje Y antes de que se le aplique la gravedad - float speed; // Velocidad a la que se mueven los globos - Uint8 size; // Tamaño del globo - Uint8 power; // Cantidad de poder que alberga el globo - Bouncing bouncing; // Contiene las variables para el efecto de rebote + float pos_x_; // Posición en el eje X + float pos_y_; // Posición en el eje Y + Uint8 width_; // Ancho + Uint8 height_; // Alto + float vel_x_; // Velocidad en el eje X. Cantidad de pixeles a desplazarse + float vel_y_; // Velocidad en el eje Y. Cantidad de pixeles a desplazarse + float gravity_; // Aceleración en el eje Y. Modifica la velocidad + float default_vel_y_; // Velocidad inicial que tienen al rebotar contra el suelo + float max_vel_y_; // Máxima velocidad que puede alcanzar el objeto en el eje Y + bool being_created_; // Indica si el globo se está creando + bool blinking_; // Indica si el globo está intermitente + bool enabled_; // Indica si el globo esta activo + bool invulnerable_; // Indica si el globo es invulnerable + bool stopped_; // Indica si el globo está parado + bool visible_; // Indica si el globo es visible + Circle collider_; // Circulo de colisión del objeto + Uint16 creation_counter_; // Temporizador para controlar el estado "creandose" + Uint16 creation_counter_ini_; // Valor inicial para el temporizador para controlar el estado "creandose" + Uint16 score_; // Puntos que da el globo al ser destruido + Uint16 stopped_counter_; // Contador para controlar el estado "parado" + Uint8 kind_; // Tipo de globo + Uint8 menace_; // Cantidad de amenaza que genera el globo + Uint32 counter_; // Contador interno + float travel_y_; // Distancia que ha de recorrer el globo en el eje Y antes de que se le aplique la gravedad + float speed_; // Velocidad a la que se mueven los globos + Uint8 size_; // Tamaño del globo + Uint8 power_; // Cantidad de poder que alberga el globo + Bouncing bouncing_; // Contiene las variables para el efecto de rebote // Alinea el circulo de colisión con la posición del objeto globo void updateColliders(); @@ -141,7 +141,7 @@ private: public: // Constructor - Balloon(float x, float y, Uint8 kind, float velx, float speed, Uint16 creationtimer, std::shared_ptr texture, std::vector *animation); + Balloon(float x, float y, Uint8 kind, float vel_x, float speed, Uint16 creation_timer, std::shared_ptr texture, std::vector *animation); // Destructor ~Balloon() = default; @@ -183,7 +183,7 @@ public: int getHeight() const; // Establece el valor de la variable - void setVelY(float velY); + void setVelY(float vel_y); // Establece el valor de la variable void setSpeed(float speed); @@ -234,7 +234,7 @@ public: Uint16 getScore() const; // Obtiene el circulo de colisión - circle_t &getCollider(); + Circle &getCollider(); // Obtiene le valor de la variable Uint8 getMenace() const; diff --git a/source/bullet.cpp b/source/bullet.cpp index 5f745d4..41160e7 100644 --- a/source/bullet.cpp +++ b/source/bullet.cpp @@ -11,46 +11,47 @@ constexpr int BULLET_VELX_LEFT = -2; constexpr int BULLET_VELX_RIGHT = 2; // Constructor -Bullet::Bullet(int x, int y, BulletType kind, bool poweredUp, int owner, SDL_Rect *playArea, std::shared_ptr texture) - : posX(x), posY(y), width(BULLET_WIDTH), height(BULLET_HEIGHT), velX(0), velY(BULLET_VELY), - kind(kind), owner(owner), playArea(playArea) +Bullet::Bullet(int x, int y, BulletType kind_, bool poweredUp, int owner, SDL_Rect *play_area, std::shared_ptr texture) + : pos_x_(x), pos_y_(y), width_(BULLET_WIDTH), height_(BULLET_HEIGHT), vel_x_(0), vel_y_(BULLET_VELY), + kind_(kind_), owner_(owner), play_area_(play_area) { - velX = (kind == BulletType::LEFT) ? BULLET_VELX_LEFT : (kind == BulletType::RIGHT) ? BULLET_VELX_RIGHT : 0; + vel_x_ = (kind_ == BulletType::LEFT) ? BULLET_VELX_LEFT : (kind_ == BulletType::RIGHT) ? BULLET_VELX_RIGHT + : 0; - auto spriteOffset = poweredUp ? 3 : 0; - auto kindIndex = static_cast(kind); - sprite = std::make_unique(SDL_Rect{x, y, BULLET_WIDTH, BULLET_HEIGHT}, texture); - sprite->setSpriteClip((kindIndex + spriteOffset) * width, 0, sprite->getWidth(), sprite->getHeight()); + auto sprite_offset = poweredUp ? 3 : 0; + auto kind_index = static_cast(kind_); + sprite_ = std::make_unique(SDL_Rect{x, y, BULLET_WIDTH, BULLET_HEIGHT}, texture); + sprite_->setSpriteClip((kind_index + sprite_offset) * width_, 0, sprite_->getWidth(), sprite_->getHeight()); - collider.r = width / 2; + collider_.r = width_ / 2; shiftColliders(); } -// Implementación de render (llama al render del sprite) +// Implementación de render (llama al render del sprite_) void Bullet::render() { - sprite->render(); + sprite_->render(); } // Implementación del movimiento usando BulletMoveStatus BulletMoveStatus Bullet::move() { - posX += velX; - if (posX < param.game.playArea.rect.x - width || posX > playArea->w) + pos_x_ += vel_x_; + if (pos_x_ < param.game.play_area.rect.x - width_ || pos_x_ > play_area_->w) { disable(); return BulletMoveStatus::OUT; } - posY += velY; - if (posY < param.game.playArea.rect.y - height) + pos_y_ += vel_y_; + if (pos_y_ < param.game.play_area.rect.y - height_) { disable(); return BulletMoveStatus::OUT; } - sprite->setPosX(posX); - sprite->setPosY(posY); + sprite_->setPosX(pos_x_); + sprite_->setPosY(pos_y_); shiftColliders(); return BulletMoveStatus::OK; @@ -58,56 +59,56 @@ BulletMoveStatus Bullet::move() bool Bullet::isEnabled() const { - return kind != BulletType::NULL_TYPE; + return kind_ != BulletType::NULL_TYPE; } void Bullet::disable() { - kind = BulletType::NULL_TYPE; + kind_ = BulletType::NULL_TYPE; } int Bullet::getPosX() const { - return posX; + return pos_x_; } int Bullet::getPosY() const { - return posY; + return pos_y_; } void Bullet::setPosX(int x) { - posX = x; + pos_x_ = x; } void Bullet::setPosY(int y) { - posY = y; + pos_y_ = y; } int Bullet::getVelY() const { - return velY; + return vel_y_; } BulletType Bullet::getKind() const { - return kind; + return kind_; } int Bullet::getOwner() const { - return owner; + return owner_; } -circle_t &Bullet::getCollider() +Circle &Bullet::getCollider() { - return collider; + return collider_; } void Bullet::shiftColliders() { - collider.x = posX + collider.r; - collider.y = posY + collider.r; + collider_.x = pos_x_ + collider_.r; + collider_.y = pos_y_ + collider_.r; } diff --git a/source/bullet.h b/source/bullet.h index 2f5d555..be13532 100644 --- a/source/bullet.h +++ b/source/bullet.h @@ -4,8 +4,8 @@ #include // for Uint8 #include // for unique_ptr #include "sprite.h" // for Sprite -#include "utils.h" // for circle_t -#include "texture.h" // lines 9-9 +#include "utils.h" // for Circle +#include "texture.h" // lines 9-9 // Enumeración para los diferentes tipos de balas enum class BulletType @@ -27,36 +27,50 @@ enum class BulletMoveStatus : Uint8 class Bullet { private: - int posX; // Posición en el eje X - int posY; // Posición en el eje Y - Uint8 width; // Ancho del objeto - Uint8 height; // Alto del objeto - int velX; // Velocidad en el eje X - int velY; // Velocidad en el eje Y - BulletType kind; // Tipo de objeto - int owner; // Identificador del dueño del objeto - circle_t collider; // Círculo de colisión del objeto - SDL_Rect *playArea; // Rectángulo con la zona de juego - std::unique_ptr sprite; // Sprite con los gráficos y métodos de pintado + int pos_x_; // Posición en el eje X + int pos_y_; // Posición en el eje Y + Uint8 width_; // Ancho del objeto + Uint8 height_; // Alto del objeto + int vel_x_; // Velocidad en el eje X + int vel_y_; // Velocidad en el eje Y + BulletType kind_; // Tipo de objeto + int owner_; // Identificador del dueño del objeto + Circle collider_; // Círculo de colisión del objeto + SDL_Rect *play_area_; // Rectángulo con la zona de juego + std::unique_ptr sprite_; // Sprite con los gráficos y métodos de pintado void shiftColliders(); // Alinea el círculo de colisión con el objeto public: - Bullet(int x, int y, BulletType kind, bool poweredUp, int owner, SDL_Rect *playArea, std::shared_ptr texture); + // Constructor + Bullet(int x, int y, BulletType kind, bool powered_up, int owner, SDL_Rect *play_area, std::shared_ptr texture); + + // Destructor ~Bullet() = default; - void render(); // Pinta el objeto en pantalla - BulletMoveStatus move(); // Actualiza la posición y estado del objeto + // Pinta el objeto en pantalla + void render(); - bool isEnabled() const; // Comprueba si el objeto está habilitado - void disable(); // Deshabilita el objeto + // Actualiza la posición y estado del objeto + BulletMoveStatus move(); + // Comprueba si el objeto está habilitado + bool isEnabled() const; + + // Deshabilita el objeto + void disable(); + + // Obtiene la posición int getPosX() const; int getPosY() const; + + // Establece la posición void setPosX(int x); void setPosY(int y); + + // Obtiene parámetros int getVelY() const; BulletType getKind() const; int getOwner() const; - circle_t &getCollider(); + Circle &getCollider(); }; diff --git a/source/define_buttons.cpp b/source/define_buttons.cpp index c620b00..3cf9ac5 100644 --- a/source/define_buttons.cpp +++ b/source/define_buttons.cpp @@ -4,7 +4,7 @@ #include "param.h" // for param #include "section.h" // for name, name_e, options, options_e #include "text.h" // for Text -#include "utils.h" // for op_controller_t, options_t, param_t, paramGame_t +#include "utils.h" // for OptionsController, Options, Param, ParamGame // Constructor DefineButtons::DefineButtons(std::unique_ptr text) diff --git a/source/director.cpp b/source/director.cpp index f5f5cfc..0ea247c 100644 --- a/source/director.cpp +++ b/source/director.cpp @@ -33,7 +33,7 @@ #include "screen.h" // for Screen #include "section.h" // for name_e, name, options, options_e #include "title.h" // for Title -#include "utils.h" // for music_file_t, sound_file_t, opt... +#include "utils.h" // for MusicFile, SoundFile, opt... #include #ifndef _WIN32 @@ -129,7 +129,7 @@ Director::~Director() SDL_Quit(); } -// Inicializa el objeto input +/// Inicializa el objeto input void Director::initInput() { // Establece si ha de mostrar mensajes @@ -350,135 +350,135 @@ bool Director::setFileList() #endif // Ficheros de configuración - Asset::get()->add(systemFolder + "/config.txt", t_data, false, true); - Asset::get()->add(systemFolder + "/score.bin", t_data, false, true); - Asset::get()->add(prefix + "/data/config/param_320x240.txt", t_data); - Asset::get()->add(prefix + "/data/config/param_320x256.txt", t_data); - Asset::get()->add(prefix + "/data/config/demo1.bin", t_data); - Asset::get()->add(prefix + "/data/config/demo2.bin", t_data); - Asset::get()->add(prefix + "/data/config/gamecontrollerdb.txt", t_data); + Asset::get()->add(systemFolder + "/config.txt", AssetType::DATA, false, true); + Asset::get()->add(systemFolder + "/score.bin", AssetType::DATA, false, true); + Asset::get()->add(prefix + "/data/config/param_320x240.txt", AssetType::DATA); + Asset::get()->add(prefix + "/data/config/param_320x256.txt", AssetType::DATA); + Asset::get()->add(prefix + "/data/config/demo1.bin", AssetType::DATA); + Asset::get()->add(prefix + "/data/config/demo2.bin", AssetType::DATA); + Asset::get()->add(prefix + "/data/config/gamecontrollerdb.txt", AssetType::DATA); // Musicas - Asset::get()->add(prefix + "/data/music/intro.ogg", t_music); - Asset::get()->add(prefix + "/data/music/playing.ogg", t_music); - Asset::get()->add(prefix + "/data/music/title.ogg", t_music); + Asset::get()->add(prefix + "/data/music/intro.ogg", AssetType::MUSIC); + Asset::get()->add(prefix + "/data/music/playing.ogg", AssetType::MUSIC); + Asset::get()->add(prefix + "/data/music/title.ogg", AssetType::MUSIC); // Sonidos - Asset::get()->add(prefix + "/data/sound/balloon.wav", t_sound); - Asset::get()->add(prefix + "/data/sound/bubble1.wav", t_sound); - Asset::get()->add(prefix + "/data/sound/bubble2.wav", t_sound); - Asset::get()->add(prefix + "/data/sound/bubble3.wav", t_sound); - Asset::get()->add(prefix + "/data/sound/bubble4.wav", t_sound); - Asset::get()->add(prefix + "/data/sound/bullet.wav", t_sound); - Asset::get()->add(prefix + "/data/sound/coffeeout.wav", t_sound); - Asset::get()->add(prefix + "/data/sound/hiscore.wav", t_sound); - Asset::get()->add(prefix + "/data/sound/itemdrop.wav", t_sound); - Asset::get()->add(prefix + "/data/sound/itempickup.wav", t_sound); - Asset::get()->add(prefix + "/data/sound/player_collision.wav", t_sound); - Asset::get()->add(prefix + "/data/sound/stage_change.wav", t_sound); - Asset::get()->add(prefix + "/data/sound/title.wav", t_sound); - Asset::get()->add(prefix + "/data/sound/clock.wav", t_sound); - Asset::get()->add(prefix + "/data/sound/powerball.wav", t_sound); - Asset::get()->add(prefix + "/data/sound/notify.wav", t_sound); + Asset::get()->add(prefix + "/data/sound/balloon.wav", AssetType::SOUND); + Asset::get()->add(prefix + "/data/sound/bubble1.wav", AssetType::SOUND); + Asset::get()->add(prefix + "/data/sound/bubble2.wav", AssetType::SOUND); + Asset::get()->add(prefix + "/data/sound/bubble3.wav", AssetType::SOUND); + Asset::get()->add(prefix + "/data/sound/bubble4.wav", AssetType::SOUND); + Asset::get()->add(prefix + "/data/sound/bullet.wav", AssetType::SOUND); + Asset::get()->add(prefix + "/data/sound/coffeeout.wav", AssetType::SOUND); + Asset::get()->add(prefix + "/data/sound/hiscore.wav", AssetType::SOUND); + Asset::get()->add(prefix + "/data/sound/itemdrop.wav", AssetType::SOUND); + Asset::get()->add(prefix + "/data/sound/itempickup.wav", AssetType::SOUND); + Asset::get()->add(prefix + "/data/sound/player_collision.wav", AssetType::SOUND); + Asset::get()->add(prefix + "/data/sound/stage_change.wav", AssetType::SOUND); + Asset::get()->add(prefix + "/data/sound/title.wav", AssetType::SOUND); + Asset::get()->add(prefix + "/data/sound/clock.wav", AssetType::SOUND); + Asset::get()->add(prefix + "/data/sound/powerball.wav", AssetType::SOUND); + Asset::get()->add(prefix + "/data/sound/notify.wav", AssetType::SOUND); // Shaders - Asset::get()->add(prefix + "/data/shaders/crtpi.glsl", t_data); + Asset::get()->add(prefix + "/data/shaders/crtpi.glsl", AssetType::DATA); // Texturas - Asset::get()->add(prefix + "/data/gfx/controllers/controllers.png", t_bitmap); + Asset::get()->add(prefix + "/data/gfx/controllers/controllers.png", AssetType::BITMAP); - Asset::get()->add(prefix + "/data/gfx/balloon/balloon1.png", t_bitmap); - Asset::get()->add(prefix + "/data/gfx/balloon/balloon1.ani", t_animation); - Asset::get()->add(prefix + "/data/gfx/balloon/balloon2.png", t_bitmap); - Asset::get()->add(prefix + "/data/gfx/balloon/balloon2.ani", t_animation); - Asset::get()->add(prefix + "/data/gfx/balloon/balloon3.png", t_bitmap); - Asset::get()->add(prefix + "/data/gfx/balloon/balloon3.ani", t_animation); - Asset::get()->add(prefix + "/data/gfx/balloon/balloon4.png", t_bitmap); - Asset::get()->add(prefix + "/data/gfx/balloon/balloon4.ani", t_animation); + Asset::get()->add(prefix + "/data/gfx/balloon/balloon1.png", AssetType::BITMAP); + Asset::get()->add(prefix + "/data/gfx/balloon/balloon1.ani", AssetType::ANIMATION); + Asset::get()->add(prefix + "/data/gfx/balloon/balloon2.png", AssetType::BITMAP); + Asset::get()->add(prefix + "/data/gfx/balloon/balloon2.ani", AssetType::ANIMATION); + Asset::get()->add(prefix + "/data/gfx/balloon/balloon3.png", AssetType::BITMAP); + Asset::get()->add(prefix + "/data/gfx/balloon/balloon3.ani", AssetType::ANIMATION); + Asset::get()->add(prefix + "/data/gfx/balloon/balloon4.png", AssetType::BITMAP); + Asset::get()->add(prefix + "/data/gfx/balloon/balloon4.ani", AssetType::ANIMATION); - Asset::get()->add(prefix + "/data/gfx/balloon/explosion1.png", t_bitmap); - Asset::get()->add(prefix + "/data/gfx/balloon/explosion1.ani", t_animation); - Asset::get()->add(prefix + "/data/gfx/balloon/explosion2.png", t_bitmap); - Asset::get()->add(prefix + "/data/gfx/balloon/explosion2.ani", t_animation); - Asset::get()->add(prefix + "/data/gfx/balloon/explosion3.png", t_bitmap); - Asset::get()->add(prefix + "/data/gfx/balloon/explosion3.ani", t_animation); - Asset::get()->add(prefix + "/data/gfx/balloon/explosion4.png", t_bitmap); - Asset::get()->add(prefix + "/data/gfx/balloon/explosion4.ani", t_animation); + Asset::get()->add(prefix + "/data/gfx/balloon/explosion1.png", AssetType::BITMAP); + Asset::get()->add(prefix + "/data/gfx/balloon/explosion1.ani", AssetType::ANIMATION); + Asset::get()->add(prefix + "/data/gfx/balloon/explosion2.png", AssetType::BITMAP); + Asset::get()->add(prefix + "/data/gfx/balloon/explosion2.ani", AssetType::ANIMATION); + Asset::get()->add(prefix + "/data/gfx/balloon/explosion3.png", AssetType::BITMAP); + Asset::get()->add(prefix + "/data/gfx/balloon/explosion3.ani", AssetType::ANIMATION); + Asset::get()->add(prefix + "/data/gfx/balloon/explosion4.png", AssetType::BITMAP); + Asset::get()->add(prefix + "/data/gfx/balloon/explosion4.ani", AssetType::ANIMATION); - Asset::get()->add(prefix + "/data/gfx/balloon/powerball.png", t_bitmap); - Asset::get()->add(prefix + "/data/gfx/balloon/powerball.ani", t_animation); + Asset::get()->add(prefix + "/data/gfx/balloon/powerball.png", AssetType::BITMAP); + Asset::get()->add(prefix + "/data/gfx/balloon/powerball.ani", AssetType::ANIMATION); - Asset::get()->add(prefix + "/data/gfx/bullet/bullet.png", t_bitmap); + Asset::get()->add(prefix + "/data/gfx/bullet/bullet.png", AssetType::BITMAP); - Asset::get()->add(prefix + "/data/gfx/game/game_buildings.png", t_bitmap); - Asset::get()->add(prefix + "/data/gfx/game/game_clouds1.png", t_bitmap); - Asset::get()->add(prefix + "/data/gfx/game/game_clouds2.png", t_bitmap); - Asset::get()->add(prefix + "/data/gfx/game/game_grass.png", t_bitmap); - Asset::get()->add(prefix + "/data/gfx/game/game_power_meter.png", t_bitmap); - Asset::get()->add(prefix + "/data/gfx/game/game_sky_colors.png", t_bitmap); - Asset::get()->add(prefix + "/data/gfx/game/game_text.png", t_bitmap); + Asset::get()->add(prefix + "/data/gfx/game/game_buildings.png", AssetType::BITMAP); + Asset::get()->add(prefix + "/data/gfx/game/game_clouds1.png", AssetType::BITMAP); + Asset::get()->add(prefix + "/data/gfx/game/game_clouds2.png", AssetType::BITMAP); + Asset::get()->add(prefix + "/data/gfx/game/game_grass.png", AssetType::BITMAP); + Asset::get()->add(prefix + "/data/gfx/game/game_power_meter.png", AssetType::BITMAP); + Asset::get()->add(prefix + "/data/gfx/game/game_sky_colors.png", AssetType::BITMAP); + Asset::get()->add(prefix + "/data/gfx/game/game_text.png", AssetType::BITMAP); - Asset::get()->add(prefix + "/data/gfx/intro/intro.png", t_bitmap); + Asset::get()->add(prefix + "/data/gfx/intro/intro.png", AssetType::BITMAP); - Asset::get()->add(prefix + "/data/gfx/logo/logo_jailgames.png", t_bitmap); - Asset::get()->add(prefix + "/data/gfx/logo/logo_jailgames_mini.png", t_bitmap); - Asset::get()->add(prefix + "/data/gfx/logo/logo_since_1998.png", t_bitmap); + Asset::get()->add(prefix + "/data/gfx/logo/logo_jailgames.png", AssetType::BITMAP); + Asset::get()->add(prefix + "/data/gfx/logo/logo_jailgames_mini.png", AssetType::BITMAP); + Asset::get()->add(prefix + "/data/gfx/logo/logo_since_1998.png", AssetType::BITMAP); - Asset::get()->add(prefix + "/data/gfx/item/item_points1_disk.png", t_bitmap); - Asset::get()->add(prefix + "/data/gfx/item/item_points1_disk.ani", t_animation); - Asset::get()->add(prefix + "/data/gfx/item/item_points2_gavina.png", t_bitmap); - Asset::get()->add(prefix + "/data/gfx/item/item_points2_gavina.ani", t_animation); - Asset::get()->add(prefix + "/data/gfx/item/item_points3_pacmar.png", t_bitmap); - Asset::get()->add(prefix + "/data/gfx/item/item_points3_pacmar.ani", t_animation); - Asset::get()->add(prefix + "/data/gfx/item/item_clock.png", t_bitmap); - Asset::get()->add(prefix + "/data/gfx/item/item_clock.ani", t_animation); - Asset::get()->add(prefix + "/data/gfx/item/item_coffee.png", t_bitmap); - Asset::get()->add(prefix + "/data/gfx/item/item_coffee.ani", t_animation); - Asset::get()->add(prefix + "/data/gfx/item/item_coffee_machine.png", t_bitmap); - Asset::get()->add(prefix + "/data/gfx/item/item_coffee_machine.ani", t_animation); + Asset::get()->add(prefix + "/data/gfx/item/item_points1_disk.png", AssetType::BITMAP); + Asset::get()->add(prefix + "/data/gfx/item/item_points1_disk.ani", AssetType::ANIMATION); + Asset::get()->add(prefix + "/data/gfx/item/item_points2_gavina.png", AssetType::BITMAP); + Asset::get()->add(prefix + "/data/gfx/item/item_points2_gavina.ani", AssetType::ANIMATION); + Asset::get()->add(prefix + "/data/gfx/item/item_points3_pacmar.png", AssetType::BITMAP); + Asset::get()->add(prefix + "/data/gfx/item/item_points3_pacmar.ani", AssetType::ANIMATION); + Asset::get()->add(prefix + "/data/gfx/item/item_clock.png", AssetType::BITMAP); + Asset::get()->add(prefix + "/data/gfx/item/item_clock.ani", AssetType::ANIMATION); + Asset::get()->add(prefix + "/data/gfx/item/item_coffee.png", AssetType::BITMAP); + Asset::get()->add(prefix + "/data/gfx/item/item_coffee.ani", AssetType::ANIMATION); + Asset::get()->add(prefix + "/data/gfx/item/item_coffee_machine.png", AssetType::BITMAP); + Asset::get()->add(prefix + "/data/gfx/item/item_coffee_machine.ani", AssetType::ANIMATION); - Asset::get()->add(prefix + "/data/gfx/title/title_bg_tile.png", t_bitmap); - Asset::get()->add(prefix + "/data/gfx/title/title_coffee.png", t_bitmap); - Asset::get()->add(prefix + "/data/gfx/title/title_crisis.png", t_bitmap); - Asset::get()->add(prefix + "/data/gfx/title/title_arcade_edition.png", t_bitmap); - Asset::get()->add(prefix + "/data/gfx/title/title_dust.png", t_bitmap); - Asset::get()->add(prefix + "/data/gfx/title/title_dust.ani", t_animation); + Asset::get()->add(prefix + "/data/gfx/title/title_bg_tile.png", AssetType::BITMAP); + Asset::get()->add(prefix + "/data/gfx/title/title_coffee.png", AssetType::BITMAP); + Asset::get()->add(prefix + "/data/gfx/title/title_crisis.png", AssetType::BITMAP); + Asset::get()->add(prefix + "/data/gfx/title/title_arcade_edition.png", AssetType::BITMAP); + Asset::get()->add(prefix + "/data/gfx/title/title_dust.png", AssetType::BITMAP); + Asset::get()->add(prefix + "/data/gfx/title/title_dust.ani", AssetType::ANIMATION); - Asset::get()->add(prefix + "/data/gfx/player/player1.gif", t_bitmap); - Asset::get()->add(prefix + "/data/gfx/player/player1_pal1.gif", t_palette); - Asset::get()->add(prefix + "/data/gfx/player/player1_pal2.gif", t_palette); - Asset::get()->add(prefix + "/data/gfx/player/player1_pal3.gif", t_palette); + Asset::get()->add(prefix + "/data/gfx/player/player1.gif", AssetType::BITMAP); + Asset::get()->add(prefix + "/data/gfx/player/player1_pal1.gif", AssetType::PALETTE); + Asset::get()->add(prefix + "/data/gfx/player/player1_pal2.gif", AssetType::PALETTE); + Asset::get()->add(prefix + "/data/gfx/player/player1_pal3.gif", AssetType::PALETTE); - Asset::get()->add(prefix + "/data/gfx/player/player2.gif", t_bitmap); - Asset::get()->add(prefix + "/data/gfx/player/player2_pal1.gif", t_palette); - Asset::get()->add(prefix + "/data/gfx/player/player2_pal2.gif", t_palette); - Asset::get()->add(prefix + "/data/gfx/player/player2_pal3.gif", t_palette); + Asset::get()->add(prefix + "/data/gfx/player/player2.gif", AssetType::BITMAP); + Asset::get()->add(prefix + "/data/gfx/player/player2_pal1.gif", AssetType::PALETTE); + Asset::get()->add(prefix + "/data/gfx/player/player2_pal2.gif", AssetType::PALETTE); + Asset::get()->add(prefix + "/data/gfx/player/player2_pal3.gif", AssetType::PALETTE); - Asset::get()->add(prefix + "/data/gfx/player/player.ani", t_animation); + Asset::get()->add(prefix + "/data/gfx/player/player.ani", AssetType::ANIMATION); - Asset::get()->add(prefix + "/data/gfx/player/player_power.gif", t_bitmap); - Asset::get()->add(prefix + "/data/gfx/player/player_power_pal.gif", t_palette); - Asset::get()->add(prefix + "/data/gfx/player/player_power.ani", t_animation); + Asset::get()->add(prefix + "/data/gfx/player/player_power.gif", AssetType::BITMAP); + Asset::get()->add(prefix + "/data/gfx/player/player_power_pal.gif", AssetType::PALETTE); + Asset::get()->add(prefix + "/data/gfx/player/player_power.ani", AssetType::ANIMATION); // Fuentes de texto - Asset::get()->add(prefix + "/data/font/8bithud.png", t_font); - Asset::get()->add(prefix + "/data/font/8bithud.txt", t_font); - Asset::get()->add(prefix + "/data/font/nokia.png", t_font); - Asset::get()->add(prefix + "/data/font/nokia_big2.png", t_font); - Asset::get()->add(prefix + "/data/font/nokia.txt", t_font); - Asset::get()->add(prefix + "/data/font/nokia2.png", t_font); - Asset::get()->add(prefix + "/data/font/nokia2.txt", t_font); - Asset::get()->add(prefix + "/data/font/nokia_big2.txt", t_font); - Asset::get()->add(prefix + "/data/font/smb2_big.png", t_font); - Asset::get()->add(prefix + "/data/font/smb2_big.txt", t_font); - Asset::get()->add(prefix + "/data/font/smb2.gif", t_font); - Asset::get()->add(prefix + "/data/font/smb2_pal1.gif", t_palette); - Asset::get()->add(prefix + "/data/font/smb2.txt", t_font); + Asset::get()->add(prefix + "/data/font/8bithud.png", AssetType::FONT); + Asset::get()->add(prefix + "/data/font/8bithud.txt", AssetType::FONT); + Asset::get()->add(prefix + "/data/font/nokia.png", AssetType::FONT); + Asset::get()->add(prefix + "/data/font/nokia_big2.png", AssetType::FONT); + Asset::get()->add(prefix + "/data/font/nokia.txt", AssetType::FONT); + Asset::get()->add(prefix + "/data/font/nokia2.png", AssetType::FONT); + Asset::get()->add(prefix + "/data/font/nokia2.txt", AssetType::FONT); + Asset::get()->add(prefix + "/data/font/nokia_big2.txt", AssetType::FONT); + Asset::get()->add(prefix + "/data/font/smb2_big.png", AssetType::FONT); + Asset::get()->add(prefix + "/data/font/smb2_big.txt", AssetType::FONT); + Asset::get()->add(prefix + "/data/font/smb2.gif", AssetType::FONT); + Asset::get()->add(prefix + "/data/font/smb2_pal1.gif", AssetType::PALETTE); + Asset::get()->add(prefix + "/data/font/smb2.txt", AssetType::FONT); // Textos - Asset::get()->add(prefix + "/data/lang/es_ES.txt", t_lang); - Asset::get()->add(prefix + "/data/lang/en_UK.txt", t_lang); - Asset::get()->add(prefix + "/data/lang/ba_BA.txt", t_lang); + Asset::get()->add(prefix + "/data/lang/es_ES.txt", AssetType::LANG); + Asset::get()->add(prefix + "/data/lang/en_UK.txt", AssetType::LANG); + Asset::get()->add(prefix + "/data/lang/ba_BA.txt", AssetType::LANG); return Asset::get()->check(); } @@ -561,14 +561,14 @@ void Director::createSystemFolder(std::string folder) void Director::loadSounds() { // Obtiene la lista con las rutas a los ficheros de sonidos - std::vector list = Asset::get()->getListByType(t_sound); + std::vector list = Asset::get()->getListByType(AssetType::SOUND); sounds.clear(); for (auto l : list) { const size_t lastIndex = l.find_last_of("/") + 1; const std::string name = l.substr(lastIndex, std::string::npos); - sound_file_t temp; + SoundFile temp; temp.name = name; // Añade el nombre del fichero temp.file = JA_LoadSound(l.c_str()); // Carga el fichero de audio sounds.push_back(temp); @@ -579,14 +579,14 @@ void Director::loadSounds() void Director::loadMusics() { // Obtiene la lista con las rutas a los ficheros musicales - std::vector list = Asset::get()->getListByType(t_music); + std::vector list = Asset::get()->getListByType(AssetType::MUSIC); musics.clear(); for (auto l : list) { const size_t lastIndex = l.find_last_of("/") + 1; const std::string name = l.substr(lastIndex, std::string::npos); - music_file_t temp; + MusicFile temp; temp.name = name; // Añade el nombre del fichero temp.file = JA_LoadMusic(l.c_str()); // Carga el fichero de audio musics.push_back(temp); diff --git a/source/director.h b/source/director.h index 023dc5f..773bd72 100644 --- a/source/director.h +++ b/source/director.h @@ -1,11 +1,11 @@ #pragma once -#include // for SDL_Renderer -#include // for SDL_Window -#include // for string, basic_string -#include // for vector -#include "lang.h" // for lang_e -#include "utils.h" // for music_file_t, sound_file_t +#include // for SDL_Renderer +#include // for SDL_Window +#include // for string, basic_string +#include // for vector +#include "lang.h" // for lang_e +#include "utils.h" // for MusicFile, SoundFile // Textos #define WINDOW_CAPTION "Coffee Crisis Arcade Edition" @@ -14,15 +14,15 @@ class Director { private: // Objetos y punteros - SDL_Window *window; // La ventana donde dibujamos - SDL_Renderer *renderer; // El renderizador de la ventana + SDL_Window *window; // La ventana donde dibujamos + SDL_Renderer *renderer; // El renderizador de la ventana // Variables - std::string executablePath; // Path del ejecutable - std::string systemFolder; // Carpeta del sistema donde guardar datos - std::string paramFileArgument; // Argumento para gestionar el fichero con los parametros del programa - std::vector sounds; // Vector con los sonidos - std::vector musics; // Vector con las musicas + std::string executablePath; // Path del ejecutable + std::string systemFolder; // Carpeta del sistema donde guardar datos + std::string paramFileArgument; // Argumento para gestionar el fichero con los parametros del programa + std::vector sounds; // Vector con los sonidos + std::vector musics; // Vector con las musicas // Inicializa jail_audio void initJailAudio(); diff --git a/source/enemy_formations.cpp b/source/enemy_formations.cpp index bd71709..740fdc3 100644 --- a/source/enemy_formations.cpp +++ b/source/enemy_formations.cpp @@ -1,7 +1,7 @@ #include "enemy_formations.h" #include "balloon.h" // for BALLOON_VELX_NEGATIVE, BALLOON_VELX_POSITIVE #include "param.h" // for param -#include "utils.h" // for paramGame_t, param_t, zone_t, BLOCK +#include "utils.h" // for ParamGame, Param, Zone, BLOCK // Constructor EnemyFormations::EnemyFormations() @@ -15,21 +15,21 @@ EnemyFormations::EnemyFormations() void EnemyFormations::initEnemyFormations() { const int y4 = -BLOCK; - const int x4_0 = param.game.playArea.rect.x; - const int x4_100 = param.game.playArea.rect.w - BALLOON_WIDTH_4; + const int x4_0 = param.game.play_area.rect.x; + const int x4_100 = param.game.play_area.rect.w - BALLOON_WIDTH_4; const int y3 = -BLOCK; - const int x3_0 = param.game.playArea.rect.x; - const int x3_100 = param.game.playArea.rect.w - BALLOON_WIDTH_3; + const int x3_0 = param.game.play_area.rect.x; + const int x3_100 = param.game.play_area.rect.w - BALLOON_WIDTH_3; const int y2 = -BLOCK; - const int x2_0 = param.game.playArea.rect.x; - const int x2_100 = param.game.playArea.rect.w - BALLOON_WIDTH_2; + const int x2_0 = param.game.play_area.rect.x; + const int x2_100 = param.game.play_area.rect.w - BALLOON_WIDTH_2; const int y1 = -BLOCK; - const int x1_0 = param.game.playArea.rect.x; - const int x1_50 = param.game.playArea.centerX - (BALLOON_WIDTH_1 / 2); - const int x1_100 = param.game.playArea.rect.w - BALLOON_WIDTH_1; + const int x1_0 = param.game.play_area.rect.x; + const int x1_50 = param.game.play_area.centerX - (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++) @@ -67,11 +67,11 @@ void EnemyFormations::initEnemyFormations() // #01 - Dos enemigos BALLOON4 uno a cada cuarto. Ambos van hacia el centro j = 1; enemyFormation[j].numberOfEnemies = 2; - incX = param.game.playArea.centerX; + incX = param.game.play_area.centerX; incTime = 0; for (int i = 0; i < enemyFormation[j].numberOfEnemies; i++) { - enemyFormation[j].init[i].x = param.game.playArea.firstQuarterX - (BALLOON_WIDTH_4 / 2) + (i * incX); + enemyFormation[j].init[i].x = param.game.play_area.firstQuarterX - (BALLOON_WIDTH_4 / 2) + (i * incX); enemyFormation[j].init[i].y = y4; enemyFormation[j].init[i].velX = BALLOON_VELX_NEGATIVE * (((i % 2) * 2) - 1); enemyFormation[j].init[i].kind = BALLOON_4; diff --git a/source/fade.cpp b/source/fade.cpp index a1eef3e..6a75331 100644 --- a/source/fade.cpp +++ b/source/fade.cpp @@ -4,7 +4,7 @@ #include // for rand #include // for min, max #include "param.h" // for param -#include "utils.h" // for param_t, paramGame_t, paramFade_t +#include "utils.h" // for Param, ParamGame, ParamFade // Constructor Fade::Fade(SDL_Renderer *renderer) @@ -38,9 +38,9 @@ void Fade::init() b = 0; postDuration = 20; postCounter = 0; - numSquaresWidth = param.fade.numSquaresWidth; - numSquaresHeight = param.fade.numSquaresHeight; - fadeRandomSquaresDelay = param.fade.randomSquaresDelay; + numSquaresWidth = param.fade.num_squares_width; + numSquaresHeight = param.fade.num_squares_height; + fadeRandomSquaresDelay = param.fade.random_squares_delay; fadeRandomSquaresMult = param.fade.randomSquaresMult; } diff --git a/source/game.cpp b/source/game.cpp index c3c4b43..aa5b889 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -74,7 +74,7 @@ Game::Game(int playerID, int currentStage, bool demo, JA_Music_t *music) loadDemoFile(asset->get("demo2.bin"), &this->demo.dataFile[index2]); } - background->setPos(param.game.playArea.rect); + background->setPos(param.game.play_area.rect); n1000Sprite = std::make_shared(gameTextTexture); n2500Sprite = std::make_shared(gameTextTexture); @@ -85,7 +85,7 @@ Game::Game(int playerID, int currentStage, bool demo, JA_Music_t *music) explosions->addTexture(3, explosionsTextures[2], explosionsAnimations[2]); explosions->addTexture(4, explosionsTextures[3], explosionsAnimations[3]); - canvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.playArea.rect.w, param.game.playArea.rect.h); + canvas = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.play_area.rect.w, param.game.play_area.rect.h); SDL_SetTextureBlendMode(canvas, SDL_BLENDMODE_BLEND); // Inicializa las variables necesarias para la sección 'Game' @@ -122,14 +122,14 @@ void Game::init(int playerID) players.clear(); // Crea los dos jugadores - auto player1 = std::make_unique(1, (param.game.playArea.firstQuarterX * ((0 * 2) + 1)) - 11, param.game.playArea.rect.h - 30, demo.enabled, ¶m.game.playArea.rect, playerTextures[0], playerAnimations); + auto player1 = std::make_unique(1, (param.game.play_area.firstQuarterX * ((0 * 2) + 1)) - 11, param.game.play_area.rect.h - 30, demo.enabled, ¶m.game.play_area.rect, playerTextures[0], playerAnimations); player1->setScoreBoardPanel(SCOREBOARD_LEFT_PANEL); player1->setName(lang::getText(53)); const auto controller1 = getController(player1->getId()); player1->setController(controller1); players.push_back(std::move(player1)); - auto player2 = std::make_unique(2, (param.game.playArea.firstQuarterX * ((1 * 2) + 1)) - 11, param.game.playArea.rect.h - 30, demo.enabled, ¶m.game.playArea.rect, playerTextures[1], playerAnimations); + auto player2 = std::make_unique(2, (param.game.play_area.firstQuarterX * ((1 * 2) + 1)) - 11, param.game.play_area.rect.h - 30, demo.enabled, ¶m.game.play_area.rect, playerTextures[1], playerAnimations); player2->setScoreBoardPanel(SCOREBOARD_RIGHT_PANEL); player2->setName(lang::getText(54)); const auto controller2 = getController(player2->getId()); @@ -582,7 +582,7 @@ void Game::unloadMedia() } // Carga el fichero de datos para la demo -bool Game::loadDemoFile(std::string filePath, demoKeys_t (*dataFile)[TOTAL_DEMO_DATA]) +bool Game::loadDemoFile(std::string filePath, DemoKeys (*dataFile)[TOTAL_DEMO_DATA]) { // Indicador de éxito en la carga auto success = true; @@ -608,7 +608,7 @@ bool Game::loadDemoFile(std::string filePath, demoKeys_t (*dataFile)[TOTAL_DEMO_ // Inicializas los datos y los guarda en el fichero for (int i = 0; i < TOTAL_DEMO_DATA; ++i) { - demoKeys_t tmp; + DemoKeys tmp; tmp.left = 0; tmp.right = 0; tmp.noInput = 0; @@ -616,7 +616,7 @@ bool Game::loadDemoFile(std::string filePath, demoKeys_t (*dataFile)[TOTAL_DEMO_ tmp.fireLeft = 0; tmp.fireRight = 0; (*dataFile)[i] = tmp; - SDL_RWwrite(file, &tmp, sizeof(demoKeys_t), 1); + SDL_RWwrite(file, &tmp, sizeof(DemoKeys), 1); } // Cerramos el fichero @@ -641,8 +641,8 @@ bool Game::loadDemoFile(std::string filePath, demoKeys_t (*dataFile)[TOTAL_DEMO_ // Lee todos los datos del fichero y los deja en el destino for (int i = 0; i < TOTAL_DEMO_DATA; ++i) { - demoKeys_t tmp; - SDL_RWread(file, &tmp, sizeof(demoKeys_t), 1); + DemoKeys tmp; + SDL_RWread(file, &tmp, sizeof(DemoKeys), 1); (*dataFile)[i] = tmp; } @@ -666,7 +666,7 @@ bool Game::saveDemoFile(std::string filePath) // Guardamos los datos for (int i = 0; i < TOTAL_DEMO_DATA; ++i) { - SDL_RWwrite(file, &demo.dataFile[0][i], sizeof(demoKeys_t), 1); + SDL_RWwrite(file, &demo.dataFile[0][i], sizeof(DemoKeys), 1); } #ifdef VERBOSE @@ -800,7 +800,7 @@ void Game::renderPlayers() player->render(); #ifdef DEBUG // SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); - // const circle_t c = player->getCollider(); + // const Circle c = player->getCollider(); // DrawCircle(renderer, c.x, c.y, c.r); #endif } @@ -921,9 +921,9 @@ void Game::createPowerBall() constexpr auto values = 6; constexpr auto posY = -BLOCK; - const auto left = param.game.playArea.rect.x; - const auto center = param.game.playArea.centerX - (BALLOON_WIDTH_4 / 2); - const auto right = param.game.playArea.rect.w - BALLOON_WIDTH_4; + const auto left = param.game.play_area.rect.x; + const auto center = param.game.play_area.centerX - (BALLOON_WIDTH_4 / 2); + const auto right = param.game.play_area.rect.w - BALLOON_WIDTH_4; const auto vpos = BALLOON_VELX_POSITIVE; const auto vneg = BALLOON_VELX_NEGATIVE; @@ -1405,7 +1405,7 @@ void Game::renderBullets() // Crea un objeto bala void Game::createBullet(int x, int y, BulletType kind, bool poweredUp, int owner) { - auto b = std::make_unique(x, y, kind, poweredUp, owner, &(param.game.playArea.rect), bulletTexture); + auto b = std::make_unique(x, y, kind, poweredUp, owner, &(param.game.play_area.rect), bulletTexture); bullets.push_back(std::move(b)); } @@ -1529,7 +1529,7 @@ int Game::dropItem() // Crea un objeto item void Game::createItem(int kind, float x, float y) { - auto item = std::make_unique(kind, x, y, &(param.game.playArea.rect), itemTextures[kind - 1], itemAnimations[kind - 1]); + auto item = std::make_unique(kind, x, y, &(param.game.play_area.rect), itemTextures[kind - 1], itemAnimations[kind - 1]); items.push_back(std::move(item)); } @@ -1587,8 +1587,8 @@ void Game::throwCoffee(int x, int y) ss->setPosX(x - 8); ss->setPosY(y - 8); - ss->setWidth(param.game.itemSize); - ss->setHeight(param.game.itemSize); + ss->setWidth(param.game.item_size); + ss->setHeight(param.game.item_size); ss->setVelX(-1.0f + ((rand() % 5) * 0.5f)); ss->setVelY(-4.0f); ss->setAccelX(0.0f); @@ -1597,7 +1597,7 @@ void Game::throwCoffee(int x, int y) ss->setDestY(param.game.height + 1); ss->setEnabled(true); ss->setFinishedCounter(1); - ss->setSpriteClip(0, param.game.itemSize, param.game.itemSize, param.game.itemSize); + ss->setSpriteClip(0, param.game.item_size, param.game.item_size, param.game.item_size); ss->setRotate(true); ss->setRotateSpeed(10); ss->setRotateAmount(90.0); @@ -1909,7 +1909,7 @@ void Game::render() screen->start(); // Copia la textura con la zona de juego a la pantalla - SDL_RenderCopy(renderer, canvas, nullptr, ¶m.game.playArea.rect); + SDL_RenderCopy(renderer, canvas, nullptr, ¶m.game.play_area.rect); // Dibuja el marcador scoreboard->render(); @@ -2206,7 +2206,7 @@ void Game::renderMessages() // GetReady if (counter < STAGE_COUNTER && !demo.enabled) { - textNokiaBig2->write((int)getReadyBitmapPath[counter], param.game.playArea.centerY - 8, lang::getText(75), -2); + textNokiaBig2->write((int)getReadyBitmapPath[counter], param.game.play_area.centerY - 8, lang::getText(75), -2); } // Time Stopped @@ -2214,7 +2214,7 @@ void Game::renderMessages() { if (timeStoppedCounter > 100 || timeStoppedCounter % 10 > 4) { - textNokia2->writeDX(TXT_CENTER, param.game.playArea.centerX, param.game.playArea.firstQuarterY, lang::getText(36) + std::to_string(timeStoppedCounter / 10), -1, noColor, 1, shdwTxtColor); + textNokia2->writeDX(TXT_CENTER, param.game.play_area.centerX, param.game.play_area.firstQuarterY, lang::getText(36) + std::to_string(timeStoppedCounter / 10), -1, noColor, 1, shdwTxtColor); } if (timeStoppedCounter > 100) @@ -2250,13 +2250,13 @@ void Game::renderMessages() if (!gameCompleted) { // Escribe el número de fases restantes - textNokiaBig2->writeDX(TXT_CENTER, param.game.playArea.centerX, stageBitmapPath[stageBitmapCounter], text, -2, noColor, 2, shdwTxtColor); + textNokiaBig2->writeDX(TXT_CENTER, param.game.play_area.centerX, stageBitmapPath[stageBitmapCounter], text, -2, noColor, 2, shdwTxtColor); } else { // Escribe el texto de juego completado text = lang::getText(50); - textNokiaBig2->writeDX(TXT_CENTER, param.game.playArea.centerX, stageBitmapPath[stageBitmapCounter], text, -2, noColor, 1, shdwTxtColor); - textNokia2->writeDX(TXT_CENTER, param.game.playArea.centerX, stageBitmapPath[stageBitmapCounter] + textNokiaBig2->getCharacterSize() + 2, lang::getText(76), -1, noColor, 1, shdwTxtColor); + textNokiaBig2->writeDX(TXT_CENTER, param.game.play_area.centerX, stageBitmapPath[stageBitmapCounter], text, -2, noColor, 1, shdwTxtColor); + textNokia2->writeDX(TXT_CENTER, param.game.play_area.centerX, stageBitmapPath[stageBitmapCounter] + textNokiaBig2->getCharacterSize() + 2, lang::getText(76), -1, noColor, 1, shdwTxtColor); } } } @@ -2353,8 +2353,8 @@ void Game::initPaths() // Letrero de STAGE # constexpr auto firstPart = STAGE_COUNTER / 4; // 50 constexpr auto secondPart = firstPart * 3; // 150 - const auto centerPoint = param.game.playArea.centerY - (BLOCK * 2); - const auto distance = (param.game.playArea.rect.h) - (param.game.playArea.centerY - 16); + const auto centerPoint = param.game.play_area.centerY - (BLOCK * 2); + const auto distance = (param.game.play_area.rect.h) - (param.game.play_area.centerY - 16); for (int i = 0; i < STAGE_COUNTER; ++i) { @@ -2377,11 +2377,11 @@ void Game::initPaths() // Letrero de GetReady const auto size = textNokiaBig2->lenght(lang::getText(75), -2); - const float start1 = param.game.playArea.rect.x - size; - const float finish1 = param.game.playArea.centerX - (size / 2); + const float start1 = param.game.play_area.rect.x - size; + const float finish1 = param.game.play_area.centerX - (size / 2); const float start2 = finish1; - const float finish2 = param.game.playArea.rect.w; + const float finish2 = param.game.play_area.rect.w; const float distance1 = finish1 - start1; const float distance2 = finish2 - start2; @@ -2668,7 +2668,7 @@ void Game::pause(bool value) // Añade una puntuación a la tabla de records void Game::addScoreToScoreBoard(std::string name, int score) { - const auto entry = (hiScoreEntry_t){trim(name), score}; + const auto entry = (HiScoreEntry){trim(name), score}; auto manager = std::make_unique(&options.game.hiScoreTable); manager->add(entry); manager->saveToFile(asset->get("score.bin")); diff --git a/source/game.h b/source/game.h index 5f9423c..befb3f6 100644 --- a/source/game.h +++ b/source/game.h @@ -6,7 +6,7 @@ #include // for string #include // for vector #include "section.h" // for options_e -#include "utils.h" // for demoKeys_t, color_t, hiScoreEntry_t +#include "utils.h" // for DemoKeys, Color, HiScoreEntry #include #include "asset.h" // lines 11-11 #include "background.h" // lines 12-12 @@ -98,11 +98,11 @@ private: struct demo_t { - bool enabled; // Indica si está activo el modo demo - bool recording; // Indica si está activado el modo para grabar la demo - int counter; // Contador para el modo demo - demoKeys_t keys; // Variable con las pulsaciones de teclas del modo demo - demoKeys_t dataFile[2][TOTAL_DEMO_DATA]; // Vector con diferentes sets de datos con los movimientos para la demo + bool enabled; // Indica si está activo el modo demo + bool recording; // Indica si está activado el modo para grabar la demo + int counter; // Contador para el modo demo + DemoKeys keys; // Variable con las pulsaciones de teclas del modo demo + DemoKeys dataFile[2][TOTAL_DEMO_DATA]; // Vector con diferentes sets de datos con los movimientos para la demo }; // Objetos y punteros @@ -173,7 +173,7 @@ private: Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa bool hiScoreAchieved; // Indica si se ha superado la puntuación máxima - hiScoreEntry_t hiScore; // Máxima puntuación y nombre de quien la ostenta + HiScoreEntry hiScore; // Máxima puntuación y nombre de quien la ostenta int currentStage; // Indica la fase actual int stageBitmapCounter; // Contador para el tiempo visible del texto de Stage float stageBitmapPath[STAGE_COUNTER]; // Vector con los puntos Y por donde se desplaza el texto @@ -197,7 +197,7 @@ private: int gameCompletedCounter; // Contador para el tramo final, cuando se ha completado la partida y ya no aparecen más enemigos GameDifficulty difficulty; // Dificultad del juego float difficultyScoreMultiplier; // Multiplicador de puntos en función de la dificultad - color_t difficultyColor; // Color asociado a la dificultad + Color difficultyColor; // Color asociado a la dificultad int lastStageReached; // Contiene el número de la última pantalla que se ha alcanzado demo_t demo; // Variable con todas las variables relacionadas con el modo demo int totalPowerToCompleteGame; // La suma del poder necesario para completar todas las fases @@ -226,7 +226,7 @@ private: void unloadMedia(); // Carga el fichero de datos para la demo - bool loadDemoFile(std::string filePath, demoKeys_t (*dataFile)[TOTAL_DEMO_DATA]); + bool loadDemoFile(std::string filePath, DemoKeys (*dataFile)[TOTAL_DEMO_DATA]); #ifdef RECORDING // Guarda el fichero de datos para la demo bool saveDemoFile(std::string filePath); diff --git a/source/game_logo.cpp b/source/game_logo.cpp index e63ced6..5b3904d 100644 --- a/source/game_logo.cpp +++ b/source/game_logo.cpp @@ -9,7 +9,7 @@ #include "smart_sprite.h" // for SmartSprite #include "sprite.h" // for Sprite #include "texture.h" // for Texture -#include "utils.h" // for param_t, paramGame_t, paramTitle_t +#include "utils.h" // for Param, ParamGame, ParamTitle // Constructor GameLogo::GameLogo(int x, int y) diff --git a/source/global_inputs.cpp b/source/global_inputs.cpp index ac9afdb..f2e2f29 100644 --- a/source/global_inputs.cpp +++ b/source/global_inputs.cpp @@ -7,7 +7,7 @@ #include "on_screen_help.h" #include "screen.h" // for Screen #include "section.h" // for options_e, name, name_e, options -#include "utils.h" // for op_audio_t, options_t, op_music_t, boolToOnOff +#include "utils.h" // for OptionsAudio, Options, OptionsMusic, boolToOnOff namespace globalInputs { diff --git a/source/hiscore_table.cpp b/source/hiscore_table.cpp index 242f75f..09ce92c 100644 --- a/source/hiscore_table.cpp +++ b/source/hiscore_table.cpp @@ -5,17 +5,17 @@ #include // for SDL_WINDOWEVENT_SIZE_CHANGED #include // for max #include // for vector -#include "asset.h" // for Asset -#include "background.h" // for Background -#include "global_inputs.h" // for globalInputs::check -#include "input.h" // for Input -#include "jail_audio.h" // for JA_GetMusicState, JA_Music_state -#include "lang.h" // for getText -#include "options.h" // for options -#include "param.h" // for param -#include "screen.h" // for Screen -#include "text.h" // for Text, TXT_CENTER, TXT_SHADOW, TXT_COLOR -#include "utils.h" // for param_t, paramGame_t, hiScoreEntry_t +#include "asset.h" // for Asset +#include "background.h" // for Background +#include "global_inputs.h" // for globalInputs::check +#include "input.h" // for Input +#include "jail_audio.h" // for JA_GetMusicState, JA_Music_state +#include "lang.h" // for getText +#include "options.h" // for options +#include "param.h" // for param +#include "screen.h" // for Screen +#include "text.h" // for Text, TXT_CENTER, TXT_SHADOW, TXT_COLOR +#include "utils.h" // for Param, ParamGame, HiScoreEntry // Constructor HiScoreTable::HiScoreTable(JA_Music_t *music) @@ -44,7 +44,7 @@ HiScoreTable::HiScoreTable(JA_Music_t *music) fadeMode = FadeMode::IN; // Inicializa objetos - background->setPos(param.game.gameArea.rect); + background->setPos(param.game.game_area.rect); background->setCloudsSpeed(-0.1f); background->setGradientNumber(1); background->setTransition(0.8f); @@ -121,7 +121,7 @@ void HiScoreTable::fillTexture() SDL_RenderClear(renderer); // Escribe el texto: Mejores puntuaciones - text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, param.game.gameArea.centerX, firstLine, lang::getText(42), 1, orangeColor, 1, shdwTxtColor); + text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, param.game.game_area.centerX, firstLine, lang::getText(42), 1, orangeColor, 1, shdwTxtColor); // Escribe los nombres de la tabla de puntuaciones for (int i = 0; i < maxNames; ++i) @@ -136,7 +136,7 @@ void HiScoreTable::fillTexture() dots = dots + "."; } const auto line = options.game.hiScoreTable[i].name + dots + score; - text->writeDX(TXT_CENTER | TXT_SHADOW, param.game.gameArea.centerX, (i * spaceBetweenLines) + firstLine + spaceBetweenHeader, line, 1, orangeColor, 1, shdwTxtColor); + text->writeDX(TXT_CENTER | TXT_SHADOW, param.game.game_area.centerX, (i * spaceBetweenLines) + firstLine + spaceBetweenHeader, line, 1, orangeColor, 1, shdwTxtColor); } // Cambia el destino de renderizado diff --git a/source/instructions.cpp b/source/instructions.cpp index 5a7fb83..ea76c07 100644 --- a/source/instructions.cpp +++ b/source/instructions.cpp @@ -18,7 +18,7 @@ #include "text.h" // for Text, TXT_CENTER, TXT_COLOR, TXT_SHADOW #include "texture.h" // for Texture #include "tiled_bg.h" // for Tiledbg, TILED_MODE_STATIC -#include "utils.h" // for param_t, paramGame_t, color_t, shdwT... +#include "utils.h" // for Param, ParamGame, Color, shdwT... struct JA_Music_t; // Constructor @@ -98,8 +98,8 @@ void Instructions::iniSprites() // Inicializa los sprites for (int i = 0; i < (int)itemTextures.size(); ++i) { - auto sprite = std::make_unique(0, 0, param.game.itemSize, param.game.itemSize, itemTextures[i]); - sprite->setPos((SDL_Point){spritePos.x, spritePos.y + ((param.game.itemSize + itemSpace) * i)}); + auto sprite = std::make_unique(0, 0, param.game.item_size, param.game.item_size, itemTextures[i]); + sprite->setPos((SDL_Point){spritePos.x, spritePos.y + ((param.game.item_size + itemSpace) * i)}); sprites.push_back(std::move(sprite)); } } @@ -107,33 +107,33 @@ void Instructions::iniSprites() // Actualiza los sprites void Instructions::updateSprites() { - SDL_Rect srcRect = {0, 0, param.game.itemSize, param.game.itemSize}; + SDL_Rect srcRect = {0, 0, param.game.item_size, param.game.item_size}; // Disquito - srcRect.y = param.game.itemSize * (((counter + 12) / 36) % 2); + srcRect.y = param.game.item_size * (((counter + 12) / 36) % 2); sprites[0]->setSpriteClip(srcRect); // Gavineixon - srcRect.y = param.game.itemSize * (((counter + 9) / 36) % 2); + srcRect.y = param.game.item_size * (((counter + 9) / 36) % 2); sprites[1]->setSpriteClip(srcRect); // Pacmar - srcRect.y = param.game.itemSize * (((counter + 6) / 36) % 2); + srcRect.y = param.game.item_size * (((counter + 6) / 36) % 2); sprites[2]->setSpriteClip(srcRect); // Time Stopper - srcRect.y = param.game.itemSize * (((counter + 3) / 36) % 2); + srcRect.y = param.game.item_size * (((counter + 3) / 36) % 2); sprites[3]->setSpriteClip(srcRect); // Coffee - srcRect.y = param.game.itemSize * (((counter + 0) / 36) % 2); + srcRect.y = param.game.item_size * (((counter + 0) / 36) % 2); sprites[4]->setSpriteClip(srcRect); } // Rellena la textura de texto void Instructions::fillTexture() { - const int despX = param.game.itemSize + 8; + const int despX = param.game.item_size + 8; // Modifica el renderizador para pintar en la textura SDL_Texture *temp = SDL_GetRenderTarget(renderer); @@ -152,7 +152,7 @@ void Instructions::fillTexture() const int spacePostHeader = 20; const int spacePreHeader = 28; const int spaceBetweenLines = text->getCharacterSize() * 1.5f; - const int spaceBetweenItemLines = param.game.itemSize + itemSpace; + const int spaceBetweenItemLines = param.game.item_size + itemSpace; const int spaceNewParagraph = spaceBetweenLines * 0.5f; const int size = (numLines * spaceBetweenLines) + (numItemLines * spaceBetweenItemLines) + (numPostHeaders * spacePostHeader) + (numPreHeaders * spacePreHeader) + (spaceNewParagraph); @@ -168,20 +168,20 @@ void Instructions::fillTexture() const int anchorItem = (param.game.width - (lenght + despX)) / 2; // Escribe el texto de las instrucciones - text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, param.game.gameArea.centerX, firstLine, lang::getText(11), 1, orangeColor, 1, shdwTxtColor); + text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, param.game.game_area.centerX, firstLine, lang::getText(11), 1, orangeColor, 1, shdwTxtColor); const int anchor1 = firstLine + spacePostHeader; - text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, param.game.gameArea.centerX, anchor1 + spaceBetweenLines * 0, lang::getText(12), 1, noColor, 1, shdwTxtColor); - text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, param.game.gameArea.centerX, anchor1 + spaceBetweenLines * 1, lang::getText(13), 1, noColor, 1, shdwTxtColor); - text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, param.game.gameArea.centerX, anchor1 + spaceNewParagraph + spaceBetweenLines * 2, lang::getText(14), 1, noColor, 1, shdwTxtColor); - text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, param.game.gameArea.centerX, anchor1 + spaceNewParagraph + spaceBetweenLines * 3, lang::getText(15), 1, noColor, 1, shdwTxtColor); + text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, param.game.game_area.centerX, anchor1 + spaceBetweenLines * 0, lang::getText(12), 1, noColor, 1, shdwTxtColor); + text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, param.game.game_area.centerX, anchor1 + spaceBetweenLines * 1, lang::getText(13), 1, noColor, 1, shdwTxtColor); + text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, param.game.game_area.centerX, anchor1 + spaceNewParagraph + spaceBetweenLines * 2, lang::getText(14), 1, noColor, 1, shdwTxtColor); + text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, param.game.game_area.centerX, anchor1 + spaceNewParagraph + spaceBetweenLines * 3, lang::getText(15), 1, noColor, 1, shdwTxtColor); // Escribe el texto de los objetos y sus puntos const int anchor2 = anchor1 + spacePreHeader + spaceNewParagraph + spaceBetweenLines * 3; - text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, param.game.gameArea.centerX, anchor2, lang::getText(16), 1, orangeColor, 1, shdwTxtColor); + text->writeDX(TXT_CENTER | TXT_COLOR | TXT_SHADOW, param.game.game_area.centerX, anchor2, lang::getText(16), 1, orangeColor, 1, shdwTxtColor); const int anchor3 = anchor2 + spacePostHeader; - // const int anchor4 = anchor3 + ((param.game.itemSize + text->getCharacterSize()) / 2); + // const int anchor4 = anchor3 + ((param.game.item_size + text->getCharacterSize()) / 2); text->writeShadowed(anchorItem + despX, anchor3 + spaceBetweenItemLines * 0, lang::getText(17), shdwTxtColor); text->writeShadowed(anchorItem + despX, anchor3 + spaceBetweenItemLines * 1, lang::getText(18), shdwTxtColor); text->writeShadowed(anchorItem + despX, anchor3 + spaceBetweenItemLines * 2, lang::getText(19), shdwTxtColor); @@ -193,7 +193,7 @@ void Instructions::fillTexture() // Da valor a la variable spritePos.x = anchorItem; - spritePos.y = anchor3 - ((param.game.itemSize - text->getCharacterSize()) / 2); + spritePos.y = anchor3 - ((param.game.item_size - text->getCharacterSize()) / 2); } // Rellena el backbuffer diff --git a/source/intro.cpp b/source/intro.cpp index 8c90708..d0b9a66 100644 --- a/source/intro.cpp +++ b/source/intro.cpp @@ -14,7 +14,7 @@ #include "smart_sprite.h" // for SmartSprite #include "text.h" // for Text #include "texture.h" // for Texture -#include "utils.h" // for paramGame_t, param_t, zone_t, BLOCK +#include "utils.h" // for ParamGame, Param, Zone, BLOCK #include "writer.h" // for Writer struct JA_Music_t; @@ -44,13 +44,13 @@ Intro::Intro(JA_Music_t *music) ss->setWidth(128); ss->setHeight(96); ss->setFinishedCounter(20); - ss->setDestX(param.game.gameArea.centerX - 64); - ss->setDestY(param.game.gameArea.firstQuarterY - 24); + ss->setDestX(param.game.game_area.centerX - 64); + ss->setDestY(param.game.game_area.firstQuarterY - 24); bitmaps.push_back(std::move(ss)); } bitmaps[0]->setPosX(-128); - bitmaps[0]->setPosY(param.game.gameArea.firstQuarterY - 24); + bitmaps[0]->setPosY(param.game.game_area.firstQuarterY - 24); bitmaps[0]->setVelX(0.0f); bitmaps[0]->setVelY(0.0f); bitmaps[0]->setAccelX(0.6f); @@ -58,14 +58,14 @@ Intro::Intro(JA_Music_t *music) bitmaps[0]->setSpriteClip(0, 0, 128, 96); bitmaps[1]->setPosX(param.game.width); - bitmaps[1]->setPosY(param.game.gameArea.firstQuarterY - 24); + bitmaps[1]->setPosY(param.game.game_area.firstQuarterY - 24); bitmaps[1]->setVelX(-1.0f); bitmaps[1]->setVelY(0.0f); bitmaps[1]->setAccelX(-0.3f); bitmaps[1]->setAccelY(0.0f); bitmaps[1]->setSpriteClip(128, 0, 128, 96); - bitmaps[2]->setPosX(param.game.gameArea.centerX - 64); + bitmaps[2]->setPosX(param.game.game_area.centerX - 64); bitmaps[2]->setPosY(-96); bitmaps[2]->setVelX(0.0f); bitmaps[2]->setVelY(3.0f); @@ -74,7 +74,7 @@ Intro::Intro(JA_Music_t *music) bitmaps[2]->setSpriteClip(0, 96, 128, 96); bitmaps[2]->setFinishedCounter(250); - bitmaps[3]->setPosX(param.game.gameArea.centerX - 64); + bitmaps[3]->setPosX(param.game.game_area.centerX - 64); bitmaps[3]->setPosY(param.game.height); bitmaps[3]->setVelX(0.0f); bitmaps[3]->setVelY(-0.7f); @@ -82,7 +82,7 @@ Intro::Intro(JA_Music_t *music) bitmaps[3]->setAccelY(0.0f); bitmaps[3]->setSpriteClip(128, 96, 128, 96); - bitmaps[4]->setPosX(param.game.gameArea.centerX - 64); + bitmaps[4]->setPosX(param.game.game_area.centerX - 64); bitmaps[4]->setPosY(-96); bitmaps[4]->setVelX(0.0f); bitmaps[4]->setVelY(3.0f); @@ -91,7 +91,7 @@ Intro::Intro(JA_Music_t *music) bitmaps[4]->setSpriteClip(0, 192, 128, 96); bitmaps[5]->setPosX(param.game.width); - bitmaps[5]->setPosY(param.game.gameArea.firstQuarterY - 24); + bitmaps[5]->setPosY(param.game.game_area.firstQuarterY - 24); bitmaps[5]->setVelX(-0.7f); bitmaps[5]->setVelY(0.0f); bitmaps[5]->setAccelX(0.0f); @@ -149,7 +149,7 @@ Intro::Intro(JA_Music_t *music) for (auto &text : texts) { - text->center(param.game.gameArea.centerX); + text->center(param.game.game_area.centerX); } } diff --git a/source/item.cpp b/source/item.cpp index 6b70e95..4a64f3f 100644 --- a/source/item.cpp +++ b/source/item.cpp @@ -48,9 +48,9 @@ void Item::allignTo(int x) { posX = float(x - (width / 2)); - if (posX < param.game.playArea.rect.x) + if (posX < param.game.play_area.rect.x) { - posX = param.game.playArea.rect.x + 1; + posX = param.game.play_area.rect.x + 1; } else if ((posX + width) > playArea->w) { @@ -95,7 +95,7 @@ void Item::move() velY += accelY; // Si queda fuera de pantalla, corregimos su posición y cambiamos su sentido - if ((posX < param.game.playArea.rect.x) || (posX + width > playArea->w)) + if ((posX < param.game.play_area.rect.x) || (posX + width > playArea->w)) { // Corregir posición posX -= velX; @@ -105,10 +105,10 @@ void Item::move() } // Si se sale por arriba rebota (excepto la maquina de café) - if ((posY < param.game.playArea.rect.y) && !(kind == ITEM_COFFEE_MACHINE)) + if ((posY < param.game.play_area.rect.y) && !(kind == ITEM_COFFEE_MACHINE)) { // Corrige - posY = param.game.playArea.rect.y; + posY = param.game.play_area.rect.y; // Invierte el sentido velY = -velY; @@ -203,7 +203,7 @@ bool Item::isEnabled() } // Obtiene el circulo de colisión -circle_t &Item::getCollider() +Circle &Item::getCollider() { return collider; } diff --git a/source/item.h b/source/item.h index 706812c..6f2af4e 100644 --- a/source/item.h +++ b/source/item.h @@ -1,11 +1,11 @@ #pragma once -#include // for SDL_Rect -#include // for Uint16 -#include // for string -#include // for vector +#include // for SDL_Rect +#include // for Uint16 +#include // for string +#include // for vector #include -#include "utils.h" // for circle_t +#include "utils.h" // for Circle #include "animated_sprite.h" #include "texture.h" @@ -37,8 +37,8 @@ private: bool floorCollision; // Indica si el objeto colisiona con el suelo int kind; // Especifica el tipo de objeto que es bool enabled; // Especifica si el objeto está habilitado - circle_t collider; // Circulo de colisión del objeto - SDL_Rect *playArea; // Rectangulo con la zona de juego + Circle collider; // Circulo de colisión del objeto + SDL_Rect *playArea; // Rectangulo con la zona de juego // Alinea el circulo de colisión con la posición del objeto void shiftColliders(); @@ -92,7 +92,7 @@ public: bool isEnabled(); // Obtiene el circulo de colisión - circle_t &getCollider(); + Circle &getCollider(); // Informa si el objeto ha colisionado con el suelo bool isOnFloor(); diff --git a/source/logo.cpp b/source/logo.cpp index 3027474..db06117 100644 --- a/source/logo.cpp +++ b/source/logo.cpp @@ -34,8 +34,8 @@ Logo::Logo() endLogo_cm = 400; postLogoDuration = 20; speed = 8; - dest.x = param.game.gameArea.centerX - jailTexture->getWidth() / 2; - dest.y = param.game.gameArea.centerY - jailTexture->getHeight() / 2; + dest.x = param.game.game_area.centerX - jailTexture->getWidth() / 2; + dest.y = param.game.game_area.centerY - jailTexture->getHeight() / 2; sinceSprite->setPosY(dest.y + jailTexture->getHeight() + 5); sinceSprite->setSpriteClip(0, 0, sinceTexture->getWidth(), sinceTexture->getHeight()); sinceSprite->setEnabled(false); @@ -147,29 +147,28 @@ void Logo::updateJAILGAMES() // Gestiona el color de las texturas void Logo::updateTextureColors() { - constexpr int inc = 4; + constexpr int inc = 4; - // Manejo de 'sinceTexture' - for (int i = 0; i <= 7; ++i) - { - if (counter == showSinceSprite_cm + inc * i) - { - sinceTexture->setColor(color[i].r, color[i].g, color[i].b); - } - } + // Manejo de 'sinceTexture' + for (int i = 0; i <= 7; ++i) + { + if (counter == showSinceSprite_cm + inc * i) + { + sinceTexture->setColor(color[i].r, color[i].g, color[i].b); + } + } - // Manejo de 'jailTexture' y 'sinceTexture' en el fade - for (int i = 0; i <= 6; ++i) - { - if (counter == initFade_cm + inc * i) - { - jailTexture->setColor(color[6 - i].r, color[6 - i].g, color[6 - i].b); - sinceTexture->setColor(color[6 - i].r, color[6 - i].g, color[6 - i].b); - } - } + // Manejo de 'jailTexture' y 'sinceTexture' en el fade + for (int i = 0; i <= 6; ++i) + { + if (counter == initFade_cm + inc * i) + { + jailTexture->setColor(color[6 - i].r, color[6 - i].g, color[6 - i].b); + sinceTexture->setColor(color[6 - i].r, color[6 - i].g, color[6 - i].b); + } + } } - // Actualiza las variables void Logo::update() { diff --git a/source/logo.h b/source/logo.h index 8d38f4b..df0a050 100644 --- a/source/logo.h +++ b/source/logo.h @@ -5,7 +5,7 @@ #include // for Uint32 #include // for vector #include -#include "utils.h" // for color_t +#include "utils.h" // for Color #include "sprite.h" #include "texture.h" @@ -28,16 +28,16 @@ private: std::vector> jailSprite; // Vector con los sprites de cada linea que forman el bitmap JAILGAMES // Variables - std::vector color; // Vector con los colores para el fade - int counter; // Contador - Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa - Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa - int showSinceSprite_cm; // Tiempo del contador en el que empieza a verse el sprite de "SINCE 1998" - int initFade_cm; // Tiempo del contador cuando inicia el fade a negro - int endLogo_cm; // Tiempo del contador para terminar el logo - int postLogoDuration; // Tiempo que dura el logo con el fade al maximo - int speed; // Velocidad de desplazamiento de cada linea - SDL_Point dest; // Posición X donde dibujar el logo + std::vector color; // Vector con los colores para el fade + int counter; // Contador + Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa + Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa + int showSinceSprite_cm; // Tiempo del contador en el que empieza a verse el sprite de "SINCE 1998" + int initFade_cm; // Tiempo del contador cuando inicia el fade a negro + int endLogo_cm; // Tiempo del contador para terminar el logo + int postLogoDuration; // Tiempo que dura el logo con el fade al maximo + int speed; // Velocidad de desplazamiento de cada linea + SDL_Point dest; // Posición X donde dibujar el logo // Actualiza las variables void update(); diff --git a/source/manage_hiscore_table.cpp b/source/manage_hiscore_table.cpp index 00088bf..b4e0d5b 100644 --- a/source/manage_hiscore_table.cpp +++ b/source/manage_hiscore_table.cpp @@ -4,13 +4,12 @@ #include // for free, malloc #include // for sort #include // for basic_ostream, char_traits, operator<< -#include "utils.h" // for hiScoreEntry_t +#include "utils.h" // for HiScoreEntry // Constructor -ManageHiScoreTable::ManageHiScoreTable(std::vector *table) +ManageHiScoreTable::ManageHiScoreTable(std::vector *table) : table(table) {} - // Resetea la tabla a los valores por defecto void ManageHiScoreTable::clear() { @@ -31,7 +30,7 @@ void ManageHiScoreTable::clear() } // Añade un elemento a la tabla -void ManageHiScoreTable::add(hiScoreEntry_t entry) +void ManageHiScoreTable::add(HiScoreEntry entry) { // Añade la entrada a la tabla table->push_back(entry); @@ -51,7 +50,7 @@ void ManageHiScoreTable::sort() { struct { - bool operator()(hiScoreEntry_t a, hiScoreEntry_t b) const { return a.score > b.score; } + bool operator()(HiScoreEntry a, HiScoreEntry b) const { return a.score > b.score; } } customLess; std::sort(table->begin(), table->end(), customLess); diff --git a/source/manage_hiscore_table.h b/source/manage_hiscore_table.h index b365268..d3d8083 100644 --- a/source/manage_hiscore_table.h +++ b/source/manage_hiscore_table.h @@ -1,13 +1,13 @@ #pragma once -#include // for string -#include // for vector -struct hiScoreEntry_t; +#include // for string +#include // for vector +struct HiScoreEntry; /* Esta clase sirve para añadir elementos hiScoreEntry_r a un vector (tabla), de manera que la tabla siempre está ordenada. - + Además tiene un método para dejar la tabla con sus valores iniciales y métodos para leer y escribir la tabla a un fichero */ @@ -17,14 +17,14 @@ class ManageHiScoreTable { private: // Variables - std::vector *table; // Tabla con los records + std::vector *table; // Tabla con los records // Ordena la tabla void sort(); public: // Constructor - ManageHiScoreTable(std::vector *table); + ManageHiScoreTable(std::vector *table); // Destructor ~ManageHiScoreTable() = default; @@ -33,7 +33,7 @@ public: void clear(); // Añade un elemento a la tabla - void add(hiScoreEntry_t entry); + void add(HiScoreEntry entry); // Carga la tabla con los datos de un fichero bool loadFromFile(std::string filePath); diff --git a/source/notify.cpp b/source/notify.cpp index 977d220..a7d8855 100644 --- a/source/notify.cpp +++ b/source/notify.cpp @@ -265,7 +265,7 @@ void Notify::showText(std::string text1, std::string text2, int icon) } // Escribe el texto de la notificación - color_t color = {255, 255, 255}; + Color color = {255, 255, 255}; if (numTexts == 2) { // Dos lineas de texto text->writeColored(paddingIn + iconSpace, paddingIn, text1, color); diff --git a/source/notify.h b/source/notify.h index cb0c5d2..5c2cd8f 100644 --- a/source/notify.h +++ b/source/notify.h @@ -5,7 +5,7 @@ #include // for basic_string, string #include // for vector #include -#include "utils.h" // for color_t +#include "utils.h" // for Color #include "text.h" #include "texture.h" #include "sprite.h" @@ -62,7 +62,7 @@ private: std::unique_ptr text; // Objeto para dibujar texto // Variables - color_t bgColor; // Color de fondo de las notificaciones + 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 diff --git a/source/on_screen_help.cpp b/source/on_screen_help.cpp index 04bb64e..a6f4f1d 100644 --- a/source/on_screen_help.cpp +++ b/source/on_screen_help.cpp @@ -10,7 +10,7 @@ #include "sprite.h" // for Sprite #include "text.h" // for Text #include "texture.h" // for Texture -#include "utils.h" // for easeInOutSine, paramGame_t, param_t +#include "utils.h" // for easeInOutSine, ParamGame, Param // [SINGLETON] Hay que definir las variables estáticas, desde el .h sólo la hemos declarado OnScreenHelp *OnScreenHelp::onScreenHelp = nullptr; diff --git a/source/options.cpp b/source/options.cpp index d3d7f22..34a335c 100644 --- a/source/options.cpp +++ b/source/options.cpp @@ -7,10 +7,10 @@ #include "input.h" // for inputs_e, INPUT_USE_ANY, INPUT_... #include "lang.h" // for lang_e #include "screen.h" // for ScreenVideoMode, ScreenFilter -#include "utils.h" // for op_controller_t, options_t, op_... +#include "utils.h" // for OptionsController, Options, op_... // Variables -options_t options; +Options options; // Declaraciones bool setOptions(std::string var, std::string value); @@ -34,7 +34,7 @@ void initOptions() options.notification.posV = pos_top; options.notification.posH = pos_left; options.notification.sound = false; - options.notification.color = (color_t){48, 48, 48}; + options.notification.color = (Color){48, 48, 48}; // Opciones de audio options.audio.music.enabled = true; @@ -49,7 +49,7 @@ void initOptions() // Opciones de control options.controller.clear(); - op_controller_t c; + OptionsController c; const int numPlayers = 2; for (int index = 0; index < numPlayers; ++index) diff --git a/source/options.h b/source/options.h index 0bb4818..4b31c05 100644 --- a/source/options.h +++ b/source/options.h @@ -1,10 +1,10 @@ #pragma once -#include // for string -struct options_t; +#include // for string +struct Options; // Variables -extern options_t options; +extern Options options; // Carga el fichero de configuración bool loadOptionsFile(std::string filePath); diff --git a/source/param.cpp b/source/param.cpp index 7e9455e..0689518 100644 --- a/source/param.cpp +++ b/source/param.cpp @@ -1,9 +1,9 @@ #include "param.h" -#include // for char_traits, basic_ostream, basic_ifstream, basi... -#include // for cout -#include "utils.h" // for param_t, paramGame_t, zone_t, paramBalloon_t +#include // for char_traits, basic_ostream, basic_ifstream, basi... +#include // for cout +#include "utils.h" // for Param, ParamGame, Zone, ParamBalloon -param_t param; +Param param; // Asigna variables a partir de dos cadenas bool setParams(std::string var, std::string value); @@ -17,41 +17,41 @@ void initParam() // GAME param.game.width = 320; param.game.height = 256; - param.game.itemSize = 20; - param.game.gameArea.rect = {0, 0, param.game.width, param.game.height}; - param.game.playArea.rect = {0, 0, param.game.width, 216}; + param.game.item_size = 20; + param.game.game_area.rect = {0, 0, param.game.width, param.game.height}; + param.game.play_area.rect = {0, 0, param.game.width, 216}; precalculateZones(); // SCOREBOARD param.scoreboard = {0, 216, param.game.width, 40}; // FADE - param.fade.numSquaresWidth = param.game.width / 2; - param.fade.numSquaresHeight = param.game.height / 2; - param.fade.randomSquaresDelay = 1; - param.fade.randomSquaresMult = 500; - param.fade.postDuration = 80; - param.fade.venetianSize = 16; + param.fade.num_squares_width = param.game.width / 2; + param.fade.num_squares_height = param.game.height / 2; + param.fade.random_squares_delay = 1; + param.fade.random_squares_mult = 500; + param.fade.post_duration = 80; + param.fade.venetian_size = 16; // TITLE - param.title.pressStartPosition = 160; - param.title.titleDuration = 800; - param.title.arcadeEditionPosition = 123; - param.title.titleCCPosition = 11; + param.title.press_start_position = 160; + param.title.title_duration = 800; + param.title.arcade_edition_position = 123; + param.title.title_c_c_position = 11; // BACKGROUND - param.background.attenuateColor = {255, 255, 255}; - param.background.attenuateAlpha = 32; + param.background.attenuate_color = {255, 255, 255}; + param.background.attenuate_alpha = 32; // BALLOONS - param.balloon1.vel = 2.60f; - param.balloon1.grav = 0.09f; - param.balloon2.vel = 3.50f; - param.balloon2.grav = 0.10f; - param.balloon3.vel = 4.50f; - param.balloon3.grav = 0.10f; - param.balloon4.vel = 4.95f; - param.balloon4.grav = 0.10f; + param.balloon_1.vel = 2.60f; + param.balloon_1.grav = 0.09f; + param.balloon_2.vel = 3.50f; + param.balloon_2.grav = 0.10f; + param.balloon_3.vel = 4.50f; + param.balloon_3.grav = 0.10f; + param.balloon_4.vel = 4.95f; + param.balloon_4.grav = 0.10f; } // Establece valores para los parametros a partir de un fichero de texto @@ -168,60 +168,60 @@ bool setParams(std::string var, std::string value) param.game.height = std::stoi(value); } - else if (var == "game.itemSize") + else if (var == "game.item_size") { - param.game.itemSize = std::stoi(value); + param.game.item_size = std::stoi(value); } - else if (var == "game.playArea.rect.x") + else if (var == "game.play_area.rect.x") { - param.game.playArea.rect.x = std::stoi(value); + param.game.play_area.rect.x = std::stoi(value); } - else if (var == "game.playArea.rect.y") + else if (var == "game.play_area.rect.y") { - param.game.playArea.rect.y = std::stoi(value); + param.game.play_area.rect.y = std::stoi(value); } - else if (var == "game.playArea.rect.w") + else if (var == "game.play_area.rect.w") { - param.game.playArea.rect.w = std::stoi(value); + param.game.play_area.rect.w = std::stoi(value); } - else if (var == "game.playArea.rect.h") + else if (var == "game.play_area.rect.h") { - param.game.playArea.rect.h = std::stoi(value); + param.game.play_area.rect.h = std::stoi(value); } // FADE - else if (var == "fade.numSquaresWidth") + else if (var == "fade.num_squares_width") { - param.fade.numSquaresWidth = std::stoi(value); + param.fade.num_squares_width = std::stoi(value); } - else if (var == "fade.numSquaresHeight") + else if (var == "fade.num_squares_height") { - param.fade.numSquaresHeight = std::stoi(value); + param.fade.num_squares_height = std::stoi(value); } - else if (var == "fade.randomSquaresDelay") + else if (var == "fade.random_squares_delay") { - param.fade.randomSquaresDelay = std::stoi(value); + param.fade.random_squares_delay = std::stoi(value); } - else if (var == "fade.randomSquaresMult") + else if (var == "fade.random_squares_mult") { - param.fade.randomSquaresMult = std::stoi(value); + param.fade.random_squares_mult = std::stoi(value); } - else if (var == "fade.postDuration") + else if (var == "fade.post_duration") { - param.fade.postDuration = std::stoi(value); + param.fade.post_duration = std::stoi(value); } - else if (var == "fade.venetianSize") + else if (var == "fade.venetian_size") { - param.fade.venetianSize = std::stoi(value); + param.fade.venetian_size = std::stoi(value); } // SCOREBOARD @@ -246,86 +246,86 @@ bool setParams(std::string var, std::string value) } // TITLE - else if (var == "title.pressStartPosition") + else if (var == "title.press_start_position") { - param.title.pressStartPosition = std::stoi(value); + param.title.press_start_position = std::stoi(value); } - else if (var == "title.titleDuration") + else if (var == "title.title_duration") { - param.title.titleDuration = std::stoi(value); + param.title.title_duration = std::stoi(value); } - else if (var == "title.arcadeEditionPosition") + else if (var == "title.arcade_edition_position") { - param.title.arcadeEditionPosition = std::stoi(value); + param.title.arcade_edition_position = std::stoi(value); } - else if (var == "title.titleCCPosition") + else if (var == "title.title_c_c_position") { - param.title.titleCCPosition = std::stoi(value); + param.title.title_c_c_position = std::stoi(value); } // BACKGROUND - else if (var == "background.attenuateColor.r") + else if (var == "background.attenuate_color.r") { - param.background.attenuateColor.r = std::stoi(value); + param.background.attenuate_color.r = std::stoi(value); } - else if (var == "background.attenuateColor.g") + else if (var == "background.attenuate_color.g") { - param.background.attenuateColor.g = std::stoi(value); + param.background.attenuate_color.g = std::stoi(value); } - else if (var == "background.attenuateColor.b") + else if (var == "background.attenuate_color.b") { - param.background.attenuateColor.b = std::stoi(value); + param.background.attenuate_color.b = std::stoi(value); } - else if (var == "background.attenuateAlpha") + else if (var == "background.attenuate_alpha") { - param.background.attenuateAlpha = std::stoi(value); + param.background.attenuate_alpha = std::stoi(value); } // BALLOON - else if (var == "balloon1.vel") + else if (var == "balloon_1.vel") { - param.balloon1.vel = std::stof(value); + param.balloon_1.vel = std::stof(value); } - else if (var == "balloon1.grav") + else if (var == "balloon_1.grav") { - param.balloon1.grav = std::stof(value); + param.balloon_1.grav = std::stof(value); } - else if (var == "balloon2.vel") + else if (var == "balloon_2.vel") { - param.balloon2.vel = std::stof(value); + param.balloon_2.vel = std::stof(value); } - else if (var == "balloon2.grav") + else if (var == "balloon_2.grav") { - param.balloon2.grav = std::stof(value); + param.balloon_2.grav = std::stof(value); } - else if (var == "balloon3.vel") + else if (var == "balloon_3.vel") { - param.balloon3.vel = std::stof(value); + param.balloon_3.vel = std::stof(value); } - else if (var == "balloon3.grav") + else if (var == "balloon_3.grav") { - param.balloon3.grav = std::stof(value); + param.balloon_3.grav = std::stof(value); } - else if (var == "balloon4.vel") + else if (var == "balloon_4.vel") { - param.balloon4.vel = std::stof(value); + param.balloon_4.vel = std::stof(value); } - else if (var == "balloon4.grav") + else if (var == "balloon_4.grav") { - param.balloon4.grav = std::stof(value); + param.balloon_4.grav = std::stof(value); } // RESTO @@ -341,19 +341,19 @@ bool setParams(std::string var, std::string value) void precalculateZones() { // playArea - param.game.playArea.centerX = param.game.playArea.rect.w / 2; - param.game.playArea.firstQuarterX = param.game.playArea.rect.w / 4; - param.game.playArea.thirdQuarterX = param.game.playArea.rect.w / 4 * 3; - param.game.playArea.centerY = param.game.playArea.rect.h / 2; - param.game.playArea.firstQuarterY = param.game.playArea.rect.h / 4; - param.game.playArea.thirdQuarterY = param.game.playArea.rect.h / 4 * 3; + param.game.play_area.center_x = param.game.play_area.rect.w / 2; + param.game.play_area.first_quarter_x = param.game.play_area.rect.w / 4; + param.game.play_area.third_quarter_x = param.game.play_area.rect.w / 4 * 3; + param.game.play_area.center_y = param.game.play_area.rect.h / 2; + param.game.play_area.first_quarter_y = param.game.play_area.rect.h / 4; + param.game.play_area.third_quarter_y = param.game.play_area.rect.h / 4 * 3; // gameArea - param.game.gameArea.rect = {0, 0, param.game.width, param.game.height}; - param.game.gameArea.centerX = param.game.gameArea.rect.w / 2; - param.game.gameArea.firstQuarterX = param.game.gameArea.rect.w / 4; - param.game.gameArea.thirdQuarterX = param.game.gameArea.rect.w / 4 * 3; - param.game.gameArea.centerY = param.game.gameArea.rect.h / 2; - param.game.gameArea.firstQuarterY = param.game.gameArea.rect.h / 4; - param.game.gameArea.thirdQuarterY = param.game.gameArea.rect.h / 4 * 3; + param.game.game_area.rect = {0, 0, param.game.width, param.game.height}; + param.game.game_area.center_x = param.game.game_area.rect.w / 2; + param.game.game_area.first_quarter_x = param.game.game_area.rect.w / 4; + param.game.game_area.third_quarter_x = param.game.game_area.rect.w / 4 * 3; + param.game.game_area.center_y = param.game.game_area.rect.h / 2; + param.game.game_area.first_quarter_y = param.game.game_area.rect.h / 4; + param.game.game_area.third_quarter_y = param.game.game_area.rect.h / 4 * 3; } \ No newline at end of file diff --git a/source/param.h b/source/param.h index 77004f9..f0f9530 100644 --- a/source/param.h +++ b/source/param.h @@ -1,9 +1,9 @@ #pragma once -#include // for string -struct param_t; +#include // for string +struct Param; -extern param_t param; +extern Param param; // Establece valores para los parametros a partir de un fichero de texto -void loadParamsFromFile(std::string filePath); \ No newline at end of file +void loadParamsFromFile(std::string file_path); \ No newline at end of file diff --git a/source/player.cpp b/source/player.cpp index b8ad76f..daccd15 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -168,7 +168,7 @@ void Player::move() posX += velX; // Si el jugador abandona el area de juego por los laterales - if ((posX < param.game.playArea.rect.x - 5) || (posX + width > playArea->w + 5)) + if ((posX < param.game.play_area.rect.x - 5) || (posX + width > playArea->w + 5)) { // Restaura su posición posX -= velX; @@ -185,7 +185,7 @@ void Player::move() playerSprite->update(); // Si el cadaver abandona el area de juego por los laterales - if ((playerSprite->getPosX() < param.game.playArea.rect.x) || (playerSprite->getPosX() + width > playArea->w)) + if ((playerSprite->getPosX() < param.game.play_area.rect.x) || (playerSprite->getPosX() + width > playArea->w)) { // Restaura su posición const float vx = playerSprite->getVelX(); @@ -196,7 +196,7 @@ void Player::move() } // Si el cadaver abandona el area de juego por abajo - if (playerSprite->getPosY() > param.game.playArea.rect.h) + if (playerSprite->getPosY() > param.game.play_area.rect.h) { setStatusPlaying(PlayerStatus::DIED); } @@ -666,7 +666,7 @@ int Player::getCoffees() const } // Obtiene el circulo de colisión -circle_t &Player::getCollider() +Circle &Player::getCollider() { return collider; } diff --git a/source/player.h b/source/player.h index 396b4d8..5e7fb1e 100644 --- a/source/player.h +++ b/source/player.h @@ -7,8 +7,8 @@ #include // for vector #include "animated_sprite.h" // for AnimatedSprite #include "enter_name.h" // for EnterName -#include "utils.h" // for circle_t -#include "texture.h" // lines 12-12 +#include "utils.h" // for Circle +#include "texture.h" // lines 12-12 enum class ScoreboardMode; // Estados del jugador @@ -71,7 +71,7 @@ private: int powerUpCounter; // Temporizador para el modo PowerUp int powerUpDespX; // Desplazamiento del sprite de PowerUp respecto al sprite del jugador bool input; // Indica si puede recibir ordenes de entrada - circle_t collider; // Circulo de colisión del jugador + Circle collider; // Circulo de colisión del jugador int continueCounter; // Contador para poder continuar Uint32 continueTicks; // Variable para poder cambiar el contador de continue en función del tiempo int scoreBoardPanel; // Panel del marcador asociado al jugador @@ -256,7 +256,7 @@ public: int getCoffees() const; // Obtiene el circulo de colisión - circle_t &getCollider(); + Circle &getCollider(); // Obtiene el valor de la variable int getContinueCounter() const; diff --git a/source/scoreboard.cpp b/source/scoreboard.cpp index 52db3d1..62ab662 100644 --- a/source/scoreboard.cpp +++ b/source/scoreboard.cpp @@ -190,7 +190,7 @@ void Scoreboard::setHiScoreName(std::string name) } // Establece el valor de la variable -void Scoreboard::setColor(color_t color) +void Scoreboard::setColor(Color color) { this->color = color; fillBackgroundTexture(); diff --git a/source/scoreboard.h b/source/scoreboard.h index bae650f..f69ccfc 100644 --- a/source/scoreboard.h +++ b/source/scoreboard.h @@ -6,10 +6,10 @@ #include // for unique_ptr #include // for string, basic_string #include // for vector -#include "utils.h" // for color_t -#include "sprite.h" // lines 11-11 -#include "text.h" // lines 12-12 -#include "texture.h" // lines 13-13 +#include "utils.h" // for Color +#include "sprite.h" // lines 11-11 +#include "text.h" // lines 12-12 +#include "texture.h" // lines 13-13 // Defines constexpr int SCOREBOARD_LEFT_PANEL = 0; @@ -66,7 +66,7 @@ private: int hiScore; // Máxima puntuación float power; // Poder actual de la fase std::string hiScoreName; // Nombre del jugador con la máxima puntuación - color_t color; // Color del marcador + Color color; // Color del marcador SDL_Rect rect; // Posición y dimensiones del marcador panel_t panel[SCOREBOARD_MAX_PANELS]; // Lista con todos los paneles del marcador Uint32 ticks; // Variable donde almacenar el valor de SDL_GetTiks() @@ -155,7 +155,7 @@ public: void setHiScoreName(std::string name); // Establece el valor de la variable - void setColor(color_t color); + void setColor(Color color); // Establece el valor de la variable void setPos(SDL_Rect rect); diff --git a/source/screen.cpp b/source/screen.cpp index a44ca7c..6b7bde1 100644 --- a/source/screen.cpp +++ b/source/screen.cpp @@ -104,7 +104,7 @@ Screen::~Screen() } // Limpia la pantalla -void Screen::clean(color_t color) +void Screen::clean(Color color) { SDL_SetRenderDrawColor(renderer, color.r, color.g, color.b, 0xFF); SDL_RenderClear(renderer); @@ -272,7 +272,7 @@ void Screen::incWindowSize() } // Cambia el color del borde -void Screen::setBorderColor(color_t color) +void Screen::setBorderColor(Color color) { borderColor = color; } @@ -405,7 +405,7 @@ void Screen::updateShake() } // Pone la pantalla de color -void Screen::flash(color_t color, int lenght) +void Screen::flash(Color color, int lenght) { flashEffect.enabled = true; flashEffect.counter = 0; diff --git a/source/screen.h b/source/screen.h index 0597671..8f5608a 100644 --- a/source/screen.h +++ b/source/screen.h @@ -6,7 +6,7 @@ #include // for Uint32 #include // for SDL_Window #include // for basic_string, string -#include "utils.h" // for color_t +#include "utils.h" // for Color #include class Asset; class Input; @@ -42,7 +42,7 @@ private: // Variables SDL_Rect srcrect; // Coordenadas de donde va a pillar la textura del juego para dibujarla SDL_Rect dstrect; // Coordenadas donde se va a dibujar la textura del juego sobre la pantalla o ventana - color_t borderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla + Color borderColor; // Color del borde añadido a la textura de juego para rellenar la pantalla bool attenuateEffect; // Indica si la pantalla ha de estar atenuada Uint32 fpsTicks; // Ticks para contar los frames por segundo int fpsCounter; // Contador de frames por segundo @@ -52,10 +52,10 @@ private: struct effect_t { - bool enabled; // Indica si el efecto está activo - int counter; // Contador para el efecto - int lenght; // Duración del efecto - color_t color; // Color del efecto + bool enabled; // Indica si el efecto está activo + int counter; // Contador para el efecto + int lenght; // Duración del efecto + Color color; // Color del efecto }; // Variables - Efectos @@ -113,7 +113,7 @@ public: void checkInput(); // Limpia la pantalla - void clean(color_t color = {0x00, 0x00, 0x00}); + void clean(Color color = {0x00, 0x00, 0x00}); // Prepara para empezar a dibujar en la textura de juego void start(); @@ -137,7 +137,7 @@ public: void incWindowSize(); // Cambia el color del borde - void setBorderColor(color_t color); + void setBorderColor(Color color); // Cambia el tipo de mezcla void setBlendMode(SDL_BlendMode blendMode); @@ -146,7 +146,7 @@ public: void shake(); // Pone la pantalla de color - void flash(color_t color, int lenght); + void flash(Color color, int lenght); // Activa/desactiva los shaders void switchShaders(); diff --git a/source/text.cpp b/source/text.cpp index 8518b80..5174a41 100644 --- a/source/text.cpp +++ b/source/text.cpp @@ -3,7 +3,7 @@ #include // for cout #include "sprite.h" // for Sprite #include "texture.h" // for Texture -#include "utils.h" // for color_t +#include "utils.h" // for Color // Llena una estructuta textFile_t desde un fichero textFile_t LoadTextFile(std::string file) @@ -167,7 +167,7 @@ void Text::write(int x, int y, std::string text, int kerning, int lenght) } // Escribe el texto con colores -void Text::writeColored(int x, int y, std::string text, color_t color, int kerning, int lenght) +void Text::writeColored(int x, int y, std::string text, Color color, int kerning, int lenght) { sprite->getTexture()->setColor(color.r, color.g, color.b); write(x, y, text, kerning, lenght); @@ -175,7 +175,7 @@ void Text::writeColored(int x, int y, std::string text, color_t color, int kerni } // Escribe el texto con sombra -void Text::writeShadowed(int x, int y, std::string text, color_t color, Uint8 shadowDistance, int kerning, int lenght) +void Text::writeShadowed(int x, int y, std::string text, Color color, Uint8 shadowDistance, int kerning, int lenght) { sprite->getTexture()->setColor(color.r, color.g, color.b); write(x + shadowDistance, y + shadowDistance, text, kerning, lenght); @@ -191,7 +191,7 @@ void Text::writeCentered(int x, int y, std::string text, int kerning, int lenght } // Escribe texto con extras -void Text::writeDX(Uint8 flags, int x, int y, std::string text, int kerning, color_t textColor, Uint8 shadowDistance, color_t shadowColor, int lenght) +void Text::writeDX(Uint8 flags, int x, int y, std::string text, int kerning, Color textColor, Uint8 shadowDistance, Color shadowColor, int lenght) { const bool centered = ((flags & TXT_CENTER) == TXT_CENTER); const bool shadowed = ((flags & TXT_SHADOW) == TXT_SHADOW); diff --git a/source/text.h b/source/text.h index 46fc58d..5c49872 100644 --- a/source/text.h +++ b/source/text.h @@ -1,8 +1,8 @@ #pragma once -#include // for SDL_Renderer -#include // for Uint8 -#include // for string +#include // for SDL_Renderer +#include // for Uint8 +#include // for string #include #include "utils.h" #include "sprite.h" @@ -55,16 +55,16 @@ public: void write(int x, int y, std::string text, int kerning = 1, int lenght = -1); // Escribe el texto con colores - void writeColored(int x, int y, std::string text, color_t color, int kerning = 1, int lenght = -1); + void writeColored(int x, int y, std::string text, Color color, int kerning = 1, int lenght = -1); // Escribe el texto con sombra - void writeShadowed(int x, int y, std::string text, color_t color, Uint8 shadowDistance = 1, int kerning = 1, int lenght = -1); + void writeShadowed(int x, int y, std::string text, Color color, Uint8 shadowDistance = 1, int kerning = 1, int lenght = -1); // Escribe el texto centrado en un punto x void writeCentered(int x, int y, std::string text, int kerning = 1, int lenght = -1); // Escribe texto con extras - void writeDX(Uint8 flags, int x, int y, std::string text, int kerning = 1, color_t textColor = {255, 255, 255}, Uint8 shadowDistance = 1, color_t shadowColor = {0, 0, 0}, int lenght = -1); + void writeDX(Uint8 flags, int x, int y, std::string text, int kerning = 1, Color textColor = {255, 255, 255}, Uint8 shadowDistance = 1, Color shadowColor = {0, 0, 0}, int lenght = -1); // Obtiene la longitud en pixels de una cadena int lenght(std::string text, int kerning = 1); diff --git a/source/title.cpp b/source/title.cpp index d5dc791..e9828ec 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -36,11 +36,11 @@ Title::Title(JA_Music_t *music) text2 = std::make_unique(asset->get("8bithud.png"), asset->get("8bithud.txt"), renderer); miniLogoTexture = std::make_shared(renderer, asset->get("logo_jailgames_mini.png")); - miniLogoSprite = std::make_unique(param.game.gameArea.centerX - miniLogoTexture->getWidth() / 2, 0, miniLogoTexture->getWidth(), miniLogoTexture->getHeight(), miniLogoTexture); + miniLogoSprite = std::make_unique(param.game.game_area.centerX - miniLogoTexture->getWidth() / 2, 0, miniLogoTexture->getWidth(), miniLogoTexture->getHeight(), miniLogoTexture); tiledbg = std::make_unique(asset->get("title_bg_tile.png"), (SDL_Rect){0, 0, param.game.width, param.game.height}, TILED_MODE_RANDOM); - gameLogo = std::make_unique(param.game.gameArea.centerX, param.title.titleCCPosition); + gameLogo = std::make_unique(param.game.game_area.centerX, param.title.titleCCPosition); gameLogo->enable(); defineButtons = std::make_unique(std::move(text2)); @@ -148,12 +148,12 @@ void Title::render() if (section::options == section::OPTIONS_TITLE_2) { - constexpr color_t shadow = {0x14, 0x87, 0xc4}; + constexpr Color shadow = {0x14, 0x87, 0xc4}; // 'PRESS TO PLAY' if (counter % 50 > 14 && !defineButtons->isEnabled()) { - text1->writeDX(TXT_CENTER | TXT_SHADOW, param.game.gameArea.centerX, param.title.pressStartPosition, lang::getText(23), 1, noColor, 1, shadow); + text1->writeDX(TXT_CENTER | TXT_SHADOW, param.game.game_area.centerX, param.title.pressStartPosition, lang::getText(23), 1, noColor, 1, shadow); } // Mini logo @@ -163,7 +163,7 @@ void Title::render() miniLogoSprite->render(); // Texto con el copyright - text1->writeDX(TXT_CENTER | TXT_SHADOW, param.game.gameArea.centerX, pos2, TEXT_COPYRIGHT, 1, noColor, 1, shadow); + text1->writeDX(TXT_CENTER | TXT_SHADOW, param.game.game_area.centerX, pos2, TEXT_COPYRIGHT, 1, noColor, 1, shadow); } // Define Buttons diff --git a/source/title.h b/source/title.h index f3ca992..e5173ba 100644 --- a/source/title.h +++ b/source/title.h @@ -8,7 +8,7 @@ #include "game_logo.h" #include "text.h" #include "tiled_bg.h" -#include "utils.h" // for section_t +#include "utils.h" // for Section #include "sprite.h" #include "texture.h" @@ -62,13 +62,13 @@ private: JA_Music_t *music; // Musica para el titulo // Variable - int counter; // Temporizador para la pantalla de titulo - Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa - bool demo; // Indica si el modo demo estará activo - section_t nextSection; // Indica cual es la siguiente sección a cargar cuando termine el contador del titulo - Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa - int postFade; // Opción a realizar cuando termina el fundido - int numControllers; // Número de mandos conectados + int counter; // Temporizador para la pantalla de titulo + Uint32 ticks; // Contador de ticks para ajustar la velocidad del programa + bool demo; // Indica si el modo demo estará activo + Section nextSection; // Indica cual es la siguiente sección a cargar cuando termine el contador del titulo + Uint32 ticksSpeed; // Velocidad a la que se repiten los bucles del programa + int postFade; // Opción a realizar cuando termina el fundido + int numControllers; // Número de mandos conectados // Inicializa los valores de las variables void init(); diff --git a/source/utils.cpp b/source/utils.cpp index 38c66ab..e8fdc10 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -4,39 +4,39 @@ #include // for isspace #include // for distance #include -struct JA_Music_t; // lines 3-3 -struct JA_Sound_t; // lines 4-4 +struct JA_Music_t; // lines 3-3 +struct JA_Sound_t; // lines 4-4 // Colores -const color_t bgColor = {0x27, 0x27, 0x36}; -const color_t noColor = {0xFF, 0xFF, 0xFF}; -const color_t shdwTxtColor = {0x43, 0x43, 0x4F}; -const color_t separatorColor = {0x0D, 0x1A, 0x2B}; -const color_t scoreboardColor = {0x2E, 0x3F, 0x47}; -const color_t difficultyEasyColor = {0x4B, 0x69, 0x2F}; -const color_t difficultyNormalColor = {0xFF, 0x7A, 0x00}; -const color_t difficultyHardColor = {0x76, 0x42, 0x8A}; -const color_t flashColor = {0xFF, 0xFF, 0xFF}; -const color_t fadeColor = {0x27, 0x27, 0x36}; -const color_t orangeColor = {0xFF, 0x7A, 0x00}; +const Color bg_color = {0x27, 0x27, 0x36}; +const Color no_color = {0xFF, 0xFF, 0xFF}; +const Color shdw_txt_color = {0x43, 0x43, 0x4F}; +const Color separator_color = {0x0D, 0x1A, 0x2B}; +const Color scoreboard_color = {0x2E, 0x3F, 0x47}; +const Color difficulty_easy_color = {0x4B, 0x69, 0x2F}; +const Color difficulty_normal_color = {0xFF, 0x7A, 0x00}; +const Color difficulty_hard_color = {0x76, 0x42, 0x8A}; +const Color flash_color = {0xFF, 0xFF, 0xFF}; +const Color fade_color = {0x27, 0x27, 0x36}; +const Color orange_color = {0xFF, 0x7A, 0x00}; // Calcula el cuadrado de la distancia entre dos puntos double distanceSquared(int x1, int y1, int x2, int y2) { - const int deltaX = x2 - x1; - const int deltaY = y2 - y1; - return deltaX * deltaX + deltaY * deltaY; + const int delta_x = x2 - x1; + const int delta_y = y2 - y1; + return delta_x * delta_x + delta_y * delta_y; } // Detector de colisiones entre dos circulos -bool checkCollision(circle_t &a, circle_t &b) +bool checkCollision(Circle &a, Circle &b) { // Calcula el radio total al cuadrado - int totalRadiusSquared = a.r + b.r; - totalRadiusSquared = totalRadiusSquared * totalRadiusSquared; + int total_radius_squared = a.r + b.r; + total_radius_squared = total_radius_squared * total_radius_squared; // Si la distancia entre el centro de los circulos es inferior a la suma de sus radios - if (distanceSquared(a.x, a.y, b.x, b.y) < (totalRadiusSquared)) + if (distanceSquared(a.x, a.y, b.x, b.y) < (total_radius_squared)) { // Los circulos han colisionado return true; @@ -47,7 +47,7 @@ bool checkCollision(circle_t &a, circle_t &b) } // Detector de colisiones entre un circulo y un rectangulo -bool checkCollision(circle_t &a, SDL_Rect &b) +bool checkCollision(Circle &a, SDL_Rect &b) { // Closest point on collision box int cX, cY; @@ -80,10 +80,10 @@ bool checkCollision(circle_t &a, SDL_Rect &b) cY = a.y; } - // If the closest point is inside the circle_t + // If the closest point is inside the Circle if (distanceSquared(a.x, a.y, cX, cY) < a.r * a.r) { - // This box and the circle_t have collided + // This box and the Circle have collided return true; } @@ -197,7 +197,7 @@ std::string toLower(std::string str) } // Obtiene el fichero de sonido a partir de un nombre -JA_Sound_t *getSound(std::vector sounds, std::string name) +JA_Sound_t *getSound(std::vector sounds, std::string name) { for (auto s : sounds) { @@ -211,7 +211,7 @@ JA_Sound_t *getSound(std::vector sounds, std::string name) } // Obtiene el fichero de música a partir de un nombre -JA_Music_t *getMusic(std::vector music, std::string name) +JA_Music_t *getMusic(std::vector music, std::string name) { for (auto m : music) { @@ -225,7 +225,7 @@ JA_Music_t *getMusic(std::vector music, std::string name) } // Ordena las entradas de la tabla de records -hiScoreEntry_t sortHiScoreTable(hiScoreEntry_t entry1, hiScoreEntry_t entry2) +HiScoreEntry sortHiScoreTable(HiScoreEntry entry1, HiScoreEntry entry2) { if (entry1.score > entry2.score) { @@ -275,9 +275,9 @@ void DrawCircle(SDL_Renderer *renderer, int32_t centerX, int32_t centerY, int32_ } // Aclara el color -color_t lightenColor(color_t color, int amount) +Color lightenColor(Color color, int amount) { - color_t newColor; + Color newColor; newColor.r = std::min(255, (int)color.r + amount); newColor.g = std::min(255, (int)color.g + amount); newColor.b = std::min(255, (int)color.b + amount); @@ -285,9 +285,9 @@ color_t lightenColor(color_t color, int amount) } // Oscurece el color -color_t DarkenColor(color_t color, int amount) +Color DarkenColor(Color color, int amount) { - color_t newColor; + Color newColor; newColor.r = std::max(0, (int)color.r - amount); newColor.g = std::max(0, (int)color.g - amount); newColor.b = std::max(0, (int)color.b - amount); @@ -319,6 +319,7 @@ double easeOutQuint(double t) } // Función de suavizado -double easeInOutSine(double t) { +double easeInOutSine(double t) +{ return -0.5 * (std::cos(M_PI * t) - 1); } \ No newline at end of file diff --git a/source/utils.h b/source/utils.h index 8d875e9..d590a93 100644 --- a/source/utils.h +++ b/source/utils.h @@ -25,128 +25,104 @@ enum class GameDifficulty #define BLOCK 8 // Estructura para definir un circulo -struct circle_t +struct Circle { int x, y, r; }; -// Estructura para definir una linea horizontal -struct h_line_t -{ - int x1, x2, y; -}; - -// Estructura para definir una linea vertical -struct v_line_t -{ - int x, y1, y2; -}; - -// Estructura para definir una linea diagonal -struct d_line_t -{ - int x1, y1, x2, y2; -}; - -// Estructura para definir una linea -struct line_t -{ - int x1, y1, x2, y2; -}; - // Estructura para definir un color -struct color_t +struct Color { Uint8 r, g, b; }; // Posiciones de las notificaciones -enum not_pos_e +enum class NotifyPosition { - pos_top, - pos_bottom, - pos_left, - pos_middle, - pos_right + TOP, + BOTTOM, + LEFT, + MIDDLE, + RIGHT, }; // Estructura para saber la seccion y subseccion del programa -struct section_t +struct Section { Uint8 name; Uint8 options; }; // Estructura para las entradas de la tabla de recirds -struct hiScoreEntry_t +struct HiScoreEntry { std::string name; // Nombre int score; // Puntuación }; // Estructura para mapear el teclado usado en la demo -struct demoKeys_t +struct DemoKeys { Uint8 left; Uint8 right; - Uint8 noInput; + Uint8 no_input; Uint8 fire; - Uint8 fireLeft; - Uint8 fireRight; + Uint8 fire_left; + Uint8 fire_right; }; // Estructura para las opciones de la ventana -struct op_window_t +struct OptionsWindow { int size; // Contiene el valor por el que se multiplica el tamaño de la ventana }; // Estructura con opciones para el video -struct op_video_t +struct OptionsVideo { - op_window_t window; // Opciones para la ventana del programa + OptionsWindow window; // Opciones para la ventana del programa ScreenVideoMode mode; // Contiene el valor del modo de pantalla completa ScreenFilter filter; // Filtro usado para el escalado de la imagen - bool vSync; // Indica si se quiere usar vsync o no + bool v_sync; // Indica si se quiere usar vsync o no bool shaders; // Indica si se van a usar shaders para los filtros de video }; // Estructura para las opciones de musica -struct op_music_t +struct OptionsMusic { bool enabled; // Indica si la musica suena o no int volume; // Volumen al que suena la música }; // Estructura para las opciones de sonido -struct op_sound_t +struct OptionsSound { bool enabled; // Indica si los sonidos suenan o no int volume; // Volumen al que suenan los sonidos }; // Estructura para las opciones de audio -struct op_audio_t +struct OptionsAudio { - op_music_t music; // Opciones para la música - op_sound_t sound; // Opciones para los efectos de sonido + OptionsMusic music; // Opciones para la música + OptionsSound sound; // Opciones para los efectos de sonido }; // Estructura para las opciones del juego -struct op_game_t +struct OptionsGame { GameDifficulty difficulty; // Dificultad del juego Uint8 language; // Idioma usado en el juego bool autofire; // Indica si el jugador ha de pulsar repetidamente para disparar o basta con mantener pulsado - std::vector hiScoreTable; // Tabla con las mejores puntuaciones + std::vector hi_score_table; // Tabla con las mejores puntuaciones }; // Estructura para los controles del juego -struct op_controller_t +struct OptionsController { int index; // Indice en el vector de mandos - int playerId; // Jugador asociado al mando - Uint8 deviceType; // Indica si se utilizará teclado o mando o ambos + int player_id; // Jugador asociado al mando + Uint8 device_type; // Indica si se utilizará teclado o mando o ambos std::string name; // Nombre del dispositivo bool plugged; // Indica si el mando se encuentra conectado std::vector inputs; // Listado de inputs @@ -154,100 +130,100 @@ struct op_controller_t }; // Estructura para las opciones de las notificaciones -struct op_notification_t +struct OptionsNotification { - not_pos_e posH; // Ubicación de las notificaciones en pantalla - not_pos_e posV; // Ubicación de las notificaciones en pantalla - bool sound; // Indica si las notificaciones suenan - color_t color; // Color de las notificaciones + NotifyPosition pos_h; // Ubicación de las notificaciones en pantalla + NotifyPosition pos_v; // Ubicación de las notificaciones en pantalla + bool sound; // Indica si las notificaciones suenan + Color color; // Color de las notificaciones }; // Estructura con todas las opciones de configuración del programa -struct options_t +struct Options { - op_game_t game; // Opciones para el propio juego - op_video_t video; // Opciones relativas a la clase screen - op_audio_t audio; // Opciones para el audio - op_notification_t notification; // Opciones para las notificaciones - std::vector controller; // Opciones con las asignaciones del mando para cada jugador + OptionsGame game; // Opciones para el propio juego + OptionsVideo video; // Opciones relativas a la clase screen + OptionsAudio audio; // Opciones para el audio + OptionsNotification notification; // Opciones para las notificaciones + std::vector controller; // Opciones con las asignaciones del mando para cada jugador }; // Posiciones dentro de un rectangulo -struct zone_t +struct Zone { - SDL_Rect rect; // Rectangulo que define la zona - int centerX; // Anclaje al 50% del eje X - int firstQuarterX; // Anclaje al 25% del eje X - int thirdQuarterX; // Anclaje al 75% del eje X - int centerY; // Anclaje al 50% del eje Y - int firstQuarterY; // Anclaje al 25% del eje Y - int thirdQuarterY; // Anclaje al 75% del eje X + SDL_Rect rect; // Rectangulo que define la zona + int center_x; // Anclaje al 50% del eje X + int first_quarter_x; // Anclaje al 25% del eje X + int third_quarter_x; // Anclaje al 75% del eje X + int center_y; // Anclaje al 50% del eje Y + int first_quarter_y; // Anclaje al 25% del eje Y + int third_quarter_y; // Anclaje al 75% del eje X }; // param.game -struct paramGame_t +struct ParamGame { - int width; // Ancho de la resolucion nativa del juego - int height; // Alto de la resolucion nativa del juego - int itemSize; // Tamaño de los items del juego - zone_t playArea; // Rectangulo con la posición de la zona de juego - zone_t gameArea; // Rectangulo con las dimensiones del juego + int width; // Ancho de la resolucion nativa del juego + int height; // Alto de la resolucion nativa del juego + int item_size; // Tamaño de los items del juego + Zone play_area; // Rectangulo con la posición de la zona de juego + Zone game_area; // Rectangulo con las dimensiones del juego }; // param.fade -struct paramFade_t +struct ParamFade { - int numSquaresWidth; // Cantidad total de cuadraditos en horizontal para el FadeType::RANDOM_SQUARE - int numSquaresHeight; // Cantidad total de cuadraditos en vertical para el FadeType::RANDOM_SQUARE - int randomSquaresDelay; // Duración entre cada pintado de cuadrados - int randomSquaresMult; // Cantidad de cuadrados que se pintaran cada vez - int postDuration; // Duración final del fade - int venetianSize; // Altura de los rectangulos para FadeType::VENETIAN + int num_squares_width; // Cantidad total de cuadraditos en horizontal para el FadeType::RANDOM_SQUARE + int num_squares_height; // Cantidad total de cuadraditos en vertical para el FadeType::RANDOM_SQUARE + int random_squares_delay; // Duración entre cada pintado de cuadrados + int random_squares_mult; // Cantidad de cuadrados que se pintaran cada vez + int post_duration; // Duración final del fade + int venetian_size; // Altura de los rectangulos para FadeType::VENETIAN }; // param.title -struct paramTitle_t +struct ParamTitle { - int pressStartPosition; // Posición del texto para empezar a jugar - int titleDuration; // Tiempo de inactividad del titulo - int arcadeEditionPosition; // Posición del bitmap - int titleCCPosition; // Posición del bitmap + int press_start_position; // Posición del texto para empezar a jugar + int title_duration; // Tiempo de inactividad del titulo + int arcade_edition_position; // Posición del bitmap + int title_c_c_position; // Posición del bitmap }; // param.background -struct paramBackground_t +struct ParamBackground { - color_t attenuateColor; - int attenuateAlpha; + Color attenuate_color; + int attenuate_alpha; }; // Estructura para guardar los parametros de un globo -struct paramBalloon_t +struct ParamBalloon { float grav; // Aceleración en el eje Y. Modifica la velocidad float vel; // Velocidad inicial que tienen al rebotar contra el suelo }; // Estructura para almacenar todos los parámetros del juego -struct param_t +struct Param { - paramGame_t game; // Parametros relacionados con el juego - paramFade_t fade; // Parametros para ajustar el fade - SDL_Rect scoreboard; // Posición y tamaño del marcador - paramTitle_t title; // Parametros con ajustes para la sección Title - paramBackground_t background; // Parametros que afectan a la clase Background - paramBalloon_t balloon1, balloon2, balloon3, balloon4; // Parametros de velocidad y gravedad de cada tipo de globo + ParamGame game; // Parametros relacionados con el juego + ParamFade fade; // Parametros para ajustar el fade + SDL_Rect scoreboard; // Posición y tamaño del marcador + ParamTitle title; // Parametros con ajustes para la sección Title + ParamBackground background; // Parametros que afectan a la clase Background + ParamBalloon balloon_1, balloon_2, balloon_3, balloon_4; // Parametros de velocidad y gravedad de cada tipo de globo }; // Estructura para almacenar ficheros de sonido y su nombre -struct sound_file_t +struct SoundFile { std::string name; // Nombre del sonido JA_Sound_t *file; // Fichero con el sonido }; // Estructura para almacenar ficheros musicales y su nombre -struct music_file_t +struct MusicFile { std::string name; // Nombre de la musica JA_Music_t *file; // Fichero con la música @@ -257,10 +233,10 @@ struct music_file_t double distanceSquared(int x1, int y1, int x2, int y2); // Detector de colisiones entre dos circulos -bool checkCollision(circle_t &a, circle_t &b); +bool checkCollision(Circle &a, Circle &b); // Detector de colisiones entre un circulo y un rectangulo -bool checkCollision(circle_t &a, SDL_Rect &b); +bool checkCollision(Circle &a, SDL_Rect &b); // Detector de colisiones entre un dos rectangulos bool checkCollision(SDL_Rect &a, SDL_Rect &b); @@ -281,22 +257,22 @@ std::string boolToOnOff(bool value); std::string toLower(std::string str); // Obtiene el fichero de sonido a partir de un nombre -JA_Sound_t *getSound(std::vector sounds, std::string name); +JA_Sound_t *getSound(std::vector sounds, std::string name); // Obtiene el fichero de música a partir de un nombre -JA_Music_t *getMusic(std::vector music, std::string name); +JA_Music_t *getMusic(std::vector music, std::string name); // Ordena las entradas de la tabla de records -hiScoreEntry_t sortHiScoreTable(hiScoreEntry_t entry1, hiScoreEntry_t entry2); +HiScoreEntry sortHiScoreTable(HiScoreEntry entry1, HiScoreEntry entry2); // Dibuja un circulo void DrawCircle(SDL_Renderer *renderer, int32_t centerX, int32_t centerY, int32_t radius); // Aclara el color -color_t lightenColor(color_t color, int amount); +Color lightenColor(Color color, int amount); // Oscurece el color -color_t DarkenColor(color_t color, int amount); +Color DarkenColor(Color color, int amount); // Quita los espacioes en un string std::string trim(const std::string &str); @@ -308,14 +284,14 @@ double easeOutQuint(double t); double easeInOutSine(double t); // Colores -extern const color_t bgColor; -extern const color_t noColor; -extern const color_t shdwTxtColor; -extern const color_t separatorColor; -extern const color_t scoreboardColor; -extern const color_t difficultyEasyColor; -extern const color_t difficultyNormalColor; -extern const color_t difficultyHardColor; -extern const color_t flashColor; -extern const color_t fadeColor; -extern const color_t orangeColor; \ No newline at end of file +extern const Color bg_color; +extern const Color no_color; +extern const Color shdw_txt_color; +extern const Color separator_color; +extern const Color scoreboard_color; +extern const Color difficulty_easy_color; +extern const Color difficulty_normal_color; +extern const Color difficulty_hard_color; +extern const Color flash_color; +extern const Color fade_color; +extern const Color orange_color; \ No newline at end of file