- [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:
2078
data/gamecontrollerdb.txt
Normal file
2078
data/gamecontrollerdb.txt
Normal file
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -6,8 +6,8 @@ namespace config
|
|||||||
{
|
{
|
||||||
bool musicEnabled = true;
|
bool musicEnabled = true;
|
||||||
int soundMode = SOUND_ALL;
|
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};
|
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[6] = {0, 1, 2, 3, 4, 5};
|
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)
|
void setMusic(const bool value)
|
||||||
{
|
{
|
||||||
@@ -46,7 +46,7 @@ namespace config
|
|||||||
|
|
||||||
void defineKey(const int which, const int key)
|
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;
|
keys[which] = key;
|
||||||
char tmp[5];
|
char tmp[5];
|
||||||
file::setConfigValue(nomtecles[which], SDL_itoa(key, tmp, 10));
|
file::setConfigValue(nomtecles[which], SDL_itoa(key, tmp, 10));
|
||||||
@@ -59,7 +59,7 @@ namespace config
|
|||||||
|
|
||||||
void definePadBtn(const int which, const int btn)
|
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;
|
pad_btns[which] = btn;
|
||||||
char tmp[5];
|
char tmp[5];
|
||||||
file::setConfigValue(nombotons[which], SDL_itoa(btn, tmp, 10));
|
file::setConfigValue(nombotons[which], SDL_itoa(btn, tmp, 10));
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ namespace config
|
|||||||
#define KEY_RIGHT 3
|
#define KEY_RIGHT 3
|
||||||
#define KEY_JUMP 4
|
#define KEY_JUMP 4
|
||||||
#define KEY_PICK 5
|
#define KEY_PICK 5
|
||||||
|
#define KEY_MENU 6
|
||||||
|
|
||||||
void setMusic(const bool value);
|
void setMusic(const bool value);
|
||||||
void toggleMusic();
|
void toggleMusic();
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "jinput.h"
|
#include "jinput.h"
|
||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#include "jdraw.h"
|
#include "jdraw.h"
|
||||||
|
#include "jfile.h"
|
||||||
|
|
||||||
namespace input
|
namespace input
|
||||||
{
|
{
|
||||||
@@ -15,6 +16,11 @@ namespace input
|
|||||||
|
|
||||||
void initGamePad()
|
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();
|
const int num_joysticks = SDL_NumJoysticks();
|
||||||
if (num_joysticks>=1) {
|
if (num_joysticks>=1) {
|
||||||
for (int i=0; i<num_joysticks; ++i) {
|
for (int i=0; i<num_joysticks; ++i) {
|
||||||
|
|||||||
@@ -9,6 +9,8 @@
|
|||||||
#include "jutil.h"
|
#include "jutil.h"
|
||||||
#include "jaudio.h"
|
#include "jaudio.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include "controller.h"
|
||||||
|
|
||||||
namespace modules
|
namespace modules
|
||||||
{
|
{
|
||||||
namespace game
|
namespace game
|
||||||
@@ -292,7 +294,7 @@ namespace modules
|
|||||||
|
|
||||||
if (actor::hero::isDead()) return GAME_DEAD;
|
if (actor::hero::isDead()) return GAME_DEAD;
|
||||||
|
|
||||||
if (input::keyPressed(SDL_SCANCODE_ESCAPE))
|
if (controller::pressed(KEY_MENU))
|
||||||
{
|
{
|
||||||
if (console::isEnabled()) {
|
if (console::isEnabled()) {
|
||||||
console::toggle();
|
console::toggle();
|
||||||
|
|||||||
@@ -69,20 +69,20 @@ namespace modules
|
|||||||
|
|
||||||
int loop()
|
int loop()
|
||||||
{
|
{
|
||||||
if (input::keyPressed(SDL_SCANCODE_ESCAPE)) {
|
if (controller::pressed(KEY_MENU)) {
|
||||||
return INGAME_CONTINUAR;
|
return INGAME_CONTINUAR;
|
||||||
}
|
}
|
||||||
if (controller::pressed(KEY_DOWN))
|
if (controller::pressed(KEY_DOWN) || input::keyPressed(SDL_SCANCODE_DOWN))
|
||||||
{
|
{
|
||||||
selected_option = (selected_option+1)&1;
|
selected_option = (selected_option+1)&1;
|
||||||
audio::playSound("snd_push.wav", SOUND_BASIC);
|
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;
|
selected_option = (selected_option-1)&1;
|
||||||
audio::playSound("snd_push.wav", SOUND_BASIC);
|
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);
|
audio::playSound("snd_push.wav", SOUND_BASIC);
|
||||||
return selected_option;
|
return selected_option;
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ namespace modules
|
|||||||
|
|
||||||
bool loop()
|
bool loop()
|
||||||
{
|
{
|
||||||
if (input::keyPressed(SDL_SCANCODE_ESCAPE)) return false;
|
if (controller::pressed(KEY_MENU)) return false;
|
||||||
|
|
||||||
if (shouldGoToNext())
|
if (shouldGoToNext())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -53,14 +53,14 @@ namespace modules
|
|||||||
num_pixels++;
|
num_pixels++;
|
||||||
}
|
}
|
||||||
|
|
||||||
audio::playSound("snd_logo.wav", SOUND_BASIC);
|
if (config::isMusicEnabled()) audio::playSound("snd_logo.wav", SOUND_BASIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
int steps=0;
|
int steps=0;
|
||||||
|
|
||||||
bool loop()
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace modules
|
|||||||
|
|
||||||
int loop()
|
int loop()
|
||||||
{
|
{
|
||||||
if (input::keyPressed(SDL_SCANCODE_ESCAPE)) {
|
if (controller::pressed(KEY_MENU)) {
|
||||||
return OPTION_EIXIR;
|
return OPTION_EIXIR;
|
||||||
}
|
}
|
||||||
if (controller::pressed(KEY_DOWN) || input::keyPressed(SDL_SCANCODE_DOWN))
|
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;
|
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);
|
audio::playSound("snd_push.wav", SOUND_BASIC);
|
||||||
return selected_option;
|
return selected_option;
|
||||||
|
|||||||
@@ -20,20 +20,20 @@ namespace modules
|
|||||||
|
|
||||||
int loop()
|
int loop()
|
||||||
{
|
{
|
||||||
if (input::keyPressed(SDL_SCANCODE_ESCAPE)) {
|
if (controller::pressed(KEY_MENU)) {
|
||||||
return MENU_AUDIO_TORNAR;
|
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;
|
selected_option = (selected_option==2)?0:selected_option+1;
|
||||||
audio::playSound("snd_push.wav", SOUND_BASIC);
|
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;
|
selected_option = (selected_option==0)?2:selected_option-1;
|
||||||
audio::playSound("snd_push.wav", SOUND_BASIC);
|
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) {
|
if (selected_option==MENU_AUDIO_MUSICA) {
|
||||||
config::toggleMusic();
|
config::toggleMusic();
|
||||||
if (config::isMusicEnabled())
|
if (config::isMusicEnabled())
|
||||||
|
|||||||
@@ -32,22 +32,22 @@ namespace modules
|
|||||||
{
|
{
|
||||||
if (state == STATE_SELECTING)
|
if (state == STATE_SELECTING)
|
||||||
{
|
{
|
||||||
if (input::keyPressed(SDL_SCANCODE_ESCAPE)) {
|
if (controller::pressed(KEY_MENU)) {
|
||||||
return MENU_GAMEPAD_TORNAR;
|
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);
|
audio::playSound("snd_push.wav", SOUND_BASIC);
|
||||||
selected_option++; if (selected_option>6) selected_option=0;
|
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);
|
audio::playSound("snd_push.wav", SOUND_BASIC);
|
||||||
selected_option--; if (selected_option<0) selected_option=6;
|
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);
|
audio::playSound("snd_push.wav", SOUND_BASIC);
|
||||||
if (selected_option==MENU_GAMEPAD_TORNAR)
|
if (selected_option==MENU_GAMEPAD_TORNAR)
|
||||||
@@ -59,7 +59,8 @@ namespace modules
|
|||||||
const int8_t btn = input::getPadBtnPressed();
|
const int8_t btn = input::getPadBtnPressed();
|
||||||
if (btn != SDL_CONTROLLER_BUTTON_INVALID) {
|
if (btn != SDL_CONTROLLER_BUTTON_INVALID) {
|
||||||
config::definePadBtn(selected_option, btn);
|
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;
|
if (input::keyPressed(SDL_SCANCODE_ESCAPE)) state = STATE_SELECTING;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ namespace modules
|
|||||||
{
|
{
|
||||||
if (state == STATE_SELECTING)
|
if (state == STATE_SELECTING)
|
||||||
{
|
{
|
||||||
if (input::keyPressed(SDL_SCANCODE_ESCAPE)) {
|
if (controller::pressed(KEY_MENU)) {
|
||||||
return MENU_TECLES_TORNAR;
|
return MENU_TECLES_TORNAR;
|
||||||
}
|
}
|
||||||
if (controller::pressed(KEY_DOWN) || input::keyPressed(SDL_SCANCODE_DOWN))
|
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;
|
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);
|
audio::playSound("snd_push.wav", SOUND_BASIC);
|
||||||
if (selected_option==MENU_TECLES_TORNAR)
|
if (selected_option==MENU_TECLES_TORNAR)
|
||||||
@@ -68,7 +68,8 @@ namespace modules
|
|||||||
const uint8_t key = input::getKeyPressed();
|
const uint8_t key = input::getKeyPressed();
|
||||||
if (key != SDL_SCANCODE_UNKNOWN) {
|
if (key != SDL_SCANCODE_UNKNOWN) {
|
||||||
if (key != SDL_SCANCODE_ESCAPE) config::defineKey(selected_option, key);
|
if (key != SDL_SCANCODE_ESCAPE) config::defineKey(selected_option, key);
|
||||||
state = STATE_SELECTING;
|
selected_option++;
|
||||||
|
if (selected_option==6) state = STATE_SELECTING;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user