From 9496a6b4c9a7a24beec73271da54886461a6f4f7 Mon Sep 17 00:00:00 2001 From: Ty3r0X Date: Wed, 21 Feb 2024 09:55:29 +0200 Subject: [PATCH] Minor changes --- src/init.c | 8 +++++++- src/main.c | 29 +++++++++++++++++++---------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/init.c b/src/init.c index c3fa3ff..72900b6 100644 --- a/src/init.c +++ b/src/init.c @@ -88,9 +88,15 @@ init_program (void) { counter_box.x = COUNTER_BOX_X; counter_box.y = COUNTER_BOX_Y; - text_font = TTF_OpenFont ("arimo.ttf", COUNTER_TEXT_SIZE); + + text_font = TTF_OpenFont ("arimo.ttf", COUNTER_TEXT_SIZE); + + if (text_font == NULL) + fprintf (stderr, "Failed to load counter - arimo.ttf may be missing\n"); + text_surface = NULL; text_texture = NULL; + text_color = calloc (1, sizeof (SDL_Color)); text_color->r = 255; text_color->g = 255; diff --git a/src/main.c b/src/main.c index 4c0b266..5e3fbd3 100644 --- a/src/main.c +++ b/src/main.c @@ -29,11 +29,11 @@ #include #include -#define HEX_POKE 0xFF -#define COUNTER_DIGITS 100 +#define HEX_POKE 0xFF +#define COUNTER_SIZE 100 int -main (int argc, char *argv[]) { +main (int argc, const char *argv[]) { struct pos ray; int counter = 0; @@ -42,9 +42,14 @@ main (int argc, char *argv[]) { Uint8 bg_green = HEX_POKE; Uint8 bg_blue = 0x00; + printf ("MMXXIII Ty3r0X\n"); + if (init_program () != EXIT_SUCCESS) return EXIT_FAILURE; + /* Print argv - useless but used to stop + * my compiler from yelling */ + for (int i = 0; i < argc; i++) printf ("%s\n", argv[i]); @@ -56,9 +61,9 @@ main (int argc, char *argv[]) { for (;;) { - /* Initialize counter array - max 100 digits */ + /* Initialize counter array */ - char counter_text[COUNTER_DIGITS]; + char counter_text[COUNTER_SIZE]; /* Constantly initialize boolean values for corners, each for loop * iteration they change values */ @@ -115,8 +120,7 @@ main (int argc, char *argv[]) { switch (main_event->type) { case SDL_QUIT: - printf ("Quit event detected, now exiting. See ya! :)\n"); - printf ("MMXXIII Ty3r0X - The Eye shall forsee...\n"); + printf ("Quit event detected, now exiting.\n"); SDL_DestroyRenderer (main_render); SDL_DestroyWindow (window); SDL_Quit (); @@ -127,13 +131,17 @@ main (int argc, char *argv[]) { printf ("Mouse cursor is inside the square at position (%d,%d)\n", main_event->motion.x, main_event->motion.y); + ray.x *= -1; ray.y *= -1; + rectangle->x = rand () % (int) (SCREEN_WIDTH - 1 - RECT_SIZE); rectangle->y = rand () % (int) (SCREEN_HEIGHT - 1 - RECT_SIZE); - bg_red = rand () & HEX_POKE; - bg_green = rand () & HEX_POKE; - bg_blue = rand () & HEX_POKE; + + bg_red = rand () & HEX_POKE; + bg_green = rand () & HEX_POKE; + bg_blue = rand () & HEX_POKE; + counter++; } break; @@ -141,6 +149,7 @@ main (int argc, char *argv[]) { default: break; } + /* Constantly increment / decrement rectangle position */ rectangle->x = rectangle->x + (1 * ray.x);