a-game

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

commit da58fb6496abc1442dd1efbb3eacdd31b4a7bb76
parent 577882b9f54d09eb4108d1c3d21941b978284749
Author: Amin Mesbah <dev@aminmesbah.com>
Date:   Fri,  8 Nov 2019 22:34:31 -0800

Nudge player

When the player reaches the top of the wall, nudge them slightly so they
end up standing on the top solid tile. When they jump while climbing,
nudge them slightly away from the wall.

Diffstat:
Msrc/game.c | 44+++++++++++++++++++++++++++++++++++++++-----
1 file changed, 39 insertions(+), 5 deletions(-)

diff --git a/src/game.c b/src/game.c @@ -233,7 +233,7 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga dt = 1.0f / 60.0f; } - v2 max_velocity = {6.0f, 10.0f}; + v2 max_velocity = {6.0f, 7.0f}; f32 acceleration_rate = 50.0f; f32 friction = 0.7f; enum Direction previous_facing_dir = player->facing; @@ -287,12 +287,46 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga } break; case MOVE_MODE_CLIMBING: - if (player->facing == previous_facing_dir - && entity_is_adjacent_to_solid_tiles(game_state->world, player->pos, player_rect, player->facing)) + if (player->facing == previous_facing_dir) { - if (btn_was_just_pressed(game_input, BTN_JUMP)) + if (entity_is_adjacent_to_solid_tiles(game_state->world, player->pos, player_rect, player->facing)) { - player->move_mode = MOVE_MODE_JUMPING; + 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; + } + else + { + assert(false); + } + player->move_mode = MOVE_MODE_JUMPING; + } + } + else + { + // nudge the player over the ledge + if (player->facing == DIR_RIGHT) + { + player->velocity.x = 3.0f; + } + else if (player->facing == DIR_LEFT) + { + player->velocity.x = -3.0f; + } + else + { + assert(false); + } + player->acceleration.y = 0.0f; + player->velocity.y = 0.0f; + player->move_mode = MOVE_MODE_FALLING; } } else