From 5f3ecbbd79cf285e66ecc78af7e19ac1b59a7f36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Valor=20Mart=C3=ADnez?= Date: Wed, 7 Feb 2024 18:48:53 +0100 Subject: [PATCH] Ya funciona el fade de la pantalla de carga --- source/gamestate_title.cpp | 20 ++++++++++++++++---- source/jail_engine/paleta.cpp | 23 +++++++++++++++++++++-- source/jail_engine/paleta.h | 2 ++ 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/source/gamestate_title.cpp b/source/gamestate_title.cpp index 62009c1..95cba44 100644 --- a/source/gamestate_title.cpp +++ b/source/gamestate_title.cpp @@ -281,18 +281,23 @@ void Title::update() switch (state) { case show_loading_screen: - if (counter == 2000) + if (counter == 200) { counter = 0; - state = show_menu; + state = fade_loading_screen; } break; case fade_loading_screen: + if (counter % 4 == 0) + if (pFadePal()) + { + counter = 0; + state = show_menu; + } break; case show_menu: - // Actualiza la marquesina updateMarquee(); @@ -324,7 +329,7 @@ void Title::render() case show_loading_screen: // Dibuja la textura de fondo SDL_RenderCopy(renderer, bgTexture, nullptr, nullptr); - + // Dibuja la pantalla de carga pCls(4); pBlit(0, 0, 0, 0, 256, 128); @@ -332,6 +337,13 @@ void Title::render() break; case fade_loading_screen: + // Dibuja la textura de fondo + SDL_RenderCopy(renderer, bgTexture, nullptr, nullptr); + + // Dibuja la pantalla de carga + pCls(4); + pBlit(0, 0, 0, 0, 256, 128); + pFlip(renderer); break; case show_menu: diff --git a/source/jail_engine/paleta.cpp b/source/jail_engine/paleta.cpp index 93d7261..c09dcb2 100644 --- a/source/jail_engine/paleta.cpp +++ b/source/jail_engine/paleta.cpp @@ -61,7 +61,7 @@ void pBlit(int dx, int dy, int sx, int sy, int w, int h) { if (jSourceSurf == NULL) return; - + for (int iy = 0; iy < h; ++iy) { for (int ix = 0; ix < w; ++ix) @@ -140,7 +140,7 @@ void pFlip(SDL_Renderer *renderer) for (int i = 0; i < jWidth * jHeight; ++i) pixels[i] = paleta[jScreen->data[i]]; SDL_UnlockTexture(jTex); - SDL_Rect rect = {0,64,256,128}; + SDL_Rect rect = {0, 64, 256, 128}; SDL_RenderCopy(renderer, jTex, NULL, &rect); } @@ -154,4 +154,23 @@ void pPutPixel(int x, int y, Uint8 color) Uint8 pGetPixel(int x, int y) { return jSourceSurf->data[x + y * jSourceSurf->w]; +} + +bool pFadePal() +{ + paleta[1] = paleta[0]; + + // Colores pares + for (int i = 18; i > 0; i = i - 2) + { + paleta[i] = paleta[i - 2]; + } + + // Colores impares + for (int i = 17; i > 1; i = i - 2) + { + paleta[i] = paleta[i - 2]; + } + + return paleta[15] == paleta[0] ? true : false; } \ No newline at end of file diff --git a/source/jail_engine/paleta.h b/source/jail_engine/paleta.h index 3d6a0e4..c78c9a5 100644 --- a/source/jail_engine/paleta.h +++ b/source/jail_engine/paleta.h @@ -23,3 +23,5 @@ void pLoadPal(const char *filename); void pCls(Uint8 color); void pFlip(SDL_Renderer *renderer); + +bool pFadePal();