From bcc20de802c40506205ec0a7388262e94cf07668 Mon Sep 17 00:00:00 2001 From: Juan Manuel Tomas Date: Tue, 25 Jan 2022 03:12:03 -0300 Subject: Walk velocity --- main.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/main.c b/main.c index ebae9da..d08090f 100644 --- a/main.c +++ b/main.c @@ -5,6 +5,7 @@ #define WINDOW_W 1280 #define WINDOW_H 720 +#define WALK_VEL 20 static inline double GetCurrentTimestamp() { return (double) SDL_GetTicks64() / 1000.0; @@ -99,24 +100,29 @@ void GameMain(SDL_Renderer *context) { const Uint8 *keys = SDL_GetKeyboardState(0); if (keys[SDL_SCANCODE_D]) { - player_x += 10 * dt; + player_x += WALK_VEL * dt; } if (keys[SDL_SCANCODE_A]) { - player_x -= 10 * dt; + player_x -= WALK_VEL * dt; } if (player_x < 0) { - player_x += 10 * dt; + player_x += WALK_VEL * dt; } else if (player_x >= WINDOW_W) { - player_x -= 10 * dt; + player_x -= WALK_VEL * dt; + } + if (player_y >= WINDOW_H) { + player_y = WINDOW_H - 1; + player_vy = 0; } if (mask[(int)player_x + (int)player_y * WINDOW_W] == 0.0 && - player_y >= 0 && player_y < WINDOW_H) { + player_y >= 0) { player_y += player_vy * dt; player_vy += player_ay * dt; - } else { - player_y += 10 * dt; - player_vy = 0; + while (mask[(int)player_x + (int)player_y * WINDOW_W] != 0.0) { + player_y += 1; + player_vy = 0; + } } void *pixels; -- cgit v1.2.3