summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c28
1 files changed, 6 insertions, 22 deletions
diff --git a/src/main.c b/src/main.c
index 70b283d..f9b89bf 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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();