home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / dev / misc / gms_dev.lha / GMS / Source / C / BounceLine.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-16  |  2.6 KB  |  109 lines

  1.  
  2. /* Line Bounce
  3. ** -----------
  4. ** Line bouncing demo that works on a screen of any type of dimensions as
  5. ** specified by the user in GMSPrefs.
  6. **
  7. */
  8.  
  9. #include <proto/games.h>
  10. #include <proto/exec.h>
  11.  
  12. #define AMT_PLANES 1
  13.  
  14. struct GMSBase *GMSBase;
  15. extern struct ExecBase *SysBase;
  16.  
  17. UWORD Palette[] = 
  18. {
  19.     0x0000,0x08ff
  20. };
  21.  
  22. struct GameScreen GameScreen = {
  23.     GSV1,
  24.     0,0,0,          /* Screen Memory 1,2,3 */
  25.     0,              /* ScreenLink */
  26.     Palette,        /* Address of palette */
  27.     0,              /* Address of rasterlist */
  28.     2,              /* Amount of colours in palette */
  29.     0,0,            /* Screen Width and Height */
  30.     0,0,0,          /* Picture Widths and Height */
  31.     AMT_PLANES,     /* Amount of Planes */
  32.     0,0,            /* X/Y screen offset */
  33.     0,0,            /* X/Y picture offset */
  34.     DBLBUFFER,      /* Special attributes */
  35.     LORES|COL12BIT, /* Screen mode */
  36.     0,              /* Screen type */
  37. };
  38.  
  39. struct GameScreen *OurScreen = &GameScreen;
  40.  
  41. /*=========================================================================*/
  42.  
  43. void main(void)
  44. {
  45.   ULONG mousestat;
  46.   int sx,sy,ex,ey,dsx,dsy,dex,dey;
  47.  
  48.   if (GMSBase = (struct GMSBase *) OpenLibrary("games.library",0))
  49.   {
  50.     SetUserPrefs(0);
  51.     if (AllocBlitter() == NULL)
  52.     {
  53.       if (AddScreen(OurScreen) == NULL)
  54.       {
  55.         sx = SlowRandom(OurScreen->ScrWidth);  dsx = -1;
  56.         sy = SlowRandom(OurScreen->ScrHeight); dsy = 2;
  57.         ex = SlowRandom(OurScreen->ScrWidth);  dex = 3;
  58.         ey = SlowRandom(OurScreen->ScrHeight); dey = 1;
  59.  
  60.         ShowScreen(OurScreen);
  61.  
  62.         do
  63.         {
  64.           ClrScreen(OurScreen,BUFFER2);
  65.           mousestat = ReadMouse(JPORT1);
  66.           sx += dsx;
  67.           sy += dsy;
  68.           ex += dex;
  69.           ey += dey;
  70.  
  71.           if(sx<0) { sx = 0; dsx = -(dsx); }
  72.           if(sy<0) { sy = 0; dsy = -(dsy); }
  73.           if(ex<0) { ex = 0; dex = -(dex); }
  74.           if(ey<0) { ey = 0; dey = -(dey); }
  75.  
  76.           if(sx>OurScreen->ScrWidth-1) {
  77.             sx  = OurScreen->ScrWidth-1;
  78.             dsx = -(dsx);
  79.           }
  80.  
  81.           if(sy>OurScreen->ScrHeight-1) {
  82.             sy  = OurScreen->ScrHeight-1;
  83.             dsy = -(dsy);
  84.           }
  85.  
  86.           if(ex>OurScreen->ScrWidth-1) {
  87.             ex  = OurScreen->ScrWidth-1;
  88.             dex = -(dex);
  89.           }
  90.  
  91.           if(ey>OurScreen->ScrHeight-1) {
  92.             ey  = OurScreen->ScrHeight-1;
  93.             dey = -(dey);
  94.           }
  95.  
  96.           DrawUCLine(OurScreen,BUFFER2,sx,sy,ex,ey,1);
  97.           WaitSVBL();
  98.           SwapBuffers(OurScreen);
  99.         } while (!(mousestat & MB_LMB));
  100.  
  101.       DeleteScreen(OurScreen);
  102.       }
  103.     FreeBlitter();
  104.     }
  105.   CloseLibrary((struct Library *)GMSBase);
  106.   }
  107. }
  108.  
  109.