feat(input): binding START per jugador (teclat 1/2 fix, mando remapejable; pausa només per F11)
This commit is contained in:
1 parent
165499b9d4
commit
5710568af8
9 files changed
+21
-9
No files matched your search
@@ -76,6 +76,7 @@ menu:
|
|||||||
move_right: "Dreta"
|
move_right: "Dreta"
|
||||||
jump: "Saltar"
|
jump: "Saltar"
|
||||||
attack: "Atacar"
|
attack: "Atacar"
|
||||||
|
start: "Start"
|
||||||
service: "Opcions"
|
service: "Opcions"
|
||||||
gamepad_p1: "Comandament P1"
|
gamepad_p1: "Comandament P1"
|
||||||
gamepad_p2: "Comandament P2"
|
gamepad_p2: "Comandament P2"
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ menu:
|
|||||||
move_right: "Right"
|
move_right: "Right"
|
||||||
jump: "Jump"
|
jump: "Jump"
|
||||||
attack: "Attack"
|
attack: "Attack"
|
||||||
|
start: "Start"
|
||||||
service: "Options"
|
service: "Options"
|
||||||
gamepad_p1: "Gamepad P1"
|
gamepad_p1: "Gamepad P1"
|
||||||
gamepad_p2: "Gamepad P2"
|
gamepad_p2: "Gamepad P2"
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ void DefineButtons::disable() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DefineButtons::resetSequence() {
|
void DefineButtons::resetSequence() {
|
||||||
// Ordre: ATTACK, JUMP, SERVICE — replica l'estructura de
|
// Ordre: ATTACK, JUMP, START, SERVICE — replica l'estructura de
|
||||||
// `clearButtons()` de coffee_crisis_arcade_edition (seqüència ordenada
|
// `clearButtons()` de coffee_crisis_arcade_edition (seqüència ordenada
|
||||||
// d'accions amb la SERVICE al final) adaptada al joc actual. La label
|
// d'accions amb la SERVICE al final) adaptada al joc actual. La label
|
||||||
// de SERVICE va a una clau pròpia (`menu.items.service`) per no
|
// de SERVICE va a una clau pròpia (`menu.items.service`) per no
|
||||||
@@ -70,6 +70,7 @@ void DefineButtons::resetSequence() {
|
|||||||
sequence_.clear();
|
sequence_.clear();
|
||||||
sequence_.push_back({"menu.items.attack", GamepadBindings::Action::ATTACK, static_cast<int>(SDL_GAMEPAD_BUTTON_INVALID)});
|
sequence_.push_back({"menu.items.attack", GamepadBindings::Action::ATTACK, static_cast<int>(SDL_GAMEPAD_BUTTON_INVALID)});
|
||||||
sequence_.push_back({"menu.items.jump", GamepadBindings::Action::JUMP, static_cast<int>(SDL_GAMEPAD_BUTTON_INVALID)});
|
sequence_.push_back({"menu.items.jump", GamepadBindings::Action::JUMP, static_cast<int>(SDL_GAMEPAD_BUTTON_INVALID)});
|
||||||
|
sequence_.push_back({"menu.items.start", GamepadBindings::Action::START, static_cast<int>(SDL_GAMEPAD_BUTTON_INVALID)});
|
||||||
sequence_.push_back({"menu.items.service", GamepadBindings::Action::SERVICE, static_cast<int>(SDL_GAMEPAD_BUTTON_INVALID)});
|
sequence_.push_back({"menu.items.service", GamepadBindings::Action::SERVICE, static_cast<int>(SDL_GAMEPAD_BUTTON_INVALID)});
|
||||||
index_ = 0;
|
index_ = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ namespace {
|
|||||||
ActionPair{GamepadBindings::Action::JUMP, std::string_view{"jump"}},
|
ActionPair{GamepadBindings::Action::JUMP, std::string_view{"jump"}},
|
||||||
ActionPair{GamepadBindings::Action::ATTACK, std::string_view{"attack"}},
|
ActionPair{GamepadBindings::Action::ATTACK, std::string_view{"attack"}},
|
||||||
ActionPair{GamepadBindings::Action::SERVICE, std::string_view{"service"}},
|
ActionPair{GamepadBindings::Action::SERVICE, std::string_view{"service"}},
|
||||||
|
ActionPair{GamepadBindings::Action::START, std::string_view{"start"}},
|
||||||
};
|
};
|
||||||
|
|
||||||
using ButtonPair = std::pair<int, std::string_view>;
|
using ButtonPair = std::pair<int, std::string_view>;
|
||||||
@@ -98,6 +99,8 @@ auto GamepadBindings::defaultButton(Action action) -> int {
|
|||||||
return static_cast<int>(SDL_GAMEPAD_BUTTON_WEST);
|
return static_cast<int>(SDL_GAMEPAD_BUTTON_WEST);
|
||||||
case Action::SERVICE:
|
case Action::SERVICE:
|
||||||
return static_cast<int>(SDL_GAMEPAD_BUTTON_BACK);
|
return static_cast<int>(SDL_GAMEPAD_BUTTON_BACK);
|
||||||
|
case Action::START:
|
||||||
|
return static_cast<int>(SDL_GAMEPAD_BUTTON_START);
|
||||||
}
|
}
|
||||||
return static_cast<int>(SDL_GAMEPAD_BUTTON_INVALID);
|
return static_cast<int>(SDL_GAMEPAD_BUTTON_INVALID);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ class GamepadBindings {
|
|||||||
JUMP,
|
JUMP,
|
||||||
ATTACK,
|
ATTACK,
|
||||||
SERVICE,
|
SERVICE,
|
||||||
|
START,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Triggers L2/R2 representats com a "botons virtuals" — replica la
|
// Triggers L2/R2 representats com a "botons virtuals" — replica la
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ class Player : public AnimatedSprite {
|
|||||||
SDL_Scancode right;
|
SDL_Scancode right;
|
||||||
SDL_Scancode jump;
|
SDL_Scancode jump;
|
||||||
SDL_Scancode attack;
|
SDL_Scancode attack;
|
||||||
|
// No remapejable des del menú de servei: P1 → "1", P2 → "2".
|
||||||
|
SDL_Scancode start;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Estat d'alt nivell del jugador. Ortogonal a `Facing`/`Cardinal`
|
// Estat d'alt nivell del jugador. Ortogonal a `Facing`/`Cardinal`
|
||||||
|
|||||||
@@ -14,7 +14,6 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "core/audio/audio.hpp"
|
#include "core/audio/audio.hpp"
|
||||||
#include "core/input/gamepad_manager.hpp"
|
|
||||||
#include "core/input/global_inputs.hpp"
|
#include "core/input/global_inputs.hpp"
|
||||||
#include "core/input/key_config.hpp"
|
#include "core/input/key_config.hpp"
|
||||||
#include "core/locale/locale.hpp"
|
#include "core/locale/locale.hpp"
|
||||||
@@ -348,6 +347,7 @@ GameScene::GameScene(Config config)
|
|||||||
.right = kb_p1.right,
|
.right = kb_p1.right,
|
||||||
.jump = kb_p1.jump,
|
.jump = kb_p1.jump,
|
||||||
.attack = kb_p1.attack,
|
.attack = kb_p1.attack,
|
||||||
|
.start = Defaults::KeysGame::START,
|
||||||
};
|
};
|
||||||
const Player::Controls CONTROLS_P2{
|
const Player::Controls CONTROLS_P2{
|
||||||
.up = kb_p2.up,
|
.up = kb_p2.up,
|
||||||
@@ -356,6 +356,7 @@ GameScene::GameScene(Config config)
|
|||||||
.right = kb_p2.right,
|
.right = kb_p2.right,
|
||||||
.jump = kb_p2.jump,
|
.jump = kb_p2.jump,
|
||||||
.attack = kb_p2.attack,
|
.attack = kb_p2.attack,
|
||||||
|
.start = Defaults::KeysGameP2::START,
|
||||||
};
|
};
|
||||||
// Spawn lligat a la porta: tots els jugadors apareixen davant del
|
// Spawn lligat a la porta: tots els jugadors apareixen davant del
|
||||||
// passadís de sortida. `computeSpawn` deriva les coordenades de
|
// passadís de sortida. `computeSpawn` deriva les coordenades de
|
||||||
@@ -1044,11 +1045,9 @@ void GameScene::handlePauseInput() {
|
|||||||
if (editor_.active()) { return; }
|
if (editor_.active()) { return; }
|
||||||
#endif
|
#endif
|
||||||
const SDL_Scancode PAUSE_SC = KeyConfig::get().scancode("pause");
|
const SDL_Scancode PAUSE_SC = KeyConfig::get().scancode("pause");
|
||||||
SDL_Gamepad* pad = GamepadManager::get().getPrimary();
|
|
||||||
for (const auto& event : EventBuffer::events) {
|
for (const auto& event : EventBuffer::events) {
|
||||||
const bool KEY_HIT = (event.type == SDL_EVENT_KEY_DOWN && PAUSE_SC != SDL_SCANCODE_UNKNOWN && event.key.scancode == PAUSE_SC);
|
const bool KEY_HIT = (event.type == SDL_EVENT_KEY_DOWN && PAUSE_SC != SDL_SCANCODE_UNKNOWN && event.key.scancode == PAUSE_SC);
|
||||||
const bool PAD_HIT = (event.type == SDL_EVENT_GAMEPAD_BUTTON_DOWN && pad != nullptr && event.gbutton.which == SDL_GetGamepadID(pad) && event.gbutton.button == SDL_GAMEPAD_BUTTON_START);
|
if (!KEY_HIT) { continue; }
|
||||||
if (!KEY_HIT && !PAD_HIT) { continue; }
|
|
||||||
|
|
||||||
// Determinem cap a quin estat anem. Si estem quiets (IDLE o
|
// Determinem cap a quin estat anem. Si estem quiets (IDLE o
|
||||||
// PAUSED) arranquem la transició contrària. Si estem en marxa
|
// PAUSED) arranquem la transició contrària. Si estem en marxa
|
||||||
|
|||||||
@@ -58,10 +58,12 @@ class GameScene : public Scene {
|
|||||||
// crida `setState` (que reseteja la `Transition`).
|
// crida `setState` (que reseteja la `Transition`).
|
||||||
void updateRoomTransition(int delta_ms);
|
void updateRoomTransition(int delta_ms);
|
||||||
|
|
||||||
// Consumeix events d'aquest frame (F11 del KeyConfig "pause" o botó
|
// Consumeix events d'aquest frame (F11 del KeyConfig "pause") per
|
||||||
// START del gamepad primari) per disparar les transicions de pausa.
|
// disparar les transicions de pausa. El mando ja no participa: el
|
||||||
// No alterna un flag binari: inicia (o inverteix mid-flight) un
|
// botó START és ara una acció remapeable per dispositiu i el menú
|
||||||
// "dial" de temps que frena el món amb easing.
|
// de servei fa de pausa quan cal. No alterna un flag binari: inicia
|
||||||
|
// (o inverteix mid-flight) un "dial" de temps que frena el món amb
|
||||||
|
// easing.
|
||||||
void handlePauseInput();
|
void handlePauseInput();
|
||||||
|
|
||||||
// Avança la transició activa, recalcula `pause_.scale` i aplica el
|
// Avança la transició activa, recalcula `pause_.scale` i aplica el
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ namespace Defaults {
|
|||||||
constexpr SDL_Scancode RIGHT = SDL_SCANCODE_RIGHT;
|
constexpr SDL_Scancode RIGHT = SDL_SCANCODE_RIGHT;
|
||||||
constexpr SDL_Scancode JUMP = SDL_SCANCODE_M;
|
constexpr SDL_Scancode JUMP = SDL_SCANCODE_M;
|
||||||
constexpr SDL_Scancode ATTACK = SDL_SCANCODE_N;
|
constexpr SDL_Scancode ATTACK = SDL_SCANCODE_N;
|
||||||
|
constexpr SDL_Scancode START = SDL_SCANCODE_1;
|
||||||
constexpr SDL_Scancode EXIT = SDL_SCANCODE_ESCAPE;
|
constexpr SDL_Scancode EXIT = SDL_SCANCODE_ESCAPE;
|
||||||
} // namespace KeysGame
|
} // namespace KeysGame
|
||||||
|
|
||||||
@@ -93,6 +94,7 @@ namespace Defaults {
|
|||||||
constexpr SDL_Scancode RIGHT = SDL_SCANCODE_D;
|
constexpr SDL_Scancode RIGHT = SDL_SCANCODE_D;
|
||||||
constexpr SDL_Scancode JUMP = SDL_SCANCODE_V;
|
constexpr SDL_Scancode JUMP = SDL_SCANCODE_V;
|
||||||
constexpr SDL_Scancode ATTACK = SDL_SCANCODE_C;
|
constexpr SDL_Scancode ATTACK = SDL_SCANCODE_C;
|
||||||
|
constexpr SDL_Scancode START = SDL_SCANCODE_2;
|
||||||
} // namespace KeysGameP2
|
} // namespace KeysGameP2
|
||||||
|
|
||||||
namespace Player {
|
namespace Player {
|
||||||
|
|||||||
Reference in new issue
Block a user