eliminats tots els SDL_Delay i bucles bloquejants (milestone 1)

- shakeScreen() convertit a màquina d'estats amb SDL_GetTicks (50ms per pas)
- killPlayer() convertit a seqüència de fases (Shaking → Waiting → Done)
- Fade FADE_FULLSCREEN convertit a per-frame amb alpha incremental
- Fade FADE_RANDOM_SQUARE convertit a per-frame (un quadrat cada 100ms)
- Title SUBSECTION_TITLE_2 convertit a no-bloquejant, variables static eliminades
- Corregit so duplicat del crashSound al títol
- Congelat input del jugador durant la seqüència de mort

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-12 19:02:44 +02:00
parent 4bd07216f3
commit 9365f80e8b
6 changed files with 204 additions and 119 deletions

View File

@@ -120,6 +120,8 @@ void Title::init() {
ticksSpeed = 15;
fade->init(0x17, 0x17, 0x26);
demo = true;
vibrationStep = 0;
vibrationInitialized = false;
// Pone valores por defecto a las opciones de control
options->input.clear();
@@ -257,21 +259,27 @@ void Title::update() {
// Sección 2 - Titulo vibrando
case SUBSECTION_TITLE_2: {
// Agita la pantalla
static const int v[] = {-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, 0};
static const int a = coffeeBitmap->getPosX();
static const int b = crisisBitmap->getPosX();
static int step = 0;
// Captura las posiciones base y reproduce el sonido la primera vez
if (!vibrationInitialized) {
vibrationCoffeeBaseX = coffeeBitmap->getPosX();
vibrationCrisisBaseX = crisisBitmap->getPosX();
vibrationInitialized = true;
}
coffeeBitmap->setPosX(a + v[step / 3]);
crisisBitmap->setPosX(b + v[step / 3]);
// Agita la pantalla
const int v[] = {-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, 0};
coffeeBitmap->setPosX(vibrationCoffeeBaseX + v[vibrationStep / 3]);
crisisBitmap->setPosX(vibrationCrisisBaseX + v[vibrationStep / 3]);
dustBitmapR->update();
dustBitmapL->update();
step++;
vibrationStep++;
if (step == 33) {
if (vibrationStep >= 33) {
section->subsection = SUBSECTION_TITLE_3;
vibrationStep = 0;
vibrationInitialized = false;
}
} break;
@@ -539,48 +547,32 @@ void Title::render() {
} break;
// Sección 2 - Titulo vibrando
case SUBSECTION_TITLE_2: { // Reproduce el efecto sonoro
JA_PlaySound(crashSound);
case SUBSECTION_TITLE_2: {
// Prepara para empezar a dibujar en la textura de juego
screen->start();
// Agita la pantalla
const int v[] = {-1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, -1, 1, 0};
const int a = coffeeBitmap->getPosX();
const int b = crisisBitmap->getPosX();
for (int n = 0; n < 11 * 3; ++n) {
// Prepara para empezar a dibujar en la textura de juego
screen->start();
// Limpia la pantalla
screen->clean(bgColor);
// Limpia la pantalla
screen->clean(bgColor);
// Dibuja el tileado de fondo
{
SDL_FRect fSrc = {(float)backgroundWindow.x, (float)backgroundWindow.y, (float)backgroundWindow.w, (float)backgroundWindow.h};
SDL_RenderTexture(renderer, background, &fSrc, nullptr);
};
// Dibuja el tileado de fondo
{
SDL_FRect fSrc = {(float)backgroundWindow.x, (float)backgroundWindow.y, (float)backgroundWindow.w, (float)backgroundWindow.h};
SDL_RenderTexture(renderer, background, &fSrc, nullptr);
};
// Dibuja el degradado
gradient->render();
// Dibuja el degradado
gradient->render();
// Dibuja los objetos (posiciones ya actualizadas por update)
coffeeBitmap->render();
crisisBitmap->render();
// Dibuja los objetos
coffeeBitmap->setPosX(a + v[n / 3]);
crisisBitmap->setPosX(b + v[n / 3]);
coffeeBitmap->render();
crisisBitmap->render();
dustBitmapR->render();
dustBitmapL->render();
dustBitmapR->update();
dustBitmapL->update();
dustBitmapR->render();
dustBitmapL->render();
// Vuelca el contenido del renderizador en pantalla
screen->blit();
}
section->subsection = SUBSECTION_TITLE_3;
}
break;
// Vuelca el contenido del renderizador en pantalla
screen->blit();
} break;
// Sección 3 - La pantalla de titulo con el menú y la música
case SUBSECTION_TITLE_3: { // Prepara para empezar a dibujar en la textura de juego