commit 1156fa00d74aa59a51e2d7158cb2cfbe5cf77385
parent e232b9fef7f563f4d3bad962963914b628e083e7
Author: amin <dev@aminmesbah.com>
Date: Sat, 9 Nov 2019 06:34:30 +0000
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.
FossilOrigin-Name: eaf9fdd2bf5f0ec3513761da990308cac1fe71a7d243a0e0bfc8ad2a7b019e32
Diffstat:
M | src/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