home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 092.lha / Bob_to_C / bob.c < prev    next >
C/C++ Source or Header  |  1986-11-20  |  9KB  |  318 lines

  1.  
  2. #include <exec/types.h>
  3. #include <stdio.h>
  4. #include <intuition/intuition.h>
  5. #include <graphics/gels.h>
  6. #include "insert.c"
  7. #define usr UserPort->mp_SigBit
  8.  
  9. void demo();
  10.  
  11.  
  12. WORD Savebuf[_HEIGHT * WidinW * _DEPTH];
  13. WORD Cmask[WidinW * _HEIGHT];
  14. WORD Bline[WidinW];
  15.  
  16. struct VSprite v=
  17.  
  18. {
  19.  
  20. NULL,NULL,NULL,
  21. NULL,NULL,NULL,        /* System variables */
  22. OVERLAY | SAVEBACK,    /* Flags */
  23. 0,                    /* Y position */
  24. 0,                    /* X position */
  25. _HEIGHT,               /* Height from defines in insert.c */
  26. WidinW,                /* Words per row  64 bits */
  27. _DEPTH,                /* Depth from defines in insert.c */
  28. 1,                     /* MeMask */
  29. 1,                     /* HitMask */
  30. &mydata[0],            /* ImageData from insert.c*/
  31. &Bline[0],             /* BorderLine */
  32. &Cmask[0],             /* CollMask */
  33. NULL,                  /* doesn't use sprite colors */
  34. NULL,                  /* pointer to bob filled in by main */
  35. PLANEPICK,             /* PlanePick from defines in insert.c */
  36. PLANEONOFF,            /* PlaneOff all zeros */
  37. NULL                   /* User data */
  38. };
  39.  
  40.  
  41. struct Bob b=
  42. {
  43. 0,                     /* Flags */
  44. &Savebuf[0],           /* pointer to savebuffer */
  45. &Cmask[0],             /* ImageShadow */
  46. NULL,                  /* Before */
  47. NULL,                  /* After */
  48. &v,                    /* pointer to BobVSprite to link */
  49. NULL,                  /* Animation Component (BobComp) */
  50. NULL,                  /* not double buffered (DBuffer) */
  51. NULL                   /* user data */
  52. };
  53.  
  54. /* BIRD SPRITE DATA */
  55.  
  56.  
  57. UWORD b1data[]={
  58.  
  59. 0x0000,0x0000,      /* Position pad bytes */
  60. 0x8020,0x0020,0x4140,0x0140,0x22c0,0x12c0,0x05c0,0x19c0,
  61. 0x03c0,0x1f40,0x07c0,0x06c0,0x03c0,0x05c0,0x03c0,0x07c0,
  62. 0x0100,0x03c0,0x0010,0x01ec,0x0020,0x00d8,0x0040,0x00b0,
  63. 0x0000,0x00e0,0x0000,0x0080,0x0000,0x0000,0x0000,0x0000,
  64. 0x0000,0x0000,      /* Linkage pad bytes */
  65. };
  66.  
  67. /* sizebody=           0x40 HEX     ....64 decimal */
  68. /* width=              0x10 HEX     ....16 decimal */
  69. /* Width in WORDS=     0x1 HEX      ....1 decimal */
  70. /* height=             0x10 HEX     ....16 decimal */
  71. /* number of planes=   0x2 HEX */
  72.  
  73.  
  74.  
  75. UWORD b2data[]={
  76. 0x0000,0x0000,      /* Position pad bytes */
  77. 0x8000,0x0000,0x4000,0x0000,0x2000,0x1000,0x0500,0x1900,
  78. 0x0380,0x1e80,0x2ec0,0x2fc0,0x30c0,0x27c0,0x3f40,0x37c0,
  79. 0x1f00,0x1fc0,0x0f10,0x0fe8,0x0220,0x02d0,0x0040,0x00a0,
  80. 0x0000,0x00c0,0x0000,0x0080,0x0000,0x0000,0x0000,0x0000,
  81. 0x0000,0x0000,      /* Linkage pad bytes */
  82. };
  83.  
  84. /* sizebody=           0x40 HEX     ....64 decimal */
  85. /* width=              0x10 HEX     ....16 decimal */
  86. /* Width in WORDS=     0x1HEX      ....1 decimal */
  87. /* height=             0x10 HEX     ....16 decimal */
  88. /* number of planes=   0x2 HEX */
  89.  
  90.  
  91.  
  92. UWORD b3data[]={
  93. 0x0000,0x0000,      /* Position pad bytes */
  94. 0x4000,0x0000,0x2000,0x0000,0x1200,0x0a00,0x03c0,0x0dc0,
  95. 0x01e0,0x0fe0,0x0760,0x07e0,0xf840,0xebc0,0xff80,0xdfc0,
  96. 0x7f80,0x7fe0,0x1e08,0x1e76,0x0010,0x006c,0x0020,0x0058,
  97. 0x0000,0x0070,0x0000,0x0040,0x0000,0x0000,0x0000,0x0000,
  98. 0x0000,0x0000,      /* Linkage pad bytes */
  99. };
  100.  
  101. /* sizebody=           0x40 HEX     ....64 decimal */
  102. /* width=              0x10 HEX     ....16 decimal */
  103. /* Width in WORDS=     0x1 HEX      ....1 decimal */
  104. /* height=             0x10 HEX     ....16 decimal */
  105. /* number of planes=   0x2 HEX */
  106.  
  107.  
  108. /* *****************************SCREEN*********************************** */
  109.  
  110. struct NewScreen _NewScreen = {
  111.  
  112.  
  113. 0,                 /* LeftEdge */
  114. 0,                 /* TopEdge */
  115. 320,               /* Width */
  116. 200,               /* Height */
  117. _DEPTH,            /* DEPTH  from defines in insert.c */
  118. 0,                 /* DetailPen */
  119. 1,                 /* BlockPen */
  120. NULL,              /* ViewModes */
  121. CUSTOMSCREEN,      /* Type */
  122. NULL,              /* Font */
  123. NULL,             /* DefaultTitle */
  124. NULL,              /* Gadgets */
  125. NULL               /* Custom  */
  126. };
  127.  
  128. struct Screen *OpenScreen();
  129. struct Window *OpenWindow();
  130. struct IntuiMessage *GetMsg();
  131. /* ********************************WINDOW********************************* */
  132.  
  133.  
  134. struct NewWindow newwindow = {
  135.  
  136.     0,0,                                       /* LeftEdge , TopEdge */
  137.     320,200,                                   /* Width, Height */
  138.     1,0,                                       /* DetailPen, BlockPen */
  139.     CLOSEWINDOW | MOUSEMOVE | INTUITICKS,      /* IDCMPFlags */
  140.     WINDOWCLOSE | REPORTMOUSE |
  141.     NOCAREREFRESH | SMART_REFRESH,             /* flags */
  142.     NULL,                                      /* FirstGadget */
  143.     NULL,                                      /* Checkmark */
  144.     "       BRUSH TO BOB DISPLAY   ",          /* Title */
  145.     NULL,                                 /* Screen (pointer init by main) */
  146.     NULL,                                 /* Bitmap */
  147.     0,0,320,200,               /* MinWidth, MinHeight, MaxWidth, MaxHeight */
  148.     CUSTOMSCREEN
  149.   };
  150. /* **************************color pallette**************************** */
  151.  
  152.  
  153.  
  154.     struct GfxBase *GfxBase;
  155.     struct Screen *screen;
  156.     struct Window *window;
  157.     struct IntuitionBase *IntuitionBase; /* last two must be of same type */
  158.     struct ViewPort *ViewPortAddress();  /* woo compiler */
  159.     struct ViewPort *vp;
  160.  
  161.     struct VSprite s1,s2;          /* dummy sprites for gels list */
  162.     struct GelsInfo gelsinfo;     /* gelsinfo to link to window Rp */
  163.     struct collTable Ctable;
  164.  
  165.  
  166.  
  167. void main();
  168. void handle_message();
  169. void handle_window();
  170. void OPPS();
  171.  
  172. UWORD *birdpointer[3];
  173.  
  174. void main()
  175.  
  176.      {
  177. struct IntuiMessage *message;
  178. struct Image *Iptr;
  179. Iptr=&mydataImage;
  180.  
  181.          if ((IntuitionBase =
  182.             (struct IntuitionBase *)OpenLibrary("intuition.library",0)) == NULL)
  183.                OPPS("Error: couldn't open intuition.library\n");
  184.          if ((GfxBase =
  185.             (struct GfxBase *)OpenLibrary("graphics.library",0)) == NULL)
  186.                OPPS("Error: couldn't open graphics.library\n");
  187.          if ((screen = OpenScreen(&_NewScreen)) == NULL)
  188.                OPPS("Error: couldn't open screen\n");
  189.  
  190.          newwindow.Screen = screen;
  191.  
  192.          if ((window = OpenWindow(&newwindow))== NULL)
  193.                OPPS("Error: couldn't open window\n");
  194.  
  195.          vp = ViewPortAddress(window);
  196.  
  197.          LoadRGB4(vp,&colormap[0],NUMOFCOLORS);
  198.  
  199.          gelsinfo.nextLine = NULL;
  200.          gelsinfo.lastColor = NULL;
  201.          gelsinfo.collHandler = &Ctable;
  202.          InitGels(&s1,&s2,&gelsinfo);
  203.          window->RPort->GelsInfo = &gelsinfo;
  204.          v.VSBob=&b;
  205.          InitMasks(&v);
  206.          AddBob(&b,window->RPort);
  207.  
  208.          DrawImage(window->RPort,Iptr,0,10);
  209.          DrawImage(window->RPort,Iptr,0,200-_HEIGHT);
  210.          DrawImage(window->RPort,Iptr,(320-(WidinW*16)),10);
  211.          DrawImage(window->RPort,Iptr,(320-(WidinW*16)),200-_HEIGHT);
  212.  
  213.          birdpointer[0]=&b1data[0];
  214.          birdpointer[1]=&b2data[0];
  215.          birdpointer[2]=&b3data[0];
  216.  
  217.  
  218. for (;;){
  219.          Wait( 1<< (window->UserPort->mp_SigBit));
  220.          while((window!=NULL)&&(message=GetMsg(window->UserPort))!=NULL)
  221.          handle_message(message);
  222.  
  223.         }
  224.  
  225. } /*main*/
  226.  
  227.  
  228.  
  229. USHORT x,y;
  230.  
  231. void handle_message(msgs)
  232. struct IntuiMessage *msgs;
  233. {
  234.  
  235.    ULONG class = msgs->Class;
  236.    USHORT code = msgs->Code;
  237.    APTR address = msgs->IAddress;
  238.  
  239.    if(class==MOUSEMOVE){
  240.       x = msgs->MouseX;
  241.       y = msgs->MouseY;
  242.                        }
  243.    ReplyMsg(msgs);
  244.  
  245.    handle_window(class,code,address);
  246.  
  247. }
  248.  
  249.  
  250. void handle_window(cls,cde,addrs)
  251. ULONG cls;
  252. USHORT cde;
  253. APTR addrs;
  254.  
  255. {
  256.  extern USHORT x;
  257.  extern USHORT y;
  258.  static USHORT birdi=0;
  259.  static SHORT sign = 1;
  260.  static USHORT toggle=1;
  261.  
  262.       switch(cls){
  263.             case CLOSEWINDOW:
  264.                OPPS(NULL);
  265.                break;
  266.             case MOUSEMOVE:
  267.                toggle ^=1;
  268.                  if(toggle){
  269.                     SetPointer(window,birdpointer[birdi],16,16,0,0);
  270.                     if(birdi==0)sign=1;
  271.                     if(birdi==2)sign=-1;
  272.                     birdi+=sign;
  273.                            }
  274.                break;
  275.             case INTUITICKS:
  276.  
  277.                   if(b.BobVSprite->Y!=y || b.BobVSprite->X!=x){
  278.                      b.BobVSprite->Y=y;
  279.                      b.BobVSprite->X=x;
  280.                      demo();
  281.                                                               }
  282.                break;
  283.  
  284.             default:
  285.                OPPS("Dump out of Switch and Case Handle_window\n");
  286.                      } /* switch and case */
  287. } /* handle_message */
  288.  
  289.  
  290.  
  291. void demo()
  292.  
  293. {
  294.     extern USHORT x;
  295.     extern USHORT y;
  296.  
  297.     if(y<90)
  298.       WaitTOF();
  299.     else
  300.       WaitBOVP();
  301.     SortGList(window->RPort);
  302.     DrawGList(window->RPort,vp);
  303.  
  304. }
  305.  
  306. void OPPS(ExitText)
  307.      char *ExitText;
  308.  
  309.  {
  310.  
  311.           if (window) CloseWindow(window);
  312.           if (screen) CloseScreen(screen);
  313.           if (GfxBase) CloseLibrary(GfxBase);
  314.           if (IntuitionBase) CloseLibrary(IntuitionBase);
  315.           if (ExitText) fprintf(stderr,ExitText);
  316.           exit(!!ExitText);
  317.   }
  318.