This commit is contained in:
2025-10-19 22:01:31 +02:00
parent 16306f2325
commit 2b4523d644
101 changed files with 2058 additions and 1564 deletions

View File

@@ -1,10 +1,11 @@
// IWYU pragma: no_include <bits/std_abs.h>
#include "credits.hpp"
#include <SDL3/SDL.h> // Para SDL_RenderFillRect, SDL_RenderTexture, SDL_SetRenderTarget, SDL_SetRenderDrawColor, SDL_CreateTexture, SDL_DestroyTexture, SDL_GetTicks, SDL_GetRenderTarget, SDL_PixelFormat, SDL_PollEvent, SDL_RenderClear, SDL_RenderRect, SDL_SetTextureBlendMode, SDL_TextureAccess, SDL_BLENDMODE_BLEND, SDL_Event
#include <SDL3/SDL.h> // Para SDL_RenderFillRect, SDL_RenderTexture, SDL_SetRenderTarget, SDL_SetRenderDrawColor, SDL_CreateTexture, SDL_DestroyTexture, SDL_GetTicks, SDL_GetRenderTarget, SDL_PixelFormat, SDL_PollEvent, SDL_RenderClear, SDL_RenderRect, SDL_SetTextureBlendMode, SDL_TextureAccess, SDL_BLENDMODE_BLEND, SDL_Event, Uint64
#include <algorithm> // Para max, min, clamp
#include <array> // Para array
#include <cmath> // Para abs
#include <stdexcept> // Para runtime_error
#include <string> // Para basic_string, string
#include <string_view> // Para string_view
@@ -12,23 +13,23 @@
#include "audio.hpp" // Para Audio
#include "balloon_manager.hpp" // Para BalloonManager
#include "color.hpp" // Para Zone, Colors::SHADOW_TEXT, Colors::NO_COLOR_MOD, Color
#include "fade.hpp" // Para Fade, FadeType, FadeMode
#include "global_events.hpp" // Para check
#include "color.hpp" // Para Color, SHADOW_TEXT, NO_COLOR_MOD
#include "fade.hpp" // Para Fade
#include "global_events.hpp" // Para handle
#include "global_inputs.hpp" // Para check
#include "input.hpp" // Para Input, Input::ALLOW_REPEAT
#include "input.hpp" // Para Input
#include "lang.hpp" // Para getText
#include "param.hpp" // Para Param, param, ParamGame, ParamFade
#include "player.hpp" // Para Player, PlayerState
#include "player.hpp" // Para Player
#include "resource.hpp" // Para Resource
#include "screen.hpp" // Para Screen
#include "section.hpp" // Para Name, name
#include "sprite.hpp" // Para Sprite
#include "text.hpp" // Para Text, Text::CENTER, Text::SHADOW
#include "text.hpp" // Para Text
#include "texture.hpp" // Para Texture
#include "tiled_bg.hpp" // Para TiledBG, TiledBGMode
#include "ui/service_menu.hpp" // Para ServiceMenu
#include "utils.hpp"
#include "utils.hpp" // Para Zone
// Textos
constexpr std::string_view TEXT_COPYRIGHT = "@2020,2025 JailDesigner";
@@ -81,10 +82,10 @@ Credits::~Credits() {
// Calcula el deltatime
auto Credits::calculateDeltaTime() -> float {
const Uint64 current_time = SDL_GetTicks();
const float delta_time = static_cast<float>(current_time - last_time_) / 1000.0f; // Convertir ms a segundos
last_time_ = current_time;
return delta_time;
const Uint64 CURRENT_TIME = SDL_GetTicks();
const float DELTA_TIME = static_cast<float>(CURRENT_TIME - last_time_) / 1000.0F; // Convertir ms a segundos
last_time_ = CURRENT_TIME;
return DELTA_TIME;
}
// Bucle principal
@@ -93,33 +94,33 @@ void Credits::run() {
while (Section::name == Section::Name::CREDITS) {
checkInput();
const float delta_time = calculateDeltaTime();
update(delta_time);
const float DELTA_TIME = calculateDeltaTime();
update(DELTA_TIME);
checkEvents(); // Tiene que ir antes del render
render();
}
}
// Actualiza las variables (time-based)
void Credits::update(float deltaTime) {
const float multiplier = want_to_pass_ ? 4.0f : 1.0f;
const float adjusted_delta_time = deltaTime * multiplier;
void Credits::update(float delta_time) {
const float MULTIPLIER = want_to_pass_ ? 4.0F : 1.0F;
const float ADJUSTED_DELTA_TIME = delta_time * MULTIPLIER;
static auto* const SCREEN = Screen::get();
SCREEN->update(deltaTime); // Actualiza el objeto screen
Audio::update(); // Actualiza el objeto audio
SCREEN->update(delta_time); // Actualiza el objeto screen
Audio::update(); // Actualiza el objeto audio
tiled_bg_->update(adjusted_delta_time);
tiled_bg_->update(ADJUSTED_DELTA_TIME);
cycleColors();
balloon_manager_->update(adjusted_delta_time);
updateTextureDstRects(adjusted_delta_time);
throwBalloons(adjusted_delta_time);
updatePlayers(adjusted_delta_time);
updateAllFades(adjusted_delta_time);
balloon_manager_->update(ADJUSTED_DELTA_TIME);
updateTextureDstRects(ADJUSTED_DELTA_TIME);
throwBalloons(ADJUSTED_DELTA_TIME);
updatePlayers(ADJUSTED_DELTA_TIME);
updateAllFades(ADJUSTED_DELTA_TIME);
// Convertir deltaTime a equivalente de frames (60fps)
const float frameFactor = adjusted_delta_time * 60.0f;
counter_ += frameFactor;
const float FRAME_FACTOR = ADJUSTED_DELTA_TIME * 60.0F;
counter_ += FRAME_FACTOR;
fillCanvas();
}
@@ -291,9 +292,9 @@ void Credits::fillCanvas() {
}
// Actualiza el destino de los rectangulos de las texturas (time-based)
void Credits::updateTextureDstRects(float deltaTime) {
constexpr float TEXTURE_UPDATE_INTERVAL_S = 10.0f / 60.0f; // ~0.167s (cada 10 frames)
credits_state_.texture_accumulator += deltaTime;
void Credits::updateTextureDstRects(float delta_time) {
constexpr float TEXTURE_UPDATE_INTERVAL_S = 10.0F / 60.0F; // ~0.167s (cada 10 frames)
credits_state_.texture_accumulator += delta_time;
if (credits_state_.texture_accumulator >= TEXTURE_UPDATE_INTERVAL_S) {
credits_state_.texture_accumulator -= TEXTURE_UPDATE_INTERVAL_S;
@@ -325,18 +326,18 @@ void Credits::updateTextureDstRects(float deltaTime) {
}
// Tira globos al escenario (time-based)
void Credits::throwBalloons(float deltaTime) {
void Credits::throwBalloons(float delta_time) {
constexpr int SPEED = 200;
const std::vector<int> SETS = {0, 63, 25, 67, 17, 75, 13, 50};
constexpr float BALLOON_INTERVAL_S = SPEED / 60.0f; // ~3.33s (cada 200 frames)
constexpr float POWERBALL_INTERVAL_S = (SPEED * 4) / 60.0f; // ~13.33s (cada 800 frames)
constexpr float BALLOON_INTERVAL_S = SPEED / 60.0F; // ~3.33s (cada 200 frames)
constexpr float POWERBALL_INTERVAL_S = (SPEED * 4) / 60.0F; // ~13.33s (cada 800 frames)
if (counter_ > ((SETS.size() - 1) * SPEED) * 3) {
return;
}
credits_state_.balloon_accumulator += deltaTime;
credits_state_.powerball_accumulator += deltaTime;
credits_state_.balloon_accumulator += delta_time;
credits_state_.powerball_accumulator += delta_time;
if (credits_state_.balloon_accumulator >= BALLOON_INTERVAL_S) {
credits_state_.balloon_accumulator -= BALLOON_INTERVAL_S;
@@ -418,12 +419,12 @@ void Credits::initPlayers() {
}
// Actualiza los rectangulos negros (time-based)
void Credits::updateBlackRects(float deltaTime) {
static float current_step_ = static_cast<float>(steps_);
constexpr float BLACK_RECT_INTERVAL_S = 4.0f / 60.0f; // ~0.067s (cada 4 frames)
void Credits::updateBlackRects(float delta_time) {
static auto current_step_ = static_cast<float>(steps_);
constexpr float BLACK_RECT_INTERVAL_S = 4.0F / 60.0F; // ~0.067s (cada 4 frames)
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
credits_state_.black_rect_accumulator += deltaTime;
credits_state_.black_rect_accumulator += delta_time;
if (credits_state_.black_rect_accumulator >= BLACK_RECT_INTERVAL_S) {
credits_state_.black_rect_accumulator -= BLACK_RECT_INTERVAL_S;
@@ -459,8 +460,8 @@ void Credits::updateBlackRects(float deltaTime) {
fade_out_->activate();
} else {
// Convertir deltaTime a equivalente de frames
const float frameFactor = deltaTime * 60.0f;
counter_pre_fade_ += frameFactor;
const float FRAME_FACTOR = delta_time * 60.0F;
counter_pre_fade_ += FRAME_FACTOR;
}
}
}
@@ -475,9 +476,9 @@ void Credits::updateRedRect() {
}
// Actualiza el estado de fade (time-based)
void Credits::updateAllFades(float deltaTime) {
void Credits::updateAllFades(float delta_time) {
if (fading_) {
updateBlackRects(deltaTime);
updateBlackRects(delta_time);
updateRedRect();
}
@@ -510,7 +511,7 @@ void Credits::cycleColors() {
constexpr int LOWER_LIMIT = 30; // Límite inferior
// Inicializar valores RGB si es la primera vez
if (credits_state_.r == 255.0f && credits_state_.g == 0.0f && credits_state_.b == 0.0f && credits_state_.step_r == -0.5f) {
if (credits_state_.r == 255.0F && credits_state_.g == 0.0F && credits_state_.b == 0.0F && credits_state_.step_r == -0.5F) {
credits_state_.r = static_cast<float>(UPPER_LIMIT);
credits_state_.g = static_cast<float>(LOWER_LIMIT);
credits_state_.b = static_cast<float>(LOWER_LIMIT);
@@ -540,9 +541,9 @@ void Credits::cycleColors() {
}
// Actualza los jugadores (time-based)
void Credits::updatePlayers(float deltaTime) {
void Credits::updatePlayers(float delta_time) {
for (auto& player : players_) {
player->update(deltaTime);
player->update(delta_time);
}
}