- Remodelat un poc el codi

This commit is contained in:
2024-01-31 12:47:51 +01:00
parent 80234e195e
commit fe444fc0ec
10 changed files with 629 additions and 674 deletions

View File

@@ -3,10 +3,7 @@
#include "jsound.h" #include "jsound.h"
#include "jfile.h" #include "jfile.h"
#include "info.h" #include "info.h"
#include "modulestaticscreen.h" #include "modules.h"
#include "modulemenu.h"
#include "moduleselect.h"
#include "modulesequence.h"
#include "time.h" #include "time.h"
#include <string> #include <string>
@@ -55,28 +52,16 @@ int main( int argc, char* args[] ) {
switch (info::estat_joc) { switch (info::estat_joc) {
case ESTAT_ICEKAS: case ESTAT_ICEKAS:
case ESTAT_LOGO: case ESTAT_LOGO:
ModuleStaticScreen * moduleStaticScreen; module::staticScreen::go();
moduleStaticScreen = new ModuleStaticScreen();
info::estat_joc = moduleStaticScreen->Go();
delete moduleStaticScreen;
break; break;
case ESTAT_MENU: case ESTAT_MENU:
ModuleMenu * moduleMenu; module::menu::go();
moduleMenu = new ModuleMenu();
info::estat_joc = moduleMenu->Go();
delete moduleMenu;
break; break;
case ESTAT_SELECT: case ESTAT_SELECT:
ModuleSelect * moduleSelect; module::select::go();
moduleSelect = new ModuleSelect();
info::estat_joc = moduleSelect->Go();
delete moduleSelect;
break; break;
case ESTAT_SEQUENCIA: case ESTAT_SEQUENCIA:
ModuleSequence * moduleSequence; module::sequence::go();
moduleSequence = new ModuleSequence();
info::estat_joc = moduleSequence->Go();
delete moduleSequence;
break; break;
} }
} }

View File

@@ -1,4 +1,4 @@
#include "modulemenu.h" #include "modules.h"
#include "jgame.h" #include "jgame.h"
#include "jdraw8.h" #include "jdraw8.h"
@@ -14,14 +14,15 @@
#define OPCIO_CLASSICMODE 2 #define OPCIO_CLASSICMODE 2
#define OPCIO_OPTIONS 3 #define OPCIO_OPTIONS 3
ModuleMenu::ModuleMenu() { namespace module
} {
namespace menu
ModuleMenu::~ModuleMenu(void) { {
} void go()
{
int ModuleMenu::Go() { // [RZC 31/01/2024] [TODO] Menú del mode nocturn
// Inicialitzem música i gràfics per al menú
JS_LoadMusic("mtitle.mid"); JS_LoadMusic("mtitle.mid");
JS_PlayMusic(-1); JS_PlayMusic(-1);
@@ -33,13 +34,16 @@ int ModuleMenu::Go() {
JD8_ClearScreen(0); JD8_ClearScreen(0);
JD8_Flip(); JD8_Flip();
// FADE IN
// Fade in
JD8_Blit(fondo); JD8_Blit(fondo);
JG_SetUpdateTicks(1); JG_SetUpdateTicks(1);
while (!JD8_FadeToPalAsync(pal) && !JG_Quitting()) { while (!JD8_FadeToPalAsync(pal) && !JG_Quitting()) {
while (!JG_ShouldUpdate()) { JI_Update(); } while (!JG_ShouldUpdate()) { JI_Update(); }
} }
// Movem la primera opció del menú al lloc
int x = 320; int x = 320;
while (!JG_Quitting() && x > 0) { while (!JG_Quitting() && x > 0) {
while (!JG_ShouldUpdate()) { JI_Update(); } while (!JG_ShouldUpdate()) { JI_Update(); }
@@ -50,6 +54,8 @@ int ModuleMenu::Go() {
} }
JD8_BlitCKToSurface(0, 50, opcions, 0, 50, 320, 38, fondo, 0); JD8_BlitCKToSurface(0, 50, opcions, 0, 50, 320, 38, fondo, 0);
// Movem la segona opció del menú al lloc
x = 320; x = 320;
while (!JG_Quitting() && x > 25) { while (!JG_Quitting() && x > 25) {
while (!JG_ShouldUpdate()) { JI_Update(); } while (!JG_ShouldUpdate()) { JI_Update(); }
@@ -60,6 +66,8 @@ int ModuleMenu::Go() {
} }
JD8_BlitCKToSurface(25, 88, opcions, 25, 88, 135, 37, fondo, 0); JD8_BlitCKToSurface(25, 88, opcions, 25, 88, 135, 37, fondo, 0);
// Movem la tercera opció del menú al lloc
x = 320; x = 320;
while (!JG_Quitting() && x > 0) { while (!JG_Quitting() && x > 0) {
while (!JG_ShouldUpdate()) { JI_Update(); } while (!JG_ShouldUpdate()) { JI_Update(); }
@@ -70,6 +78,8 @@ int ModuleMenu::Go() {
} }
JD8_BlitCKToSurface(0, 125, opcions, 0, 125, 320, 38, fondo, 0); JD8_BlitCKToSurface(0, 125, opcions, 0, 125, 320, 38, fondo, 0);
// Movem la quarta opció del menú al lloc
x = 320; x = 320;
while (!JG_Quitting() && x > 0) { while (!JG_Quitting() && x > 0) {
while (!JG_ShouldUpdate()) { JI_Update(); } while (!JG_ShouldUpdate()) { JI_Update(); }
@@ -80,6 +90,8 @@ int ModuleMenu::Go() {
} }
JD8_BlitCKToSurface(0, 163, opcions, 0, 163, 320, 37, fondo, 0); JD8_BlitCKToSurface(0, 163, opcions, 0, 163, 320, 37, fondo, 0);
// Movem el titol del menú al lloc
int y = 50; int y = 50;
while (!JG_Quitting() && y > 0) { while (!JG_Quitting() && y > 0) {
while (!JG_ShouldUpdate()) { JI_Update(); } while (!JG_ShouldUpdate()) { JI_Update(); }
@@ -90,6 +102,8 @@ int ModuleMenu::Go() {
} }
JD8_BlitCKToSurface(0, 0, opcions, 0, 0, 320, 50, fondo, 0); JD8_BlitCKToSurface(0, 0, opcions, 0, 0, 320, 50, fondo, 0);
// Variables necessaries per al menú
int opcio_seleccionada = OPCIO_TIMEATTACK; int opcio_seleccionada = OPCIO_TIMEATTACK;
int opcio_triada = SENSE_OPCIO; int opcio_triada = SENSE_OPCIO;
bool fletxa_amunt_pulsada = false; bool fletxa_amunt_pulsada = false;
@@ -99,51 +113,79 @@ int ModuleMenu::Go() {
JG_SetUpdateTicks(20); JG_SetUpdateTicks(20);
while (!JG_Quitting() && opcio_triada == SENSE_OPCIO) {
while (!JG_ShouldUpdate()) { // Gestió del menú en sí (triar opció)
// [RZC 31/01/2024] [TODO] Al temps que se fiquen els marcadors
while (!JG_Quitting() && opcio_triada == SENSE_OPCIO)
{
while (!JG_ShouldUpdate())
{
JI_Update(); JI_Update();
if (JI_KeyPressed(SDL_SCANCODE_UP)) {
if (!fletxa_amunt_pulsada) { if (JI_KeyPressed(SDL_SCANCODE_UP))
{
if (!fletxa_amunt_pulsada)
{
fletxa_amunt_pulsada = true; fletxa_amunt_pulsada = true;
opcio_seleccionada--; if (opcio_seleccionada < 0) opcio_seleccionada = 3; opcio_seleccionada--; if (opcio_seleccionada < 0) opcio_seleccionada = 3;
} }
} else { }
else
{
fletxa_amunt_pulsada = false; fletxa_amunt_pulsada = false;
} }
if (JI_KeyPressed(SDL_SCANCODE_DOWN)) {
if (!fletxa_avall_pulsada) { if (JI_KeyPressed(SDL_SCANCODE_DOWN))
{
if (!fletxa_avall_pulsada)
{
fletxa_avall_pulsada = true; fletxa_avall_pulsada = true;
opcio_seleccionada++; if (opcio_seleccionada > 3) opcio_seleccionada = 0; opcio_seleccionada++; if (opcio_seleccionada > 3) opcio_seleccionada = 0;
} }
} else { }
else
{
fletxa_avall_pulsada = false; fletxa_avall_pulsada = false;
} }
if (JI_KeyPressed(SDL_SCANCODE_SPACE)) {
if (JI_KeyPressed(SDL_SCANCODE_SPACE))
{
opcio_triada = opcio_seleccionada; opcio_triada = opcio_seleccionada;
} }
if (JI_KeyPressed(SDL_SCANCODE_ESCAPE))
{
JG_QuitSignal();
}
} }
x_fletxa += x_velocitat; x_fletxa += x_velocitat;
x_velocitat -= 0.1; x_velocitat -= 0.1;
if (x_fletxa < 0) { if (x_fletxa < 0)
{
x_fletxa = 0; x_fletxa = 0;
x_velocitat = 1; x_velocitat = 1;
} }
JD8_Blit(fondo); JD8_Blit(fondo);
JD8_BlitCK(10+x_fletxa, 60+opcio_seleccionada*37, gfx, 18, 5, 9, 10, 255); JD8_BlitCK(10+x_fletxa, 60+opcio_seleccionada*37, gfx, 18, 5, 9, 10, 255);
JD8_Flip(); JD8_Flip();
} }
JD8_BlitCKToSurface(10 + x_fletxa, 60 + opcio_seleccionada * 37, gfx, 18, 5, 9, 10, fondo, 255); JD8_BlitCKToSurface(10 + x_fletxa, 60 + opcio_seleccionada * 37, gfx, 18, 5, 9, 10, fondo, 255);
// BLINDS OUT
// Blinds out
JG_SetUpdateTicks(8); JG_SetUpdateTicks(8);
x = 0; x = 0;
while (x < 32 && !JG_Quitting()) { while (x < 32 && !JG_Quitting())
{
while (!JG_ShouldUpdate()) { JI_Update(); } while (!JG_ShouldUpdate()) { JI_Update(); }
for (y = 0; y < 200; y++) { for (y = 0; y < 200; y++)
for (int i = 0; i < 10; i++) { {
for (int i = 0; i < 10; i++)
{
JD8_PutPixel(fondo, i * 32 + x, y, 0); JD8_PutPixel(fondo, i * 32 + x, y, 0);
} }
} }
@@ -152,24 +194,29 @@ int ModuleMenu::Go() {
JD8_Flip(); JD8_Flip();
} }
// FREE EVERYTHING
// Alliberar memòria
JD8_FreeSurface(fondo); JD8_FreeSurface(fondo);
JD8_FreeSurface(opcions); JD8_FreeSurface(opcions);
JD8_FreeSurface(gfx); JD8_FreeSurface(gfx);
free(pal); free(pal);
// Canviar el estat al que toque
if (JG_Quitting())
if (JG_Quitting()) { {
return ESTAT_EIXIR; info::estat_joc = ESTAT_EIXIR;
} else { }
switch (opcio_triada) { else
case OPCIO_TIMEATTACK: return ESTAT_LOGO; break; {
case OPCIO_WORLDTOUR: return ESTAT_SELECT; break; switch (opcio_triada)
case OPCIO_CLASSICMODE: return ESTAT_MENU; break; {
case OPCIO_OPTIONS: return ESTAT_MENU; break; case OPCIO_TIMEATTACK: info::estat_joc = ESTAT_LOGO; break;
case OPCIO_WORLDTOUR: info::estat_joc = ESTAT_SELECT; break;
case OPCIO_CLASSICMODE: info::estat_joc = ESTAT_MENU; break;
case OPCIO_OPTIONS: info::estat_joc = ESTAT_MENU; break;
}
}
} }
} }
return ESTAT_EIXIR;
} }

View File

@@ -1,17 +0,0 @@
#pragma once
class ModuleMenu {
public:
ModuleMenu();
~ModuleMenu(void);
int Go();
private:
//void showMenu();
int contador;
};

9
modules.h Normal file
View File

@@ -0,0 +1,9 @@
#pragma once
namespace module
{
namespace staticScreen { void go(); }
namespace menu { void go(); }
namespace select { void go(); }
namespace sequence { void go(); }
}

View File

@@ -1,4 +1,4 @@
#include "moduleselect.h" #include "modules.h"
#include "jgame.h" #include "jgame.h"
#include "jdraw8.h" #include "jdraw8.h"
@@ -8,37 +8,22 @@
#include <string> #include <string>
#include "info.h" #include "info.h"
ModuleSelect::ModuleSelect() { namespace module
{
} namespace select
{
ModuleSelect::~ModuleSelect(void) { void go()
} {
// Inicialitzem gràfics
void pintaMarc(int posicio) {
for (int i = posicio; i <= posicio + 75; i++) {
JD8_PutPixel(i, 11, 15);
JD8_PutPixel(i, 12, 15);
JD8_PutPixel(i, 90, 15);
JD8_PutPixel(i, 91, 15);
}
for (int i = 11; i <= 91; i++) {
JD8_PutPixel(posicio, i, 15);
JD8_PutPixel(posicio + 1, i, 15);
JD8_PutPixel(posicio + 74, i, 15);
JD8_PutPixel(posicio + 75, i, 15);
}
}
int ModuleSelect::Go() {
JD8_Surface fondo = JD8_LoadSurface("select.gif"); JD8_Surface fondo = JD8_LoadSurface("select.gif");
JD8_Palette pal = JD8_LoadPalette("select.gif"); JD8_Palette pal = JD8_LoadPalette("select.gif");
JD8_Surface gfx = JD8_LoadSurface("sprites.gif"); JD8_Surface gfx = JD8_LoadSurface("sprites.gif");
int num_personatges = 3; int num_personatges = 3;
if (!info::rosita_enabled) { // Llevem els persoantges que encara no estàn desbloquejats
if (!info::rosita_enabled)
{
num_personatges--; num_personatges--;
for (int i = 137; i <= 212; i++) for (int j = 11; j <= 91; j++) JD8_PutPixel(fondo, i, j, 0); for (int i = 137; i <= 212; i++) for (int j = 11; j <= 91; j++) JD8_PutPixel(fondo, i, j, 0);
JD8_PutPixel(fondo, 145, 19, 14); JD8_PutPixel(fondo, 145, 19, 14);
@@ -53,7 +38,8 @@ int ModuleSelect::Go() {
JD8_PutPixel(fondo, 139, 37, 9); JD8_PutPixel(fondo, 139, 37, 9);
JD8_PutPixel(fondo, 211, 81, 9); JD8_PutPixel(fondo, 211, 81, 9);
} }
if (!info::job_enabled) { if (!info::job_enabled)
{
num_personatges--; num_personatges--;
for (int i = 219; i <= 294; i++) for (int j = 11; j <= 91; j++) JD8_PutPixel(fondo, i, j, 0); for (int i = 219; i <= 294; i++) for (int j = 11; j <= 91; j++) JD8_PutPixel(fondo, i, j, 0);
JD8_PutPixel(fondo, 228, 65, 14); JD8_PutPixel(fondo, 228, 65, 14);
@@ -72,13 +58,16 @@ int ModuleSelect::Go() {
JD8_ClearScreen(0); JD8_ClearScreen(0);
JD8_Flip(); JD8_Flip();
// FADE IN
// Fade in
JD8_Blit(fondo); JD8_Blit(fondo);
JG_SetUpdateTicks(1); JG_SetUpdateTicks(1);
while (!JD8_FadeToPalAsync(pal) && !JG_Quitting()) { while (!JD8_FadeToPalAsync(pal) && !JG_Quitting())
{
while (!JG_ShouldUpdate()) { JI_Update(); } while (!JG_ShouldUpdate()) { JI_Update(); }
} }
// Variables necessaries per a triar personatge i dificultat
int opcio_seleccionada = info::dificultat; int opcio_seleccionada = info::dificultat;
int opcio_triada = SENSE_OPCIO; int opcio_triada = SENSE_OPCIO;
int personatge_seleccionat = info::personatge; int personatge_seleccionat = info::personatge;
@@ -93,81 +82,126 @@ int ModuleSelect::Go() {
int G = 0; int G = 0;
int B = 0; int B = 0;
while (!JG_Quitting() && opcio_triada == SENSE_OPCIO) {
while (!JG_ShouldUpdate()) { // Ací se controla la tria de opcions en sí
while (!JG_Quitting() && opcio_triada == SENSE_OPCIO)
{
while (!JG_ShouldUpdate())
{
JI_Update(); JI_Update();
if (JI_KeyPressed(SDL_SCANCODE_UP)) { if (JI_KeyPressed(SDL_SCANCODE_UP))
if (!fletxa_amunt_pulsada) { {
if (!fletxa_amunt_pulsada)
{
fletxa_amunt_pulsada = true; fletxa_amunt_pulsada = true;
opcio_seleccionada--; if (opcio_seleccionada < 0) opcio_seleccionada = 2; opcio_seleccionada--; if (opcio_seleccionada < 0) opcio_seleccionada = 2;
} }
} else { }
else
{
fletxa_amunt_pulsada = false; fletxa_amunt_pulsada = false;
} }
if (JI_KeyPressed(SDL_SCANCODE_DOWN)) { if (JI_KeyPressed(SDL_SCANCODE_DOWN))
if (!fletxa_avall_pulsada) { {
if (!fletxa_avall_pulsada)
{
fletxa_avall_pulsada = true; fletxa_avall_pulsada = true;
opcio_seleccionada++; if (opcio_seleccionada > 2) opcio_seleccionada = 0; opcio_seleccionada++; if (opcio_seleccionada > 2) opcio_seleccionada = 0;
} }
} else { }
else
{
fletxa_avall_pulsada = false; fletxa_avall_pulsada = false;
} }
if (JI_KeyPressed(SDL_SCANCODE_LEFT)) { if (JI_KeyPressed(SDL_SCANCODE_LEFT))
if (!fletxa_esquerra_pulsada) { {
if (!fletxa_esquerra_pulsada)
{
fletxa_esquerra_pulsada = true; fletxa_esquerra_pulsada = true;
personatge_seleccionat--; if (personatge_seleccionat < 0) personatge_seleccionat = num_personatges-1; personatge_seleccionat--; if (personatge_seleccionat < 0) personatge_seleccionat = num_personatges-1;
} }
} else { }
else
{
fletxa_esquerra_pulsada = false; fletxa_esquerra_pulsada = false;
} }
if (JI_KeyPressed(SDL_SCANCODE_RIGHT)) { if (JI_KeyPressed(SDL_SCANCODE_RIGHT))
if (!fletxa_dreta_pulsada) { {
if (!fletxa_dreta_pulsada)
{
fletxa_dreta_pulsada = true; fletxa_dreta_pulsada = true;
personatge_seleccionat++; if (personatge_seleccionat > num_personatges-1) personatge_seleccionat = 0; personatge_seleccionat++; if (personatge_seleccionat > num_personatges-1) personatge_seleccionat = 0;
} }
} else { }
else
{
fletxa_dreta_pulsada = false; fletxa_dreta_pulsada = false;
} }
if (JI_KeyPressed(SDL_SCANCODE_SPACE)) { if (JI_KeyPressed(SDL_SCANCODE_SPACE))
{
opcio_triada = opcio_seleccionada; opcio_triada = opcio_seleccionada;
} }
} }
// Fer cicle dels colorets de la vora del personatge
i = (i + 1) % 127; i = (i + 1) % 127;
G = B = abs(63-i); G = B = abs(63-i);
JD8_SetPaletteColor(15, 252, G, B); JD8_SetPaletteColor(15, 252, G, B);
// Pintar-ho tot
JD8_Blit(fondo); JD8_Blit(fondo);
pintaMarc(55 + personatge_seleccionat * 82);
const int posicio = 55 + personatge_seleccionat * 82;
for (int i = posicio; i <= posicio + 75; i++) {
JD8_PutPixel(i, 11, 15);
JD8_PutPixel(i, 12, 15);
JD8_PutPixel(i, 90, 15);
JD8_PutPixel(i, 91, 15);
}
for (int i = 11; i <= 91; i++) {
JD8_PutPixel(posicio, i, 15);
JD8_PutPixel(posicio + 1, i, 15);
JD8_PutPixel(posicio + 74, i, 15);
JD8_PutPixel(posicio + 75, i, 15);
}
JD8_BlitCK(100, 120 + opcio_seleccionada * 25, gfx, 9, 5, 9, 10, 255); JD8_BlitCK(100, 120 + opcio_seleccionada * 25, gfx, 9, 5, 9, 10, 255);
JD8_Flip(); JD8_Flip();
} }
JD8_BlitCKToSurface(100, 120 + opcio_seleccionada * 25, gfx, 9, 5, 9, 10, fondo, 255); JD8_BlitCKToSurface(100, 120 + opcio_seleccionada * 25, gfx, 9, 5, 9, 10, fondo, 255);
// FADE OUT
// Fade out
JG_SetUpdateTicks(2); JG_SetUpdateTicks(2);
while (!JD8_FadeOutAsync() && !JG_Quitting()) { while (!JD8_FadeOutAsync() && !JG_Quitting())
{
while (!JG_ShouldUpdate()) { JI_Update(); } while (!JG_ShouldUpdate()) { JI_Update(); }
} }
// FREE EVERYTHING // Alliberem memòria
JD8_FreeSurface(fondo); JD8_FreeSurface(fondo);
JD8_FreeSurface(gfx); JD8_FreeSurface(gfx);
free(pal); free(pal);
// Canviar el estat al que toque
if (JG_Quitting())
if (JG_Quitting()) { {
return ESTAT_EIXIR; info::estat_joc = ESTAT_EIXIR;
} else { }
else
{
info::dificultat = opcio_triada; info::dificultat = opcio_triada;
info::personatge = personatge_seleccionat; info::personatge = personatge_seleccionat;
return ESTAT_SEQUENCIA; info::estat_joc = ESTAT_SEQUENCIA;
}
}
} }
} }

View File

@@ -1,14 +0,0 @@
#pragma once
class ModuleSelect {
public:
ModuleSelect();
~ModuleSelect(void);
int Go();
private:
};

View File

@@ -1,4 +1,4 @@
#include "modulesequence.h" #include "modules.h"
#include "jgame.h" #include "jgame.h"
#include "jdraw8.h" #include "jdraw8.h"
@@ -8,21 +8,126 @@
#include <string> #include <string>
#include "info.h" #include "info.h"
JD8_Surface gfx = nullptr; namespace module
JD8_Surface fondo = nullptr; {
JD8_Palette pal = nullptr; namespace sequence
{
JD8_Surface gfx = nullptr;
JD8_Surface fondo = nullptr;
JD8_Surface fondo_temp = nullptr;
JD8_Palette pal = nullptr;
ModuleSequence::ModuleSequence() { void fadeIn()
gfx = nullptr; {
fondo = nullptr; JD8_Blit(fondo);
pal = nullptr; JG_SetUpdateTicks(1);
} while (!JD8_FadeToPalAsync(pal) && !JG_Quitting())
{
while (!JG_ShouldUpdate()) { JI_Update(); }
}
}
ModuleSequence::~ModuleSequence(void) { void fadeOut()
} {
JG_SetUpdateTicks(2);
while (!JD8_FadeOutAsync() && !JG_Quitting())
{
while (!JG_ShouldUpdate()) { JI_Update(); }
}
}
int ModuleSequence::Go() { void drawChar(int x, int y, char char_actual)
{
char_actual -= 42; if (char_actual < 0) char_actual = 57;
if (char_actual == 4) char_actual = 56;
JD8_BlitCKToSurface(x, y, gfx, (char_actual % 35) * 9, 6 + floorf(char_actual / 35) * 9, 9, 9, fondo_temp, 255);
}
void wait(int time)
{
bool eixir = false;
int temps_inicial = JG_GetCycleCounter();
while ((JG_GetCycleCounter() - temps_inicial < time) && !eixir)
{
while (!JG_ShouldUpdate()) { JI_Update(); if (JI_AnyKey() || JG_Quitting()) { eixir = true; } }
}
}
void showText(int x, int y, int color, int speed, const char * text1, const char * text2 = NULL, const char * text3 = NULL)
{
bool eixir = false;
fondo_temp = JD8_NewSurface();
JD8_BlitToSurface(0, 0, fondo, 0, 0, 320, 200, fondo_temp);
JD8_Blit(fondo_temp);
JG_SetUpdateTicks(10);
JD8_SetPaletteColor(254, color);
// mod 35
// A (65) = 23 -> char - 42
// Special chars: ( ) <20> ' - : ! .
// [ \ ] ^ _ ` a b
int tamany_text = strlen(text1);
int temps_total = tamany_text * speed;
int temps_inicial = JG_GetCycleCounter();
while ((JG_GetCycleCounter() - temps_inicial < temps_total) && !eixir && !JG_Quitting())
{
int num_chars_actual = (JG_GetCycleCounter() - temps_inicial) / speed;
drawChar(x + (num_chars_actual + 1) * 8, y, text1[num_chars_actual]);
while (!JG_ShouldUpdate()) { JI_Update(); if (JI_AnyKey()) { eixir = true; } }
JD8_Blit(fondo_temp);
JD8_Flip();
}
if (eixir) for (int i = 0; i <= tamany_text; i++) drawChar(x + (i + 1) * 8, y, text1[i]);
if (text2 != NULL)
{
tamany_text = strlen(text2);
temps_total = tamany_text * speed;
temps_inicial = JG_GetCycleCounter();
while ((JG_GetCycleCounter() - temps_inicial < temps_total) && !eixir && !JG_Quitting())
{
int num_chars_actual = (JG_GetCycleCounter() - temps_inicial) / speed;
drawChar(x + (num_chars_actual + 1) * 8, y+10, text2[num_chars_actual]);
while (!JG_ShouldUpdate()) { JI_Update(); if (JI_AnyKey()) { eixir = true; } }
JD8_Blit(fondo_temp);
JD8_Flip();
}
if (eixir) for (int i = 0; i <= tamany_text; i++) drawChar(x + (i + 1) * 8, y+10, text2[i]);
if (text3 != NULL)
{
tamany_text = strlen(text3);
temps_total = tamany_text * speed;
temps_inicial = JG_GetCycleCounter();
while ((JG_GetCycleCounter() - temps_inicial < temps_total) && !eixir && !JG_Quitting())
{
int num_chars_actual = (JG_GetCycleCounter() - temps_inicial) / speed;
drawChar(x + (num_chars_actual + 1) * 8, y+20, text3[num_chars_actual]);
while (!JG_ShouldUpdate()) { JI_Update(); if (JI_AnyKey()) { eixir = true; } }
JD8_Blit(fondo_temp);
JD8_Flip();
}
if (eixir) for (int i = 0; i <= tamany_text; i++) drawChar(x + (i + 1) * 8, y+10, text3[i]);
}
}
JD8_Blit(fondo_temp);
JD8_Flip();
wait(200);
}
void go()
{
JS_LoadMusic("mhist.mid"); JS_LoadMusic("mhist.mid");
JS_PlayMusic(-1); JS_PlayMusic(-1);
@@ -33,54 +138,51 @@ int ModuleSequence::Go() {
fondo = JD8_LoadSurface("hist01.gif"); fondo = JD8_LoadSurface("hist01.gif");
pal = JD8_LoadPalette("hist01.gif"); pal = JD8_LoadPalette("hist01.gif");
this->FadeIn(); fadeIn();
this->ShowText(40, 90, 2, 10, "QUE BON DIA FA NO CREUS PEPE"); showText(40, 90, 2, 10, "QUE BON DIA FA NO CREUS PEPE");
this->ShowText(50, 80, 10, 10, "EEEE..SS..SSIII.SI"); showText(50, 80, 10, 10, "EEEE..SS..SSIII.SI");
this->ShowText(140, 140, 2, 10, "[SEMPRE QUE M^ACOSTE", "A PEPE ES POSA RARO\\"); showText(140, 140, 2, 10, "[SEMPRE QUE M^ACOSTE", "A PEPE ES POSA RARO\\");
JD8_Blit(fondo); wait(200);
JD8_Flip(); fadeOut();
this->Wait(200);
this->FadeOut();
JD8_FreeSurface(fondo); JD8_FreeSurface(fondo);
free(pal); free(pal);
if (!JG_Quitting()) { if (!JG_Quitting())
{
fondo = JD8_LoadSurface("hist02.gif"); fondo = JD8_LoadSurface("hist02.gif");
pal = JD8_LoadPalette("hist02.gif"); pal = JD8_LoadPalette("hist02.gif");
this->FadeIn(); fadeIn();
this->ShowText(100, 140, 10, 10, "AAAAY a"); showText(100, 140, 10, 10, "AAAAY a");
this->ShowText(100, 55, 3, 10, "JA T^HE PILLAT PEPE"); showText(100, 55, 3, 10, "JA T^HE PILLAT PEPE");
this->ShowText(145, 125, 2, 1, "AUXILIa"); showText(145, 125, 2, 1, "AUXILIa");
JD8_Blit(fondo); wait(200);
JD8_Flip(); fadeOut();
this->Wait(200);
this->FadeOut();
JD8_FreeSurface(fondo); JD8_FreeSurface(fondo);
free(pal); free(pal);
} }
if (!JG_Quitting()) { if (!JG_Quitting())
{
fondo = JD8_LoadSurface("hist03.gif"); fondo = JD8_LoadSurface("hist03.gif");
pal = JD8_LoadPalette("hist03.gif"); pal = JD8_LoadPalette("hist03.gif");
this->FadeIn(); fadeIn();
this->ShowText(50, 80, 5, 10, "ARA ROSITA ES MEUA"); showText(50, 80, 5, 10, "ARA ROSITA ES MEUA");
this->ShowText(50, 80, 5, 10, "SI VOLS ACONSEGUIR_LA", "HAURAS DE SEGUIR_ME", "PER TOT EL MONb"); showText(50, 80, 5, 10, "SI VOLS ACONSEGUIR_LA", "HAURAS DE SEGUIR_ME", "PER TOT EL MONb");
this->ShowText(60, 80, 5, 1, "JA JA JA JA JA aa"); showText(60, 80, 5, 1, "JA JA JA JA JA aa");
JD8_Blit(fondo); wait(200);
JD8_Flip(); fadeOut();
this->Wait(200);
this->FadeOut();
JD8_FreeSurface(fondo); JD8_FreeSurface(fondo);
free(pal); free(pal);
} }
if (!JG_Quitting()) { if (!JG_Quitting())
{
fondo = JD8_LoadSurface("hist04.gif"); fondo = JD8_LoadSurface("hist04.gif");
pal = JD8_LoadPalette("hist04.gif"); pal = JD8_LoadPalette("hist04.gif");
this->FadeIn(); fadeIn();
this->ShowText(120, 60, 2, 5, "AJUDA^M PEPEa"); showText(120, 60, 2, 5, "AJUDA^M PEPEa");
this->ShowText(50, 50, 7, 50, "MALEIT SIGUES", "ET TROBAREbbb"); showText(50, 50, 7, 50, "MALEIT SIGUES", "ET TROBAREbbb");
this->FadeOut(); fadeOut();
JD8_FreeSurface(fondo); JD8_FreeSurface(fondo);
free(pal); free(pal);
} }
@@ -89,141 +191,10 @@ int ModuleSequence::Go() {
JD8_FreeSurface(gfx); JD8_FreeSurface(gfx);
if (JG_Quitting()) { if (JG_Quitting()) {
return ESTAT_EIXIR; info::estat_joc = ESTAT_EIXIR;
} else { } else {
return ESTAT_JOC; info::estat_joc = ESTAT_MENU;
} }
} }
void ModuleSequence::FadeIn() {
JD8_Blit(fondo);
JG_SetUpdateTicks(1);
while (!JD8_FadeToPalAsync(pal) && !JG_Quitting()) {
while (!JG_ShouldUpdate()) { JI_Update(); }
}
}
void ModuleSequence::FadeOut() {
JG_SetUpdateTicks(2);
while (!JD8_FadeOutAsync() && !JG_Quitting()) {
while (!JG_ShouldUpdate()) { JI_Update(); }
}
}
void ModuleSequence::ShowText(int x, int y, int color, int speed, const char * text1, const char * text2, const char * text3) {
bool eixir = false;
JG_SetUpdateTicks(10);
JD8_SetPaletteColor(254, color);
// mod 35
// A (65) = 23 -> char - 42
// Special chars: ( ) <20> ' - : ! .
// [ \ ] ^ _ ` a b
int tamany_text1 = strlen(text1);
int temps_total = tamany_text1 * speed;
int temps_inicial = JG_GetCycleCounter();
while ((JG_GetCycleCounter() - temps_inicial < temps_total) && !eixir && !JG_Quitting()) {
JD8_Blit(fondo);
int num_chars_actual = (JG_GetCycleCounter() - temps_inicial) / speed;
for (int i = 0; i <= num_chars_actual; i++) {
int char_actual = text1[i] - 42; if (char_actual < 0) char_actual = 57;
if (text1[i] == '.') char_actual = 56;
JD8_BlitCK(x + (i+1) * 8, y, gfx, (char_actual % 35) * 9, 6+floorf(char_actual / 35) * 9, 9, 9, 255);
}
while (!JG_ShouldUpdate()) { JI_Update(); if (JI_AnyKey()) { eixir = true; } }
JD8_Flip();
}
if (eixir) {
for (int i = 0; i <= tamany_text1; i++) {
int char_actual = text1[i] - 42; if (char_actual < 0) char_actual = 57;
if (text1[i] == '.') char_actual = 56;
JD8_BlitCK(x + (i + 1) * 8, y, gfx, (char_actual % 35) * 9, 6 + floorf(char_actual / 35) * 9, 9, 9, 255);
}
}
if (text2 != NULL) {
int tamany_text2 = strlen(text2);
temps_total = tamany_text2 * speed;
temps_inicial = JG_GetCycleCounter();
while ((JG_GetCycleCounter() - temps_inicial < temps_total) && !eixir && !JG_Quitting()) {
JD8_Blit(fondo);
int num_chars_actual = (JG_GetCycleCounter() - temps_inicial) / speed;
for (int i = 0; i <= tamany_text1; i++) {
int char_actual = text1[i] - 42; if (char_actual < 0) char_actual = 57;
if (text1[i] == '.') char_actual = 56;
JD8_BlitCK(x + (i + 1) * 8, y, gfx, (char_actual % 35) * 9, 6 + floorf(char_actual / 35) * 9, 9, 9, 255);
}
for (int i = 0; i <= num_chars_actual; i++) {
int char_actual = text2[i] - 42; if (char_actual < 0) char_actual = 57;
if (text2[i] == '.') char_actual = 56;
JD8_BlitCK(x + (i + 1) * 8, y+10, gfx, (char_actual % 35) * 9, 6 + floorf(char_actual / 35) * 9, 9, 9, 255);
}
while (!JG_ShouldUpdate()) { JI_Update(); if (JI_AnyKey()) { eixir = true; } }
JD8_Flip();
}
if (eixir) {
for (int i = 0; i <= tamany_text2; i++) {
int char_actual = text2[i] - 42; if (char_actual < 0) char_actual = 57;
if (text2[i] == '.') char_actual = 56;
JD8_BlitCK(x + (i + 1) * 8, y + 10, gfx, (char_actual % 35) * 9, 6 + floorf(char_actual / 35) * 9, 9, 9, 255);
}
}
if (text3 != NULL) {
int tamany_text3 = strlen(text3);
temps_total = tamany_text3 * speed;
temps_inicial = JG_GetCycleCounter();
while ((JG_GetCycleCounter() - temps_inicial < temps_total) && !eixir && !JG_Quitting()) {
JD8_Blit(fondo);
int num_chars_actual = (JG_GetCycleCounter() - temps_inicial) / speed;
for (int i = 0; i <= tamany_text1; i++) {
int char_actual = text1[i] - 42; if (char_actual < 0) char_actual = 57;
if (text1[i] == '.') char_actual = 56;
JD8_BlitCK(x + (i + 1) * 8, y, gfx, (char_actual % 35) * 9, 6 + floorf(char_actual / 35) * 9, 9, 9, 255);
}
for (int i = 0; i <= tamany_text2; i++) {
int char_actual = text2[i] - 42; if (char_actual < 0) char_actual = 57;
if (text2[i] == '.') char_actual = 56;
JD8_BlitCK(x + (i + 1) * 8, y+10, gfx, (char_actual % 35) * 9, 6 + floorf(char_actual / 35) * 9, 9, 9, 255);
}
for (int i = 0; i <= num_chars_actual; i++) {
int char_actual = text3[i] - 42; if (char_actual < 0) char_actual = 57;
if (text3[i] == '.') char_actual = 56;
JD8_BlitCK(x + (i + 1) * 8, y + 20, gfx, (char_actual % 35) * 9, 6 + floorf(char_actual / 35) * 9, 9, 9, 255);
}
while (!JG_ShouldUpdate()) { JI_Update(); if (JI_AnyKey()) { eixir = true; } }
JD8_Flip();
}
for (int i = 0; i <= tamany_text3; i++) {
int char_actual = text3[i] - 42; if (char_actual < 0) char_actual = 57;
if (text3[i] == '.') char_actual = 56;
JD8_BlitCK(x + (i + 1) * 8, y + 20, gfx, (char_actual % 35) * 9, 6 + floorf(char_actual / 35) * 9, 9, 9, 255);
}
JD8_Flip();
}
}
JD8_Flip();
Wait(200);
}
void ModuleSequence::Wait(int time) {
bool eixir = false;
int temps_inicial = JG_GetCycleCounter();
while ((JG_GetCycleCounter() - temps_inicial < time) && !eixir) {
while (!JG_ShouldUpdate()) { JI_Update(); if (JI_AnyKey() || JG_Quitting()) { eixir = true; } }
} }
} }

View File

@@ -1,18 +0,0 @@
#pragma once
class ModuleSequence {
public:
ModuleSequence();
~ModuleSequence(void);
int Go();
private:
void FadeIn();
void FadeOut();
void ShowText(int x, int y, int color, int speed, const char* text1, const char* text2 = nullptr, const char* text3 = nullptr);
void Wait(int time);
};

View File

@@ -1,4 +1,4 @@
#include "modulestaticscreen.h" #include "modules.h"
#include "jgame.h" #include "jgame.h"
#include "jdraw8.h" #include "jdraw8.h"
@@ -8,55 +8,46 @@
#include <string> #include <string>
#include "info.h" #include "info.h"
ModuleStaticScreen::ModuleStaticScreen() {
} namespace module
{
ModuleStaticScreen::~ModuleStaticScreen(void) { namespace staticScreen
} {
void go()
int ModuleStaticScreen::Go() { {
bool eixir = false;
JD8_Surface gfx = nullptr;
JD8_Palette pal = nullptr;
// Carrega grafics i música
switch( info::estat_joc ) { switch( info::estat_joc ) {
case ESTAT_ICEKAS: case ESTAT_ICEKAS:
doIcekas();
break;
case ESTAT_LOGO:
doLogo();
break;
}
JD8_FadeOut();
if( JG_Quitting() ) {
return ESTAT_EIXIR;
} else {
switch (info::estat_joc) {
case ESTAT_ICEKAS: return ESTAT_LOGO; break;
case ESTAT_LOGO: return ESTAT_MENU; break;
}
}
return 0;
}
void ModuleStaticScreen::doIcekas() {
bool eixir = false;
JS_LoadMusic("mlogo.mid"); JS_LoadMusic("mlogo.mid");
JS_PlayMusic(1); JS_PlayMusic(1);
JD8_Surface gfx = JD8_LoadSurface( "logo.gif" ); gfx = JD8_LoadSurface( "logo.gif" );
JD8_Palette pal = JD8_LoadPalette( "logo.gif" ); pal = JD8_LoadPalette( "logo.gif" );
break;
JD8_ClearScreen( 0 ); case ESTAT_LOGO:
JD8_Flip(); gfx = JD8_LoadSurface("titol.gif");
pal = JD8_LoadPalette("titol.gif");
break;
}
// FADE IN // Fade in
JD8_Blit(gfx); JD8_Blit(gfx);
JG_SetUpdateTicks(8); JG_SetUpdateTicks(8);
while (!JD8_FadeToPalAsync(pal) && !eixir) { while (!JD8_FadeToPalAsync(pal))
while (!JG_ShouldUpdate()) { JI_Update(); if (JI_AnyKey() || JG_Quitting()) { eixir = true; } } {
while (!JG_ShouldUpdate())
{
JI_Update();
if (JI_AnyKey() || JG_Quitting())
{
eixir = true;
}
}
} }
// DELAY // DELAY
@@ -64,50 +55,35 @@ void ModuleStaticScreen::doIcekas() {
int contador = 20; int contador = 20;
while (contador > 0 && !eixir) { while (contador > 0 && !eixir) {
contador--; contador--;
while (!JG_ShouldUpdate()) { JI_Update(); if (JI_AnyKey() || JG_Quitting()) { eixir = true; } } while (!JG_ShouldUpdate())
{
JI_Update();
if (JI_AnyKey() || JG_Quitting())
{
eixir = true;
}
}
} }
// FADE OUT // FADE OUT
JG_SetUpdateTicks(2); JG_SetUpdateTicks(2);
while (!JD8_FadeOutAsync() && !eixir) { while (!JD8_FadeOutAsync()) {
while (!JG_ShouldUpdate()) { JI_Update(); if (JI_AnyKey() || JG_Quitting()) { eixir = true; } } while (!JG_ShouldUpdate()) { JI_Update(); if (JI_AnyKey() || JG_Quitting()) { eixir = true; } }
} }
JD8_FreeSurface( gfx ); JD8_FreeSurface( gfx );
free(pal); free(pal);
}
//JD8_FadeOut();
void ModuleStaticScreen::doLogo() {
if( JG_Quitting() ) {
bool eixir = false; info::estat_joc = ESTAT_EIXIR;
} else {
JD8_Surface gfx = JD8_LoadSurface("titol.gif"); switch (info::estat_joc) {
JD8_Palette pal = JD8_LoadPalette("titol.gif"); case ESTAT_ICEKAS: info::estat_joc = ESTAT_LOGO; break;
case ESTAT_LOGO: info::estat_joc = ESTAT_MENU; break;
JD8_ClearScreen(0); }
JD8_Flip(); }
}
// FADE IN }
JD8_Blit(gfx);
JG_SetUpdateTicks(8);
while (!JD8_FadeToPalAsync(pal) && !eixir) {
while (!JG_ShouldUpdate()) { JI_Update(); if (JI_AnyKey() || JG_Quitting()) { eixir = true; } }
}
// DELAY
JG_SetUpdateTicks(100);
int contador = 20;
while (contador > 0 && !eixir) {
contador--;
while (!JG_ShouldUpdate()) { JI_Update(); if (JI_AnyKey() || JG_Quitting()) { eixir = true; } }
}
// FADE OUT
JG_SetUpdateTicks(2);
while (!JD8_FadeOutAsync() && !eixir) {
while (!JG_ShouldUpdate()) { JI_Update(); if (JI_AnyKey() || JG_Quitting()) { eixir = true; } }
}
JD8_FreeSurface(gfx);
free(pal);
} }

View File

@@ -1,18 +0,0 @@
#pragma once
class ModuleStaticScreen {
public:
ModuleStaticScreen();
~ModuleStaticScreen(void);
int Go();
private:
void doIcekas();
void doLogo();
int contador;
};