Treballant en els credits

This commit is contained in:
2024-11-25 22:56:59 +01:00
parent fd7beee5a1
commit a2d4331430
4 changed files with 187 additions and 20 deletions

View File

@@ -17,6 +17,7 @@
#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
#include "player.h"
// Textos
constexpr const char TEXT_COPYRIGHT[] = "@2020,2024 JailDesigner";
@@ -28,10 +29,10 @@ Credits::Credits()
tiled_bg_(std::make_unique<TiledBG>(param.game.game_area.rect, TiledBGMode::DIAGONAL))
{
section::name = section::Name::CREDITS;
// balloon_manager_->setPlayArea(param.game.game_area.rect);
const auto r = param.game.game_area.rect;
const int bars = 30;
balloon_manager_->setPlayArea({r.x, r.y + bars, r.w, r.h - bars});
top_black_rect_ = {play_area_.x, 0, play_area_.w, black_bars_size_};
bottom_black_rect_ = {play_area_.x, param.game.game_area.rect.h - black_bars_size_, play_area_.w, black_bars_size_};
balloon_manager_->setPlayArea(play_area_);
initPlayers();
SDL_SetTextureBlendMode(text_texture_, SDL_BLENDMODE_BLEND);
fillTextTexture();
JA_PlayMusic(Resource::get()->getMusic("credits.ogg"));
@@ -65,8 +66,13 @@ void Credits::update()
ticks_ = SDL_GetTicks();
tiled_bg_->update();
balloon_manager_->update();
updateRects();
updateTextureDstRects();
throwBalloons();
for (auto &player : players_)
{
player->update();
}
updateFinalFade();
Screen::get()->update();
++counter_;
}
@@ -81,16 +87,27 @@ void Credits::render()
// Limpia la pantalla
Screen::get()->clean();
// Dibuja el fondo, los globos y los jugadores
tiled_bg_->render();
balloon_manager_->render();
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 255);
SDL_Rect r1 = {0, 0, 320, 30};
SDL_Rect r2 = {0, 255 - 30, 320, 30};
SDL_RenderFillRect(Screen::get()->getRenderer(), &r1);
SDL_RenderFillRect(Screen::get()->getRenderer(), &r2);
for (auto const &player : players_)
{
player->render();
}
// Dibuja los titulos de credito
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_);
// Dibuja los rectangulos negros
SDL_SetRenderDrawColor(Screen::get()->getRenderer(), 0, 0, 0, 255);
SDL_RenderFillRect(Screen::get()->getRenderer(), &top_black_rect_);
SDL_RenderFillRect(Screen::get()->getRenderer(), &bottom_black_rect_);
SDL_RenderFillRect(Screen::get()->getRenderer(), &left_black_rect_);
SDL_RenderFillRect(Screen::get()->getRenderer(), &right_black_rect_);
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();
}
@@ -119,9 +136,10 @@ void Credits::checkInput()
// Comprueba si se ha pulsado cualquier botón (de los usados para jugar)
if (Input::get()->checkAnyButtonPressed())
{
JA_StopMusic();
section::name = section::Name::LOGO;
return;
// JA_StopMusic();
// section::name = section::Name::LOGO;
// return;
fading = true;
}
// Comprueba los inputs que se pueden introducir en cualquier sección del juego
@@ -150,7 +168,7 @@ void Credits::fillTextTexture()
"JAILDOCTOR"};
const int space_post_title = 3 + text->getCharacterSize();
const int space_pre_title = text->getCharacterSize() * 3;
const int space_pre_title = text->getCharacterSize() * 4;
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;
@@ -217,7 +235,7 @@ void Credits::fillTextTexture()
}
// Actualiza el destino de los rectangulos de las texturas
void Credits::updateRects()
void Credits::updateTextureDstRects()
{
if (counter_ % 10 == 0)
{
@@ -242,8 +260,91 @@ void Credits::throwBalloons()
balloon_manager_->deploySet(sets.at(index), -50);
}
if (counter_ % (speed * 4) == 0)
if (counter_ % (speed * 4) == 0 && counter_ > 0)
{
balloon_manager_->createPowerBall();
}
}
// Inicializa los jugadores
void Credits::initPlayers()
{
std::vector<std::vector<std::shared_ptr<Texture>>> player_textures; // Vector con todas las texturas de los jugadores;
std::vector<std::vector<std::string>> player_animations; // Vector con las animaciones del jugador
// Texturas - Player1
{
std::vector<std::shared_ptr<Texture>> player_texture;
player_texture.emplace_back(Resource::get()->getTexture("player1.gif"));
player_texture.emplace_back(Resource::get()->getTexture("player1_power.png"));
player_textures.push_back(player_texture);
}
// Texturas - Player2
{
std::vector<std::shared_ptr<Texture>> player_texture;
player_texture.emplace_back(Resource::get()->getTexture("player2.gif"));
player_texture.emplace_back(Resource::get()->getTexture("player2_power.png"));
player_textures.push_back(player_texture);
}
// Animaciones -- Jugador
{
player_animations.emplace_back(Resource::get()->getAnimation("player.ani"));
player_animations.emplace_back(Resource::get()->getAnimation("player_power.ani"));
}
// Crea los dos jugadores
constexpr int player_width = 30;
const int y = play_area_.h - player_width;
constexpr bool demo = false;
constexpr int away_distance = 700;
players_.emplace_back(std::make_unique<Player>(1, play_area_.x - away_distance - player_width, y, demo, play_area_, player_textures.at(0), player_animations));
players_.back()->setWalkingState(PlayerState::WALKING_RIGHT);
players_.back()->setPlayingState(PlayerState::CREDITS);
players_.back()->setInvulnerable(false);
players_.emplace_back(std::make_unique<Player>(2, play_area_.x + play_area_.w + away_distance, y, demo, play_area_, player_textures.at(1), player_animations));
players_.back()->setWalkingState(PlayerState::WALKING_LEFT);
players_.back()->setPlayingState(PlayerState::CREDITS);
players_.back()->setInvulnerable(false);
}
// Actualiza los rectangulos negros
void Credits::updateBlackRects()
{
if (top_black_rect_.h != param.game.game_area.center_y - 1 && bottom_black_rect_.y != param.game.game_area.center_y + 1)
{
// Si los rectangulos superior e inferior no han llegado al centro
if (counter_ % 4 == 0)
{
// Incrementa la altura del rectangulo superior
top_black_rect_.h = std::min(top_black_rect_.h + 1, param.game.game_area.center_y - 1);
// Incrementa la altura y modifica la posición del rectangulo inferior
++bottom_black_rect_.h;
bottom_black_rect_.y = std::max(bottom_black_rect_.y - 1, param.game.game_area.center_y + 1);
}
}
else
{
// Si los rectangulos superior e inferior han llegado al centro
{
// Incrementa la anchura del rectangulo situado a la izquierda
left_black_rect_.w = std::min(left_black_rect_.w + 4, param.game.game_area.center_x);
// Incrementa la anchura y modifica la posición del rectangulo situado a la derecha
right_black_rect_.w += 4;
right_black_rect_.x = std::max(right_black_rect_.x - 4, param.game.game_area.center_x);
}
}
}
// Actualiza el estado de fade
void Credits::updateFinalFade()
{
if (fading)
{
updateBlackRects();
}
}