a-game

2D platformer written from scratch.
git clone git://git.amin.space/a-game.git
Log | Files | Refs | README | LICENSE

commit 52016f3f71a55e7666fe0b2186a959653340f5f7
parent 3c544cda10bb1cf7b063fa17fd3e52aaf7407973
Author: amin <dev@aminmesbah.com>
Date:   Sat,  7 Dec 2019 01:13:05 +0000

Handle all wall jump cases

Before we would handle the player pressing the jump and direction keys
on different frames in either order, but we would make them fall if they
were pressed on the same frame! Now we handle all three cases properly.

FossilOrigin-Name: 45304881d44c2799f833a0fd6af19844c056d198ae05075103b50a8eb9b68984
Diffstat:
Msrc/game.c | 28++++++++++++++++++++--------
1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/src/game.c b/src/game.c @@ -335,10 +335,6 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga { player->velocity.x = 3.0f; } - else - { - assert(false); - } player->move_mode = MOVE_MODE_JUMPING; } } @@ -363,10 +359,26 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga } else { - player->acceleration.y = 0.0f; - player->velocity.y = 0.0f; - timer_init(&game_state->jump_allowance_timer, JUMP_ALLOWANCE_MS); - player->move_mode = MOVE_MODE_FALLING; + if (btn_was_just_pressed(game_input, BTN_JUMP)) + { + // nudge the player away from the wall + if (player->facing == DIR_RIGHT) + { + player->velocity.x = 3.0f; + } + else if (player->facing == DIR_LEFT) + { + player->velocity.x = -3.0f; + } + player->move_mode = MOVE_MODE_JUMPING; + } + else + { + player->acceleration.y = 0.0f; + player->velocity.y = 0.0f; + timer_init(&game_state->jump_allowance_timer, JUMP_ALLOWANCE_MS); + player->move_mode = MOVE_MODE_FALLING; + } } break; case MOVE_MODE_JUMPING: