diff options
author | Juan Manuel Tomas <jtomas1815@gmail.com> | 2022-01-25 03:12:03 -0300 |
---|---|---|
committer | Juan Manuel Tomas <jtomas1815@gmail.com> | 2022-01-25 03:12:03 -0300 |
commit | bcc20de802c40506205ec0a7388262e94cf07668 (patch) | |
tree | 004117848f1e583521893d3fce90c4967a408ff8 /main.c | |
parent | 102e4722a3ddcc3702c4445f4e746bc888b83335 (diff) | |
download | cannons-bcc20de802c40506205ec0a7388262e94cf07668.tar.gz cannons-bcc20de802c40506205ec0a7388262e94cf07668.zip |
Walk velocity
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 22 |
1 files changed, 14 insertions, 8 deletions
@@ -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; |