Skip to content
Snippets Groups Projects
Commit d176b4e1 authored by opgrsankkar's avatar opgrsankkar
Browse files

bouncing ball

parent f7f6480e
No related branches found
No related tags found
No related merge requests found
/**
* 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;
}
...@@ -87,6 +87,7 @@ int main() ...@@ -87,6 +87,7 @@ int main()
/* request autodetection */ /* request autodetection */
int gdriver = DETECT, gmode, errorcode; int gdriver = DETECT, gmode, errorcode;
/* Local Variables */
int xmax, ymax; int xmax, ymax;
/* initialize graphics and local variables */ /* initialize graphics and local variables */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment