From 6a388227febcdb246c302fba81421fa9a863308c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20=C4=8C=C3=AD=C5=BE?= Date: Mon, 30 Nov 2020 21:06:52 +0100 Subject: [PATCH] Fix a speed bug --- TODO.txt | 8 ++++---- game.h | 15 +++++++++++++++ main_pokitto.cpp | 6 ++---- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/TODO.txt b/TODO.txt index d15d8f4..03be0ed 100644 --- a/TODO.txt +++ b/TODO.txt @@ -126,13 +126,9 @@ level ideas: over a hole, leading to an easter egg - start of level: a corner blocked by an invisible wall, to indicate entrance DONE - small pyramid from diffetently elevated floor tiles -- add time slowdown constant bugs: -- On Pokitto/GB Meta sometimes after turn on the game starts midway loading the - first level. - done: - add headbob @@ -221,6 +217,10 @@ done: - Add FOV options. RCL doesn't project sprites with different FOV correctly - FIX! - When selecting continue from menu, the player shoots - fix! +- FIX: running diagonally (forward + strafe) player can jump over 3 squares! +- add time slowdown constant +- On Pokitto/GB Meta sometimes after turn on the game starts midway loading the + first level. scratched: - option for disabling wall transparency, for performance? diff --git a/game.h b/game.h index 90d0201..743fc5d 100755 --- a/game.h +++ b/game.h @@ -3237,8 +3237,23 @@ void SFG_gameStepPlaying() if (strafe != 0) { + uint8_t normalize = (moveOffset.x != 0) || (moveOffset.y != 0); + moveOffset.x += strafe * SFG_player.direction.y; moveOffset.y -= strafe * SFG_player.direction.x; + + if (normalize) + { + // This prevents reaching higher speed when moving diagonally. + + moveOffset = RCL_normalize(moveOffset); + + moveOffset.x = (moveOffset.x * SFG_PLAYER_MOVE_UNITS_PER_FRAME) + / RCL_UNITS_PER_SQUARE; + + moveOffset.y = (moveOffset.y * SFG_PLAYER_MOVE_UNITS_PER_FRAME) + / RCL_UNITS_PER_SQUARE; + } } #if SFG_PREVIEW_MODE diff --git a/main_pokitto.cpp b/main_pokitto.cpp index c4f7445..0bedcd9 100644 --- a/main_pokitto.cpp +++ b/main_pokitto.cpp @@ -106,8 +106,6 @@ int8_t SFG_keyPressed(uint8_t key) case SFG_KEY_DOWN: return joy.JoyX() > axisThreshold2; break; case SFG_KEY_RIGHT: return joy.JoyY() > axisThreshold2; break; case SFG_KEY_LEFT: return joy.JoyY() < axisThreshold1; break; - case SFG_KEY_A: return pokitto.bBtn(); break; - case SFG_KEY_B: return pokitto.aBtn(); break; case SFG_KEY_JUMP: return pokitto.rightBtn(); break; case SFG_KEY_STRAFE_RIGHT: return pokitto.downBtn(); break; case SFG_KEY_STRAFE_LEFT: return pokitto.upBtn(); break; @@ -119,10 +117,10 @@ int8_t SFG_keyPressed(uint8_t key) case SFG_KEY_DOWN: return pokitto.downBtn(); break; case SFG_KEY_RIGHT: return pokitto.rightBtn(); break; case SFG_KEY_LEFT: return pokitto.leftBtn(); break; - case SFG_KEY_A: return pokitto.aBtn(); break; - case SFG_KEY_B: return pokitto.bBtn(); break; #endif + case SFG_KEY_A: return pokitto.aBtn(); break; + case SFG_KEY_B: return pokitto.bBtn(); break; case SFG_KEY_C: return pokitto.cBtn(); break; default: return 0; break; }