From 01432a529c665a57e83bfbd670c3f277e1029ac9 Mon Sep 17 00:00:00 2001 From: Ty3r0X Date: Fri, 15 Dec 2023 19:38:51 +0200 Subject: [PATCH] Added delay, finally CPU can breathe... --- src/init.c | 4 ++-- src/main.c | 6 ++++-- src/window.h | 2 ++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/init.c b/src/init.c index b5da705..5ec1551 100644 --- a/src/init.c +++ b/src/init.c @@ -71,8 +71,8 @@ init_program (void) { /* Initialize rectangle*/ rectangle = calloc (1, sizeof (SDL_Rect)); - rectangle->w = 100; - rectangle->h = 100; + rectangle->w = RECT_SIZE; + rectangle->h = RECT_SIZE; /* A new variable is created called main_event, which is a SDL_Event type, which itself is a structure * of multiple structures... of events... */ diff --git a/src/main.c b/src/main.c index 3b10a85..c7bb20d 100644 --- a/src/main.c +++ b/src/main.c @@ -67,8 +67,8 @@ main (int argc, char *argv[]) { /* Constantly initialize boolean values for corners, each for loop * iteration they change values */ - bool x_limit = (rectangle->x == 0 || rectangle->x == SCREEN_WIDTH); - bool y_limit = (rectangle->y == 0 || rectangle->y == SCREEN_HEIGHT); + bool x_limit = (rectangle->x == 0 || rectangle->x == SCREEN_WIDTH - RECT_SIZE); + bool y_limit = (rectangle->y == 0 || rectangle->y == SCREEN_HEIGHT - RECT_SIZE); /* Normally the rect constantly goes up diagonally, if it reaches a * corner the next position gets multiplied with -1 on its respective @@ -110,6 +110,8 @@ main (int argc, char *argv[]) { rectangle->x = rectangle->x + (1 * ray.x); rectangle->y = rectangle->y + (1 * ray.y); + SDL_Delay (3); + /*while (SDL_PollEvent (main_event)) { switch (main_event->type) { case SDL_MOUSEMOTION: diff --git a/src/window.h b/src/window.h index 9371f98..a7593dc 100644 --- a/src/window.h +++ b/src/window.h @@ -39,6 +39,8 @@ #define COLOR_G 0xA5 #define COLOR_B 0x00 +#define RECT_SIZE 100 + extern SDL_Window *window; extern SDL_Renderer *main_render; extern SDL_Texture *background;