Files
aee/source/game/modulesequence.cpp

1246 lines
37 KiB
C++
Raw Blame History

#include "game/modulesequence.hpp"
#include <stdlib.h>
#include <string>
#include "core/jail/jail_audio.hpp"
#include "core/jail/jdraw8.hpp"
#include "core/jail/jfile.hpp"
#include "core/jail/jgame.hpp"
#include "core/jail/jinput.hpp"
#include "game/options.hpp"
ModuleSequence::ModuleSequence() {
}
ModuleSequence::~ModuleSequence(void) {
}
namespace {
// Espera fins que passe el tick de JG_ShouldUpdate o fins que el jugador
// polse qualsevol tecla. Torna `true` si la seqüència s'ha de cancel·lar.
// Centralitza el patró repetit de les cinemàtiques; a la Fase 5 (quan
// eliminem el game thread) passarà a ser un pas de màquina d'estats real.
bool wait_frame_or_skip() {
while (!JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || JG_Quitting()) return true;
}
return false;
}
} // namespace
int ModuleSequence::Go() {
if (info::ctx.num_piramide == 6 && info::ctx.diners < 200) info::ctx.num_piramide = 7;
switch (info::ctx.num_piramide) {
case 255: // Intro
doIntro();
break;
case 0: // Men<65>
doMenu();
break;
case 1: // Slides
case 7:
doSlides();
break;
// case 2..5 (Pre-piràmide) → migrat a scenes::BannerScene.
case 6: // Pre-Secreta
doSecreta();
break;
case 8: // Credits
doCredits();
break;
// case 100 (Mort) → migrat a scenes::MortScene, dispatch via SceneRegistry.
}
JD8_FadeOut();
if (JG_Quitting()) {
return -1;
} else {
if (info::ctx.num_piramide == 255) {
info::ctx.num_piramide = 0;
return 1;
} else if (info::ctx.num_piramide == 0) {
info::ctx.num_piramide = 1;
// info::ctx.num_piramide = 6;
// info::ctx.diners = 200;
return 1;
} else if (info::ctx.num_piramide == 7) {
info::ctx.num_piramide = 8;
return 1;
} else if (info::ctx.num_piramide == 8) {
info::ctx.num_piramide = 255;
return 1;
} else if (info::ctx.num_piramide == 100) {
info::ctx.num_piramide = 0;
return 1;
} else {
return 0;
}
}
return 0;
}
const int minim(const int a, const int b) {
if (b < a) {
return b;
} else {
return a;
}
}
// Pinta el wordmark JAILGAMES/Jailgames en el mateix lloc (y=78) durant les
// animacions de sprites de l'intro. Branqueja entre logo vell i nou segons
// Options::game.use_new_logo.
static void drawIntroWordmark(JD8_Surface gfx) {
if (Options::game.use_new_logo) {
JD8_Blit(60, 78, gfx, 60, 158, 188, 28);
} else {
JD8_Blit(43, 78, gfx, 43, 155, 231, 45);
}
}
void play_music(const char* music, bool loop = -1) {
int size;
char* buffer = file_getfilebuffer(music, size);
JA_PlayMusic(JA_LoadMusic((Uint8*)buffer, size, music), loop);
}
void ModuleSequence::doIntro() {
if (Options::game.use_new_logo) {
doIntroNewLogo();
return;
}
JG_SetUpdateTicks(1000);
play_music("00000003.ogg");
JD8_Surface gfx = JD8_LoadSurface("logo.gif");
JD8_Palette pal = JD8_LoadPalette("logo.gif");
JD8_SetScreenPalette(pal);
JD8_ClearScreen(0);
JD8_Flip();
if (wait_frame_or_skip()) {
JD8_FreeSurface(gfx);
return;
}
JG_SetUpdateTicks(100);
JD8_Blit(43, 78, gfx, 43, 155, 27, 45);
JD8_Blit(68, 78, gfx, 274, 155, 27, 45);
JD8_Flip();
if (wait_frame_or_skip()) {
JD8_FreeSurface(gfx);
return;
}
JD8_Blit(43, 78, gfx, 43, 155, 53, 45);
JD8_Blit(96, 78, gfx, 274, 155, 27, 45);
JD8_Flip();
if (wait_frame_or_skip()) {
JD8_FreeSurface(gfx);
return;
}
JD8_Blit(43, 78, gfx, 43, 155, 66, 45);
JD8_Blit(109, 78, gfx, 274, 155, 27, 45);
JD8_Flip();
if (wait_frame_or_skip()) {
JD8_FreeSurface(gfx);
return;
}
JG_SetUpdateTicks(200);
JD8_Blit(43, 78, gfx, 43, 155, 92, 45);
JD8_Blit(136, 78, gfx, 274, 155, 27, 45);
JD8_Flip();
if (wait_frame_or_skip()) {
JD8_FreeSurface(gfx);
return;
}
JD8_ClearScreen(0);
JD8_Blit(43, 78, gfx, 43, 155, 92, 45);
// JD8_Blit( 136, 78, gfx, 274, 155, 27, 45 );
JD8_Flip();
if (wait_frame_or_skip()) {
JD8_FreeSurface(gfx);
return;
}
JG_SetUpdateTicks(100);
JD8_Blit(43, 78, gfx, 43, 155, 118, 45);
JD8_Blit(160, 78, gfx, 274, 155, 27, 45);
JD8_Flip();
if (wait_frame_or_skip()) {
JD8_FreeSurface(gfx);
return;
}
JD8_Blit(43, 78, gfx, 43, 155, 145, 45);
JD8_Blit(188, 78, gfx, 274, 155, 27, 45);
JD8_Flip();
if (wait_frame_or_skip()) {
JD8_FreeSurface(gfx);
return;
}
JD8_Blit(43, 78, gfx, 43, 155, 178, 45);
JD8_Blit(221, 78, gfx, 274, 155, 27, 45);
JD8_Flip();
if (wait_frame_or_skip()) {
JD8_FreeSurface(gfx);
return;
}
JD8_Blit(43, 78, gfx, 43, 155, 205, 45);
JD8_Blit(248, 78, gfx, 274, 155, 27, 45);
JD8_Flip();
if (wait_frame_or_skip()) {
JD8_FreeSurface(gfx);
return;
}
JG_SetUpdateTicks(200);
drawIntroWordmark(gfx);
JD8_Blit(274, 78, gfx, 274, 155, 27, 45);
JD8_Flip();
if (wait_frame_or_skip()) {
JD8_FreeSurface(gfx);
return;
}
JD8_ClearScreen(0);
drawIntroWordmark(gfx);
JD8_Flip();
if (wait_frame_or_skip()) {
JD8_FreeSurface(gfx);
return;
}
drawIntroWordmark(gfx);
JD8_Blit(274, 78, gfx, 274, 155, 27, 45);
JD8_Flip();
if (wait_frame_or_skip()) {
JD8_FreeSurface(gfx);
return;
}
JD8_ClearScreen(0);
drawIntroWordmark(gfx);
JD8_Flip();
if (wait_frame_or_skip()) {
JD8_FreeSurface(gfx);
return;
}
drawIntroWordmark(gfx);
JD8_Blit(274, 78, gfx, 274, 155, 27, 45);
JD8_Flip();
if (wait_frame_or_skip()) {
JD8_FreeSurface(gfx);
return;
}
JD8_ClearScreen(0);
drawIntroWordmark(gfx);
JD8_Flip();
if (wait_frame_or_skip()) {
JD8_FreeSurface(gfx);
return;
}
for (int j = 0; j < 256; j++) {
for (int i = 16; i < 32; i++) {
if (i == 17) {
if (pal[i].r < 255) pal[i].r++;
if (pal[i].g < 255) pal[i].g++;
if (pal[i].b < 255) pal[i].b++;
}
if (pal[i].b < pal[i].g) pal[i].b++;
if (pal[i].b > pal[i].g) pal[i].b--;
if (pal[i].r < pal[i].g) pal[i].r++;
if (pal[i].r > pal[i].g) pal[i].r--;
}
JD8_Flip();
}
if (wait_frame_or_skip()) {
JD8_FreeSurface(gfx);
return;
}
doIntroSprites(gfx);
}
void ModuleSequence::doIntroSprites(JD8_Surface gfx) {
JG_SetUpdateTicks(20);
Uint16 fr1 = 13;
Uint16 fr2 = fr1;
Uint16 fr3 = 11;
Uint16 fr4 = fr3;
Uint16 fr5 = 20;
Uint16 fr6 = 8;
Uint16 fr7 = 29;
Uint16 fr8 = 4;
Uint16 fr9 = 16;
Uint16 fr10 = fr9;
Uint16 fr11 = 6;
Uint16 creu = 75;
Uint16 interrogant = 90;
Uint16 fr_ani_1[13]; // camina dreta
Uint16 fr_ani_2[13]; // camina esquerra
Uint16 fr_ani_3[11]; // trau el mapa DRETA
Uint16 fr_ani_4[11]; // trau el mapa ESQUERRA
Uint16 fr_ani_5[20]; // bot de susto
Uint16 fr_ani_6[8]; // momia
Uint16 fr_ani_7[29]; // deixa caure el PAPER i SOMBRA
Uint16 fr_ani_8[4]; // PEDRA
Uint16 fr_ani_9[16]; // prota BALL
Uint16 fr_ani_10[16]; // momia BALL
Uint16 fr_ani_11[6]; // altaveu
for (int i = 0; i < fr1; i++) fr_ani_1[i] = i * 15;
for (int i = 0; i < fr2; i++) fr_ani_2[i] = i * 15; // 15
for (int i = 0; i < fr3; i++) fr_ani_3[i] = i * 15; // 30
for (int i = 0; i < fr4; i++) fr_ani_4[i] = i * 15; // 45
for (int i = 0; i <= 9; i++) fr_ani_5[i] = (i + 11) * 15; // 45
for (int i = 10; i <= 19; i++) fr_ani_5[i] = fr_ani_5[19 - i];
for (int i = 0; i < fr6; i++) fr_ani_6[i] = i * 15; // 60
for (int i = 0; i <= 13; i++) fr_ani_7[i] = (i + 5) * 15; // 75
for (int i = 14; i < fr7; i++) fr_ani_7[i] = (i - 14) * 15; // 105
for (int i = 0; i < fr8; i++) fr_ani_8[i] = (i + 1) * 15; // 75
for (int i = 0; i < fr9; i++) fr_ani_9[i] = i * 15; // 120
for (int i = 0; i < fr10; i++) fr_ani_10[i] = i * 15; // 135
for (int i = 0; i < fr11; i++) fr_ani_11[i] = (i + 1) * 15; // 90
fr_ani_11[fr11 - 1] = fr_ani_11[3];
switch (rand() % 3) {
case 0:
// camina cap a la DRETA }
for (int i = 0; i <= 200; i++) {
JD8_ClearScreen(0);
drawIntroWordmark(gfx);
// Put_sprite(from,where,fr_ani_1[(i div 5) mod fr1],15,15,i,150);
JD8_BlitCK(i, 150, gfx, fr_ani_1[(i / 5) % fr1], 0, 15, 15, 0);
JD8_Flip();
if (wait_frame_or_skip()) {
JD8_FreeSurface(gfx);
return;
}
}
// trau el MAPA DRETA }
for (int i = 0; i <= 200; i++) {
JD8_ClearScreen(0);
drawIntroWordmark(gfx);
// Put_sprite(from,where,fr_ani_3[minim((i div 5),fr3-1)],15,15,200,150);
JD8_BlitCK(200, 150, gfx, fr_ani_3[minim((i / 5), fr3 - 1)], 30, 15, 15, 0);
JD8_Flip();
if (wait_frame_or_skip()) {
JD8_FreeSurface(gfx);
return;
}
}
// guarda el MAPA }
for (int i = 200; i >= 0; i--) {
JD8_ClearScreen(0);
drawIntroWordmark(gfx);
// Put_sprite(from,where,fr_ani_3[minim((i div 5),fr3-1)],15,15,200,150);
JD8_BlitCK(200, 150, gfx, fr_ani_3[minim((i / 5), fr3 - 1)], 30, 15, 15, 0);
JD8_Flip();
if (wait_frame_or_skip()) {
JD8_FreeSurface(gfx);
return;
}
}
// camina cap a la ESQUERRA }
for (int i = 200; i >= 80; i--) {
JD8_ClearScreen(0);
drawIntroWordmark(gfx);
// Put_sprite(from,where,fr_ani_2[(i div 5) mod fr2],15,15,i,150);
JD8_BlitCK(i, 150, gfx, fr_ani_2[(i / 5) % fr2], 15, 15, 15, 0);
JD8_Flip();
if (wait_frame_or_skip()) {
JD8_FreeSurface(gfx);
return;
}
}
// trau el MAPA ESQUERRA }
for (int i = 0; i <= 200; i++) {
JD8_ClearScreen(0);
drawIntroWordmark(gfx);
// Put_sprite(from,where,fr_ani_4[minim((i div 5),fr4-1)],15,15,80,150);
JD8_BlitCK(80, 150, gfx, fr_ani_4[minim((i / 5), fr4 - 1)], 45, 15, 15, 0);
JD8_Flip();
if (wait_frame_or_skip()) {
JD8_FreeSurface(gfx);
return;
}
}
// momia cap a la ESQUERRA }
for (int i = 300; i >= 95; i--) {
JD8_ClearScreen(0);
drawIntroWordmark(gfx);
// Put_sprite(from,where,fr_ani_6[(i div 10) mod fr6],15,15,i,150);
JD8_BlitCK(i, 150, gfx, fr_ani_6[(i / 5) % fr6], 60, 15, 15, 0);
// Put_sprite(from,where,fr_ani_4[fr4-1],15,15,80,150);
JD8_BlitCK(80, 150, gfx, fr_ani_4[fr4 - 1], 45, 15, 15, 0);
JD8_Flip();
if (wait_frame_or_skip()) {
JD8_FreeSurface(gfx);
return;
}
}
// girar-se }
for (int i = 0; i <= 50; i++) {
JD8_ClearScreen(0);
drawIntroWordmark(gfx);
// Put_sprite(from,where,fr_ani_1[1],15,15,80,150);
JD8_BlitCK(80, 150, gfx, fr_ani_1[1], 0, 15, 15, 0);
// Put_sprite(from,where,fr_ani_6[4],15,15,95,150);
JD8_BlitCK(95, 150, gfx, fr_ani_6[4], 60, 15, 15, 0);
// Put_sprite(from,where,interrogant,15,15,80,133);
JD8_BlitCK(80, 133, gfx, 0, interrogant, 15, 15, 0);
JD8_Flip();
if (wait_frame_or_skip()) {
JD8_FreeSurface(gfx);
return;
}
}
// bot de SUSTO }
for (int i = 0; i <= 49; i++) {
JD8_ClearScreen(0);
drawIntroWordmark(gfx);
// Put_sprite(from,where,fr_ani_5[minim((i div 5),fr5-1)],15,15,80,150-((i mod 50) div 5));
JD8_BlitCK(80, 150 - ((i % 50) / 5), gfx, fr_ani_5[minim(i / 5, fr5 - 1)], 45, 15, 15, 0);
// Put_sprite(from,where,fr_ani_6[4],15,15,95,150);
JD8_BlitCK(95, 150, gfx, fr_ani_6[4], 60, 15, 15, 0);
JD8_Flip();
if (wait_frame_or_skip()) {
JD8_FreeSurface(gfx);
return;
}
}
// bot de SUSTO }
for (int i = 50; i <= 99; i++) {
JD8_ClearScreen(0);
drawIntroWordmark(gfx);
// Put_sprite(from,where,fr_ani_5[minim((i div 5),fr5-1)],15,15,80,140+((i mod 50) div 5));
JD8_BlitCK(80, 140 + ((i % 50) / 5), gfx, fr_ani_5[minim(i / 5, fr5 - 1)], 45, 15, 15, 0);
// Put_sprite(from,where,fr_ani_6[4],15,15,95,150);
JD8_BlitCK(95, 150, gfx, fr_ani_6[4], 60, 15, 15, 0);
JD8_Flip();
if (wait_frame_or_skip()) {
JD8_FreeSurface(gfx);
return;
}
}
// camina cap a la ESQUERRA }
for (int i = 80; i >= 0; i--) {
JD8_ClearScreen(0);
drawIntroWordmark(gfx);
// Put_sprite(from,where,fr_ani_2[(i div 5) mod fr2],15,15,i,150);
JD8_BlitCK(i, 150, gfx, fr_ani_2[(i / 5) % fr2], 15, 15, 15, 0);
// Put_sprite(from,where,fr_ani_6[4],15,15,95,150);
JD8_BlitCK(95, 150, gfx, fr_ani_6[4], 60, 15, 15, 0);
JD8_Flip();
if (wait_frame_or_skip()) {
JD8_FreeSurface(gfx);
return;
}
}
// final }
for (int i = 0; i <= 150; i++) {
JD8_ClearScreen(0);
drawIntroWordmark(gfx);
// Put_sprite(from,where,fr_ani_6[4],15,15,95,150);
JD8_BlitCK(95, 150, gfx, fr_ani_6[4], 60, 15, 15, 0);
// Put_sprite(from,where,interrogant,15,15,95,133);
JD8_BlitCK(95, 133, gfx, 0, interrogant, 15, 15, 0);
JD8_Flip();
}
//-----}
break;
case 1:
// camina cap a la DRETA }
for (int i = 0; i <= 200; i++) {
JD8_ClearScreen(0);
drawIntroWordmark(gfx);
// Put_sprite(from,where,creu,15,15,200,155);
JD8_BlitCK(200, 155, gfx, 0, creu, 15, 15, 255);
// Put_sprite(from,where,fr_ani_1[(i div 5) mod fr1],15,15,i,150);
JD8_BlitCK(i, 150, gfx, fr_ani_1[(i / 5) % fr1], 0, 15, 15, 255);
JD8_Flip();
if (wait_frame_or_skip()) {
JD8_FreeSurface(gfx);
return;
}
}
// trau el MAPA DRETA }
for (int i = 0; i <= 300; i++) {
JD8_ClearScreen(0);
drawIntroWordmark(gfx);
// Put_sprite(from,where,creu,15,15,200,155);
JD8_BlitCK(200, 155, gfx, 0, creu, 15, 15, 255);
// Put_sprite(from,where,fr_ani_3[minim((i div 5),fr3-1)],15,15,200,150);
JD8_BlitCK(200, 150, gfx, fr_ani_3[minim(i / 5, fr3 - 1)], 30, 15, 15, 255);
JD8_Flip();
if (wait_frame_or_skip()) {
JD8_FreeSurface(gfx);
return;
}
}
// INTERROGANT }
for (int i = 0; i <= 100; i++) {
JD8_ClearScreen(0);
drawIntroWordmark(gfx);
// Put_sprite(from,where,creu,15,15,200,155);
JD8_BlitCK(200, 155, gfx, 0, creu, 15, 15, 255);
// Put_sprite(from,where,interrogant,15,15,200,134);
JD8_BlitCK(200, 134, gfx, 0, interrogant, 15, 15, 255);
// Put_sprite(from,where,fr_ani_3[fr3-1],15,15,200,150);
JD8_BlitCK(200, 150, gfx, fr_ani_3[fr3 - 1], 30, 15, 15, 255);
JD8_Flip();
if (wait_frame_or_skip()) {
JD8_FreeSurface(gfx);
return;
}
}
// deixa caure el MAPA i SOMBRA }
for (int i = 0; i <= 200; i++) {
JD8_ClearScreen(0);
drawIntroWordmark(gfx);
// Put_sprite(from,where,creu,15,15,200,155);
JD8_BlitCK(200, 155, gfx, 0, creu, 15, 15, 255);
// Put_sprite(from,where,fr_ani_7[minim((i div 5),fr7-1)],15,15,200,150);
if (minim(i / 5, fr7 - 1) <= 13) {
JD8_BlitCK(200, 150, gfx, fr_ani_7[minim(i / 5, fr7 - 1)], 75, 15, 15, 255);
} else {
JD8_BlitCK(200, 150, gfx, fr_ani_7[minim(i / 5, fr7 - 1)], 105, 15, 15, 255);
}
JD8_Flip();
if (wait_frame_or_skip()) {
JD8_FreeSurface(gfx);
return;
}
}
// SOMBRA i PEDRA }
for (int i = 0; i <= 75; i++) {
JD8_ClearScreen(0);
drawIntroWordmark(gfx);
// Put_sprite(from,where,creu,15,15,200,155);
JD8_BlitCK(200, 155, gfx, 0, creu, 15, 15, 255);
// Put_sprite(from,where,fr_ani_7[fr7-1],15,15,200,150);
JD8_BlitCK(200, 150, gfx, fr_ani_7[fr7 - 1], 105, 15, 15, 255);
// Put_sprite(from,where,fr_ani_8[0],15,15,200,i*2);
JD8_BlitCK(200, i * 2, gfx, fr_ani_8[0], 75, 15, 15, 255);
JD8_Flip();
if (wait_frame_or_skip()) {
JD8_FreeSurface(gfx);
return;
}
}
// trencar PEDRA }
for (int i = 0; i <= 19; i++) {
JD8_ClearScreen(0);
drawIntroWordmark(gfx);
// Put_sprite(from,where,creu,15,15,200,155);
JD8_BlitCK(200, 155, gfx, 0, creu, 15, 15, 255);
// Put_sprite(from,where,fr_ani_8[i div 10],15,15,200,150);
JD8_BlitCK(200, 150, gfx, fr_ani_8[i / 10], 75, 15, 15, 255);
JD8_Flip();
if (wait_frame_or_skip()) {
JD8_FreeSurface(gfx);
return;
}
}
// FINAL }
for (int i = 0; i <= 200; i++) {
JD8_ClearScreen(0);
drawIntroWordmark(gfx);
// Put_sprite(from,where,creu,15,15,200,155);
JD8_BlitCK(200, 155, gfx, 0, creu, 15, 15, 255);
// Put_sprite(from,where,fr_ani_8[1],15,15,200,150);
JD8_BlitCK(200, 150, gfx, fr_ani_8[1], 75, 15, 15, 255);
// Put_sprite(from,where,fr_ani_8[2],15,15,185,150);
JD8_BlitCK(185, 150, gfx, fr_ani_8[2], 75, 15, 15, 255);
// Put_sprite(from,where,fr_ani_8[3],15,15,215,150);
JD8_BlitCK(215, 150, gfx, fr_ani_8[3], 75, 15, 15, 255);
JD8_Flip();
if (wait_frame_or_skip()) {
JD8_FreeSurface(gfx);
return;
}
}
break;
case 2:
// camina cap a la DRETA }
for (int i = 0; i <= 145; i++) {
JD8_ClearScreen(0);
drawIntroWordmark(gfx);
// Put_sprite(from,where,fr_ani_1[(i div 5) mod fr1],15,15,i,150);
JD8_BlitCK(i, 150, gfx, fr_ani_1[(i / 5) % fr1], 0, 15, 15, 255);
// Put_sprite(from,where,fr_ani_6[(i div 10) mod fr6],15,15,304-i,150);
JD8_BlitCK(304 - i, 150, gfx, fr_ani_6[(i / 10) % fr6], 60, 15, 15, 255);
JD8_Flip();
if (wait_frame_or_skip()) {
JD8_FreeSurface(gfx);
return;
}
}
// els dos quets }
for (int i = 0; i <= 100; i++) {
JD8_ClearScreen(0);
drawIntroWordmark(gfx);
// Put_sprite(from,where,fr_ani_1[1],15,15,145,150);
JD8_BlitCK(145, 150, gfx, fr_ani_1[1], 0, 15, 15, 255);
// Put_sprite(from,where,fr_ani_6[1],15,15,160,150);
JD8_BlitCK(160, 150, gfx, fr_ani_6[1], 60, 15, 15, 255);
JD8_Flip();
if (wait_frame_or_skip()) {
JD8_FreeSurface(gfx);
return;
}
}
// aparicio altaveu }
for (int i = 0; i <= 50; i++) {
JD8_ClearScreen(0);
drawIntroWordmark(gfx);
// Put_sprite(from,where,fr_ani_11[(i div 10) mod 2],15,15,125,150);
JD8_BlitCK(125, 150, gfx, fr_ani_11[(i / 10) % 2], 90, 15, 15, 255);
// Put_sprite(from,where,fr_ani_1[1],15,15,145,150);
JD8_BlitCK(145, 150, gfx, fr_ani_1[1], 0, 15, 15, 255);
// Put_sprite(from,where,fr_ani_6[1],15,15,160,150);
JD8_BlitCK(160, 150, gfx, fr_ani_6[1], 60, 15, 15, 255);
JD8_Flip();
if (wait_frame_or_skip()) {
JD8_FreeSurface(gfx);
return;
}
}
// BALL }
for (int i = 0; i <= 800; i++) {
JD8_ClearScreen(0);
drawIntroWordmark(gfx);
// Put_sprite(from,where,fr_ani_9[(i div 10) mod fr9],15,15,145,150);
JD8_BlitCK(145, 150, gfx, fr_ani_9[(i / 10) % fr9], 120, 15, 15, 255);
// Put_sprite(from,where,fr_ani_10[(i div 10) mod fr10],15,15,160,150);
JD8_BlitCK(160, 150, gfx, fr_ani_10[(i / 10) % fr10], 135, 15, 15, 255);
// Put_sprite(from,where,fr_ani_11[((i div 5) mod 4)+2],15,15,125,150);
JD8_BlitCK(125, 150, gfx, fr_ani_11[((i / 5) % 4) + 2], 90, 15, 15, 255);
JD8_Flip();
if (wait_frame_or_skip()) {
JD8_FreeSurface(gfx);
return;
}
}
break;
}
JD8_FreeSurface(gfx);
}
void ModuleSequence::doIntroNewLogo() {
// Coordenades mesurades del wordmark "Jailgames" dins logo/logo_new.gif
// (imatge 320x200, fons negre = index 0, lletres en index 17 = verd brillant).
// TUNE: ajusta aquests valors si canvies el logo.
constexpr int LOGO_SRC_X = 60; // x d'inici de la 'J' a la imatge font
constexpr int LOGO_SRC_Y = 158; // y del top del wordmark a la imatge font
constexpr int LOGO_DST_Y = 78; // y de destinació en pantalla (igual que logo vell)
constexpr int LOGO_HEIGHT = 28; // alçada del wordmark
// Amplada del crop des de LOGO_SRC_X fins al final de cada lletra
// (J, Ja, Jai, Jail, Jailg, Jailga, Jailgam, Jailgame, Jailgames):
constexpr int LETTER_WIDTHS[9] = {16, 39, 50, 69, 92, 115, 146, 169, 188};
// Cursor horitzontal (subratllat) al peu de la lletra següent que apareixerà.
// x absolut en pantalla, on comença cada cursor (just després de l'última lletra revelada):
constexpr int CURSOR_X[9] = {77, 100, 111, 130, 153, 176, 207, 230, 249};
constexpr int CURSOR_W = 12;
constexpr int CURSOR_H = 3;
constexpr int CURSOR_Y = LOGO_DST_Y + LOGO_HEIGHT - CURSOR_H; // peu de la lletra (y=103)
constexpr Uint8 CURSOR_COLOR = 17; // mateix index verd que les lletres (cicla amb el palette)
JG_SetUpdateTicks(1000);
play_music("00000003.ogg");
JD8_Surface gfx = JD8_LoadSurface("logo/logo_new.gif");
JD8_Palette pal = JD8_LoadPalette("logo/logo_new.gif");
JD8_SetScreenPalette(pal);
// Surface auxiliar plena amb el color del cursor, per poder "blittejar" rectangles.
JD8_Surface cursor_surf = JD8_NewSurface();
memset(cursor_surf, CURSOR_COLOR, 64000);
auto cleanup = [&]() {
JD8_FreeSurface(gfx);
JD8_FreeSurface(cursor_surf);
};
auto waitTick = [&]() -> bool {
// Retorna true si cal sortir (tecla o quitting).
while (!JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || JG_Quitting()) return true;
}
return false;
};
JD8_ClearScreen(0);
JD8_Flip();
if (waitTick()) {
cleanup();
return;
}
JG_SetUpdateTicks(150);
// Revelat progressiu lletra-a-lletra amb cursor parpadejant (subratllat horitzontal).
for (int i = 0; i < 9; i++) {
// Frame amb cursor visible
JD8_ClearScreen(0);
JD8_Blit(LOGO_SRC_X, LOGO_DST_Y, gfx, LOGO_SRC_X, LOGO_SRC_Y, LETTER_WIDTHS[i], LOGO_HEIGHT);
JD8_Blit(CURSOR_X[i], CURSOR_Y, cursor_surf, 0, 0, CURSOR_W, CURSOR_H);
JD8_Flip();
if (waitTick()) {
cleanup();
return;
}
// Frame sense cursor (parpadeig)
JD8_ClearScreen(0);
JD8_Blit(LOGO_SRC_X, LOGO_DST_Y, gfx, LOGO_SRC_X, LOGO_SRC_Y, LETTER_WIDTHS[i], LOGO_HEIGHT);
JD8_Flip();
if (waitTick()) {
cleanup();
return;
}
}
// Mostra el logo complet amb el cursor final fix un moment més.
JG_SetUpdateTicks(200);
JD8_ClearScreen(0);
JD8_Blit(LOGO_SRC_X, LOGO_DST_Y, gfx, LOGO_SRC_X, LOGO_SRC_Y, LETTER_WIDTHS[8], LOGO_HEIGHT);
JD8_Blit(CURSOR_X[8], CURSOR_Y, cursor_surf, 0, 0, CURSOR_W, CURSOR_H);
JD8_Flip();
if (waitTick()) {
cleanup();
return;
}
// Treu el cursor abans del cicle de paleta (els seus pixels cicla rien amb les lletres).
JD8_ClearScreen(0);
JD8_Blit(LOGO_SRC_X, LOGO_DST_Y, gfx, LOGO_SRC_X, LOGO_SRC_Y, LETTER_WIDTHS[8], LOGO_HEIGHT);
JD8_Flip();
// Cicle de paleta final (mateix efecte que l'intro original, indexs 16-31).
JG_SetUpdateTicks(20);
for (int j = 0; j < 256; j++) {
for (int i = 16; i < 32; i++) {
if (i == 17) {
if (pal[i].r < 255) pal[i].r++;
if (pal[i].g < 255) pal[i].g++;
if (pal[i].b < 255) pal[i].b++;
}
if (pal[i].b < pal[i].g) pal[i].b++;
if (pal[i].b > pal[i].g) pal[i].b--;
if (pal[i].r < pal[i].g) pal[i].r++;
if (pal[i].r > pal[i].g) pal[i].r--;
}
JD8_Flip();
if (waitTick()) {
cleanup();
return;
}
}
// Espera abans d'entrar a les animacions de sprites (igual que l'intro vella).
if (waitTick()) {
cleanup();
return;
}
// doIntroSprites pren propietat de gfx i el allibera ell mateix.
JD8_FreeSurface(cursor_surf);
doIntroSprites(gfx);
}
void ModuleSequence::doMenu() {
JG_SetUpdateTicks(20);
JD8_Surface fondo = JD8_LoadSurface("menu.gif");
JD8_Surface gfx = JD8_LoadSurface("menu2.gif");
JD8_Palette pal = JD8_LoadPalette("menu2.gif");
JD8_Blit(fondo);
JD8_BlitCK(100, 25, gfx, 0, 74, 124, 68, 255); // logo
JD8_BlitCK(130, 100, gfx, 0, 0, 80, 74, 255);
JD8_BlitCK(0, 150, gfx, 0, 150, 320, 50, 255);
JD8_FadeToPal(pal);
contador = 0;
int palmeres = 0;
int horitzo = 0;
int camello = 0;
JI_Update();
while (!JI_AnyKey() && !JG_Quitting() && !JI_KeyPressed(SDL_SCANCODE_P)) {
JD8_Blit(0, 0, fondo, 0, 0, 320, 100); // fondo sol estatic
JD8_BlitCK(horitzo, 100, fondo, 0, 100, 320 - horitzo, 100, 255); // fondo moviment
JD8_BlitCK(0, 100, fondo, 320 - horitzo, 100, horitzo, 100, 255);
JD8_BlitCK(100, 25, gfx, 0, 74, 124, 68, 255); // logo
JD8_BlitCK(130, 100, gfx, camello * 80, 0, 80, 74, 255); // camello
JD8_BlitCK(palmeres, 150, gfx, 0, 150, 320 - palmeres, 50, 255); // palemeres moviment
JD8_BlitCK(0, 150, gfx, 320 - palmeres, 150, palmeres, 50, 255);
JD8_BlitCK(87, 167, gfx, 127, 124, 150, 24, 255); // jdes
JD8_BlitCK(303, 193, gfx, 305, 143, 15, 5, 255); // versio
if (contador % 100 > 30) JD8_BlitCK(98, 130, gfx, 161, 92, 127, 9, 255); // pulsa tecla...
if ((contador % 100 > 30) && info::ctx.nou_personatge) JD8_BlitCK(68, 141, gfx, 128, 105, 189, 9, 255); // 'p' per a personatge nou...
JD8_Flip();
if (JG_ShouldUpdate()) {
if (contador % 4 == 0) {
palmeres--;
if (palmeres < 0) palmeres = 319;
}
if (contador % 8 == 0) {
camello++;
if (camello == 4) camello = 0;
}
if (contador % 16 == 0) {
horitzo--;
if (horitzo < 0) horitzo = 319;
}
contador++;
JI_Update();
}
}
info::ctx.pepe_activat = JI_KeyPressed(SDL_SCANCODE_P);
JI_DisableKeyboard(60);
JD8_FreeSurface(fondo);
JD8_FreeSurface(gfx);
free(pal);
}
void ModuleSequence::doSlides() {
JG_SetUpdateTicks(20);
const char* arxiu;
if (info::ctx.num_piramide == 7) {
play_music("00000005.ogg", 1);
if (info::ctx.diners < 200) {
arxiu = "intro2.gif";
} else {
arxiu = "intro3.gif";
}
} else {
arxiu = "intro.gif";
}
JD8_Surface gfx = JD8_LoadSurface(arxiu);
JD8_Palette pal_aux = JD8_LoadPalette(arxiu);
JD8_Palette pal = (JD8_Palette)malloc(768);
memcpy(pal, pal_aux, 768);
JD8_ClearScreen(255);
JD8_SetScreenPalette(pal);
bool exit = false;
int step = 0;
contador = 1;
while (!exit && !JG_Quitting()) {
if (JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey()) {
exit = true;
}
switch (step) {
case 0:
JD8_Blit(320 - (contador * 4), 65, gfx, 0, 0, contador * 4, 65);
JD8_Flip();
contador++;
if (contador == 80) step++;
break;
case 3:
JD8_Blit(0, 65, gfx, 320 - (contador * 4), 65, contador * 4, 65);
JD8_Flip();
contador++;
if (contador == 80) step++;
break;
case 6:
JD8_Blit(320 - (contador * 4), 65, gfx, 0, 130, contador * 4, 65);
JD8_Flip();
contador++;
if (contador == 80) step++;
break;
case 1:
case 4:
case 7:
contador--;
if (contador == -150) {
contador = 0;
step++;
}
break;
case 2:
case 5:
JD8_FadeOut();
memcpy(pal, pal_aux, 768);
JD8_ClearScreen(255);
step++;
break;
case 8:
if (info::ctx.num_piramide != 7) JA_FadeOutMusic(250);
exit = true;
break;
}
}
}
JD8_FreeSurface(gfx);
free(pal_aux);
}
// doBanner() — migrat a scenes::BannerScene (source/scenes/banner_scene.cpp)
void ModuleSequence::doSecreta() {
play_music("00000002.ogg");
JG_SetUpdateTicks(20);
JD8_FadeOut();
JD8_Surface gfx = JD8_LoadSurface("tomba1.gif");
JD8_Palette pal_aux = JD8_LoadPalette("tomba1.gif");
JD8_Palette pal = (JD8_Palette)malloc(768);
memcpy(pal, pal_aux, 768);
JD8_ClearScreen(255);
JD8_SetScreenPalette(pal);
bool exit = false;
int step = 0;
contador = 1;
while (!exit && !JG_Quitting()) {
if (JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey()) {
exit = true;
}
switch (step) {
case 0:
JD8_Blit(70, 60, gfx, 0, contador, 178, 70); // Put_Sprite(from, where, 0 + (320 * i), 178, 70, 70, 60);
JD8_BlitCK(70, 60, gfx, 178, contador >> 1, 142, 70, 255); // Put_Sprite(from, where, 178 + (320 * (i div 2)), 142, 70, 70, 60);
JD8_Flip();
contador++;
if (contador == 128) step++;
break;
case 1:
case 4:
case 7:
case 9:
contador--;
if (contador == 0) step++;
break;
case 2:
JD8_ClearScreen(255);
JD8_Flip();
gfx = JD8_LoadSurface("tomba2.gif");
pal_aux = JD8_LoadPalette("tomba2.gif");
memcpy(pal, pal_aux, 768);
JD8_SetScreenPalette(pal);
step++;
break;
case 3:
JD8_Blit(55, 53, gfx, 0, 158 - contador, 211, contador); // Put_Sprite(from, where, 0 + ((158 - i) * 320), 211, i, 55, 53);
JD8_Flip();
contador++;
if (contador == 94) step++;
break;
case 5:
JD8_ClearScreen(0);
JD8_Flip();
JD8_SetPaletteColor(254, 12, 11, 11);
JD8_SetPaletteColor(253, 12, 11, 11);
step++;
break;
case 6:
JD8_Blit(80, 68, gfx, 160 - (contador * 2), 0, contador * 2, 64); // Put_Sprite(from, where, 160 - (i * 2), (i * 2), 64, 80, 68);
JD8_Flip();
contador++;
if (contador == 80) step++;
break;
case 8:
JD8_SetPaletteColor(254, contador + 12, 11, 11);
JD8_SetPaletteColor(253, (contador + 12) >> 1, 11, 11);
JD8_Flip();
contador++;
if (contador == 51) step++;
break;
case 10:
JD8_FadeOut();
memcpy(pal, pal_aux, 768);
JD8_ClearScreen(255);
JA_FadeOutMusic(250);
exit = true;
break;
}
}
}
JD8_FreeSurface(gfx);
free(pal_aux);
}
void ModuleSequence::doCredits() {
struct {
Uint16 x, y;
} frames_coche[8] = {{214, 152}, {214, 104}, {214, 56}, {214, 104}, {214, 152}, {214, 8}, {108, 152}, {214, 8}};
const Uint32 n_frames_coche = 8;
const Uint32 velocitat_coche = 3;
JD8_Surface vaddr2 = JD8_LoadSurface("final.gif");
JD8_Surface vaddr3 = JD8_LoadSurface("finals.gif");
JD8_Palette pal = JD8_LoadPalette("final.gif");
JD8_SetScreenPalette(pal);
int contador = 0;
bool exit = false;
contador = 1;
while (!exit && !JG_Quitting()) {
if (JG_ShouldUpdate()) {
JI_Update();
if (JI_AnyKey() || contador >= 3100) {
exit = true;
}
JD8_ClearScreen(255);
if (contador < 2750) {
JD8_BlitCKCut(115, 200 - (contador / 6), vaddr2, 0, 0, 80, 200, 0);
}
if ((contador > 1200) && (contador < 2280)) {
JD8_BlitCKCut(100, 200 - ((contador - 1200) / 6), vaddr2, 85, 0, 120, 140, 0);
} else if (contador >= 2250) {
JD8_BlitCK(100, 20, vaddr2, 85, 0, 120, 140, 0);
}
if (info::ctx.diamants == 16) {
// scroll_final_joc(vaddr3, vaddr, contador_final);
JD8_BlitCKScroll(50, vaddr3, ((contador >> 3) % 320) + 1, 0, 50, 255);
JD8_BlitCKScroll(50, vaddr3, ((contador >> 2) % 320) + 1, 50, 50, 255);
JD8_BlitCKScroll(50, vaddr3, ((contador >> 1) % 320) + 1, 100, 50, 255);
JD8_BlitCKScroll(50, vaddr3, (contador % 320) + 1, 150, 50, 255);
JD8_BlitCK(100, 50, vaddr2, frames_coche[(contador / velocitat_coche) % n_frames_coche].x, frames_coche[(contador / velocitat_coche) % n_frames_coche].y, 106, 48, 255);
} else {
JD8_BlitCK(0, 50, vaddr3, 0, 0, 320, 50, 255);
JD8_BlitCK(0, 50, vaddr3, 0, 50, 320, 50, 255);
}
JD8_FillSquare(0, 50, 255);
JD8_FillSquare(100, 10, 255);
JD8_Flip();
contador++;
}
}
FILE* ini = fopen("trick.ini", "wb");
fwrite("1", 1, 1, ini);
fclose(ini);
info::ctx.nou_personatge = true;
JD8_FreeSurface(vaddr3);
JD8_FreeSurface(vaddr2);
}
// doMort() — migrat a scenes::MortScene (source/scenes/mort_scene.cpp)