diff --git a/info.cpp b/info.cpp new file mode 100644 index 0000000..d157e7c --- /dev/null +++ b/info.cpp @@ -0,0 +1,10 @@ +#include "info.h" + +namespace info +{ + int estat_joc; + bool rosita_enabled; + bool job_enabled; + int dificultat; + int personatge; +} diff --git a/info.h b/info.h index 83a85c8..0ae699a 100644 --- a/info.h +++ b/info.h @@ -21,10 +21,10 @@ #define PERSONATGE_ROSITA 1 #define PERSONATGE_JOB 2 -struct Info { - int estat_joc; - bool rosita_enabled; - bool job_enabled; - int dificultat; - int personatge; -}; +namespace info{ + extern int estat_joc; + extern bool rosita_enabled; + extern bool job_enabled; + extern int dificultat; + extern int personatge; +} diff --git a/main.cpp b/main.cpp index 1bed702..c6ed7b1 100644 --- a/main.cpp +++ b/main.cpp @@ -36,47 +36,46 @@ int main( int argc, char* args[] ) { JD8_Init("Pepe El Pintor"); JS_Init(); - Info info; - info.estat_joc = ESTAT_ICEKAS; // ESTAT_SEQUENCIA; // ESTAT_ICEKAS; - info.rosita_enabled = false; - info.job_enabled = false; - info.dificultat = MODE_FACIL; - info.personatge = PERSONATGE_PEPE; + info::estat_joc = ESTAT_ICEKAS; // ESTAT_SEQUENCIA; // ESTAT_ICEKAS; + info::rosita_enabled = false; + info::job_enabled = false; + info::dificultat = MODE_FACIL; + info::personatge = PERSONATGE_PEPE; FILE* ini = fopen("trick.ini", "rb"); if (ini != NULL) { unsigned char contingut = 0; fread(&contingut, 1, 1, ini); fclose(ini); - if (contingut > 0) info.rosita_enabled = true; - if (contingut > 1) info.job_enabled = true; + if (contingut > 0) info::rosita_enabled = true; + if (contingut > 1) info::job_enabled = true; } - while (info.estat_joc != ESTAT_EIXIR) { - switch (info.estat_joc) { + while (info::estat_joc != ESTAT_EIXIR) { + switch (info::estat_joc) { case ESTAT_ICEKAS: case ESTAT_LOGO: ModuleStaticScreen * moduleStaticScreen; - moduleStaticScreen = new ModuleStaticScreen(&info); - info.estat_joc = moduleStaticScreen->Go(); + moduleStaticScreen = new ModuleStaticScreen(); + info::estat_joc = moduleStaticScreen->Go(); delete moduleStaticScreen; break; case ESTAT_MENU: ModuleMenu * moduleMenu; - moduleMenu = new ModuleMenu(&info); - info.estat_joc = moduleMenu->Go(); + moduleMenu = new ModuleMenu(); + info::estat_joc = moduleMenu->Go(); delete moduleMenu; break; case ESTAT_SELECT: ModuleSelect * moduleSelect; - moduleSelect = new ModuleSelect(&info); - info.estat_joc = moduleSelect->Go(); + moduleSelect = new ModuleSelect(); + info::estat_joc = moduleSelect->Go(); delete moduleSelect; break; case ESTAT_SEQUENCIA: ModuleSequence * moduleSequence; - moduleSequence = new ModuleSequence(&info); - info.estat_joc = moduleSequence->Go(); + moduleSequence = new ModuleSequence(); + info::estat_joc = moduleSequence->Go(); delete moduleSequence; break; } diff --git a/modulemenu.cpp b/modulemenu.cpp index a0a110d..189c349 100644 --- a/modulemenu.cpp +++ b/modulemenu.cpp @@ -6,6 +6,7 @@ #include "jsound.h" #include #include +#include "info.h" #define SENSE_OPCIO -1 #define OPCIO_TIMEATTACK 0 @@ -13,8 +14,7 @@ #define OPCIO_CLASSICMODE 2 #define OPCIO_OPTIONS 3 -ModuleMenu::ModuleMenu(Info* info) { - this->info = info; +ModuleMenu::ModuleMenu() { } ModuleMenu::~ModuleMenu(void) { diff --git a/modulemenu.h b/modulemenu.h index 243789e..c9c0963 100644 --- a/modulemenu.h +++ b/modulemenu.h @@ -1,12 +1,10 @@ #pragma once -#include "info.h" - class ModuleMenu { public: - ModuleMenu(Info* info); + ModuleMenu(); ~ModuleMenu(void); int Go(); @@ -15,6 +13,5 @@ private: //void showMenu(); - Info* info; int contador; }; diff --git a/moduleselect.cpp b/moduleselect.cpp index e031723..b85cd14 100644 --- a/moduleselect.cpp +++ b/moduleselect.cpp @@ -6,9 +6,10 @@ #include "jsound.h" #include #include +#include "info.h" -ModuleSelect::ModuleSelect(Info* info) { - this->info = info; +ModuleSelect::ModuleSelect() { + } ModuleSelect::~ModuleSelect(void) { @@ -37,7 +38,7 @@ int ModuleSelect::Go() { int num_personatges = 3; - if (!this->info->rosita_enabled) { + if (!info::rosita_enabled) { num_personatges--; 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); @@ -52,7 +53,7 @@ int ModuleSelect::Go() { JD8_PutPixel(fondo, 139, 37, 9); JD8_PutPixel(fondo, 211, 81, 9); } - if (!this->info->job_enabled) { + if (!info::job_enabled) { num_personatges--; 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); @@ -78,9 +79,9 @@ int ModuleSelect::Go() { while (!JG_ShouldUpdate()) { JI_Update(); } } - int opcio_seleccionada = this->info->dificultat; + int opcio_seleccionada = info::dificultat; int opcio_triada = SENSE_OPCIO; - int personatge_seleccionat = this->info->personatge; + int personatge_seleccionat = info::personatge; bool fletxa_amunt_pulsada = false; bool fletxa_avall_pulsada = false; bool fletxa_esquerra_pulsada = false; @@ -165,8 +166,8 @@ int ModuleSelect::Go() { if (JG_Quitting()) { return ESTAT_EIXIR; } else { - this->info->dificultat = opcio_triada; - this->info->personatge = personatge_seleccionat; + info::dificultat = opcio_triada; + info::personatge = personatge_seleccionat; return ESTAT_SEQUENCIA; } } diff --git a/moduleselect.h b/moduleselect.h index 3aa5ee9..3ae1827 100644 --- a/moduleselect.h +++ b/moduleselect.h @@ -1,17 +1,14 @@ #pragma once -#include "info.h" - class ModuleSelect { public: - ModuleSelect(Info* info); + ModuleSelect(); ~ModuleSelect(void); int Go(); private: - Info* info; }; diff --git a/modulesequence.cpp b/modulesequence.cpp index 7a47680..48cd3bb 100644 --- a/modulesequence.cpp +++ b/modulesequence.cpp @@ -6,13 +6,13 @@ #include "jsound.h" #include #include +#include "info.h" JD8_Surface gfx = nullptr; JD8_Surface fondo = nullptr; JD8_Palette pal = nullptr; -ModuleSequence::ModuleSequence(Info* info) { - this->info = info; +ModuleSequence::ModuleSequence() { gfx = nullptr; fondo = nullptr; pal = nullptr; diff --git a/modulesequence.h b/modulesequence.h index cf0e87c..89bc167 100644 --- a/modulesequence.h +++ b/modulesequence.h @@ -1,20 +1,16 @@ #pragma once -#include "info.h" - class ModuleSequence { public: - ModuleSequence(Info* info); + ModuleSequence(); ~ModuleSequence(void); int Go(); private: - Info * info; - 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); diff --git a/modulestaticscreen.cpp b/modulestaticscreen.cpp index 5b8d309..3250aea 100644 --- a/modulestaticscreen.cpp +++ b/modulestaticscreen.cpp @@ -6,9 +6,10 @@ #include "jsound.h" #include #include +#include "info.h" + +ModuleStaticScreen::ModuleStaticScreen() { -ModuleStaticScreen::ModuleStaticScreen( Info* info ) { - this->info = info; } ModuleStaticScreen::~ModuleStaticScreen(void) { @@ -16,7 +17,7 @@ ModuleStaticScreen::~ModuleStaticScreen(void) { int ModuleStaticScreen::Go() { - switch( this->info->estat_joc ) { + switch( info::estat_joc ) { case ESTAT_ICEKAS: doIcekas(); break; @@ -30,7 +31,7 @@ int ModuleStaticScreen::Go() { if( JG_Quitting() ) { return ESTAT_EIXIR; } else { - switch (this->info->estat_joc) { + switch (info::estat_joc) { case ESTAT_ICEKAS: return ESTAT_LOGO; break; case ESTAT_LOGO: return ESTAT_MENU; break; } @@ -38,10 +39,6 @@ int ModuleStaticScreen::Go() { return 0; } -const int minim( const int a, const int b ) { - if( b < a ) { return b; } else { return a; } -} - void ModuleStaticScreen::doIcekas() { bool eixir = false; diff --git a/modulestaticscreen.h b/modulestaticscreen.h index 42a3798..5599351 100644 --- a/modulestaticscreen.h +++ b/modulestaticscreen.h @@ -1,12 +1,10 @@ #pragma once -#include "info.h" - class ModuleStaticScreen { public: - ModuleStaticScreen( Info* info ); + ModuleStaticScreen(); ~ModuleStaticScreen(void); int Go(); @@ -16,6 +14,5 @@ private: void doIcekas(); void doLogo(); - Info* info; int contador; };