- "Info" ara es una unitat simple

This commit is contained in:
2024-01-29 14:52:53 +01:00
parent aca0f646b3
commit 80234e195e
11 changed files with 56 additions and 62 deletions

10
info.cpp Normal file
View File

@@ -0,0 +1,10 @@
#include "info.h"
namespace info
{
int estat_joc;
bool rosita_enabled;
bool job_enabled;
int dificultat;
int personatge;
}

14
info.h
View File

@@ -21,10 +21,10 @@
#define PERSONATGE_ROSITA 1 #define PERSONATGE_ROSITA 1
#define PERSONATGE_JOB 2 #define PERSONATGE_JOB 2
struct Info { namespace info{
int estat_joc; extern int estat_joc;
bool rosita_enabled; extern bool rosita_enabled;
bool job_enabled; extern bool job_enabled;
int dificultat; extern int dificultat;
int personatge; extern int personatge;
}; }

View File

@@ -36,47 +36,46 @@ int main( int argc, char* args[] ) {
JD8_Init("Pepe El Pintor"); JD8_Init("Pepe El Pintor");
JS_Init(); JS_Init();
Info info; info::estat_joc = ESTAT_ICEKAS; // ESTAT_SEQUENCIA; // ESTAT_ICEKAS;
info.estat_joc = ESTAT_ICEKAS; // ESTAT_SEQUENCIA; // ESTAT_ICEKAS; info::rosita_enabled = false;
info.rosita_enabled = false; info::job_enabled = false;
info.job_enabled = false; info::dificultat = MODE_FACIL;
info.dificultat = MODE_FACIL; info::personatge = PERSONATGE_PEPE;
info.personatge = PERSONATGE_PEPE;
FILE* ini = fopen("trick.ini", "rb"); FILE* ini = fopen("trick.ini", "rb");
if (ini != NULL) { if (ini != NULL) {
unsigned char contingut = 0; unsigned char contingut = 0;
fread(&contingut, 1, 1, ini); fread(&contingut, 1, 1, ini);
fclose(ini); fclose(ini);
if (contingut > 0) info.rosita_enabled = true; if (contingut > 0) info::rosita_enabled = true;
if (contingut > 1) info.job_enabled = true; if (contingut > 1) info::job_enabled = true;
} }
while (info.estat_joc != ESTAT_EIXIR) { while (info::estat_joc != ESTAT_EIXIR) {
switch (info.estat_joc) { switch (info::estat_joc) {
case ESTAT_ICEKAS: case ESTAT_ICEKAS:
case ESTAT_LOGO: case ESTAT_LOGO:
ModuleStaticScreen * moduleStaticScreen; ModuleStaticScreen * moduleStaticScreen;
moduleStaticScreen = new ModuleStaticScreen(&info); moduleStaticScreen = new ModuleStaticScreen();
info.estat_joc = moduleStaticScreen->Go(); info::estat_joc = moduleStaticScreen->Go();
delete moduleStaticScreen; delete moduleStaticScreen;
break; break;
case ESTAT_MENU: case ESTAT_MENU:
ModuleMenu * moduleMenu; ModuleMenu * moduleMenu;
moduleMenu = new ModuleMenu(&info); moduleMenu = new ModuleMenu();
info.estat_joc = moduleMenu->Go(); info::estat_joc = moduleMenu->Go();
delete moduleMenu; delete moduleMenu;
break; break;
case ESTAT_SELECT: case ESTAT_SELECT:
ModuleSelect * moduleSelect; ModuleSelect * moduleSelect;
moduleSelect = new ModuleSelect(&info); moduleSelect = new ModuleSelect();
info.estat_joc = moduleSelect->Go(); info::estat_joc = moduleSelect->Go();
delete moduleSelect; delete moduleSelect;
break; break;
case ESTAT_SEQUENCIA: case ESTAT_SEQUENCIA:
ModuleSequence * moduleSequence; ModuleSequence * moduleSequence;
moduleSequence = new ModuleSequence(&info); moduleSequence = new ModuleSequence();
info.estat_joc = moduleSequence->Go(); info::estat_joc = moduleSequence->Go();
delete moduleSequence; delete moduleSequence;
break; break;
} }

View File

@@ -6,6 +6,7 @@
#include "jsound.h" #include "jsound.h"
#include <stdlib.h> #include <stdlib.h>
#include <string> #include <string>
#include "info.h"
#define SENSE_OPCIO -1 #define SENSE_OPCIO -1
#define OPCIO_TIMEATTACK 0 #define OPCIO_TIMEATTACK 0
@@ -13,8 +14,7 @@
#define OPCIO_CLASSICMODE 2 #define OPCIO_CLASSICMODE 2
#define OPCIO_OPTIONS 3 #define OPCIO_OPTIONS 3
ModuleMenu::ModuleMenu(Info* info) { ModuleMenu::ModuleMenu() {
this->info = info;
} }
ModuleMenu::~ModuleMenu(void) { ModuleMenu::~ModuleMenu(void) {

View File

@@ -1,12 +1,10 @@
#pragma once #pragma once
#include "info.h"
class ModuleMenu { class ModuleMenu {
public: public:
ModuleMenu(Info* info); ModuleMenu();
~ModuleMenu(void); ~ModuleMenu(void);
int Go(); int Go();
@@ -15,6 +13,5 @@ private:
//void showMenu(); //void showMenu();
Info* info;
int contador; int contador;
}; };

View File

@@ -6,9 +6,10 @@
#include "jsound.h" #include "jsound.h"
#include <stdlib.h> #include <stdlib.h>
#include <string> #include <string>
#include "info.h"
ModuleSelect::ModuleSelect() {
ModuleSelect::ModuleSelect(Info* info) {
this->info = info;
} }
ModuleSelect::~ModuleSelect(void) { ModuleSelect::~ModuleSelect(void) {
@@ -37,7 +38,7 @@ int ModuleSelect::Go() {
int num_personatges = 3; int num_personatges = 3;
if (!this->info->rosita_enabled) { 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);
@@ -52,7 +53,7 @@ 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 (!this->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);
@@ -78,9 +79,9 @@ int ModuleSelect::Go() {
while (!JG_ShouldUpdate()) { JI_Update(); } while (!JG_ShouldUpdate()) { JI_Update(); }
} }
int opcio_seleccionada = this->info->dificultat; int opcio_seleccionada = info::dificultat;
int opcio_triada = SENSE_OPCIO; int opcio_triada = SENSE_OPCIO;
int personatge_seleccionat = this->info->personatge; int personatge_seleccionat = info::personatge;
bool fletxa_amunt_pulsada = false; bool fletxa_amunt_pulsada = false;
bool fletxa_avall_pulsada = false; bool fletxa_avall_pulsada = false;
bool fletxa_esquerra_pulsada = false; bool fletxa_esquerra_pulsada = false;
@@ -165,8 +166,8 @@ int ModuleSelect::Go() {
if (JG_Quitting()) { if (JG_Quitting()) {
return ESTAT_EIXIR; return ESTAT_EIXIR;
} else { } else {
this->info->dificultat = opcio_triada; info::dificultat = opcio_triada;
this->info->personatge = personatge_seleccionat; info::personatge = personatge_seleccionat;
return ESTAT_SEQUENCIA; return ESTAT_SEQUENCIA;
} }
} }

View File

@@ -1,17 +1,14 @@
#pragma once #pragma once
#include "info.h"
class ModuleSelect { class ModuleSelect {
public: public:
ModuleSelect(Info* info); ModuleSelect();
~ModuleSelect(void); ~ModuleSelect(void);
int Go(); int Go();
private: private:
Info* info;
}; };

View File

@@ -6,13 +6,13 @@
#include "jsound.h" #include "jsound.h"
#include <stdlib.h> #include <stdlib.h>
#include <string> #include <string>
#include "info.h"
JD8_Surface gfx = nullptr; JD8_Surface gfx = nullptr;
JD8_Surface fondo = nullptr; JD8_Surface fondo = nullptr;
JD8_Palette pal = nullptr; JD8_Palette pal = nullptr;
ModuleSequence::ModuleSequence(Info* info) { ModuleSequence::ModuleSequence() {
this->info = info;
gfx = nullptr; gfx = nullptr;
fondo = nullptr; fondo = nullptr;
pal = nullptr; pal = nullptr;

View File

@@ -1,20 +1,16 @@
#pragma once #pragma once
#include "info.h"
class ModuleSequence { class ModuleSequence {
public: public:
ModuleSequence(Info* info); ModuleSequence();
~ModuleSequence(void); ~ModuleSequence(void);
int Go(); int Go();
private: private:
Info * info;
void FadeIn(); void FadeIn();
void FadeOut(); void FadeOut();
void ShowText(int x, int y, int color, int speed, const char* text1, const char* text2 = nullptr, const char* text3 = nullptr); void ShowText(int x, int y, int color, int speed, const char* text1, const char* text2 = nullptr, const char* text3 = nullptr);

View File

@@ -6,9 +6,10 @@
#include "jsound.h" #include "jsound.h"
#include <stdlib.h> #include <stdlib.h>
#include <string> #include <string>
#include "info.h"
ModuleStaticScreen::ModuleStaticScreen() {
ModuleStaticScreen::ModuleStaticScreen( Info* info ) {
this->info = info;
} }
ModuleStaticScreen::~ModuleStaticScreen(void) { ModuleStaticScreen::~ModuleStaticScreen(void) {
@@ -16,7 +17,7 @@ ModuleStaticScreen::~ModuleStaticScreen(void) {
int ModuleStaticScreen::Go() { int ModuleStaticScreen::Go() {
switch( this->info->estat_joc ) { switch( info::estat_joc ) {
case ESTAT_ICEKAS: case ESTAT_ICEKAS:
doIcekas(); doIcekas();
break; break;
@@ -30,7 +31,7 @@ int ModuleStaticScreen::Go() {
if( JG_Quitting() ) { if( JG_Quitting() ) {
return ESTAT_EIXIR; return ESTAT_EIXIR;
} else { } else {
switch (this->info->estat_joc) { switch (info::estat_joc) {
case ESTAT_ICEKAS: return ESTAT_LOGO; break; case ESTAT_ICEKAS: return ESTAT_LOGO; break;
case ESTAT_LOGO: return ESTAT_MENU; break; case ESTAT_LOGO: return ESTAT_MENU; break;
} }
@@ -38,10 +39,6 @@ int ModuleStaticScreen::Go() {
return 0; return 0;
} }
const int minim( const int a, const int b ) {
if( b < a ) { return b; } else { return a; }
}
void ModuleStaticScreen::doIcekas() { void ModuleStaticScreen::doIcekas() {
bool eixir = false; bool eixir = false;

View File

@@ -1,12 +1,10 @@
#pragma once #pragma once
#include "info.h"
class ModuleStaticScreen { class ModuleStaticScreen {
public: public:
ModuleStaticScreen( Info* info ); ModuleStaticScreen();
~ModuleStaticScreen(void); ~ModuleStaticScreen(void);
int Go(); int Go();
@@ -16,6 +14,5 @@ private:
void doIcekas(); void doIcekas();
void doLogo(); void doLogo();
Info* info;
int contador; int contador;
}; };