Category : C Source Code
Archive   : QCTBOX.ZIP
Filename : GRAPTEST.C

 
Output of file : GRAPTEST.C contained in archive : QCTBOX.ZIP
/*----------------------------------------------------------------------------
Name: GRAPTEST.C
Type: Demonstration Program
Language: Microsoft QuickC
Video: Requires CGA or better Graphics capability

Program List: GRAPTEST.C
GRAPHICS.C
GRAPHICS.LIB

Variables: i Looping index
j Looping index
x1 Triangle corner coordinate
y1 Triangle corner coordinate
x2 Triangle corner coordinate
y2 Triangle corner coordinate
x3 Triangle corner coordinate
y3 Triangle corner coordinate
x Ball coordinate for collision check
y Ball coordinate for collision check
dx Change in x for each ball movement
dy Change in y for each ball movement
tnum Bounce direction control

Usage: (no command line parameters)

Description: Demonstrates the GRAPHICS toolbox functions
-------------------------------------------------------------------
*/

#include
#include
#include
#include
#include
#include
#include "graphics.h"

#define BALLX 5
#define BALLY 5
#define DELAY 500
char far ball[500];
char far back[500];
long far n;

main()
{
int i, j;
int x1, y1, x2, y2, x3, y3;
int x, y, dx, dy, tnum = 0;

/* Define a polygon */
int xybuf[6][2] =
{
{ 259, 100 },{ 210, 34 }, { 110, 34 },
{ 61, 100 }, { 110, 186 }, { 210, 186 },
};

/* Set a graphics mode */
if ( _setvideomode( _MRES256COLOR ) == 0 )
if ( _setvideomode( _MRES16COLOR ) == 0 )
if ( _setvideomode( _MRES4COLOR ) == 0 )
{
printf( "This program requires VGA, EGA, or CGA\n");
exit( 1 );
};

/* Shuffle the random numbers */
srand( (unsigned)time( NULL ) );


/* Draw several triangle outlines */
for (i = 0;i < 7;i++ )
{
x1 = rand() % 320;
y1 = rand() % 200;
x2 = rand() % 320;
y2 = rand() % 200;
x3 = rand() % 320;
y3 = rand() % 200;
_setcolor( rand() % 3 + 1 );
triangle( LINED, x1, y1, x2, y2, x3, y3 );
}
printf( "LINED Triangles\n" );
printf( "Press any key to continue..." );
getch();
_clearscreen( _GCLEARSCREEN );

/* Draw several solid triangles @/
for (i = O;i < 7;i++ )
{
x1 = rand() % 320;
y1 = rand() % 200;
x2 = rand() % 320;
y2 = rand() % 200;
x3 = rand() % 320;
y3 = rand() % 200;
_setcolor( rand() % 3 + 1 );
triangle( SOLID, x1, y1, x2, y2, x3, y3 );
}
printf( "SOLID Triangles\n" );
printf( "Press any key to continue..." ):
getch();
_clearscreen( _GCLEARSCREEN );

/* Draw the polygon outline */
_setcolor( 3 );
polygon( LINED, 6, xybuf );
printf( "LINED Polygon\n" );
printf( "Press any key to continue..." );
getch();
_clearscreen( _GCLEARSCREEN );

/* Draw a solid polygon */
_setcolor( 2 );
polygon( SOLID, 6, xybuf );
printf( "SOLID Polygon\n" );
printf( "Press any key to continue..." );
getch();
_clearscreen( _GCLEARSCREEN );

/* Draw background for the collision detection */
_setcolor( 3 );
_rectangle( _GBORDER, 10, 10, 310, 190 );
_floodfill( 0, 0, 3 );
_setcolor( 1 );
_rectangle( _GFILLINTERIOR, 80, 40, 100, 70 );
_rectangle( _GFILLINTERIOR, 60, 140, 90, 170 );
_setcolor( 2 );
_rectangle( _GFILLINTERIOR, 180, 120, 250, 140 );
_rectangle( _GFILLINTERIOR, 180, 40, 250, 80 );

/* Set initial conditions for collision detection */

x = 160;
y = 100;
dx = 1;
dy = 1;
_setcolor( 3 );
_getimage( 0, 0, BALLX, BALLY, ball );

/* Draw the ball at the center of the screen to start */
_putimage( x, y, ball, _GXOR );
n = _imagesize( 0, 0, BALLX, BALLY );
printf( "collision()..." );

/* Drift and bounce */
while ( !kbhit() )
{

/* Change value of DELAY to speed up or slow the ball */
for(i=0;i {;}

/* Erase the ball at the current location */
_putimage( x, y, ball, _GXOR );

/* Change the location */
x += dx;
y += dy;

/* Grab the background so we can check for collision */
/* Grab the background so we can check for collision */
_getimage( x, y, x + BALLX, y + BALLY, back );

/* Draw the ball at the new location */
_putimage( x, y, ball, _GXOR );
/* Is there a collision here? */
if ( collision( ball, back, n ) )
{

/* Erase the ball at the collision point */
_putimage( x, y, ball, _GXOR );

/* Shift back to the previous point */
x -= dx;

y -= dy;

/* Redraw the ball at the previous position */
_putimage( x, y, ball, _GXOR );

/* Modify the test for which way to bounce */
if ( ++tnum > 3 )
tnum = 0;

/* bounce in appropriate direction */
switch ( tnum )
{
case 1:
dx = -dx;
break;
case 2:
dx = -dx;
dy = -dy;
break;
case 3:
dy = -dy;
break;
default:
dx = -dx;
dy = -dy;
break;
}
}
/* No collision detected */
else

tnum = 0;
}
/* Reset default video mode */

_setvideomode( _DEFAULTMODE );
}




  3 Responses to “Category : C Source Code
Archive   : QCTBOX.ZIP
Filename : GRAPTEST.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/