From 80a8e87d455a7d37a2fdfb8e1bcf041dc320229d Mon Sep 17 00:00:00 2001 From: bit6tream Date: Sun, 14 Jan 2024 02:17:53 +0300 Subject: [PATCH] Stats are now closed on a key release, instead of a key press --- src/stribun.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/stribun.c b/src/stribun.c index 9ced27a..4b638be 100644 --- a/src/stribun.c +++ b/src/stribun.c @@ -5355,10 +5355,27 @@ char *perkName(Perk perk) { assert(false); } +static bool pressedKeys[420] = {0}; + void updateAndRenderStats(void) { - if (GetKeyPressed() != KEY_NULL || - IsMouseButtonPressed(MOUSE_BUTTON_LEFT) || - IsMouseButtonPressed(MOUSE_BUTTON_RIGHT)) { + KeyboardKey key = KEY_NULL; + + if ((key = GetKeyPressed()) != KEY_NULL) { + pressedKeys[key] = true; + } + + bool anyKeyReleased = false; + for (int i = 0; i < sizeof(pressedKeys) / sizeof(pressedKeys[0]); i++) { + if (pressedKeys[i] && IsKeyReleased(i)) { + anyKeyReleased = true; + memset(pressedKeys, 0, sizeof(pressedKeys)); + break; + } + } + + if (anyKeyReleased || + IsMouseButtonReleased(MOUSE_BUTTON_LEFT) || + IsMouseButtonReleased(MOUSE_BUTTON_RIGHT)) { PlaySound(beep); if (player.health == 0) {