#include <stdio.h>
#include <graphics.h>
int main(void)
{
int gd, gm = DETECT, area, x = 25, y = 25, xdirn = 1, ydirn = 1;
char ch, *buff;
int maxx, maxy;
initgraph( &gm, &gd, "C:\\TC\\BGI" );
maxx = getmaxx(); maxy = getmaxy();
/* Draw a rectangle */
rectangle( 0, 0, maxx, maxy );
/* Draw a circle and fill it with a fill pattern */
circle( 50, 50, 25 );
setfillstyle( SLASH_FILL, WHITE );
floodfill( 50, 50, WHITE );
/* Get a snapshot of the image */
area = imagesize( 25, 25, 75, 75 );
/* Allocate a buffer to store the image snapshot */
buff = malloc( area );
if( buff == NULL )
{
outtextxy( maxx/2, maxy/2, "Memory allocation Failed" );
closegraph();
restorecrtmode();
exit(0);
}
/* Store the image snapshot in the buffer */
getimage(25, 25, 75, 75, buff );
/* Setup an infinite loop for a moving image */
while(1)
{
/* Check for keyhit by the user */
if( kbhit() )
{
ch = getch();
if( ch == '\r' ) /* ENTER KEY */
{ /* 180 degree reversal of motion */
xdirn = xdirn * -1;
ydirn = ydirn * -1;
}
else if( ch == 27 ) /* ESCAPE KEY */
break;
} /* End of if */
/* Erase existing image at the current position */
putimage( x, y, buff, XOR_PUT );
/* Calculate new image position */
x = x + xdirn*5;
y = y + ydirn*5;
/* Draw the image at the new position */
putimage( x, y, buff, XOR_PUT );
/* delay to let the program work properly on fast processors */
delay(20); /* 10 milliseconds */
/* Check the collision with the horizontal wall */
if( y < 0 || y > (maxy - 55 ) )
{
/* Play sound and reverse y component of the motion */
sound(1000);
delay(50);
nosound();
ydirn = ydirn * -1;
}
/* Check the collision with the vertical wall */
if( x < 5 || x > (maxx - 50) )
{
sound(3000);
delay(100);
nosound();
xdirn = xdirn * -1;
}
} /* End of while loop */
closegraph();
restorecrtmode();
return 0;
} /* End of main */
#include <graphics.h>
int main(void)
{
int gd, gm = DETECT, area, x = 25, y = 25, xdirn = 1, ydirn = 1;
char ch, *buff;
int maxx, maxy;
initgraph( &gm, &gd, "C:\\TC\\BGI" );
maxx = getmaxx(); maxy = getmaxy();
/* Draw a rectangle */
rectangle( 0, 0, maxx, maxy );
/* Draw a circle and fill it with a fill pattern */
circle( 50, 50, 25 );
setfillstyle( SLASH_FILL, WHITE );
floodfill( 50, 50, WHITE );
/* Get a snapshot of the image */
area = imagesize( 25, 25, 75, 75 );
/* Allocate a buffer to store the image snapshot */
buff = malloc( area );
if( buff == NULL )
{
outtextxy( maxx/2, maxy/2, "Memory allocation Failed" );
closegraph();
restorecrtmode();
exit(0);
}
/* Store the image snapshot in the buffer */
getimage(25, 25, 75, 75, buff );
/* Setup an infinite loop for a moving image */
while(1)
{
/* Check for keyhit by the user */
if( kbhit() )
{
ch = getch();
if( ch == '\r' ) /* ENTER KEY */
{ /* 180 degree reversal of motion */
xdirn = xdirn * -1;
ydirn = ydirn * -1;
}
else if( ch == 27 ) /* ESCAPE KEY */
break;
} /* End of if */
/* Erase existing image at the current position */
putimage( x, y, buff, XOR_PUT );
/* Calculate new image position */
x = x + xdirn*5;
y = y + ydirn*5;
/* Draw the image at the new position */
putimage( x, y, buff, XOR_PUT );
/* delay to let the program work properly on fast processors */
delay(20); /* 10 milliseconds */
/* Check the collision with the horizontal wall */
if( y < 0 || y > (maxy - 55 ) )
{
/* Play sound and reverse y component of the motion */
sound(1000);
delay(50);
nosound();
ydirn = ydirn * -1;
}
/* Check the collision with the vertical wall */
if( x < 5 || x > (maxx - 50) )
{
sound(3000);
delay(100);
nosound();
xdirn = xdirn * -1;
}
} /* End of while loop */
closegraph();
restorecrtmode();
return 0;
} /* End of main */
No comments:
Post a Comment
kiss on google ads if you are anonymous because your ip is trackable.thank you.
......from.admin