a-game

2D platformer written from scratch.
Log | Files | Refs | README | LICENSE

commit fc617dd7277c908561d1dda09a3dce863dabad8c
parent db4418e4e37573519644cc633692bc6192080696
Author: Amin Mesbah <dev@aminmesbah.com>
Date:   Fri,  6 Dec 2019 17:13:06 -0800

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.

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: