commit de63587c14d5cc5837bfbae605c123b859fee25a
parent da58fb6496abc1442dd1efbb3eacdd31b4a7bb76
Author: Amin Mesbah <dev@aminmesbah.com>
Date: Fri, 8 Nov 2019 22:42:20 -0800
Specify separate speed limits per direction
Diffstat:
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/src/game.c b/src/game.c
@@ -233,7 +233,12 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga
dt = 1.0f / 60.0f;
}
- v2 max_velocity = {6.0f, 7.0f};
+ f32 max_velocity[] = {
+ [DIR_RIGHT] = 6.0f,
+ [DIR_LEFT] = -6.0f,
+ [DIR_UP] = 7.0f,
+ [DIR_DOWN] = -10.0f,
+ };
f32 acceleration_rate = 50.0f;
f32 friction = 0.7f;
enum Direction previous_facing_dir = player->facing;
@@ -387,7 +392,7 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga
}
break;
case MOVE_MODE_JUMPING:
- max_velocity.y = 100.0f;
+ max_velocity[DIR_UP] = 100.0f;
player->acceleration.y = 13.0f * acceleration_rate;
player->move_mode = MOVE_MODE_FALLING;
break;
@@ -414,8 +419,8 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga
// Semi implicit Euler integration: https://gafferongames.com/post/integration_basics/
player->velocity = math_v2_a(player->velocity, math_v2f_m(player->acceleration, dt));
// TODO: clamp the length of the velocity vector, not each of its components
- math_clamp(&player->velocity.x, -max_velocity.x, max_velocity.x);
- math_clamp(&player->velocity.y, -max_velocity.y, max_velocity.y);
+ math_clamp(&player->velocity.x, max_velocity[DIR_LEFT], max_velocity[DIR_RIGHT]);
+ math_clamp(&player->velocity.y, max_velocity[DIR_DOWN], max_velocity[DIR_UP]);
// game_detect_collisions
{