diff --git a/bouncing_ball.c b/bouncing_ball.c new file mode 100644 index 0000000000000000000000000000000000000000..dc0530da315265b3be1fe54077dfd073497f01dc --- /dev/null +++ b/bouncing_ball.c @@ -0,0 +1,70 @@ +/** + * bouncing ball + */ +#include <graphics.h> +#include <stdlib.h> +#include <stdio.h> + +int kbhit() +{ + struct timeval tv; + fd_set fds; + tv.tv_sec = 0; + tv.tv_usec = 0; + FD_ZERO(&fds); + FD_SET(STDIN_FILENO, &fds); //STDIN_FILENO is 0 + select(STDIN_FILENO+1, &fds, NULL, NULL, &tv); + return FD_ISSET(STDIN_FILENO, &fds); +} + +int main() +{ + + /* request autodetection */ + int gdriver = DETECT, gmode, errorcode; + /* Local Variables */ + int x, y; + int up = 0; + int left = 0; + + /* initialize graphics and local variables */ + initgraph(&gdriver, &gmode, ""); + + /* get mid positions in x and y-axis */ + x = getmaxx() / 2; + y = getmaxy() / 2; + + while (!kbhit()) { + if (y >= getmaxy() - 30) + up = 1; + if (y <= 30) + up = 0; + + if (x >= getmaxx() - 30) + left = 1; + if (x <= 30) + left = 0; + + setcolor(RED); + circle(x, y, 30); + floodfill(x, y, RED); + + /* prepare for next frame */ + delay(15); + cleardevice(); + + if (up) + y = y - 5; + else + y = y + 5; + + if (left) + x = x - 5; + else + x = x + 5; + } + + /* clean up */ + closegraph(); + return 0; +} diff --git a/line.c b/line.c index 375cc7a7dcfb9ff4d8d7dcb6215eb63741060293..ee0ac5646f8782db906479d8821cc19f06526b5f 100644 --- a/line.c +++ b/line.c @@ -87,6 +87,7 @@ int main() /* request autodetection */ int gdriver = DETECT, gmode, errorcode; + /* Local Variables */ int xmax, ymax; /* initialize graphics and local variables */