- treballant en el menu de redefinició de tecles

This commit is contained in:
2024-07-09 06:52:05 +02:00
parent 1e216bfd24
commit 4d91e86178
3 changed files with 38 additions and 5 deletions

View File

@@ -1,5 +1,8 @@
#include "m_menu_tecles.h" #include "m_menu_tecles.h"
#include "jdraw.h" #include "jdraw.h"
#include "jinput.h"
#include "config.h"
#include <SDL2/SDL.h>
namespace modules namespace modules
{ {
@@ -14,21 +17,42 @@ namespace modules
int loop() int loop()
{ {
if (input::keyPressed(SDL_SCANCODE_ESCAPE)) {
return MENU_TECLES_TORNAR;
}
if (input::keyPressed(SDL_SCANCODE_DOWN) || input::keyPressed(config::getKey(KEY_DOWN)))
{ selected_option++; if (selected_option>6) selected_option=0; }
if (input::keyPressed(SDL_SCANCODE_UP) || input::keyPressed(config::getKey(KEY_UP)))
{ selected_option--; if (selected_option<0) selected_option=6; }
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_TECLES_TORNAR) return MENU_TECLES_TORNAR;
}
draw::cls(2); draw::cls(2);
draw::color(1); draw::color(1);
draw::print2("REDEFINIR TECLES", 13, 3, YELLOW, FONT_ZOOM_VERTICAL); draw::print2("REDEFINIR TECLES", 13, 3, YELLOW, FONT_ZOOM_VERTICAL);
int pos = 10; int pos = 10;
static char *textos[6] = { "AMUNT:", "AVALL:", "ESQUERRA:", "DRETA:", "BOTAR: ", "AGAFAR: " }; static const char *textos[6] = { "AMUNT:", "AVALL:", "ESQUERRA:", "DRETA:", "BOTAR: ", "AGAFAR: " };
for (int i=0; i<6; ++i) for (int i=0; i<6; ++i)
{ {
draw::print2(i==selected_option?"fg":"de", 13, pos, i==selected_option?YELLOW:TEAL, i==selected_option?FONT_ZOOM_VERTICAL:FONT_ZOOM_NONE); const bool selected = (i==selected_option);
draw::print2(textos[i], 18, pos, i==selected_option?YELLOW:TEAL, i==selected_option?FONT_ZOOM_VERTICAL:FONT_ZOOM_NONE); draw::print2(selected?"fg":"de", 13, pos, selected?YELLOW:TEAL, selected?FONT_ZOOM_VERTICAL:FONT_ZOOM_NONE);
draw::print2(textos[i], 18, pos, selected?YELLOW:TEAL, selected?FONT_ZOOM_VERTICAL:FONT_ZOOM_NONE);
pos += selected?3:2;
} }
const bool selected = (selected_option==MENU_TECLES_TORNAR);
draw::print2(selected?"fg":"de", 13, pos, selected?YELLOW:TEAL, selected?FONT_ZOOM_VERTICAL:FONT_ZOOM_NONE);
draw::print2("TORNAR", 18, pos, selected?YELLOW:TEAL, selected?FONT_ZOOM_VERTICAL:FONT_ZOOM_NONE);
draw::print2("(C) JAILDOCTOR 2024", 11, 28, TEAL, FONT_ZOOM_NONE); draw::print2("(C) JAILDOCTOR 2024", 11, 28, TEAL, FONT_ZOOM_NONE);
draw::render(); draw::render();

View File

@@ -11,6 +11,7 @@ namespace modules
#define MENU_TECLES_DRETA 3 #define MENU_TECLES_DRETA 3
#define MENU_TECLES_BOTAR 4 #define MENU_TECLES_BOTAR 4
#define MENU_TECLES_AGAFAR 5 #define MENU_TECLES_AGAFAR 5
#define MENU_TECLES_TORNAR 6
void init(); void init();
int loop(); int loop();

View File

@@ -12,13 +12,15 @@
#include "m_menu.h" #include "m_menu.h"
#include "m_logo.h" #include "m_logo.h"
#include "m_ingame.h" #include "m_ingame.h"
#include "m_menu_tecles.h"
#include "m_menu_audio.h" #include "m_menu_audio.h"
#define M_LOGO 0 #define M_LOGO 0
#define M_MENU 1 #define M_MENU 1
#define M_GAME 2 #define M_GAME 2
#define M_INGAME 3 #define M_INGAME 3
#define M_MENU_AUDIO 4 #define M_MENU_TECLES 4
#define M_MENU_AUDIO 5
int current_module = M_LOGO; int current_module = M_LOGO;
int zoom = 3; int zoom = 3;
@@ -95,6 +97,7 @@ bool game::loop()
if (option != OPTION_NONE) { if (option != OPTION_NONE) {
if (option == OPTION_EIXIR) return false; if (option == OPTION_EIXIR) return false;
if (option == OPTION_JUGAR) { modules::game::init(); current_module = M_GAME; } if (option == OPTION_JUGAR) { modules::game::init(); current_module = M_GAME; }
if (option == OPTION_TECLES) { modules::menu_tecles::init(); current_module = M_MENU_TECLES; }
if (option == OPTION_AUDIO) { modules::menu_audio::init(); current_module = M_MENU_AUDIO; } if (option == OPTION_AUDIO) { modules::menu_audio::init(); current_module = M_MENU_AUDIO; }
} }
break; break;
@@ -108,6 +111,11 @@ bool game::loop()
if (option == INGAME_CONTINUAR) { current_module = M_GAME; } if (option == INGAME_CONTINUAR) { current_module = M_GAME; }
} }
break; break;
case M_MENU_TECLES:
if (modules::menu_tecles::loop() == MENU_TECLES_TORNAR) {
modules::menu::init(); current_module = M_MENU;
}
break;
case M_MENU_AUDIO: case M_MENU_AUDIO:
if (modules::menu_audio::loop() == MENU_AUDIO_TORNAR) { if (modules::menu_audio::loop() == MENU_AUDIO_TORNAR) {
modules::menu::init(); current_module = M_MENU; modules::menu::init(); current_module = M_MENU;