pasaeta loca de clang-format (despres m'arrepentiré pero bueno)
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
// IWYU pragma: no_include <bits/std_abs.h>
|
||||
#include "credits.h"
|
||||
|
||||
#include <SDL3/SDL.h> // Para SDL_RenderFillRect, SDL_RenderTexture
|
||||
#include <SDL3/SDL.h> // Para SDL_RenderFillRect, SDL_RenderTexture
|
||||
|
||||
#include <algorithm> // Para max, min, clamp
|
||||
#include <array> // Para array
|
||||
#include <cmath> // Para abs
|
||||
@@ -9,24 +10,24 @@
|
||||
#include <string> // Para basic_string, string
|
||||
#include <vector> // Para vector
|
||||
|
||||
#include "audio.h" // Para Audio
|
||||
#include "balloon_manager.h" // Para BalloonManager
|
||||
#include "fade.h" // Para Fade, FadeType, FadeMode
|
||||
#include "global_events.h" // Para check
|
||||
#include "global_inputs.h" // Para check
|
||||
#include "input.h" // Para Input, INPUT_ALLOW_REPEAT
|
||||
#include "lang.h" // Para getText
|
||||
#include "param.h" // Para Param, param, ParamGame, ParamFade
|
||||
#include "player.h" // Para Player, PlayerState
|
||||
#include "resource.h" // Para Resource
|
||||
#include "screen.h" // Para Screen
|
||||
#include "section.h" // Para Name, name
|
||||
#include "sprite.h" // Para Sprite
|
||||
#include "text.h" // Para Text, TEXT_CENTER, TEXT_SHADOW
|
||||
#include "texture.h" // Para Texture
|
||||
#include "tiled_bg.h" // Para TiledBG, TiledBGMode
|
||||
#include "ui/service_menu.h" // Para ServiceMenu
|
||||
#include "utils.h" // Para Color, Zone, SHADOW_TEXT_COLOR, NO_TEXT...
|
||||
#include "audio.h" // Para Audio
|
||||
#include "balloon_manager.h" // Para BalloonManager
|
||||
#include "fade.h" // Para Fade, FadeType, FadeMode
|
||||
#include "global_events.h" // Para check
|
||||
#include "global_inputs.h" // Para check
|
||||
#include "input.h" // Para Input, INPUT_ALLOW_REPEAT
|
||||
#include "lang.h" // Para getText
|
||||
#include "param.h" // Para Param, param, ParamGame, ParamFade
|
||||
#include "player.h" // Para Player, PlayerState
|
||||
#include "resource.h" // Para Resource
|
||||
#include "screen.h" // Para Screen
|
||||
#include "section.h" // Para Name, name
|
||||
#include "sprite.h" // Para Sprite
|
||||
#include "text.h" // Para Text, TEXT_CENTER, TEXT_SHADOW
|
||||
#include "texture.h" // Para Texture
|
||||
#include "tiled_bg.h" // Para TiledBG, TiledBGMode
|
||||
#include "ui/service_menu.h" // Para ServiceMenu
|
||||
#include "utils.h" // Para Color, Zone, SHADOW_TEXT_COLOR, NO_TEXT...
|
||||
|
||||
// Textos
|
||||
constexpr const char TEXT_COPYRIGHT[] = "@2020,2025 JailDesigner";
|
||||
@@ -38,10 +39,8 @@ Credits::Credits()
|
||||
fade_in_(std::make_unique<Fade>()),
|
||||
fade_out_(std::make_unique<Fade>()),
|
||||
text_texture_(SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)),
|
||||
canvas_(SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height))
|
||||
{
|
||||
if (!text_texture_)
|
||||
{
|
||||
canvas_(SDL_CreateTexture(Screen::get()->getRenderer(), SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_TARGET, param.game.width, param.game.height)) {
|
||||
if (!text_texture_) {
|
||||
throw std::runtime_error("Failed to create SDL texture for text.");
|
||||
}
|
||||
Section::name = Section::Name::CREDITS;
|
||||
@@ -67,8 +66,7 @@ Credits::Credits()
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Credits::~Credits()
|
||||
{
|
||||
Credits::~Credits() {
|
||||
SDL_DestroyTexture(text_texture_);
|
||||
SDL_DestroyTexture(canvas_);
|
||||
resetVolume();
|
||||
@@ -76,26 +74,21 @@ Credits::~Credits()
|
||||
}
|
||||
|
||||
// Bucle principal
|
||||
void Credits::run()
|
||||
{
|
||||
while (Section::name == Section::Name::CREDITS)
|
||||
{
|
||||
void Credits::run() {
|
||||
while (Section::name == Section::Name::CREDITS) {
|
||||
checkInput();
|
||||
update();
|
||||
checkEvents(); // Tiene que ir antes del render
|
||||
checkEvents(); // Tiene que ir antes del render
|
||||
render();
|
||||
}
|
||||
}
|
||||
|
||||
// Actualiza las variables
|
||||
void Credits::update()
|
||||
{
|
||||
if (SDL_GetTicks() - ticks_ > param.game.speed)
|
||||
{
|
||||
void Credits::update() {
|
||||
if (SDL_GetTicks() - ticks_ > param.game.speed) {
|
||||
ticks_ = SDL_GetTicks();
|
||||
const int REPEAT = want_to_pass_ ? 4 : 1;
|
||||
for (int i = 0; i < REPEAT; ++i)
|
||||
{
|
||||
for (int i = 0; i < REPEAT; ++i) {
|
||||
tiled_bg_->update();
|
||||
cycleColors();
|
||||
balloon_manager_->update();
|
||||
@@ -113,8 +106,7 @@ void Credits::update()
|
||||
}
|
||||
|
||||
// Dibuja Credits::en patalla
|
||||
void Credits::render()
|
||||
{
|
||||
void Credits::render() {
|
||||
// Prepara para empezar a dibujar en la textura de juego
|
||||
Screen::get()->start();
|
||||
|
||||
@@ -126,30 +118,23 @@ void Credits::render()
|
||||
}
|
||||
|
||||
// Comprueba el manejador de eventos
|
||||
void Credits::checkEvents()
|
||||
{
|
||||
void Credits::checkEvents() {
|
||||
SDL_Event event;
|
||||
while (SDL_PollEvent(&event))
|
||||
{
|
||||
while (SDL_PollEvent(&event)) {
|
||||
GlobalEvents::check(event);
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba las entradas
|
||||
void Credits::checkInput()
|
||||
{
|
||||
void Credits::checkInput() {
|
||||
Input::get()->update();
|
||||
|
||||
if (!ServiceMenu::get()->isEnabled())
|
||||
{
|
||||
if (!ServiceMenu::get()->isEnabled()) {
|
||||
// Comprueba si se ha pulsado cualquier botón (de los usados para jugar)
|
||||
if (Input::get()->checkAnyButton(INPUT_ALLOW_REPEAT))
|
||||
{
|
||||
if (Input::get()->checkAnyButton(INPUT_ALLOW_REPEAT)) {
|
||||
want_to_pass_ = true;
|
||||
fading_ = mini_logo_on_position_;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
want_to_pass_ = false;
|
||||
}
|
||||
}
|
||||
@@ -159,8 +144,7 @@ void Credits::checkInput()
|
||||
}
|
||||
|
||||
// Crea la textura con el texto
|
||||
void Credits::fillTextTexture()
|
||||
{
|
||||
void Credits::fillTextTexture() {
|
||||
auto text = Resource::get()->getText("smb2");
|
||||
auto text_grad = Resource::get()->getText("smb2_grad");
|
||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), text_texture_);
|
||||
@@ -248,8 +232,7 @@ void Credits::fillTextTexture()
|
||||
}
|
||||
|
||||
// Dibuja todos los sprites en la textura
|
||||
void Credits::fillCanvas()
|
||||
{
|
||||
void Credits::fillCanvas() {
|
||||
// Cambia el destino del renderizador
|
||||
auto temp = SDL_GetRenderTarget(Screen::get()->getRenderer());
|
||||
SDL_SetRenderTarget(Screen::get()->getRenderer(), canvas_);
|
||||
@@ -279,8 +262,7 @@ void Credits::fillCanvas()
|
||||
SDL_RenderRect(Screen::get()->getRenderer(), &red_rect);
|
||||
|
||||
// Si el mini_logo está en su destino, lo dibuja encima de lo anterior
|
||||
if (mini_logo_on_position_)
|
||||
{
|
||||
if (mini_logo_on_position_) {
|
||||
SDL_RenderTexture(Screen::get()->getRenderer(), text_texture_, &mini_logo_rect_src_, &mini_logo_rect_dst_);
|
||||
}
|
||||
|
||||
@@ -293,72 +275,57 @@ void Credits::fillCanvas()
|
||||
}
|
||||
|
||||
// Actualiza el destino de los rectangulos de las texturas
|
||||
void Credits::updateTextureDstRects()
|
||||
{
|
||||
if (counter_ % 10 == 0)
|
||||
{
|
||||
void Credits::updateTextureDstRects() {
|
||||
if (counter_ % 10 == 0) {
|
||||
// Comprueba la posición de la textura con los titulos de credito
|
||||
if (credits_rect_dst_.y + credits_rect_dst_.h > play_area_.y)
|
||||
{
|
||||
if (credits_rect_dst_.y + credits_rect_dst_.h > play_area_.y) {
|
||||
--credits_rect_dst_.y;
|
||||
}
|
||||
|
||||
// Comprueba la posición de la textura con el mini_logo
|
||||
if (mini_logo_rect_dst_.y == mini_logo_final_pos_)
|
||||
{
|
||||
if (mini_logo_rect_dst_.y == mini_logo_final_pos_) {
|
||||
mini_logo_on_position_ = true;
|
||||
|
||||
// Si el jugador quiere pasar los titulos de credito, el fade se inicia solo
|
||||
if (want_to_pass_)
|
||||
{
|
||||
if (want_to_pass_) {
|
||||
fading_ = true;
|
||||
}
|
||||
|
||||
// Se activa el contador para evitar que la sección sea infinita
|
||||
if (counter_prevent_endless_ == 1000)
|
||||
{
|
||||
if (counter_prevent_endless_ == 1000) {
|
||||
fading_ = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
++counter_prevent_endless_;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
--mini_logo_rect_dst_.y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Tira globos al escenario
|
||||
void Credits::throwBalloons()
|
||||
{
|
||||
void Credits::throwBalloons() {
|
||||
constexpr int speed = 200;
|
||||
const std::vector<int> sets = {0, 63, 25, 67, 17, 75, 13, 50};
|
||||
|
||||
if (counter_ > ((sets.size() - 1) * speed) * 3)
|
||||
{
|
||||
if (counter_ > ((sets.size() - 1) * speed) * 3) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (counter_ % speed == 0)
|
||||
{
|
||||
if (counter_ % speed == 0) {
|
||||
const int index = (counter_ / speed) % sets.size();
|
||||
balloon_manager_->deploySet(sets.at(index), -60);
|
||||
}
|
||||
|
||||
if (counter_ % (speed * 4) == 0 && counter_ > 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
|
||||
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
|
||||
{
|
||||
@@ -397,14 +364,11 @@ void Credits::initPlayers()
|
||||
}
|
||||
|
||||
// Actualiza los rectangulos negros
|
||||
void Credits::updateBlackRects()
|
||||
{
|
||||
void Credits::updateBlackRects() {
|
||||
static int current_step = steps_;
|
||||
if (top_black_rect_.h != param.game.game_area.center_y - 1 && bottom_black_rect_.y != param.game.game_area.center_y + 1)
|
||||
{
|
||||
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)
|
||||
{
|
||||
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);
|
||||
|
||||
@@ -415,12 +379,9 @@ void Credits::updateBlackRects()
|
||||
--current_step;
|
||||
setVolume(static_cast<int>(initial_volume_ * current_step / steps_));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// Si los rectangulos superior e inferior han llegado al centro
|
||||
if (left_black_rect_.w != param.game.game_area.center_x && right_black_rect_.x != param.game.game_area.center_x)
|
||||
{
|
||||
if (left_black_rect_.w != param.game.game_area.center_x && right_black_rect_.x != param.game.game_area.center_x) {
|
||||
constexpr int SPEED = 2;
|
||||
// Si los rectangulos izquierdo y derecho no han llegado al centro
|
||||
// Incrementa la anchura del rectangulo situado a la izquierda
|
||||
@@ -432,18 +393,13 @@ void Credits::updateBlackRects()
|
||||
|
||||
--current_step;
|
||||
setVolume(static_cast<int>(initial_volume_ * current_step / steps_));
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
// Si los rectangulos izquierdo y derecho han llegado al centro
|
||||
setVolume(0);
|
||||
Audio::get()->stopMusic();
|
||||
if (counter_pre_fade_ == 400)
|
||||
{
|
||||
if (counter_pre_fade_ == 400) {
|
||||
fade_out_->activate();
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
++counter_pre_fade_;
|
||||
}
|
||||
}
|
||||
@@ -451,8 +407,7 @@ void Credits::updateBlackRects()
|
||||
}
|
||||
|
||||
// Actualiza el rectangulo rojo
|
||||
void Credits::updateRedRect()
|
||||
{
|
||||
void Credits::updateRedRect() {
|
||||
red_rect.x = left_black_rect_.x + left_black_rect_.w;
|
||||
red_rect.y = top_black_rect_.y + top_black_rect_.h - 1;
|
||||
red_rect.w = right_black_rect_.x - red_rect.x;
|
||||
@@ -460,76 +415,66 @@ void Credits::updateRedRect()
|
||||
}
|
||||
|
||||
// Actualiza el estado de fade
|
||||
void Credits::updateAllFades()
|
||||
{
|
||||
if (fading_)
|
||||
{
|
||||
void Credits::updateAllFades() {
|
||||
if (fading_) {
|
||||
updateBlackRects();
|
||||
updateRedRect();
|
||||
}
|
||||
|
||||
fade_in_->update();
|
||||
if (fade_in_->hasEnded())
|
||||
{
|
||||
if (fade_in_->hasEnded()) {
|
||||
Audio::get()->playMusic("credits.ogg");
|
||||
}
|
||||
|
||||
fade_out_->update();
|
||||
if (fade_out_->hasEnded())
|
||||
{
|
||||
if (fade_out_->hasEnded()) {
|
||||
Section::name = Section::Name::HI_SCORE_TABLE;
|
||||
}
|
||||
}
|
||||
|
||||
// Establece el nivel de volumen
|
||||
void Credits::setVolume(int amount)
|
||||
{
|
||||
void Credits::setVolume(int amount) {
|
||||
Options::audio.music.volume = std::clamp(amount, 0, 100);
|
||||
Audio::get()->setMusicVolume(Options::audio.music.volume);
|
||||
}
|
||||
|
||||
// Reestablece el nivel de volumen
|
||||
void Credits::resetVolume()
|
||||
{
|
||||
void Credits::resetVolume() {
|
||||
Options::audio.music.volume = initial_volume_;
|
||||
Audio::get()->setMusicVolume(Options::audio.music.volume);
|
||||
}
|
||||
|
||||
// Cambia el color del fondo
|
||||
void Credits::cycleColors()
|
||||
{
|
||||
void Credits::cycleColors() {
|
||||
// constexpr int UPPER_LIMIT = 255; // Límite superior
|
||||
// constexpr int LOWER_LIMIT = 80; // Límite inferior
|
||||
|
||||
constexpr int UPPER_LIMIT = 140; // Límite superior
|
||||
constexpr int LOWER_LIMIT = 30; // Límite inferior
|
||||
constexpr int UPPER_LIMIT = 140; // Límite superior
|
||||
constexpr int LOWER_LIMIT = 30; // Límite inferior
|
||||
|
||||
static float r = static_cast<float>(UPPER_LIMIT);
|
||||
static float g = static_cast<float>(LOWER_LIMIT);
|
||||
static float b = static_cast<float>(LOWER_LIMIT);
|
||||
static float stepR = -0.5f; // Paso flotante para transiciones suaves
|
||||
static float stepR = -0.5f; // Paso flotante para transiciones suaves
|
||||
static float stepG = 0.3f;
|
||||
static float stepB = 0.1f;
|
||||
|
||||
// Ajustar valores de R
|
||||
r += stepR;
|
||||
if (r >= UPPER_LIMIT || r <= LOWER_LIMIT)
|
||||
{
|
||||
stepR = -stepR; // Cambia de dirección al alcanzar los límites
|
||||
if (r >= UPPER_LIMIT || r <= LOWER_LIMIT) {
|
||||
stepR = -stepR; // Cambia de dirección al alcanzar los límites
|
||||
}
|
||||
|
||||
// Ajustar valores de G
|
||||
g += stepG;
|
||||
if (g >= UPPER_LIMIT || g <= LOWER_LIMIT)
|
||||
{
|
||||
stepG = -stepG; // Cambia de dirección al alcanzar los límites
|
||||
if (g >= UPPER_LIMIT || g <= LOWER_LIMIT) {
|
||||
stepG = -stepG; // Cambia de dirección al alcanzar los límites
|
||||
}
|
||||
|
||||
// Ajustar valores de B
|
||||
b += stepB;
|
||||
if (b >= UPPER_LIMIT || b <= LOWER_LIMIT)
|
||||
{
|
||||
stepB = -stepB; // Cambia de dirección al alcanzar los límites
|
||||
if (b >= UPPER_LIMIT || b <= LOWER_LIMIT) {
|
||||
stepB = -stepB; // Cambia de dirección al alcanzar los límites
|
||||
}
|
||||
|
||||
// Aplicar el color, redondeando a enteros antes de usar
|
||||
@@ -538,19 +483,15 @@ void Credits::cycleColors()
|
||||
}
|
||||
|
||||
// Actualza los jugadores
|
||||
void Credits::updatePlayers()
|
||||
{
|
||||
for (auto &player : players_)
|
||||
{
|
||||
void Credits::updatePlayers() {
|
||||
for (auto &player : players_) {
|
||||
player->update();
|
||||
}
|
||||
}
|
||||
|
||||
// Renderiza los jugadores
|
||||
void Credits::renderPlayers()
|
||||
{
|
||||
for (auto const &player : players_)
|
||||
{
|
||||
void Credits::renderPlayers() {
|
||||
for (auto const &player : players_) {
|
||||
player->render();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user