home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / grafik / gamegraf / dac.c next >
Encoding:
C/C++ Source or Header  |  1992-03-20  |  2.9 KB  |  145 lines

  1. #include <graph.h>
  2. #include <games.h>
  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;
  12.  
  13. main()
  14. {
  15.  
  16.         step=10;
  17.     vscreen=_amem(4000);
  18.     background=_amem(3000);
  19.     dac=_amem(539);
  20.     ball=_amem(95);
  21.     face1=_amem(56);
  22.     face2=_amem(56);
  23.     face3=_amem(56);
  24.  
  25.         _setvideomode(_MRES256COLOR);
  26.     _outtext("Make sure your joystick is centered.");
  27.     _settextposition(25,0);
  28.     _outtext("Press left mouse button to exit");
  29.     jxcenter=_stickx();
  30.     jycenter=_sticky();
  31.         LoadPCX("rocks.pcx",vscreen);
  32.     _getv(0,0,320,150,background,vscreen,320);
  33.     _getv(24,150,38,38,ball,vscreen,320);
  34.     _getv(68,150,28,28,face1,vscreen,320);
  35.     _getv(98,150,28,28,face2,vscreen,320);
  36.     _getv(128,150,28,28,face3,vscreen,320);
  37.     LoadPCX("dom1.pcx",vscreen);
  38.         _getv(0,0,154,56,dac,vscreen,320);
  39.     _showpointer();
  40.  
  41.         while (_getbuttondown()!=1 && kbhit()==0)
  42.         {
  43.         _screencopy(background,vscreen,24000);
  44.         _ball();
  45.                 _dac();
  46.         _face();
  47.         _putv(0,25,320,150,vscreen,mscreen,320);
  48.  
  49.     }
  50.  
  51.         _damem(vscreen);
  52.     _damem(background);
  53.     _damem(dac);
  54.     _damem(ball);
  55.     _damem(face1);
  56.     _damem(face2);
  57.     _damem(face3);
  58.         _setvideomode(_DEFAULTMODE);
  59. }
  60.  
  61. void _ball(void)
  62. {
  63.     x1=x1+dx1;
  64.     y1=y1+dy1;
  65.  
  66.         if (x1>280)
  67.         dx1=-step,x1=x1+dx1;
  68.         if (x1<0)
  69.         dx1=step,x1=x1+dx1;
  70.     if (y1>110)
  71.         dy1=-step,y1=y1+dy1;
  72.     if (y1<0)
  73.         dy1=step,y1=y1+dy1;
  74.  
  75.         x2=x2+dx2,y2=y2+dy2;
  76.     if (x2>280)
  77.         dx2=-step,x2=x2+dx2;
  78.     if (x2<0)
  79.         dx2=step,x2=x2+dx2;
  80.     if (y2>110)
  81.         dy2=-step,y2=y2+dy2;
  82.     if (y2<0)
  83.         dy2=step,y2=y2+dy2;
  84.  
  85.         x3=x3+dx3,y3=y3+dy3;
  86.     if (x3>280)
  87.         dx3=-step,x3=x3+dx3;
  88.     if (x3<0)
  89.         dx3=step,x3=x3+dx3;
  90.     if (y3>110)
  91.         dy3=-step,y3=y3+dy3;
  92.     if (y3<0)
  93.         dy3=step,y3=y3+dy3;
  94.  
  95.         x4=x4+dx4,y4=y4+dy4;
  96.     if (x4>280)
  97.         dx4=-step,x4=x4+dx4;
  98.     if (x4<0)
  99.         dx4=step,x4=x4+dx4;
  100.     if (y4>110)
  101.         dy4=-step,y4=y4+dy4;
  102.     if (y4<0)
  103.         dy4=step,y4=y4+dy4;
  104.  
  105.         _spritev(x1,y1,38,38,ball,vscreen,320,0);
  106.     _spritev(x2,y2,38,38,ball,vscreen,320,0);
  107.     _spritev(x3,y3,38,38,ball,vscreen,320,0);
  108.     _spritev(x4,y4,38,38,ball,vscreen,320,0);
  109. }
  110.  
  111. void _dac(void)
  112. {
  113.     _spritev(83,47,154,56,dac,vscreen,320,0);
  114. }
  115.  
  116. void _face(void)
  117. {
  118.     jx=_stickx();
  119.     jy=_sticky();
  120.  
  121.     if (jx>jxcenter+5 && fx<290)
  122.         fx=fx+8;
  123.     if (jx<jxcenter-5 && fx>8)
  124.         fx=fx-8;
  125.     if (jy>jycenter+5 && fy<120)
  126.         fy=fy+8;
  127.     if (jy<jycenter-5 && fy>8)
  128.         fy=fy-8;
  129.  
  130.         if (_button1()==1)
  131.     {
  132.         _spritev(fx,fy,28,28,face2,vscreen,320,0);
  133.         return;
  134.     }
  135.  
  136.         if (_button2()==1)
  137.     {
  138.         _spritev(fx,fy,28,28,face3,vscreen,320,0);
  139.         return;
  140.     }
  141.  
  142.     _spritev(fx,fy,28,28,face1,vscreen,320,0);
  143. }
  144.  
  145.