# a-game

2D platformer written from scratch.

```commit 5fcdd7cc0c0b8f060b16cd16ec5accc41ee1e1d0
parent 9a64c28966c2c305f648820e89277e9c912fd8ef
Author: Amin Mesbah <dev@aminmesbah.com>
Date:   Fri, 19 Apr 2019 12:28:45 -0700

Tune new movement code

It's surprising how much nicer this feels compared to simply adding a
velocity constant to position.

Diffstat:
Msrc/game.c | 16++++++++++------
```
```1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/src/game.c b/src/game.c
@@ -126,11 +126,12 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga
struct Entity *player = &game_state->player;
f32 dt = game_input->dt;
f32 max_meters_per_second = 5.0f;
-        f32 acceleration_rate = 10.0f;
+        f32 acceleration_rate = 50.0f;
+        f32 friction = 0.7f;

if (game_input->key_up)
{
-            player->acceleration.y = +acceleration_rate;
+            player->acceleration.y = acceleration_rate;
}
else if (game_input->key_down)
{
@@ -139,6 +140,7 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga
else
{
player->acceleration.y = 0.0f;
+            player->velocity.y = player->velocity.y * friction;
}

if (game_input->key_left)
@@ -147,21 +149,23 @@ void game_update_and_render(struct GameMemory *game_memory, struct GameInput *ga
}
else if (game_input->key_right)
{
-            player->acceleration.x = +acceleration_rate;
+            player->acceleration.x = acceleration_rate;
}
else
{
player->acceleration.x = 0.0f;
+            player->velocity.x = player->velocity.x * friction;
}

-        glmth_clamp(&player->velocity.x, -max_meters_per_second, max_meters_per_second);
-
// Semi implicit Euler integration: https://gafferongames.com/post/integration_basics/
player->velocity = glmth_v2_a(player->velocity, glmth_v2f_m(player->acceleration, dt));
-        player->pos = glmth_v2_a(player->pos, glmth_v2f_m(player->velocity, dt));
+        glmth_clamp(&player->velocity.x, -max_meters_per_second, max_meters_per_second);
+        glmth_clamp(&player->velocity.y, -max_meters_per_second, max_meters_per_second);

+        player->pos = glmth_v2_a(player->pos, glmth_v2f_m(player->velocity, dt));
glmth_clamp(&(player->pos.x), 0, ROOM_TILE_DIM_X);
glmth_clamp(&(player->pos.y), 0, ROOM_TILE_DIM_Y);
+
printf("A: ");
glmth_v2_print(player->acceleration);
printf("V: ");
```
{"ft_lang_label":"__label__en","ft_lang_prob":0.5604972,"math_prob":0.9121385,"size":2143,"snap":"2023-40-2023-50","text_gpt3_token_len":668,"char_repetition_ratio":0.19728845,"word_repetition_ratio":0.067307696,"special_character_ratio":0.33364442,"punctuation_ratio":0.26268658,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.95429295,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-12-07T11:01:40Z\",\"WARC-Record-ID\":\"<urn:uuid:cb9ab25c-6a5d-439c-aa84-321ca3a8ed6a>\",\"Content-Length\":\"5815\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:7531166f-2644-4cde-9575-240eba5880b2>\",\"WARC-Concurrent-To\":\"<urn:uuid:50dd337a-797d-47c8-803f-d7205dc19e54>\",\"WARC-IP-Address\":\"149.248.44.219\",\"WARC-Target-URI\":\"https://git.amin.space/a-game/commit/5fcdd7cc0c0b8f060b16cd16ec5accc41ee1e1d0.html\",\"WARC-Payload-Digest\":\"sha1:D3EDUEMDU42GZMBUYXDSXPGKM7JFV6IG\",\"WARC-Block-Digest\":\"sha1:CXXTW7UIKATCQ5F65NHEJWDNJMGS4WEV\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-50/CC-MAIN-2023-50_segments_1700679100651.34_warc_CC-MAIN-20231207090036-20231207120036-00314.warc.gz\"}"}