home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 31 / CDASC_31_1996_juillet_aout.iso / vrac / gamelib.zip / EX2.C < prev    next >
C/C++ Source or Header  |  1996-04-24  |  1KB  |  74 lines

  1. //a simple example of how to update a single screen and use drawing functions
  2. //for use with game.lib, created in Turbo C++
  3. #include "stdlib.h"
  4. #include "dos.h"
  5. #include "grlib.h"
  6.  
  7. void main()
  8. {
  9.   int a,b,c;
  10.  
  11.   InitGameBuff(320,200);//make game buffer 1 screen big
  12.  
  13.   SetVGA();     //set VGA mode 13h
  14.  
  15.   randomize();
  16.  
  17.   //load in the pictures
  18.   if (LoadPic1("back.pcx",0)==0) Quit("Pcx not found");
  19.  
  20.   //cover game buffer with backdrop image
  21.   PutPic(0,0,0);
  22.  
  23.   //moving lines
  24.   for(a=0; a<2; a++)
  25.   {
  26.     for(b=0; b<320; b+=2)
  27.     {
  28.       PutPic(0,0,0);
  29.  
  30.       Line(b,0,319-b,199,250);
  31.       Line(319-b,0,b,199,250);
  32.  
  33.       DisplayBuffer(0,0);
  34.     }
  35.   }
  36.  
  37.   //99 random dots on screen - 200 times
  38.   for(a=0; a<500; a++)
  39.   {
  40.     PutPic(0,0,0);
  41.  
  42.     for(b=0; b<50; b++) PutPixel(random(320),random(200),255);
  43.  
  44.     DisplayBuffer(0,0);
  45.   }
  46.  
  47.  
  48.   //morphing rectangle
  49.   b=50; c=50;
  50.  
  51.   for(a=0; a<500; a++)
  52.   {
  53.     PutPic(0,0,0);
  54.  
  55.     b=b+random(8)-random(8);
  56.     c=c+random(6)-random(6);
  57.     if (b>150) b=150; if (b<10) b=10;
  58.     if (c>90) c=90; if (c<10) c=10;
  59.  
  60.     Rectangle(160-b,100-c,b*2,c*2,250,0);
  61.  
  62.     DisplayBuffer(0,0);
  63.   }
  64.  
  65.   //plot alternate black lines down the screen directly,
  66.   //without using the game buffer, and slowed with delays
  67.   for(a=0; a<200; a+=2) {LineVGA(0,a,319,a,0); delay(15);}
  68.   for(a=1; a<200; a+=2) {LineVGA(0,a,319,a,0); delay(15);}
  69.  
  70.   //close down
  71.   FreeMem();
  72.   SetTXT();
  73. }
  74.