From 1eb8570329ec50aac4cb5c772ae71206fd48ff13 Mon Sep 17 00:00:00 2001 From: leo60228 Date: Tue, 22 Sep 2020 15:24:23 -0400 Subject: [PATCH] Split flip logic from player input logic Closes #484 Flipping only applies momentum to the player entity currently being processed. This normally wouldn't be a problem. However, flipping involves global state, and only one flip can occur per frame. This means that additional player entities don't get this boost of momentum, which feels somewhat unnatural during gameplay. This commit fixes this by splitting flip logic out of the loop over player entities, and applying the flip momentum to all player entities. --- desktop_version/src/Input.cpp | 64 +++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 26 deletions(-) diff --git a/desktop_version/src/Input.cpp b/desktop_version/src/Input.cpp index bb86e810..6a7065f2 100644 --- a/desktop_version/src/Input.cpp +++ b/desktop_version/src/Input.cpp @@ -2210,41 +2210,53 @@ void gameinput(void) obj.entities[ie].ax = 3; obj.entities[ie].dir = 1; } + } + } - if (!game.press_action) - { - game.jumppressed = 0; - game.jumpheld = false; - } + if (!game.press_action) + { + game.jumppressed = 0; + game.jumpheld = false; + } - if (game.press_action && !game.jumpheld) - { - game.jumppressed = 5; - game.jumpheld = true; - } + if (game.press_action && !game.jumpheld) + { + game.jumppressed = 5; + game.jumpheld = true; + } - if (game.jumppressed > 0) + if (game.jumppressed > 0) + { + game.jumppressed--; + if (obj.entities[obj.getplayer()].onground>0 && game.gravitycontrol == 0) + { + game.gravitycontrol = 1; + for (size_t ie = 0; ie < obj.entities.size(); ++ie) { - game.jumppressed--; - if (obj.entities[ie].onground>0 && game.gravitycontrol == 0) + if (obj.entities[ie].rule == 0) { - game.gravitycontrol = 1; obj.entities[ie].vy = -4; obj.entities[ie].ay = -3; - music.playef(0); - game.jumppressed = 0; - game.totalflips++; - } - if (obj.entities[ie].onroof>0 && game.gravitycontrol == 1) - { - game.gravitycontrol = 0; - obj.entities[ie].vy = 4; - obj.entities[ie].ay = 3; - music.playef(1); - game.jumppressed = 0; - game.totalflips++; } } + music.playef(0); + game.jumppressed = 0; + game.totalflips++; + } + if (obj.entities[obj.getplayer()].onroof>0 && game.gravitycontrol == 1) + { + game.gravitycontrol = 0; + for (size_t ie = 0; ie < obj.entities.size(); ++ie) + { + if (obj.entities[ie].rule == 0) + { + obj.entities[ie].vy = 4; + obj.entities[ie].ay = 3; + } + } + music.playef(1); + game.jumppressed = 0; + game.totalflips++; } } }