home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / grafik / gamegraf / dac.doc < prev    next >
Encoding:
Text File  |  1992-08-06  |  4.0 KB  |  162 lines

  1. #include <graph.h>
  2. #include <games.h>    /* include games include file */
  3.  
  4. void _ball(void);
  5. void _dac(void);
  6. void _face(void);
  7.  
  8. int x1=0,y1=0,dx1=4,dy1=4,x2=30,y2=10,dx2=4,dy2=2,x3=60,y3=20,dx3=2,dy3=4,x4=90,y4=30,dx4=2,dy4=2;
  9. int count1,count2,count3,vscreen,dac,ball,background,step;
  10. int jx,jy,jpress1,jpress2,jxcenter,jycenter,face1,face2,face3,fx=150,fy=65;
  11. int mscreen=40960;    /* Start of video memory */
  12.  
  13. main()
  14. {
  15.  
  16.     /* Allocate memory for buffers */
  17.  
  18.     step=10;
  19.     vscreen=_amem(4000);   /* Virtual screen
  20.     background=_amem(3000);   /* Buffer for meteor background
  21.     dac=_amem(539);   /* Buffer for DAC letters
  22.     ball=_amem(95);   /* Buffer for ball
  23.     face1=_amem(56);
  24.     face2=_amem(56);   /* Buffers for three different faces
  25.     face3=_amem(56);
  26.  
  27.     /* Set video mode, load pictures and store in buffers */
  28.  
  29.     _setvideomode(_MRES256COLOR);  /* Set VGA 320x200x256 color mode
  30.     _outtext("Make sure your joystick is centered.");
  31.     _settextposition(25,0);
  32.     _outtext("Press left mouse button to exit");
  33.     jxcenter=_stickx();                 /* Get x and y
  34.         jycenter=_sticky();                    center of joystick
  35.         LoadPCX("rocks.pcx",vscreen);   /* Load graphics to virtual screen
  36.     _getv(0,0,320,150,background,vscreen,320);   /* Store in buffer
  37.     _getv(24,150,38,38,ball,vscreen,320);   /* Store ball in buffer
  38.     _getv(68,150,28,28,face1,vscreen,320);
  39.     _getv(98,150,28,28,face2,vscreen,320);   /* Store faces in buffers
  40.     _getv(128,150,28,28,face3,vscreen,320);
  41.     LoadPCX("dom1.pcx",vscreen);   /* Load DAC letters
  42.         _getv(0,0,154,56,dac,vscreen,320);   /* Store in buffer
  43.     _showpointer();   /* Show mouse pointer
  44.  
  45.     /* Main loop */
  46.  
  47.         while (_getbuttondown()!=1)   /* While left mouse button is not pressed
  48.     {                   loop
  49.         _screencopy(background,vscreen,24000);   /* Copy meteor back-
  50.                                 ground to virtual
  51.                                 screen
  52.         /* _ball();   Place four balls on virtual screen */
  53.         _dac();    /* Place DAC letters on virtual screen
  54.         _face();   /* Place face on screen
  55.         _putv(0,25,320,150,vscreen,mscreen,320);   /* Put virtual screen
  56.                                   to video memory
  57.     }
  58.  
  59.     /* Deallocate memory for buffers */
  60.  
  61.     _damem(vscreen);
  62.     _damem(background);
  63.     _damem(dac);
  64.     _damem(ball);
  65.     _damem(face1);
  66.     _damem(face2);
  67.     _damem(face3);
  68.         _setvideomode(_DEFAULTMODE);
  69. }
  70.  
  71. void _ball(void)
  72. {
  73.     x1=x1+dx1;
  74.     y1=y1+dy1;
  75.  
  76.         if (x1>280)
  77.         dx1=-step,x1=x1+dx1;
  78.         if (x1<0)
  79.         dx1=step,x1=x1+dx1;
  80.     if (y1>110)
  81.         dy1=-step,y1=y1+dy1;
  82.     if (y1<0)
  83.         dy1=step,y1=y1+dy1;
  84.  
  85.         x2=x2+dx2,y2=y2+dy2;
  86.     if (x2>280)
  87.         dx2=-step,x2=x2+dx2;
  88.     if (x2<0)
  89.         dx2=step,x2=x2+dx2;
  90.     if (y2>110)
  91.         dy2=-step,y2=y2+dy2;
  92.     if (y2<0)
  93.         dy2=step,y2=y2+dy2;
  94.  
  95.         x3=x3+dx3,y3=y3+dy3;
  96.     if (x3>280)
  97.         dx3=-step,x3=x3+dx3;
  98.     if (x3<0)
  99.         dx3=step,x3=x3+dx3;
  100.     if (y3>110)
  101.         dy3=-step,y3=y3+dy3;
  102.     if (y3<0)
  103.         dy3=step,y3=y3+dy3;
  104.  
  105.         x4=x4+dx4,y4=y4+dy4;
  106.     if (x4>280)
  107.         dx4=-step,x4=x4+dx4;
  108.     if (x4<0)
  109.         dx4=step,x4=x4+dx4;
  110.     if (y4>110)
  111.         dy4=-step,y4=y4+dy4;
  112.     if (y4<0)
  113.         dy4=step,y4=y4+dy4;
  114.  
  115.         _spritev(x1,y1,38,38,ball,vscreen,320,0);
  116.     _spritev(x2,y2,38,38,ball,vscreen,320,0);
  117.     _spritev(x3,y3,38,38,ball,vscreen,320,0);
  118.     _spritev(x4,y4,38,38,ball,vscreen,320,0);
  119. }
  120.  
  121. void _dac(void)
  122. {
  123.     _spritev(83,47,154,56,dac,vscreen,320,0);
  124. }
  125.  
  126. void _face(void)
  127. {
  128.     jx=_stickx();   /* Get joystick x position
  129.     jy=_sticky();   /* Get joystick y position
  130.  
  131.     /* Get direction joystick is pointing and move face in direction
  132.  
  133.     if (jx>jxcenter+5 && fx<290)
  134.         fx=fx+8;
  135.     if (jx<jxcenter-5 && fx>8)
  136.         fx=fx-8;
  137.     if (jy>jycenter+5 && fy<120)
  138.         fy=fy+8;
  139.     if (jy<jycenter-5 && fy>8)
  140.         fy=fy-8;
  141.  
  142.     /* If button 1 pressed use this face
  143.  
  144.     if (_button1()==1)
  145.     {
  146.         _spritev(fx,fy,28,28,face2,vscreen,320,0);
  147.         return;
  148.     }
  149.  
  150.     /* If button 2 pressed use this face
  151.  
  152.     if (_button2()==1)
  153.     {
  154.         _spritev(fx,fy,28,28,face3,vscreen,320,0);
  155.         return;
  156.     }
  157.  
  158.     _spritev(fx,fy,28,28,face1,vscreen,320,0);   /* If no button pressed
  159.                             use this face
  160. }
  161.  
  162.