diff options
author | Aki <please@ignore.pl> | 2022-04-18 13:24:01 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2022-04-18 13:24:01 +0200 |
commit | 753a37ca74217e10463db49dc1adf65e4e181622 (patch) | |
tree | 5fe9f7640f422ea304f06df37228850757666cc6 | |
parent | bc37e46216b7fddbf6d2fbef1eaf399a586e59fc (diff) | |
download | bullethell2022-753a37ca74217e10463db49dc1adf65e4e181622.zip bullethell2022-753a37ca74217e10463db49dc1adf65e4e181622.tar.gz bullethell2022-753a37ca74217e10463db49dc1adf65e4e181622.tar.bz2 |
Fixed not switching direction back when holding key
-rw-r--r-- | KeyboardController.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/KeyboardController.cpp b/KeyboardController.cpp index 2273008..18b548b 100644 --- a/KeyboardController.cpp +++ b/KeyboardController.cpp @@ -26,7 +26,7 @@ KeyboardController::direction() y_axis = check_axis(KEY_UP, KEY_DOWN, y_axis); if (x_axis != 0 && y_axis != 0) return {x_axis * DIAGONAL, y_axis * DIAGONAL}; - return {x_axis, y_axis}; + return {static_cast<float>(x_axis), static_cast<float>(y_axis)}; } @@ -34,10 +34,18 @@ int check_axis(const int negative_key, const int positive_key, const int last) { int next = last; - if (last == 1 && IsKeyReleased(positive_key)) - next = 0; - else if (last == -1 && IsKeyReleased(negative_key)) - next = 0; + if (last == 1 && IsKeyReleased(positive_key)) { + if (IsKeyDown(negative_key)) + next = -1; + else + next = 0; + } + else if (last == -1 && IsKeyReleased(negative_key)) { + if (IsKeyDown(positive_key)) + next = 1; + else + next = 0; + } if (IsKeyPressed(positive_key)) next = 1; else if (IsKeyPressed(negative_key)) |