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

  1. //a simple example of how to do a vertically scrolling game
  2. //for use with game.lib, created in Turbo C++
  3. #include "alloc.h"
  4. #include "grlib.h"
  5.  
  6. void main()
  7. {
  8.   int a,x=160,y=100,dir=1;
  9.   unsigned char *bptr=(unsigned char *)malloc(37*37+2);
  10.  
  11.   InitGameBuff(320,800);//make game buffer 4 screens tall
  12.  
  13.   InitKeyScan();//start up key press scanning
  14.   SetVGA();     //set VGA mode 13h
  15.  
  16.   //load in the pictures
  17.   if (LoadPic1("back.pcx",0)==0) Quit("Pcx not found");
  18.   if (LoadMBM("sph.mbm",1)==0) Quit("mbm not found");
  19.  
  20.   //cover game buffer with backdrop image
  21.   PutPic(0,0,0);
  22.   PutPic(0,0,200);
  23.   PutPic(0,0,400);
  24.   PutPic(0,0,600);
  25.  
  26.   //save backdrop area under foreground sphere
  27.   CutOut(x-18,y-18,37,37,bptr);
  28.   //put foreground sphere
  29.   PutMBM(1,x-18,y-18);
  30.  
  31.   //morph viewport from small to full screen size
  32.   for(a=90; a>=0; a--) DWinBuffer(a,a,a,a,320-(2*a),200-(2*a));
  33.   a=0;
  34.  
  35.   //main loop
  36.   do
  37.   {
  38.     //replace saved backdrop area over foreground sphere
  39.     PutBitmap(x-18,y-18,bptr);
  40.  
  41.     //do movement left/right if relevant key pressed
  42.     if (CheckKey(77)==1&&x<300) x+=2;
  43.     if (CheckKey(75)==1&&x>18) x-=2;
  44.  
  45.     //move sphere in y dimension
  46.     if (dir==1) y+=2; else y-=2;
  47.     if (y>700) {y=700; dir=0;}
  48.     else if (y<100) {y=100; dir=1;}
  49.  
  50.     //save new backdrop area under foreground sphere
  51.     CutOut(x-18,y-18,37,37,bptr);
  52.     //put foreground sphere
  53.     PutMBM(1,x-18,y-18);
  54.  
  55.     //display window on buffer, to the screen
  56.     DisplayBuffer(0,y-100);
  57.  
  58.     a++;
  59.   }
  60.   while(CheckKey(1)!=1&&a<2000); //while escape key not pressed
  61.  
  62.   //close down
  63.   FreeMem();
  64.   SetTXT();
  65.   CloseKeyScan();
  66. }