diff --git a/data/rooms/08.txt b/data/rooms/08.txt index 6c1edfe..c83fb44 100644 --- a/data/rooms/08.txt +++ b/data/rooms/08.txt @@ -8,28 +8,74 @@ door-texture: 0 under-door-texture: 0 exit-xp: 7 +actor{ + name: P-ELBOW + bmp: objectes.gif + bmp-rect: 0 32 22 32 + bmp-offset: -2 35 + pos: 8 16 0 + size: 4 4 4 + anim-wait: 6 + flags: ANIMATED SPECIAL + movement: CW +} + +actor{ + name: P-PIPE + bmp: objectes.gif + bmp-rect: 0 64 16 32 + bmp-offset: -8 36 + pos: 8 24 0 + size: 4 4 4 + anim-wait: 6 + flags: ANIMATED SPECIAL + movement: CW +} + +actor{ + name: P-SALT + bmp: objectes.gif + bmp-rect: 66 32 20 32 + bmp-offset: -7 35 + pos: 8 32 0 + size: 4 4 4 + anim-wait: 6 + flags: ANIMATED SPECIAL + movement: CW +} + actor{ name: P-FILTER bmp: objectes.gif - bmp-rect: 24 0 24 32 + bmp-rect: 0 0 24 32 bmp-offset: -4 34 - pos: 8 8 0 + pos: 8 24 8 size: 4 4 4 - anim-cycle: SEQ - anim-wait: 2 - flags: SPECIAL + anim-wait: 6 + flags: ANIMATED SPECIAL + movement: CW +} + +actor{ + name: P-PUMP + bmp: objectes.gif + bmp-rect: 48 64 22 32 + bmp-offset: -5 35 + pos: 8 32 11 + size: 4 4 4 + anim-wait: 6 + flags: ANIMATED SPECIAL movement: CW } actor{ name: P-TIMER bmp: objectes.gif - bmp-rect: 96 0 24 32 + bmp-rect: 72 0 24 32 bmp-offset: -4 34 - pos: 8 16 0 + pos: 8 40 8 size: 4 4 4 - anim-cycle: SEQ - anim-wait: 2 - flags: SPECIAL + anim-wait: 6 + flags: ANIMATED SPECIAL movement: CW } diff --git a/data/rooms/09.txt b/data/rooms/09.txt new file mode 100644 index 0000000..0d0d028 --- /dev/null +++ b/data/rooms/09.txt @@ -0,0 +1,7 @@ +width: 2 +height: 2 +color: CYAN +floor-texture: 0 +wall-texture: 0 +door-texture: 0 +under-door-texture: 0 diff --git a/data/templates.txt b/data/templates.txt index ddad13f..891bb87 100644 --- a/data/templates.txt +++ b/data/templates.txt @@ -85,6 +85,32 @@ actor{ bmp: objectes.gif bmp-rect: 96 0 24 32 bmp-offset: -4 34 + pos: 8 40 8 + size: 4 4 4 + anim-cycle: SEQ + anim-wait: 2 + flags: SPECIAL + movement: CW +} + +actor{ + name: P-FILTER + bmp: objectes.gif + bmp-rect: 24 0 24 32 + bmp-offset: -4 34 + pos: 8 24 8 + size: 4 4 4 + anim-cycle: SEQ + anim-wait: 2 + flags: SPECIAL + movement: CW +} + +actor{ + name: P-ELBOW + bmp: objectes.gif + bmp-rect: 22 32 22 32 + bmp-offset: -2 35 pos: 8 16 0 size: 4 4 4 anim-cycle: SEQ @@ -92,3 +118,42 @@ actor{ flags: SPECIAL movement: CW } + +actor{ + name: P-PIPE + bmp: objectes.gif + bmp-rect: 16 64 16 32 + bmp-offset: -8 36 + pos: 8 24 0 + size: 4 4 4 + anim-cycle: SEQ + anim-wait: 2 + flags: SPECIAL + movement: CW +} + +actor{ + name: P-SALT + bmp: objectes.gif + bmp-rect: 86 32 20 32 + bmp-offset: -7 35 + pos: 8 32 0 + size: 4 4 4 + anim-cycle: SEQ + anim-wait: 2 + flags: SPECIAL + movement: CW +} + +actor{ + name: P-PUMP + bmp: objectes.gif + bmp-rect: 70 64 22 32 + bmp-offset: -5 35 + pos: 8 32 11 + size: 4 4 4 + anim-cycle: SEQ + anim-wait: 2 + flags: SPECIAL + movement: CW +} diff --git a/source/actor.cpp b/source/actor.cpp index 614eaa1..6fcc455 100644 --- a/source/actor.cpp +++ b/source/actor.cpp @@ -5,6 +5,8 @@ #include "jutil.h" #include "room.h" #include "editor.h" +#include "debug.h" +#include "config.h" #include namespace actor @@ -455,7 +457,7 @@ namespace actor vec3_t max = room::getMax(); bool moving = false; - if ( input::keyDown(SDL_SCANCODE_LEFT) ) + if ( input::keyDown(SDL_SCANCODE_LEFT) || input::keyDown(config::getKey(KEY_LEFT)) ) { hero::useBoostRun(); act->orient=PUSH_XN; @@ -473,7 +475,7 @@ namespace actor act->push |= PUSH_XN; } } - else if ( input::keyDown(SDL_SCANCODE_RIGHT) ) + else if ( input::keyDown(SDL_SCANCODE_RIGHT) || input::keyDown(config::getKey(KEY_RIGHT)) ) { hero::useBoostRun(); act->orient=PUSH_XP; @@ -491,7 +493,7 @@ namespace actor act->push |= PUSH_XP; } } - else if ( input::keyDown(SDL_SCANCODE_UP) ) + else if ( input::keyDown(SDL_SCANCODE_UP) || input::keyDown(config::getKey(KEY_UP)) ) { hero::useBoostRun(); act->orient=PUSH_YN; @@ -509,7 +511,7 @@ namespace actor act->push |= PUSH_YN; } } - else if ( input::keyDown(SDL_SCANCODE_DOWN) ) + else if ( input::keyDown(SDL_SCANCODE_DOWN) || input::keyDown(config::getKey(KEY_DOWN)) ) { hero::useBoostRun(); act->orient=PUSH_YP; @@ -527,7 +529,7 @@ namespace actor act->push |= PUSH_YP; } } - if (input::keyPressed(SDL_SCANCODE_RETURN) && (hero::getSkills()&SKILL_PANTS)) + if ((input::keyPressed(SDL_SCANCODE_RETURN) || input::keyDown(config::getKey(KEY_PICK)) ) && (hero::getSkills()&SKILL_PANTS)) { if (picked) { @@ -552,10 +554,10 @@ namespace actor { const int height = act->below->size.z; pick(act->below); - if (!input::keyDown(SDL_SCANCODE_SPACE)) act->pos.z -= height; + if (!input::keyDown(SDL_SCANCODE_SPACE) && !input::keyDown(config::getKey(KEY_JUMP))) act->pos.z -= height; } } - if ( input::keyDown(SDL_SCANCODE_SPACE) && (hero::getSkills()&SKILL_SHOES) && (act->pos.y+act->size.y)<=max.y && act->pos.y>=min.y && (act->pos.x+act->size.x)<=max.x && act->pos.x>=min.x && act->react_mask==0 && (act->pos.z==0 || act->below)) + if (( input::keyDown(SDL_SCANCODE_SPACE) || input::keyDown(config::getKey(KEY_JUMP)) ) && (hero::getSkills()&SKILL_SHOES) && (act->pos.y+act->size.y)<=max.y && act->pos.y>=min.y && (act->pos.x+act->size.x)<=max.x && act->pos.x>=min.x && act->react_mask==0 && (act->pos.z==0 || act->below)) { // [RZC 14/05/2024] hack usant react_mask i react_push del heroi. Llegir més avall. act->react_mask=hero::getBoostJump()>0 ? 2 : 1; // =1 estic botant (anant cap amunt) @@ -992,11 +994,13 @@ namespace actor draw::draw(x, y, act->bmp_rect.w, act->bmp_rect.h, act->bmp_rect.x+ao, act->bmp_rect.y+oo, flip); draw::swapcol(1, room::getColor(0)); // Tornem al color per defecte draw::popSource(); - //print(x+5,y,act->pos.x); - //print(x+5,y+6,act->pos.y); - //print(x+5,y+12,act->pos.z); - //print(x+5,y+12,order); - //print(x+5,y,act->flags); + if (debug::isEnabled(DEBUG_ACTOR_POS)) + { + char tmp[100]; + draw::print(SDL_itoa(act->inner_x, tmp, 10), x+9,y+20, LIGHT+WHITE, BLACK); + draw::print(SDL_itoa(act->inner_y, tmp, 10), x+9,y+26, LIGHT+WHITE, BLACK); + draw::swapcol(1, room::getColor(0)); // Tornem al color per defecte + } } if (draw_all && act->next) draw(act->next); } @@ -1113,14 +1117,14 @@ namespace actor actor_t *getPicked() { return picked; } - void clear() + void clear(const bool all) { actor_t *hero = nullptr; actor_t *act = first; while (act) { actor_t *tmp = act->next; - if (act->flags & FLAG_HERO) { + if (!all && (act->flags & FLAG_HERO)) { hero = act; } else { //draw::freeSurface(act->surface); diff --git a/source/actor.h b/source/actor.h index 56a8cca..f95f267 100644 --- a/source/actor.h +++ b/source/actor.h @@ -152,7 +152,7 @@ namespace actor actor_t *getPicked(); - void clear(); + void clear(const bool all=false); namespace templates { diff --git a/source/config.cpp b/source/config.cpp new file mode 100644 index 0000000..cde7478 --- /dev/null +++ b/source/config.cpp @@ -0,0 +1,55 @@ +#include "config.h" +#include "jfile.h" +#include + +namespace config +{ + bool musicEnabled = true; + int soundMode = SOUND_ALL; + uint8_t keys[6] = {SDL_SCANCODE_UP, SDL_SCANCODE_DOWN, SDL_SCANCODE_LEFT, SDL_SCANCODE_RIGHT, SDL_SCANCODE_SPACE, SDL_SCANCODE_RETURN}; + + void setMusic(const bool value) + { + musicEnabled = value; + file::setConfigValue("music", musicEnabled ? "yes" : "no"); + } + + void toggleMusic() + { + musicEnabled = !musicEnabled; + file::setConfigValue("music", musicEnabled ? "yes" : "no"); + } + + const bool isMusicEnabled() + { + return musicEnabled; + } + + void setSound(const int value) + { + soundMode = value; + file::setConfigValue("sound", soundMode==SOUND_ALL ? "all" : soundMode==SOUND_BASIC ? "basic" : "none"); + } + + void toggleSound() + { + soundMode++; + if (soundMode>SOUND_NONE) soundMode = SOUND_ALL; + file::setConfigValue("sound", soundMode==SOUND_ALL ? "all" : soundMode==SOUND_BASIC ? "basic" : "none"); + } + + const int getSoundMode() + { + return soundMode; + } + + void defineKey(const int which, const int key) + { + keys[which] = key; + } + + const int getKey(const int which) + { + return keys[which]; + } +} diff --git a/source/config.h b/source/config.h new file mode 100644 index 0000000..182a3f1 --- /dev/null +++ b/source/config.h @@ -0,0 +1,27 @@ +#pragma once + +namespace config +{ + #define SOUND_ALL 0 + #define SOUND_BASIC 1 + #define SOUND_NONE 2 + + #define KEY_UP 0 + #define KEY_DOWN 1 + #define KEY_LEFT 2 + #define KEY_RIGHT 3 + #define KEY_JUMP 4 + #define KEY_PICK 5 + + void setMusic(const bool value); + void toggleMusic(); + const bool isMusicEnabled(); + + void setSound(const int value); + void toggleSound(); + const int getSoundMode(); + + void defineKey(const int which, const int key); + const int getKey(const int which); + +} \ No newline at end of file diff --git a/source/console.cpp b/source/console.cpp index f1512db..50ca7fb 100644 --- a/source/console.cpp +++ b/source/console.cpp @@ -5,6 +5,7 @@ #include "room.h" #include "actor.h" #include "jgame.h" +#include "debug.h" namespace console { @@ -41,8 +42,9 @@ namespace console const char scancode_to_ascii(uint8_t scancode) { if (scancode == SDL_SCANCODE_SPACE) return ' '; - if (scancode == SDL_SCANCODE_0) return '0'; + if (scancode == SDL_SCANCODE_0 || scancode == SDL_SCANCODE_KP_0) return '0'; if (scancode >= SDL_SCANCODE_1 && scancode <= SDL_SCANCODE_9) return scancode+19; + if (scancode >= SDL_SCANCODE_KP_1 && scancode <= SDL_SCANCODE_KP_9) return scancode-40; if (scancode >= SDL_SCANCODE_A && scancode <= SDL_SCANCODE_Z) return scancode+61; if (scancode == SDL_SCANCODE_MINUS) return '-'; @@ -130,9 +132,11 @@ namespace console #define CMD_GOTO 2 #define CMD_MOVE 3 #define CMD_EXIT 4 - #define NUM_CMDS 5 + #define CMD_SHOW 5 + #define CMD_HIDE 6 + #define NUM_CMDS 7 - const char *command_text[NUM_CMDS] = { "GIVE", "DROP", "GOTO", "MOVE", "EXIT" }; + const char *command_text[NUM_CMDS] = { "GIVE", "DROP", "GOTO", "MOVE", "EXIT", "SHOW", "HIDE" }; #define PARAM_UNKNOWN -1 #define PARAM_RUN 0 @@ -165,6 +169,19 @@ namespace console return SDL_atoi(tokens[index]); } + const int getIndexFromString(char *str, std::vector list) + { + //static const char *skillset_name[4] = {"SHOES", "GLOVES", "PANTS", "BAG"}; + for (int i=0;i dm.w) return; + if (screen_height*value > dm.h) return; + + screen_zoom = value; + reinit(); + } + + void incZoom() + { + setZoom(screen_zoom+1); + } + + void decZoom() + { + setZoom(screen_zoom-1); + } + + void toggleFullscreen() + { + screen_fullscreen = !screen_fullscreen; + reinit(); + } + + void setFullscreen(const bool value) + { + if (screen_fullscreen == value) return; + screen_fullscreen = value; + reinit(); + } + + const bool getFullscreen() + { + return screen_fullscreen; + } + const int getZoom() { return screen_zoom; diff --git a/source/jdraw.h b/source/jdraw.h index 3bb9e0a..aebe316 100644 --- a/source/jdraw.h +++ b/source/jdraw.h @@ -31,11 +31,17 @@ namespace draw /// @param width es el ample de la finestra "virtual" /// @param height es el alt de la finestra "virtual" /// @param zoom es com de grans son els pixels. - void init(const std::string &titol, const uint16_t width, const uint16_t height, const int zoom); + void init(const std::string &titol, const uint16_t width, const uint16_t height, const int zoom, const bool fullscreen=false); /// @brief Finalització del sistema (tancar coses de SDL, superficies fixes, etc...) void quit(); + void setZoom(const int value); + void incZoom(); + void decZoom(); + void toggleFullscreen(); + void setFullscreen(const bool value); + const bool getFullscreen(); const int getZoom(); /// @brief Crea una superficie i torna un punter a ella diff --git a/source/m_game.cpp b/source/m_game.cpp index 535bb6a..b2e65f1 100644 --- a/source/m_game.cpp +++ b/source/m_game.cpp @@ -18,10 +18,11 @@ namespace modules void init() { + actor::clear(true); ::game::setUpdateTicks(64); + actor::templates::load(); if (editor::isDevMode()) { - actor::templates::load(); FILE* f = fopen("data/gifs.txt", "r"); int buffer_len=255; diff --git a/source/m_ingame.cpp b/source/m_ingame.cpp new file mode 100644 index 0000000..b6ee12b --- /dev/null +++ b/source/m_ingame.cpp @@ -0,0 +1,108 @@ +#include "m_ingame.h" +#include "jgame.h" +#include "jinput.h" +#include "jdraw.h" +#include "actor.h" +#include "room.h" +#include "config.h" +#include + +namespace modules +{ + namespace ingame + { + draw::surface *surf; + int selected_option = INGAME_CONTINUAR; + actor::actor_t *parts[6] = {nullptr,nullptr,nullptr,nullptr,nullptr,nullptr}; + + void init() + { + selected_option = INGAME_CONTINUAR; + + surf = draw::getSurface("objectes.gif"); + if (parts[0]==nullptr) + { + parts[0] = actor::createFromTemplate("P-ELBOW"); + parts[0]->inner_x=166+16; + parts[0]->inner_y=68+8; + } + if (parts[1]==nullptr) + { + parts[1] = actor::createFromTemplate("P-PIPE"); + parts[1]->inner_x=148+16; + parts[1]->inner_y=75+8; + } + if (parts[2]==nullptr) + { + parts[2] = actor::createFromTemplate("P-SALT"); + parts[2]->inner_x=123+16; + parts[2]->inner_y=84+8; + } + if (parts[3]==nullptr) + { + parts[3] = actor::createFromTemplate("P-FILTER"); + parts[3]->inner_x=144+16; + parts[3]->inner_y=45+8; + } + if (parts[4]==nullptr) + { + parts[4] = actor::createFromTemplate("P-PUMP"); + parts[4]->inner_x=121+16; + parts[4]->inner_y=54+8; + } + if (parts[5]==nullptr) + { + parts[5] = actor::createFromTemplate("P-TIMER"); + parts[5]->inner_x=96+16; + parts[5]->inner_y=69+8; + } + } + + int loop() + { + if (input::keyPressed(SDL_SCANCODE_ESCAPE)) { + return INGAME_CONTINUAR; + } + if (input::keyPressed(SDL_SCANCODE_DOWN) || input::keyPressed(config::getKey(KEY_DOWN))) + selected_option = (selected_option+1)&1; + if (input::keyPressed(SDL_SCANCODE_UP) || input::keyPressed(config::getKey(KEY_UP))) + selected_option = (selected_option-1)&1; + if (input::keyPressed(SDL_SCANCODE_SPACE) || input::keyPressed(SDL_SCANCODE_RETURN) || + input::keyPressed(config::getKey(KEY_JUMP)) || input::keyPressed(config::getKey(KEY_PICK))) { + return selected_option; + } + + draw::cls(2); + draw::color(1); + + draw::setSource(surf); + static int part[6] = { PART_ELBOW, PART_PIPE, PART_SALT, PART_FILTER, PART_PUMP, PART_TIMER}; + for (int i=0;i<6;++i) + { + draw::swapcol(1, room::getColor((actor::hero::getParts() & part[i])?1:3)); + actor::drawAt(parts[i], parts[i]->inner_x, parts[i]->inner_y); + } + + + draw::print2("PAUSA", 17, 3, YELLOW, FONT_ZOOM_VERTICAL); + + switch (selected_option) + { + case INGAME_CONTINUAR: + draw::print2("fg CONTINUAR", 13, 19, YELLOW, FONT_ZOOM_VERTICAL); + draw::print2("de EIXIR", 13, 22, TEAL, FONT_ZOOM_NONE); + break; + case INGAME_EIXIR: + draw::print2("de CONTINUAR", 13, 19, TEAL, FONT_ZOOM_NONE); + draw::print2("fg EIXIR", 13, 21, YELLOW, FONT_ZOOM_VERTICAL); + break; + + }; + + draw::print2("(C) JAILDOCTOR 2024", 11, 28, TEAL, FONT_ZOOM_NONE); + + draw::render(); + return INGAME_NONE; + } + } +} diff --git a/source/m_ingame.h b/source/m_ingame.h new file mode 100644 index 0000000..35e83fe --- /dev/null +++ b/source/m_ingame.h @@ -0,0 +1,14 @@ +#pragma once + +namespace modules +{ + namespace ingame + { + #define INGAME_NONE -1 + #define INGAME_CONTINUAR 0 + #define INGAME_EIXIR 1 + + void init(); + int loop(); + } +} diff --git a/source/m_logo.cpp b/source/m_logo.cpp index cbf787f..bd84d82 100644 --- a/source/m_logo.cpp +++ b/source/m_logo.cpp @@ -1,6 +1,7 @@ #include "m_logo.h" #include "jdraw.h" #include "jinput.h" +#include "config.h" #include namespace modules @@ -56,7 +57,9 @@ namespace modules { if (input::keyPressed(SDL_SCANCODE_ESCAPE) || input::keyPressed(SDL_SCANCODE_SPACE) || - input::keyPressed(SDL_SCANCODE_RETURN) ) { + input::keyPressed(SDL_SCANCODE_RETURN) || + input::keyPressed(config::getKey(KEY_JUMP)) || + input::keyPressed(config::getKey(KEY_PICK)) ) { return false; } diff --git a/source/m_menu.cpp b/source/m_menu.cpp index ec6a890..a6b2509 100644 --- a/source/m_menu.cpp +++ b/source/m_menu.cpp @@ -2,6 +2,7 @@ #include "jgame.h" #include "jinput.h" #include "jdraw.h" +#include "config.h" #include namespace modules @@ -16,9 +17,11 @@ namespace modules void init() { + selected_option = OPTION_JUGAR; ::game::setUpdateTicks(64); draw::loadPalette("test.gif"); surf = draw::getSurface("test.gif"); + draw::restorecol(2); } int loop() @@ -26,10 +29,15 @@ namespace modules if (input::keyPressed(SDL_SCANCODE_ESCAPE)) { return OPTION_EIXIR; } - if (input::keyPressed(SDL_SCANCODE_DOWN)) selected_option = (selected_option+1)&3; - if (input::keyPressed(SDL_SCANCODE_UP)) selected_option = (selected_option-1)&3; - if (input::keyPressed(SDL_SCANCODE_SPACE) || input::keyPressed(SDL_SCANCODE_RETURN)) { - if (selected_option == OPTION_EIXIR || selected_option == OPTION_JUGAR) return selected_option; + if (input::keyPressed(SDL_SCANCODE_DOWN) || input::keyPressed(config::getKey(KEY_DOWN))) + selected_option = (selected_option+1)&3; + + if (input::keyPressed(SDL_SCANCODE_UP) || input::keyPressed(config::getKey(KEY_UP))) + selected_option = (selected_option-1)&3; + + if (input::keyPressed(SDL_SCANCODE_SPACE) || input::keyPressed(SDL_SCANCODE_RETURN) || + input::keyPressed(config::getKey(KEY_JUMP)) || input::keyPressed(config::getKey(KEY_PICK))) { + return selected_option; } draw::cls(2); @@ -37,7 +45,7 @@ namespace modules draw::swapcol(1, WHITE); draw::setSource(surf); - draw::draw(142,48,20,32,64+anim_pos*20,32); + draw::draw(150,56,20,32,64+anim_pos*20,32); retras--; if (retras==0) {retras=4; anim_pos=(anim_pos+1)&1; } @@ -46,28 +54,28 @@ namespace modules switch (selected_option) { case OPTION_JUGAR: - draw::print2("fg JUGAR AL JOC", 11, 12, YELLOW, FONT_ZOOM_VERTICAL); - draw::print2("de REDEFINIR TECLES", 11, 15, TEAL, FONT_ZOOM_NONE); - draw::print2("de CONFIGURAR SO", 11, 17, TEAL, FONT_ZOOM_NONE); - draw::print2("de EIXIR", 11, 19, TEAL, FONT_ZOOM_NONE); + draw::print2("fg JUGAR AL JOC", 11, 14, YELLOW, FONT_ZOOM_VERTICAL); + draw::print2("de REDEFINIR TECLES", 11, 17, TEAL, FONT_ZOOM_NONE); + draw::print2("de CONFIGURAR AUDIO", 11, 19, TEAL, FONT_ZOOM_NONE); + draw::print2("de EIXIR", 11, 21, TEAL, FONT_ZOOM_NONE); break; case OPTION_TECLES: - draw::print2("de JUGAR AL JOC", 11, 12, TEAL, FONT_ZOOM_NONE); - draw::print2("fg REDEFINIR TECLES", 11, 14, YELLOW, FONT_ZOOM_VERTICAL); - draw::print2("de CONFIGURAR SO", 11, 17, TEAL, FONT_ZOOM_NONE); - draw::print2("de EIXIR", 11, 19, TEAL, FONT_ZOOM_NONE); + draw::print2("de JUGAR AL JOC", 11, 14, TEAL, FONT_ZOOM_NONE); + draw::print2("fg REDEFINIR TECLES", 11, 16, YELLOW, FONT_ZOOM_VERTICAL); + draw::print2("de CONFIGURAR AUDIO", 11, 19, TEAL, FONT_ZOOM_NONE); + draw::print2("de EIXIR", 11, 21, TEAL, FONT_ZOOM_NONE); break; - case OPTION_SO: - draw::print2("de JUGAR AL JOC", 11, 12, TEAL, FONT_ZOOM_NONE); - draw::print2("de REDEFINIR TECLES", 11, 14, TEAL, FONT_ZOOM_NONE); - draw::print2("fg CONFIGURAR SO", 11, 16, YELLOW, FONT_ZOOM_VERTICAL); - draw::print2("de EIXIR", 11, 19, TEAL, FONT_ZOOM_NONE); + case OPTION_AUDIO: + draw::print2("de JUGAR AL JOC", 11, 14, TEAL, FONT_ZOOM_NONE); + draw::print2("de REDEFINIR TECLES", 11, 16, TEAL, FONT_ZOOM_NONE); + draw::print2("fg CONFIGURAR AUDIO", 11, 18, YELLOW, FONT_ZOOM_VERTICAL); + draw::print2("de EIXIR", 11, 21, TEAL, FONT_ZOOM_NONE); break; case OPTION_EIXIR: - draw::print2("de JUGAR AL JOC", 11, 12, TEAL, FONT_ZOOM_NONE); - draw::print2("de REDEFINIR TECLES", 11, 14, TEAL, FONT_ZOOM_NONE); - draw::print2("de CONFIGURAR SO", 11, 16, TEAL, FONT_ZOOM_NONE); - draw::print2("fg EIXIR", 11, 18, YELLOW, FONT_ZOOM_VERTICAL); + draw::print2("de JUGAR AL JOC", 11, 14, TEAL, FONT_ZOOM_NONE); + draw::print2("de REDEFINIR TECLES", 11, 16, TEAL, FONT_ZOOM_NONE); + draw::print2("de CONFIGURAR AUDIO", 11, 18, TEAL, FONT_ZOOM_NONE); + draw::print2("fg EIXIR", 11, 21, YELLOW, FONT_ZOOM_VERTICAL); break; }; diff --git a/source/m_menu.h b/source/m_menu.h index ef12b69..40b83dc 100644 --- a/source/m_menu.h +++ b/source/m_menu.h @@ -7,7 +7,7 @@ namespace modules #define OPTION_NONE -1 #define OPTION_JUGAR 0 #define OPTION_TECLES 1 - #define OPTION_SO 2 + #define OPTION_AUDIO 2 #define OPTION_EIXIR 3 void init(); diff --git a/source/m_menu_audio.cpp b/source/m_menu_audio.cpp new file mode 100644 index 0000000..919c062 --- /dev/null +++ b/source/m_menu_audio.cpp @@ -0,0 +1,80 @@ +#include "m_menu_audio.h" +#include "jgame.h" +#include "jinput.h" +#include "jdraw.h" +#include +#include "config.h" + +namespace modules +{ + namespace menu_audio + { + int selected_option = MENU_AUDIO_MUSICA; + + void init() + { + selected_option = MENU_AUDIO_MUSICA; + } + + int loop() + { + if (input::keyPressed(SDL_SCANCODE_ESCAPE)) { + return MENU_AUDIO_TORNAR; + } + if (input::keyPressed(SDL_SCANCODE_DOWN) || input::keyPressed(config::getKey(KEY_DOWN))) + selected_option = (selected_option==2)?0:selected_option+1; + + if (input::keyPressed(SDL_SCANCODE_UP) || input::keyPressed(config::getKey(KEY_UP))) + selected_option = (selected_option==0)?2:selected_option-1; + + if (input::keyPressed(SDL_SCANCODE_SPACE) || input::keyPressed(SDL_SCANCODE_RETURN) || + input::keyPressed(config::getKey(KEY_JUMP)) || input::keyPressed(config::getKey(KEY_PICK))) { + if (selected_option==MENU_AUDIO_MUSICA) config::toggleMusic(); + if (selected_option==MENU_AUDIO_SO) config::toggleSound(); + if (selected_option==MENU_AUDIO_TORNAR) return MENU_AUDIO_TORNAR; + } + + draw::cls(2); + draw::color(1); + + draw::print2("CONFIGURAR AUDIO", 13, 3, YELLOW, FONT_ZOOM_VERTICAL); + + const char *musica_msg = config::isMusicEnabled() ? "MUSICA: SI" : "MUSICA: NO"; + const int soundmode=config::getSoundMode(); + const char *so_msg = soundmode==SOUND_ALL? "SO: TOT" : soundmode==SOUND_BASIC?"SO: BASIC" : "SO: SILENCI"; + + int pos = 14; + + if (selected_option==MENU_AUDIO_MUSICA) { + draw::print2("fg", 13, pos, YELLOW, FONT_ZOOM_VERTICAL); + draw::print2(musica_msg, 18, pos, YELLOW, FONT_ZOOM_VERTICAL); + pos+=3; + } else { + draw::print2("de", 13, pos, TEAL, FONT_ZOOM_NONE); + draw::print2(musica_msg, 18, pos, TEAL, FONT_ZOOM_NONE); + pos+=2; + } + + if (selected_option==MENU_AUDIO_SO) { + draw::print2("fg", 13, pos, YELLOW, FONT_ZOOM_VERTICAL); + draw::print2(so_msg, 18, pos, YELLOW, FONT_ZOOM_VERTICAL); + pos+=3; + } else { + draw::print2("de", 13, pos, TEAL, FONT_ZOOM_NONE); + draw::print2(so_msg, 18, pos, TEAL, FONT_ZOOM_NONE); + pos+=2; + } + + if (selected_option==MENU_AUDIO_TORNAR) { + draw::print2("fg TORNAR", 13, pos, YELLOW, FONT_ZOOM_VERTICAL); + } else { + draw::print2("de TORNAR", 13, pos, TEAL, FONT_ZOOM_NONE); + } + + draw::print2("(C) JAILDOCTOR 2024", 11, 28, TEAL, FONT_ZOOM_NONE); + + draw::render(); + return MENU_AUDIO_NONE; + } + } +} diff --git a/source/m_menu_audio.h b/source/m_menu_audio.h new file mode 100644 index 0000000..266b2c4 --- /dev/null +++ b/source/m_menu_audio.h @@ -0,0 +1,15 @@ +#pragma once + +namespace modules +{ + namespace menu_audio + { + #define MENU_AUDIO_NONE -1 + #define MENU_AUDIO_MUSICA 0 + #define MENU_AUDIO_SO 1 + #define MENU_AUDIO_TORNAR 2 + + void init(); + int loop(); + } +} diff --git a/source/main.cpp b/source/main.cpp index f8bc919..af4c4e3 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -1,26 +1,58 @@ #include "jgame.h" #include "jdraw.h" +#include "jfile.h" +#include "jinput.h" #include "editor.h" #include "console.h" #include "string.h" +#include "config.h" +#include #include "m_game.h" #include "m_menu.h" #include "m_logo.h" +#include "m_ingame.h" +#include "m_menu_audio.h" #define M_LOGO 0 #define M_MENU 1 #define M_GAME 2 +#define M_INGAME 3 +#define M_MENU_AUDIO 4 + int current_module = M_LOGO; +int zoom = 3; +bool fullscreen = false; +char tmp[100]; + +void loadConfig() +{ + file::setConfigFolder("thepool"); + + if (strcmp(file::getConfigValue("music").c_str(), "no")==0) config::setMusic(false); + + const char *so = file::getConfigValue("sound").c_str(); + if (strcmp(so, "basic")==0) + config::setSound(SOUND_BASIC); + else if (strcmp(so, "none")==0) + config::setSound(SOUND_NONE); + + std::string txt_zoom = file::getConfigValue("zoom"); + if (txt_zoom!="") zoom = SDL_atoi(txt_zoom.c_str()); + + std::string txt_fullscreen = file::getConfigValue("fullscreen"); + if (txt_fullscreen=="yes") fullscreen = true; +} void game::init() { if (game::getParams(1) && strcmp(game::getParams(1), "editor")==0) editor::setDevMode(); if (editor::isDevMode()) - draw::init("The Pool", 520, 240, 3); + draw::init("The Pool", 520, 240, zoom); else { - draw::init("The Pool", 320, 240, 3); + loadConfig(); + draw::init("The Pool", 320, 240, zoom, fullscreen); console::init(); } @@ -36,6 +68,22 @@ void game::init() bool game::loop() { + if (input::keyPressed(SDL_SCANCODE_F1)) { + draw::decZoom(); + zoom = draw::getZoom(); + file::setConfigValue("zoom", SDL_itoa(zoom, tmp, 10)); + } + if (input::keyPressed(SDL_SCANCODE_F2)) { + draw::incZoom(); + zoom = draw::getZoom(); + file::setConfigValue("zoom", SDL_itoa(zoom, tmp, 10)); + } + if (input::keyPressed(SDL_SCANCODE_F3)) { + draw::toggleFullscreen(); + fullscreen = draw::getFullscreen(); + file::setConfigValue("fullscreen", fullscreen?"yes":"no"); + } + int option; switch(current_module) { @@ -47,10 +95,25 @@ bool game::loop() if (option != OPTION_NONE) { if (option == OPTION_EIXIR) return false; if (option == OPTION_JUGAR) { modules::game::init(); current_module = M_GAME; } + if (option == OPTION_AUDIO) { modules::menu_audio::init(); current_module = M_MENU_AUDIO; } } break; case M_GAME: - return modules::game::loop(); + if (!modules::game::loop()) { modules::ingame::init(); current_module = M_INGAME; } + break; + case M_INGAME: + option = modules::ingame::loop(); + if (option != INGAME_NONE) { + if (option == INGAME_EIXIR) { modules::menu::init(); current_module = M_MENU; } + if (option == INGAME_CONTINUAR) { current_module = M_GAME; } + } + break; + case M_MENU_AUDIO: + if (modules::menu_audio::loop() == MENU_AUDIO_TORNAR) { + modules::menu::init(); current_module = M_MENU; + } + break; + }; return true; } \ No newline at end of file