diff options
author | Johnny Richard <johnny@johnnyrichard.com> | 2022-04-20 03:34:03 +0200 |
---|---|---|
committer | Johnny Richard <johnny@johnnyrichard.com> | 2022-04-20 03:34:03 +0200 |
commit | 9dadbc4409e2ce32eee80c7a8a6ee93e2524763b (patch) | |
tree | aed9519ce13b50622b28d4b3868389a8733d8abc /src/main.c | |
parent | 2f537114acc74a9e09443f69ab2508b292fdfa91 (diff) |
player: Introduce player object
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 28 |
1 files changed, 6 insertions, 22 deletions
@@ -35,6 +35,7 @@ #include <SDL.h> #include "controller.h" +#include "player.h" const int SCREEN_WIDTH = 640; const int SCREEN_HEIGHT = 480; @@ -76,12 +77,14 @@ main (int argc, return EXIT_FAILURE; } - SDL_Rect rect = { .x = 0, .y = 0, .w = 20, .h = 20 }; SDL_Rect bg_rect = { .x = 0, .y = 0, .w = SCREEN_WIDTH, .h = SCREEN_HEIGHT }; bool quit = false; controller_t ctrl = {0}; + player_t player; + player_init(&player); + while (!quit) { SDL_SetRenderDrawColor(renderer, 0, 0, 0, 1); SDL_RenderClear(renderer); @@ -99,28 +102,9 @@ main (int argc, controller_update(&ctrl, &event); } - if (controller_is_up_pressed(&ctrl) && rect.y > 0) { - rect.y -= 8; - rect.y = rect.y < 0 ? 0 : rect.y; - } - - if (controller_is_down_pressed(&ctrl) && rect.y + 8 < SCREEN_HEIGHT) { - rect.y += 8; - rect.y = rect.y + rect.h > SCREEN_HEIGHT ? SCREEN_HEIGHT - rect.h : rect.y; - } - - if (controller_is_left_pressed(&ctrl) && rect.x > 0) { - rect.x -= 8; - rect.x = rect.x < 0 ? 0 : rect.x; - } - - if (controller_is_right_pressed(&ctrl) && rect.x + 8 < SCREEN_WIDTH) { - rect.x += 8; - rect.x = rect.x + rect.h > SCREEN_WIDTH ? SCREEN_WIDTH - rect.h : rect.x; - } + player_update(&player, &ctrl, SCREEN_WIDTH, SCREEN_HEIGHT); + player_draw(&player, renderer); - SDL_SetRenderDrawColor(renderer, 0xFF, 0, 0, 1); - SDL_RenderFillRect(renderer, &rect); SDL_RenderPresent(renderer); uint64_t end = SDL_GetPerformanceCounter(); |