Fixed bug: square gets stuck when placed out of bounds

The rand() funtion now gets the correct limits, so in theory the square
shouldn't go out of bounds anymore...
This commit is contained in:
Ty3r0X 2023-12-19 12:25:33 +02:00
parent 144342ab81
commit 357e70e129
No known key found for this signature in database
GPG Key ID: 1987C830BBC99F38
2 changed files with 3 additions and 4 deletions

View File

@ -98,8 +98,8 @@ 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); printf ("Mouse cursor is inside the square at position (%d,%d)\n", main_event->motion.x, main_event->motion.y);
ray.x *= -1; ray.x *= -1;
ray.y *= -1; ray.y *= -1;
rectangle->x = rand () % 500; rectangle->x = rand () % (int) (SCREEN_WIDTH - 1 - RECT_SIZE);
rectangle->y = rand () % 500; rectangle->y = rand () % (int) (SCREEN_HEIGHT - 1 - RECT_SIZE);
bg_red = rand () & HEX_POKE; bg_red = rand () & HEX_POKE;
bg_green = rand () & HEX_POKE; bg_green = rand () & HEX_POKE;
bg_blue = rand () & HEX_POKE; bg_blue = rand () & HEX_POKE;
@ -111,6 +111,5 @@ main (int argc, char *argv[]) {
rectangle->y = rectangle->y + (1 * ray.y); rectangle->y = rectangle->y + (1 * ray.y);
SDL_Delay (3); SDL_Delay (3);
} }
} }

View File

@ -39,7 +39,7 @@
#define COLOR_G 0xA5 #define COLOR_G 0xA5
#define COLOR_B 0x00 #define COLOR_B 0x00
#define RECT_SIZE 100 #define RECT_SIZE 300
extern SDL_Window *window; extern SDL_Window *window;
extern SDL_Renderer *main_render; extern SDL_Renderer *main_render;