From 02c775545d36060dda08e36e13496fa186b22fa7 Mon Sep 17 00:00:00 2001 From: Gordon Weeks <627684+gcweeks@users.noreply.github.com> Date: Sat, 31 Jan 2026 10:45:35 -0800 Subject: [PATCH] Wired instrument selection into game --- src/main.cpp | 1 + src/samples/ghhb_game.h | 24 ++++++++++++++++++++++-- src/samples/instrument_select.h | 6 ++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 472082f..f51388a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,6 +9,7 @@ #endif int INSTRUMENT_GAMEPAD_INDEX[MAX_INSTRUMENT_TYPES] = {-1, -1, -1, -1}; +int INSTRUMENT_PHYSICAL_GAMEPAD[MAX_INSTRUMENT_TYPES] = {-1, -1, -1, -1}; Game game; diff --git a/src/samples/ghhb_game.h b/src/samples/ghhb_game.h index 8de349e..704f594 100644 --- a/src/samples/ghhb_game.h +++ b/src/samples/ghhb_game.h @@ -159,6 +159,7 @@ const char* const GHHB_CHART_PATH = "assets/songs/json/mary.json"; } // namespace extern int INSTRUMENT_GAMEPAD_INDEX[MAX_INSTRUMENT_TYPES]; +extern int INSTRUMENT_PHYSICAL_GAMEPAD[MAX_INSTRUMENT_TYPES]; class GHHBScene : public Scene { @@ -295,6 +296,22 @@ public: return false; } + bool lane_pressed_by_instrument_owner(int lane, int instrument_slot) const + { + int physical_id = INSTRUMENT_PHYSICAL_GAMEPAD[instrument_slot]; + if (physical_id < 0) + { + for (int i = 0; i < MAX_GAMEPADS; i++) + { + if (IsGamepadAvailable(i) && IsGamepadButtonPressed(i, GAMEPAD_BUTTONS[lane])) + return true; + } + return false; + } + return IsGamepadAvailable(physical_id) && + IsGamepadButtonPressed(physical_id, GAMEPAD_BUTTONS[lane]); + } + bool is_menu_pressed() const { if (IsKeyPressed(KEY_ENTER)) @@ -462,9 +479,12 @@ public: } if (best != nullptr) { - consume_note(best); + if (lane_pressed_by_instrument_owner(lane, best->instrument_slot)) + { + consume_note(best); + } } - else + else if (is_lane_pressed(lane)) { combo = 0; score = std::max(0, score - 25); diff --git a/src/samples/instrument_select.h b/src/samples/instrument_select.h index 94520f7..c7f2f74 100644 --- a/src/samples/instrument_select.h +++ b/src/samples/instrument_select.h @@ -98,7 +98,10 @@ public: if (IsKeyPressed(KEY_ENTER)) { for (int i = 0; i < MAX_INSTRUMENT_TYPES; i++) + { INSTRUMENT_GAMEPAD_INDEX[i] = instrument_owner[i]; + INSTRUMENT_PHYSICAL_GAMEPAD[i] = participant_order[instrument_owner[i]]; + } game->go_to_scene("ghhb"); return; } @@ -107,7 +110,10 @@ public: if (IsGamepadAvailable(gp) && IsGamepadButtonPressed(gp, GAMEPAD_BUTTON_MIDDLE_RIGHT)) { for (int i = 0; i < MAX_INSTRUMENT_TYPES; i++) + { INSTRUMENT_GAMEPAD_INDEX[i] = instrument_owner[i]; + INSTRUMENT_PHYSICAL_GAMEPAD[i] = participant_order[instrument_owner[i]]; + } game->go_to_scene("ghhb"); return; }