- [NEW] Sempre es pot navegar pels menus amb cursors, RETURN i ESCAPE

- [NEW] El gamepad es configura amb la info del gamescontrollerdb.txt per defecte
- [NEW] El botó de START en el gamepad funciona com el ESCAPE del teclat
- [FIX] La música ingame continuava estant mal
- [FIX] Si la música està desactivada que no sone la del logo
This commit is contained in:
2024-10-06 19:23:06 +02:00
parent 52d3916f8c
commit 0ccd8a570a
13 changed files with 2115 additions and 26 deletions

2078
data/gamecontrollerdb.txt Normal file

File diff suppressed because it is too large Load Diff

Binary file not shown.

View File

@@ -6,8 +6,8 @@ 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};
int8_t pad_btns[6] = {0, 1, 2, 3, 4, 5};
uint8_t keys[7] = {SDL_SCANCODE_UP, SDL_SCANCODE_DOWN, SDL_SCANCODE_LEFT, SDL_SCANCODE_RIGHT, SDL_SCANCODE_SPACE, SDL_SCANCODE_RETURN, SDL_SCANCODE_ESCAPE};
int8_t pad_btns[7] = {SDL_CONTROLLER_BUTTON_DPAD_UP, SDL_CONTROLLER_BUTTON_DPAD_DOWN, SDL_CONTROLLER_BUTTON_DPAD_LEFT, SDL_CONTROLLER_BUTTON_DPAD_RIGHT, SDL_CONTROLLER_BUTTON_A, SDL_CONTROLLER_BUTTON_B, SDL_CONTROLLER_BUTTON_START};
void setMusic(const bool value)
{
@@ -46,7 +46,7 @@ namespace config
void defineKey(const int which, const int key)
{
static const char* nomtecles[6] = {"keyup", "keydown", "keyleft", "keyright", "keyjump", "keypick"};
static const char* nomtecles[7] = {"keyup", "keydown", "keyleft", "keyright", "keyjump", "keypick", "keymenu"};
keys[which] = key;
char tmp[5];
file::setConfigValue(nomtecles[which], SDL_itoa(key, tmp, 10));
@@ -59,7 +59,7 @@ namespace config
void definePadBtn(const int which, const int btn)
{
static const char* nombotons[6] = {"btnup", "btndown", "btnleft", "btnright", "btnjump", "btnpick"};
static const char* nombotons[7] = {"btnup", "btndown", "btnleft", "btnright", "btnjump", "btnpick", "btnmenu"};
pad_btns[which] = btn;
char tmp[5];
file::setConfigValue(nombotons[which], SDL_itoa(btn, tmp, 10));

View File

@@ -12,6 +12,7 @@ namespace config
#define KEY_RIGHT 3
#define KEY_JUMP 4
#define KEY_PICK 5
#define KEY_MENU 6
void setMusic(const bool value);
void toggleMusic();

View File

@@ -1,6 +1,7 @@
#include "jinput.h"
#include <SDL2/SDL.h>
#include "jdraw.h"
#include "jfile.h"
namespace input
{
@@ -15,6 +16,11 @@ namespace input
void initGamePad()
{
int size;
char *buffer = file::getFileBuffer("gamecontrollerdb.txt", size);
if (SDL_GameControllerAddMappingsFromRW(SDL_RWFromMem(buffer, size), 1) < 0) printf("No s'ha pogut carregar el gamecontrollersdb.txt\n");
free(buffer);
const int num_joysticks = SDL_NumJoysticks();
if (num_joysticks>=1) {
for (int i=0; i<num_joysticks; ++i) {

View File

@@ -9,6 +9,8 @@
#include "jutil.h"
#include "jaudio.h"
#include "config.h"
#include "controller.h"
namespace modules
{
namespace game
@@ -292,7 +294,7 @@ namespace modules
if (actor::hero::isDead()) return GAME_DEAD;
if (input::keyPressed(SDL_SCANCODE_ESCAPE))
if (controller::pressed(KEY_MENU))
{
if (console::isEnabled()) {
console::toggle();

View File

@@ -69,20 +69,20 @@ namespace modules
int loop()
{
if (input::keyPressed(SDL_SCANCODE_ESCAPE)) {
if (controller::pressed(KEY_MENU)) {
return INGAME_CONTINUAR;
}
if (controller::pressed(KEY_DOWN))
if (controller::pressed(KEY_DOWN) || input::keyPressed(SDL_SCANCODE_DOWN))
{
selected_option = (selected_option+1)&1;
audio::playSound("snd_push.wav", SOUND_BASIC);
}
if (controller::pressed(KEY_UP))
if (controller::pressed(KEY_UP) || input::keyPressed(SDL_SCANCODE_UP))
{
selected_option = (selected_option-1)&1;
audio::playSound("snd_push.wav", SOUND_BASIC);
}
if (controller::pressed(KEY_JUMP) || controller::pressed(KEY_PICK))
if (controller::pressed(KEY_JUMP) || controller::pressed(KEY_PICK) || input::keyPressed(SDL_SCANCODE_RETURN))
{
audio::playSound("snd_push.wav", SOUND_BASIC);
return selected_option;

View File

@@ -46,7 +46,7 @@ namespace modules
bool loop()
{
if (input::keyPressed(SDL_SCANCODE_ESCAPE)) return false;
if (controller::pressed(KEY_MENU)) return false;
if (shouldGoToNext())
{

View File

@@ -53,14 +53,14 @@ namespace modules
num_pixels++;
}
audio::playSound("snd_logo.wav", SOUND_BASIC);
if (config::isMusicEnabled()) audio::playSound("snd_logo.wav", SOUND_BASIC);
}
int steps=0;
bool loop()
{
if (input::keyPressed(SDL_SCANCODE_ESCAPE) || controller::pressed(KEY_JUMP) || controller::pressed(KEY_PICK) ) {
if (controller::pressed(KEY_MENU) || controller::pressed(KEY_JUMP) || controller::pressed(KEY_PICK) ) {
return false;
}

View File

@@ -28,7 +28,7 @@ namespace modules
int loop()
{
if (input::keyPressed(SDL_SCANCODE_ESCAPE)) {
if (controller::pressed(KEY_MENU)) {
return OPTION_EIXIR;
}
if (controller::pressed(KEY_DOWN) || input::keyPressed(SDL_SCANCODE_DOWN))
@@ -43,7 +43,7 @@ namespace modules
selected_option--; if (selected_option<0) selected_option=4;
}
if (controller::pressed(KEY_JUMP) || controller::pressed(KEY_PICK) || input::keyPressed(SDL_SCANCODE_SPACE) )
if (controller::pressed(KEY_JUMP) || controller::pressed(KEY_PICK) || input::keyPressed(SDL_SCANCODE_RETURN) )
{
audio::playSound("snd_push.wav", SOUND_BASIC);
return selected_option;

View File

@@ -20,20 +20,20 @@ namespace modules
int loop()
{
if (input::keyPressed(SDL_SCANCODE_ESCAPE)) {
if (controller::pressed(KEY_MENU)) {
return MENU_AUDIO_TORNAR;
}
if (controller::pressed(KEY_DOWN))
if (controller::pressed(KEY_DOWN) || input::keyPressed(SDL_SCANCODE_DOWN))
{
selected_option = (selected_option==2)?0:selected_option+1;
audio::playSound("snd_push.wav", SOUND_BASIC);
}
if (controller::pressed(KEY_UP))
if (controller::pressed(KEY_UP) || input::keyPressed(SDL_SCANCODE_UP))
{
selected_option = (selected_option==0)?2:selected_option-1;
audio::playSound("snd_push.wav", SOUND_BASIC);
}
if (controller::pressed(KEY_JUMP) || controller::pressed(KEY_PICK)) {
if (controller::pressed(KEY_JUMP) || controller::pressed(KEY_PICK) || input::keyPressed(SDL_SCANCODE_RETURN)) {
if (selected_option==MENU_AUDIO_MUSICA) {
config::toggleMusic();
if (config::isMusicEnabled())

View File

@@ -32,22 +32,22 @@ namespace modules
{
if (state == STATE_SELECTING)
{
if (input::keyPressed(SDL_SCANCODE_ESCAPE)) {
if (controller::pressed(KEY_MENU)) {
return MENU_GAMEPAD_TORNAR;
}
if (controller::pressed(KEY_DOWN))
if (controller::pressed(KEY_DOWN) || input::keyPressed(SDL_SCANCODE_DOWN))
{
audio::playSound("snd_push.wav", SOUND_BASIC);
selected_option++; if (selected_option>6) selected_option=0;
}
if (controller::pressed(KEY_UP))
if (controller::pressed(KEY_UP) || input::keyPressed(SDL_SCANCODE_UP))
{
audio::playSound("snd_push.wav", SOUND_BASIC);
selected_option--; if (selected_option<0) selected_option=6;
}
if (controller::pressed(KEY_JUMP) || controller::pressed(KEY_PICK))
if (controller::pressed(KEY_JUMP) || controller::pressed(KEY_PICK) || input::keyPressed(SDL_SCANCODE_RETURN))
{
audio::playSound("snd_push.wav", SOUND_BASIC);
if (selected_option==MENU_GAMEPAD_TORNAR)
@@ -59,7 +59,8 @@ namespace modules
const int8_t btn = input::getPadBtnPressed();
if (btn != SDL_CONTROLLER_BUTTON_INVALID) {
config::definePadBtn(selected_option, btn);
state = STATE_SELECTING;
selected_option++;
if (selected_option==6) state = STATE_SELECTING;
}
if (input::keyPressed(SDL_SCANCODE_ESCAPE)) state = STATE_SELECTING;
}

View File

@@ -41,7 +41,7 @@ namespace modules
{
if (state == STATE_SELECTING)
{
if (input::keyPressed(SDL_SCANCODE_ESCAPE)) {
if (controller::pressed(KEY_MENU)) {
return MENU_TECLES_TORNAR;
}
if (controller::pressed(KEY_DOWN) || input::keyPressed(SDL_SCANCODE_DOWN))
@@ -56,7 +56,7 @@ namespace modules
selected_option--; if (selected_option<0) selected_option=6;
}
if (controller::pressed(KEY_JUMP) || controller::pressed(KEY_PICK) || input::keyPressed(SDL_SCANCODE_SPACE))
if (controller::pressed(KEY_JUMP) || controller::pressed(KEY_PICK) || input::keyPressed(SDL_SCANCODE_RETURN))
{
audio::playSound("snd_push.wav", SOUND_BASIC);
if (selected_option==MENU_TECLES_TORNAR)
@@ -68,7 +68,8 @@ namespace modules
const uint8_t key = input::getKeyPressed();
if (key != SDL_SCANCODE_UNKNOWN) {
if (key != SDL_SCANCODE_ESCAPE) config::defineKey(selected_option, key);
state = STATE_SELECTING;
selected_option++;
if (selected_option==6) state = STATE_SELECTING;
}
}