From a36120cf0c749d4af11cdc090054288e3c19970e Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Sun, 24 Nov 2024 20:21:46 +0100 Subject: [PATCH] Continuemtreballant enels credits --- source/balloon.h | 3 +- source/balloon_manager.cpp | 19 +++++--- source/balloon_manager.h | 7 ++- source/credits.cpp | 99 +++++++++++++++++++++++++++++--------- source/credits.h | 23 ++++++--- source/game.cpp | 4 +- source/instructions.cpp | 4 +- source/item.cpp | 12 ++--- source/path_sprite.cpp | 3 +- source/player.cpp | 20 ++++---- source/player.h | 26 +++++----- source/screen.cpp | 1 - source/stage.cpp | 3 +- source/title.cpp | 6 +-- source/title.h | 1 - 15 files changed, 149 insertions(+), 82 deletions(-) diff --git a/source/balloon.h b/source/balloon.h index e92eed2..6a4d730 100644 --- a/source/balloon.h +++ b/source/balloon.h @@ -1,12 +1,13 @@ #pragma once +#include // Para SDL_Rect #include // Para Uint8, Uint16, Uint32 #include // Para shared_ptr, unique_ptr #include // Para string #include // Para vector #include "animated_sprite.h" // Para AnimatedSprite #include "utils.h" // Para Circle -class Texture; // lines 10-10 +class Texture; // lines 9-9 // Cantidad de elementos del vector con los valores de la deformación del globo al rebotar constexpr int MAX_BOUNCE = 10; diff --git a/source/balloon_manager.cpp b/source/balloon_manager.cpp index 0ec9b14..a320ace 100644 --- a/source/balloon_manager.cpp +++ b/source/balloon_manager.cpp @@ -119,6 +119,17 @@ void BalloonManager::deployBalloonFormation(int stage) } } +void BalloonManager::deployBalloonFormation(int pool, int set_number) +{ + const auto set = balloon_formations_->getSet(pool, set_number); + const auto numEnemies = set.number_of_balloons; + for (int i = 0; i < numEnemies; ++i) + { + auto p = set.init[i]; + createBalloon(p.x, p.y, p.type, p.size, p.vel_x, balloon_speed_, p.creation_counter); + } +} + // Vacia del vector de globos los globos que ya no sirven void BalloonManager::freeBalloons() { @@ -339,13 +350,7 @@ void BalloonManager::reLoad() // Crea dos globos gordos void BalloonManager::createTwoBigBalloons() { - const auto set = balloon_formations_->getSet(0, 1); - const auto numEnemies = set.number_of_balloons; - for (int i = 0; i < numEnemies; ++i) - { - auto p = set.init[i]; - createBalloon(p.x, p.y, p.type, p.size, p.vel_x, balloon_speed_, p.creation_counter); - } + deployBalloonFormation(0, 1); } // Obtiene el nivel de ameza actual generado por los globos diff --git a/source/balloon_manager.h b/source/balloon_manager.h index 5cd9958..98ffb2a 100644 --- a/source/balloon_manager.h +++ b/source/balloon_manager.h @@ -1,13 +1,15 @@ #pragma once +#include // Para SDL_Rect #include // Para shared_ptr, unique_ptr #include // Para string #include // Para vector #include "balloon.h" // Para BALLOON_SPEED, Balloon #include "balloon_formations.h" // Para BalloonFormations #include "explosions.h" // Para Explosions -#include "param.h" -class Texture; +#include "param.h" // Para Param, ParamGame, param +#include "utils.h" // Para Zone +class Texture; // lines 10-10 using Balloons = std::vector>; @@ -53,6 +55,7 @@ public: // Crea una formación de enemigos void deployBalloonFormation(int stage); + void deployBalloonFormation(int pool, int set); // Actualiza la variable enemyDeployCounter void updateBalloonDeployCounter(); diff --git a/source/credits.cpp b/source/credits.cpp index 326d4c7..efb7b93 100644 --- a/source/credits.cpp +++ b/source/credits.cpp @@ -1,23 +1,38 @@ #include "credits.h" -#include "section.h" // Para Name, name, Options, options -#include "global_inputs.h" // Para check -#include "input.h" // Para Input -#include "jail_audio.h" // Para JA_StopMusic -#include "screen.h" // Para Screen -#include "balloon_manager.h" // Para BalloonManager -#include "param.h" -#include "resource.h" -#include "text.h" +#include // Para SDL_BLENDMODE_BLEND +#include // Para SDL_PollEvent, SDL_Event, SDL_QUIT +#include // Para SDL_PIXELFORMAT_RGBA8888 +#include // Para SDL_Rect +#include // Para SDL_GetTicks +#include // Para basic_string, string +#include // Para vector +#include "balloon_manager.h" // Para BalloonManager +#include "global_inputs.h" // Para check +#include "input.h" // Para Input +#include "jail_audio.h" // Para JA_PlayMusic, JA_StopMusic +#include "param.h" // Para Param, ParamGame, param +#include "resource.h" // Para Resource +#include "screen.h" // Para Screen +#include "section.h" // Para Name, name, Options, options +#include "text.h" // Para Text, TEXT_CENTER, TEXT_SHADOW +#include "tiled_bg.h" // Para TiledBG, TiledBGMode +#include "utils.h" // Para Color, no_color, shdw_txt_color, Zone + +// Textos +constexpr const char TEXT_COPYRIGHT[] = "@2020,2024 JailDesigner"; // Constructor Credits::Credits() : balloon_manager_(std::make_unique()), text_texture_(SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)), - tiled_bg_(std::make_unique((SDL_Rect){0, 0, param.game.width, param.game.height}, TiledBGMode::DIAGONAL)) + tiled_bg_(std::make_unique(param.game.game_area.rect, TiledBGMode::DIAGONAL)) { section::name = section::Name::CREDITS; balloon_manager_->setPlayArea(param.game.game_area.rect); balloon_manager_->createTwoBigBalloons(); + balloon_manager_->deployBalloonFormation(4,2); + balloon_manager_->deployBalloonFormation(4,5); + balloon_manager_->createPowerBall(); SDL_SetTextureBlendMode(text_texture_, SDL_BLENDMODE_BLEND); fillTextTexture(); JA_PlayMusic(Resource::get()->getMusic("credits.ogg")); @@ -51,7 +66,9 @@ void Credits::update() ticks_ = SDL_GetTicks(); tiled_bg_->update(); balloon_manager_->update(); + updateRects(); Screen::get()->update(); + ++counter_; } } @@ -64,9 +81,10 @@ void Credits::render() // Limpia la pantalla Screen::get()->clean(); - tiled_bg_->render(); + tiled_bg_->render(); balloon_manager_->render(); - SDL_RenderCopy(Screen::get()->getRenderer(), text_texture_, nullptr, nullptr); + SDL_RenderCopy(Screen::get()->getRenderer(), text_texture_, &credits_rect_src_, &credits_rect_dst_); + SDL_RenderCopy(Screen::get()->getRenderer(), text_texture_, &mini_logo_rect_src_, &mini_logo_rect_dst_); // Vuelca el contenido del renderizador en pantalla Screen::get()->blit(); @@ -129,42 +147,77 @@ void Credits::fillTextTexture() const int space_post_title = 3 + text->getCharacterSize(); const int space_pre_title = text->getCharacterSize() * 3; const int texts_height = 1 * text->getCharacterSize() + 7 * space_post_title + 3 * space_pre_title; + credits_rect_dst_.h = credits_rect_src_.h = texts_height; int y = (param.game.height - texts_height) / 2; + y = 0; text->setPalette(1); - text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.width / 2, y, texts.at(0), 1, no_color, 1, shdw_txt_color); + text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(0), 1, no_color, 1, shdw_txt_color); text->setPalette(0); y += space_post_title; - text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.width / 2, y, texts.at(4), 1, no_color, 1, shdw_txt_color); + text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(4), 1, no_color, 1, shdw_txt_color); y += space_pre_title; text->setPalette(1); - text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.width / 2, y, texts.at(1), 1, no_color, 1, shdw_txt_color); + text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(1), 1, no_color, 1, shdw_txt_color); text->setPalette(0); y += space_post_title; - text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.width / 2, y, texts.at(4), 1, no_color, 1, shdw_txt_color); + text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(4), 1, no_color, 1, shdw_txt_color); y += space_pre_title; text->setPalette(1); - text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.width / 2, y, texts.at(2), 1, no_color, 1, shdw_txt_color); + text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(2), 1, no_color, 1, shdw_txt_color); text->setPalette(0); y += space_post_title; - text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.width / 2, y, texts.at(5), 1, no_color, 1, shdw_txt_color); + text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(5), 1, no_color, 1, shdw_txt_color); y += space_post_title; - text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.width / 2, y, texts.at(6), 1, no_color, 1, shdw_txt_color); + text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(6), 1, no_color, 1, shdw_txt_color); y += space_pre_title; text->setPalette(1); - text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.width / 2, y, texts.at(3), 1, no_color, 1, shdw_txt_color); + text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(3), 1, no_color, 1, shdw_txt_color); text->setPalette(0); y += space_post_title; - text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.width / 2, y, texts.at(7), 1, no_color, 1, shdw_txt_color); + text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(7), 1, no_color, 1, shdw_txt_color); y += space_post_title; - text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.width / 2, y, texts.at(8), 1, no_color, 1, shdw_txt_color); + text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(8), 1, no_color, 1, shdw_txt_color); y += space_post_title; - text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.width / 2, y, texts.at(9), 1, no_color, 1, shdw_txt_color); + text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, texts.at(9), 1, no_color, 1, shdw_txt_color); + + // Mini logo + y += space_pre_title; + mini_logo_rect_src_.y = y; + auto mini_logo_sprite = std::make_unique(Resource::get()->getTexture("logo_jailgames_mini.png")); + mini_logo_sprite->setPosition(1 + param.game.game_area.center_x - mini_logo_sprite->getWidth() / 2, 1 + y); + Resource::get()->getTexture("logo_jailgames_mini.png")->setColor(shdw_txt_color.r, shdw_txt_color.g, shdw_txt_color.b); + mini_logo_sprite->render(); + + mini_logo_sprite->setPosition(param.game.game_area.center_x - mini_logo_sprite->getWidth() / 2, y); + Resource::get()->getTexture("logo_jailgames_mini.png")->setColor(255, 255, 255); + mini_logo_sprite->render(); + + // Texto con el copyright + y += mini_logo_sprite->getHeight() + 3; + text->writeDX(TEXT_CENTER | TEXT_SHADOW, param.game.game_area.center_x, y, TEXT_COPYRIGHT, 1, no_color, 1, shdw_txt_color); + + mini_logo_rect_dst_.h = mini_logo_rect_src_.h = mini_logo_sprite->getHeight() + 3 + text->getCharacterSize(); SDL_SetRenderTarget(Screen::get()->getRenderer(), nullptr); + + credits_rect_dst_.y = param.game.game_area.rect.h; + mini_logo_rect_dst_.y = credits_rect_dst_.y + credits_rect_dst_.h + 30; + mini_logo_final_pos_ = param.game.game_area.center_y - mini_logo_rect_src_.h / 2; +} + +// Actualiza el destino de los rectangulos de las texturas +void Credits::updateRects() +{ + if (counter_ % 10 == 0) + { + --credits_rect_dst_.y; + --mini_logo_rect_dst_.y; + } + mini_logo_rect_dst_.y = std::max(mini_logo_rect_dst_.y, mini_logo_final_pos_); } \ No newline at end of file diff --git a/source/credits.h b/source/credits.h index a0f9676..b1e0b24 100644 --- a/source/credits.h +++ b/source/credits.h @@ -1,9 +1,11 @@ #pragma once -#include "SDL2/SDL.h" -#include -#include "balloon_manager.h" -#include "texture.h" -#include "tiled_bg.h" + +#include // Para SDL_Texture +#include // Para Uint32 +#include // Para unique_ptr +#include "param.h" +class BalloonManager; +class TiledBG; class Credits { @@ -14,7 +16,13 @@ private: std::unique_ptr tiled_bg_; // Objeto para dibujar el mosaico animado de fondo // Variables - Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa + Uint32 ticks_ = 0; // Contador de ticks para ajustar la velocidad del programa + Uint32 counter_ = 0; // Contador para la lógica de la clase + SDL_Rect credits_rect_src_ = param.game.game_area.rect; // Rectangulo con el texto de los créditos (origen) + SDL_Rect credits_rect_dst_ = param.game.game_area.rect; // Rectangulo con el texto de los créditos (destino) + SDL_Rect mini_logo_rect_src_ = param.game.game_area.rect; // Rectangulo con el mini logo de JailGames y el texto de copyright (origen) + SDL_Rect mini_logo_rect_dst_ = param.game.game_area.rect; // Rectangulo con el mini logo de JailGames y el texto de copyright (destino) + int mini_logo_final_pos_ = 0; // Actualiza las variables void update(); @@ -31,6 +39,9 @@ private: // Crea la textura con el texto void fillTextTexture(); + // Actualiza el destino de los rectangulos de las texturas + void updateRects(); + public: // Constructor Credits(); diff --git a/source/game.cpp b/source/game.cpp index abe0c12..d688912 100644 --- a/source/game.cpp +++ b/source/game.cpp @@ -14,6 +14,7 @@ #include "balloon.h" // Para Balloon, BALLOON_SPEED #include "balloon_manager.h" // Para BalloonManager #include "bullet.h" // Para Bullet, BulletType, BulletMoveStatus +#include "enter_name.h" // Para NAME_LENGHT #include "fade.h" // Para Fade, FadeType #include "global_inputs.h" // Para check #include "input.h" // Para InputType, Input, INPUT_DO_NOT_ALL... @@ -30,9 +31,8 @@ #include "screen.h" // Para Screen #include "section.h" // Para Name, name, Options, options #include "smart_sprite.h" // Para SmartSprite -#include "stage.h" // Para get, number, Stage, power +#include "stage.h" // Para number, get, Stage, power, total_p... #include "text.h" // Para Text -#include "dbgtxt.h" // Para dbg_print #include "texture.h" // Para Texture struct JA_Sound_t; // lines 37-37 diff --git a/source/instructions.cpp b/source/instructions.cpp index 5f0b238..cf2f754 100644 --- a/source/instructions.cpp +++ b/source/instructions.cpp @@ -27,7 +27,7 @@ Instructions::Instructions() texture_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)), backbuffer_(SDL_CreateTexture(renderer_, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)), text_(Resource::get()->getText("smb2")), - tiled_bg_(std::make_unique((SDL_Rect){0, 0, param.game.width, param.game.height}, TiledBGMode::STATIC)), + tiled_bg_(std::make_unique(param.game.game_area.rect, TiledBGMode::STATIC)), fade_(std::make_unique()) { // Configura las texturas @@ -36,7 +36,7 @@ Instructions::Instructions() // Inicializa variables section::name = section::Name::INSTRUCTIONS; - view_ = {0, 0, param.game.width, param.game.height}; + view_ = param.game.game_area.rect; // Inicializa objetos fade_->setColor(fade_color.r, fade_color.g, fade_color.b); diff --git a/source/item.cpp b/source/item.cpp index a91bb11..109678f 100644 --- a/source/item.cpp +++ b/source/item.cpp @@ -1,9 +1,9 @@ #include "item.h" -#include // para std::clamp -#include // para rand -#include "animated_sprite.h" // para SpriteAnimated -#include "param.h" // para param -class Texture; +#include // Para rand +#include // Para clamp +#include "animated_sprite.h" // Para AnimatedSprite +#include "param.h" // Para Param, ParamGame, param +class Texture; // lines 6-6 Item::Item(ItemType type, float x, float y, SDL_Rect &play_area, std::shared_ptr texture, const std::vector &animation) : sprite_(std::make_unique(texture, animation)), @@ -73,8 +73,6 @@ void Item::render() } } -#include // Necesario para std::clamp - void Item::move() { floor_collision_ = false; diff --git a/source/path_sprite.cpp b/source/path_sprite.cpp index a3dcb53..1f3dd72 100644 --- a/source/path_sprite.cpp +++ b/source/path_sprite.cpp @@ -1,6 +1,5 @@ #include "path_sprite.h" -#include // Para abs -#include // Para abs +#include // Para abs #include // Para function #include // Para move diff --git a/source/player.cpp b/source/player.cpp index c62e14b..c13391a 100644 --- a/source/player.cpp +++ b/source/player.cpp @@ -1,15 +1,13 @@ #include "player.h" -#include // Para SDL_FLIP_HORIZONTAL, SDL_FLIP_NONE -#include // Para SDL_GetTicks -#include // Para rand -#include // Para max, min -#include "animated_sprite.h" // Para AnimatedSprite -#include "input.h" // Para InputType -#include "manage_hiscore_table.h" // Para HiScoreEntry -#include "options.h" // Para Options, OptionsGame, options -#include "param.h" // Para Param, ParamGame, param -#include "scoreboard.h" // Para Scoreboard, ScoreboardMode -#include "texture.h" // Para Texture +#include // Para SDL_FLIP_HORIZONTAL, SDL_FLIP_NONE, SDL... +#include // Para SDL_GetTicks +#include // Para rand +#include // Para clamp, max, min +#include "animated_sprite.h" // Para AnimatedSprite +#include "input.h" // Para InputType +#include "param.h" // Para Param, ParamGame, param +#include "scoreboard.h" // Para Scoreboard, ScoreboardMode +#include "texture.h" // Para Texture // Constructor Player::Player(int id, float x, int y, bool demo, SDL_Rect &play_area, std::vector> texture, const std::vector> &animations) diff --git a/source/player.h b/source/player.h index 9d20696..d97d457 100644 --- a/source/player.h +++ b/source/player.h @@ -1,18 +1,18 @@ #pragma once -#include "animated_sprite.h" // Para AnimatedSprite -#include "enter_name.h" // Para EnterName -#include "utils.h" // Para Circle -#include // Para SDL_Rect -#include // Para Uint32 -#include // Para unique_ptr, shared_ptr -#include // Para string -#include // Para vector -#include "options.h" - -class Texture; // lines 12-12 -enum class InputType : int; // lines 13-13 -enum class ScoreboardMode; // lines 14-14 +#include // Para SDL_Rect +#include // Para Uint32 +#include // Para unique_ptr, shared_ptr +#include // Para string +#include // Para vector +#include "animated_sprite.h" // Para AnimatedSprite +#include "enter_name.h" // Para EnterName +#include "manage_hiscore_table.h" // Para HiScoreEntry +#include "options.h" // Para Options, OptionsGame, options +#include "utils.h" // Para Circle +class Texture; // lines 13-13 +enum class InputType : int; // lines 14-14 +enum class ScoreboardMode; // lines 15-15 // Estados del jugador enum class PlayerState diff --git a/source/screen.cpp b/source/screen.cpp index 265534d..28f8573 100644 --- a/source/screen.cpp +++ b/source/screen.cpp @@ -11,7 +11,6 @@ #include "asset.h" // Para Asset #include "dbgtxt.h" // Para dbg_print #include "global_inputs.h" // Para service_pressed_counter -#include "jail_shader.h" // Para init, render #include "notifier.h" // Para Notifier #include "on_screen_help.h" // Para OnScreenHelp #include "options.h" // Para Options, OptionsVideo, options, Options... diff --git a/source/stage.cpp b/source/stage.cpp index 64b2077..0a8d3dd 100644 --- a/source/stage.cpp +++ b/source/stage.cpp @@ -1,5 +1,6 @@ #include "stage.h" -#include +#include // Para min +#include // Para vector namespace Stage { diff --git a/source/title.cpp b/source/title.cpp index 4cbd7c2..fce9503 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -29,15 +29,15 @@ Title::Title() : text_(Resource::get()->getText("smb2")), fade_(std::make_unique()), - tiled_bg_(std::make_unique((SDL_Rect){0, 0, param.game.width, param.game.height}, TiledBGMode::RANDOM)), + tiled_bg_(std::make_unique(param.game.game_area.rect, TiledBGMode::RANDOM)), game_logo_(std::make_unique(param.game.game_area.center_x, param.title.title_c_c_position)), - mini_logo_texture_(Resource::get()->getTexture("logo_jailgames_mini.png")), - mini_logo_sprite_(std::make_unique(mini_logo_texture_, param.game.game_area.center_x - mini_logo_texture_->getWidth() / 2, 0, mini_logo_texture_->getWidth(), mini_logo_texture_->getHeight())), + mini_logo_sprite_(std::make_unique(Resource::get()->getTexture("logo_jailgames_mini.png"))), define_buttons_(std::make_unique()), num_controllers_(Input::get()->getNumControllers()) { // Configura objetos game_logo_->enable(); + mini_logo_sprite_->setX(param.game.game_area.center_x - mini_logo_sprite_->getWidth() / 2); fade_->setColor(fade_color.r, fade_color.g, fade_color.b); fade_->setType(FadeType::RANDOM_SQUARE); fade_->setPost(param.fade.post_duration); diff --git a/source/title.h b/source/title.h index 6e0f14e..badce90 100644 --- a/source/title.h +++ b/source/title.h @@ -44,7 +44,6 @@ private: std::unique_ptr fade_; // Objeto para realizar fundidos en pantalla std::unique_ptr tiled_bg_; // Objeto para dibujar el mosaico animado de fondo std::unique_ptr game_logo_; // Objeto para dibujar el logo con el título del juego - std::shared_ptr mini_logo_texture_; // Textura con el logo de JailGames mini std::unique_ptr mini_logo_sprite_; // Sprite con el logo de JailGames mini std::unique_ptr define_buttons_; // Objeto para definir los botones del joystic