a-game

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

commit 3a4df3bbd702c5d1ce1abd94636459f0489525f6
parent 1156fa00d74aa59a51e2d7158cb2cfbe5cf77385
Author: amin <dev@aminmesbah.com>
Date:   Sat,  9 Nov 2019 06:42:19 +0000

Specify separate speed limits per direction

FossilOrigin-Name: 9d554e5d10d02073e8916b771625a1c4581953885d3fcc0ce011b2e5eb430cfc
Diffstat:
Msrc/game.c | 13+++++++++----
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 {