home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_progs / prog_oth / monopoly.lzh / bob_source.LZH / bob / makebob1.c
Encoding:
C/C++ Source or Header  |  1992-01-04  |  19.4 KB  |  644 lines

  1. /* Here is a sample program that demonstrates the animation routines
  2.    (for Bobs and VSprites) on the Amiga.  It also uses double buffering
  3.    (drawing into one area while displaying another) so as to smooth
  4.    the display motion.
  5.  
  6.    Amiga/Lattice C 3.03 linking information:
  7.       FROM    lib:Astartup.obj, dbuf.gels.o
  8.       TO      dbuff.gels
  9.       LIBRARY lib:amiga.lib
  10. */
  11.  
  12. /* dbuff.gels.c */
  13.  
  14. /* SAMPLE PROGRAM THAT USES GELTOOLS TO PRODUCE A DOUBLE BUFFERED DISPLAY
  15.  * SCREEN CONTAINING TWO BOBS AND TWO VSPRITES
  16.  *
  17.  * Author:  David Lucas
  18.  */
  19.  
  20.  
  21. /* Leave this structure definition at the top. Look at gels.h. */
  22. struct vInfo {
  23.    short vx,vy;      /* This VSprites velocity. */
  24.    short id;
  25. };
  26. #define VUserStuff struct vInfo
  27.  
  28.  
  29. /* Things to notice:
  30.  
  31.         Default value in sprite/playfield priority register has all
  32.         hardware sprites having a higher priority than either of the
  33.         two playfields.   Areas containing color 0 of both the bob and
  34.         vsprite are shown as transparent (see hole in center of each).
  35.  
  36.         You can specify bob drawing order by using the before and after
  37.         pointers, thereby always maintaining an apparent precedence of
  38.         one bob over another.  Re Vsprites.... because they are assigned
  39.         sequentially from top of screen to bottom, in sprite numerical
  40.         order (0, 1, 2, 3 etc), and because the lowest numbered hardware
  41.         sprite has the highest video precedence, the sprite that is
  42.         closest to the top of the screen always appears in front of the
  43.         sprite beneath it.
  44.  
  45.         Without double-buffering, there would be flicker on the part
  46.    of the bobs.  Double buffering consists of writing into an area 
  47.    that is not being displayed.  Some of the flicker could have been
  48.    alleviated by waiting for the video beam to reach top-of-frame 
  49.    before doing the drawing, but when the bobs are near the top, 
  50.    it makes it all the more difficult to draw without apparent 
  51.    flicker in that case.  Also note that multitasking will 
  52.    occasionally upset even this plan in that it can delay the 
  53.    drawing operation until the beam is in the area that is being drawn.
  54.  
  55. */
  56.  
  57.  
  58. /*******************************************************************************
  59.  * A sprite and a bob on a screen.
  60.  */
  61.  
  62. #include "exec/types.h"
  63. #include "exec/memory.h"
  64. #include "intuition/intuition.h"
  65. #include "graphics/gels.h"
  66. #include "graphics/collide.h"
  67.  
  68. #define LIBRARY_VERSION 29
  69.  
  70. #define SBMWIDTH 320   /* My screen size constants. */
  71. #define SBMHEIGHT 200
  72. #define SBMDEPTH 4
  73.  
  74. #define RBMWIDTH 320   /* My rastport size constants. */
  75. #define RBMHEIGHT 200
  76. #define RBMDEPTH SBMDEPTH
  77.  
  78. #define VSPRITEWIDTH 1   /* My VSprite constants. */
  79. #define VSPRITEHEIGHT 12
  80. #define VSPRITEDEPTH 2
  81. #define NSPRITES 2
  82.  
  83. #define BOBWIDTH 62   /* My Bob constants. */
  84. #define BOBHEIGHT 31
  85. #define BOBDEPTH 4
  86. #define NBOBS 2
  87.  
  88. extern struct VSprite *MakeVSprite();
  89. extern struct Bob     *MakeBob();
  90.  
  91. struct IntuitionBase *IntuitionBase = NULL;
  92. struct GfxBase *GfxBase = NULL;
  93.  
  94. struct IntuiMessage *MyIntuiMessage = NULL;
  95.  
  96. struct TextAttr TestFont = {   /* Needed for opening screen. */
  97.    (STRPTR)"topaz.font", TOPAZ_EIGHTY, 0, 0
  98. };
  99.  
  100. /* DBL BUF */
  101. struct BitMap *MyBitMapPtrs[2] = {
  102.    NULL, NULL};
  103. WORD ToggleFrame = 0;
  104.  
  105. struct GelsInfo GInfo;      /* For all Gels. */
  106.  
  107. struct VSprite *VSprites[NSPRITES];
  108. WORDBITS VSpriteImage[] = {
  109.    /* Plane 0, Plane 1 */
  110.    0x0000, 0x0000,   /* Line 1, first. */
  111.    0x0000, 0x0000,
  112.    0x0000, 0x0000,
  113.    0x0000, 0x0000,
  114.    0x0000, 0x0000,
  115.    0x0000, 0x0000,
  116.    0x0000, 0x0000,
  117.    0x0000, 0x0000,
  118.    0x0000, 0x0000,
  119.    0x0000, 0x0000,
  120.    0x0000, 0x0000,
  121.    0x0000, 0x0000,   /* Line 12, last. */
  122. };
  123. USHORT *VSpriteImage_chip = 0;
  124.  
  125. /* These are the colors that will be used for my VSprites. Note I really do mean
  126.  * colors, not color register numbers. High to low, starting at bit 12 and going
  127.  * down to LSB, there are four bits each of red, green and blue. Please read the
  128.  * sprite section of the hardware manual. The gels system will put them into the
  129.  * proper color registers when they are displayed. Reminder: Sprites can only
  130.  * use color registers in sets of 3...
  131.  *   17,18,19 = sprite 0 and 1,
  132.  *   21,22,23 = sprite 2 and 3,
  133.  *   25,26,27 = sprite 4 and 5,
  134.  *   29,30,31 = sprite 6 and 7.
  135.  * Please read the section on how VSprites are assigned in the RKM.
  136.  */
  137. WORD MyVSpriteColors[] = {
  138.    0x0f00,   /* Full red. */
  139.    0x00f0,   /* Full green. */
  140.    0x000f   /* Full blue. */
  141. };
  142.  
  143. struct Bob *Bobs[NBOBS];
  144. short BobImage[] = {
  145.    0xFFFF, 0xFFFF,   0xFFFF, 0xFFFC,   /* Plane 0, line 1. */
  146.    0xC000, 0x0000,   0x0000, 0x000C,
  147.    0xCFFF, 0xFFFF,   0xFFFF, 0xFFCC,
  148.    0xCC00, 0x0000,   0x0000, 0x00CC,
  149.    0xCCFF, 0xFFFF,   0xFFFF, 0xFCCC,
  150.    0xCCC0, 0x0000,   0x0000, 0x0CCC,
  151.    0xCCCF, 0xFFFF,   0xFFFF, 0xCCCC,
  152.    0xCCCC, 0x0000,   0x0000, 0xCCCC,
  153.    0xCCCC, 0xFFFF,   0xFFFC, 0xCCCC,
  154.    0xCCCC, 0xC000,   0x000C, 0xCCCC,
  155.    0xCCCC, 0xCFFF,   0xFFCC, 0xCCCC,
  156.    0xCCCC, 0xCC00,   0x00CC, 0xCCCC,
  157.    0xCCCC, 0xCCFF,   0xFCCC, 0xCCCC,
  158.    0xCCCC, 0xCCC0,   0x0CCC, 0xCCCC,
  159.    0xCCCC, 0xCCCF,   0xCCCC, 0xCCCC,
  160.    0xCCCC, 0xCCCC,   0xCCCC, 0xCCCC,
  161.    0xCCCC, 0xCCCF,   0xCCCC, 0xCCCC,
  162.    0xCCCC, 0xCCC0,   0x0CCC, 0xCCCC,
  163.    0xCCCC, 0xCCFF,   0xFCCC, 0xCCCC,
  164.    0xCCCC, 0xCC00,   0x00CC, 0xCCCC,
  165.    0xCCCC, 0xCFFF,   0xFFCC, 0xCCCC,
  166.    0xCCCC, 0xC000,   0x000C, 0xCCCC,
  167.    0xCCCC, 0xFFFF,   0xFFFC, 0xCCCC,
  168.    0xCCCC, 0x0000,   0x0000, 0xCCCC,
  169.    0xCCCF, 0xFFFF,   0xFFFF, 0xCCCC,
  170.    0xCCC0, 0x0000,   0x0000, 0x0CCC,
  171.    0xCCFF, 0xFFFF,   0xFFFF, 0xFCCC,
  172.    0xCC00, 0x0000,   0x0000, 0x00CC,
  173.    0xCFFF, 0xFFFF,   0xFFFF, 0xFFCC,
  174.    0xC000, 0x0000,   0x0000, 0x000C,
  175.    0xFFFF, 0xFFFF,   0xFFFF, 0xFFFC,   /* Plane 0, line 31. */
  176.  
  177.    0xFFFF, 0xFFFF, 0xFFFF, 0xFFFC,   /* Plane 1, line 1. */
  178.    0xFFFF, 0xFFFF, 0xFFFF, 0xFFFC,
  179.    0xF000, 0x0000, 0x0000, 0x003C,
  180.    0xF000, 0x0000, 0x0000, 0x003C,
  181.    0xF0FF, 0xFFFF, 0xFFFF, 0xFC3C,
  182.    0xF0FF, 0xFFFF, 0xFFFF, 0xFC3C,
  183.    0xF0F0, 0x0000, 0x0000, 0x3C3C,
  184.    0xF0F0, 0x0000, 0x0000, 0x3C3C,
  185.    0xF0F0, 0xFFFF, 0xFFFC, 0x3C3C,
  186.    0xF0F0, 0xFFFF, 0xFFFC, 0x3C3C,
  187.    0xF0F0, 0xF000, 0x003C, 0x3C3C,
  188.    0xF0F0, 0xF000, 0x003C, 0x3C3C,
  189.    0xF0F0, 0xF0FF, 0xFC3C, 0x3C3C,
  190.    0xF0F0, 0xF0FF, 0xFC3C, 0x3C3C,
  191.    0xF0F0, 0xF0F0, 0x3C3C, 0x3C3C,
  192.    0xF0F0, 0xF0F0, 0x3C3C, 0x3C3C,
  193.    0xF0F0, 0xF0F0, 0x3C3C, 0x3C3C,
  194.    0xF0F0, 0xF0FF, 0xFC3C, 0x3C3C,
  195.    0xF0F0, 0xF0FF, 0xFC3C, 0x3C3C,
  196.    0xF0F0, 0xF000, 0x003C, 0x3C3C,
  197.    0xF0F0, 0xF000, 0x003C, 0x3C3C,
  198.    0xF0F0, 0xFFFF, 0xFFFC, 0x3C3C,
  199.    0xF0F0, 0xFFFF, 0xFFFC, 0x3C3C,
  200.    0xF0F0, 0x0000, 0x0000, 0x3C3C,
  201.    0xF0F0, 0x0000, 0x0000, 0x3C3C,
  202.    0xF0FF, 0xFFFF, 0xFFFF, 0xFC3C,
  203.    0xF0FF, 0xFFFF, 0xFFFF, 0xFC3C,
  204.    0xF000, 0x0000, 0x0000, 0x003C,
  205.    0xF000, 0x0000, 0x0000, 0x003C,
  206.    0xFFFF, 0xFFFF, 0xFFFF, 0xFFFC,
  207.    0xFFFF, 0xFFFF, 0xFFFF, 0xFFFC,   /* Plane 1, line 31. */
  208.  
  209.    0xFFFF, 0xFFFF, 0xFFFF, 0xFFFC, /* Plane 2, line 1. */
  210.    0xFFFF, 0xFFFF, 0xFFFF, 0xFFFC,
  211.    0xFFFF, 0xFFFF, 0xFFFF, 0xFFFC,
  212.    0xFFFF, 0xFFFF, 0xFFFF, 0xFFFC,
  213.    0xFF00, 0x0000, 0x0000, 0x03FC,
  214.    0xFF00, 0x0000, 0x0000, 0x03FC,
  215.    0xFF00, 0x0000, 0x0000, 0x03FC,
  216.    0xFF00, 0x0000, 0x0000, 0x03FC,
  217.    0xFF00, 0xFFFF, 0xFFFC, 0x03FC,
  218.    0xFF00, 0xFFFF, 0xFFFC, 0x03FC,
  219.    0xFF00, 0xFFFF, 0xFFFC, 0x03FC,
  220.    0xFF00, 0xFFFF, 0xFFFC, 0x03FC,
  221.    0xFF00, 0xFF00, 0x03FC, 0x03FC,
  222.    0xFF00, 0xFF00, 0x03FC, 0x03FC,
  223.    0xFF00, 0xFF00, 0x03FC, 0x03FC,
  224.    0xFF00, 0xFF00, 0x03FC, 0x03FC,
  225.    0xFF00, 0xFF00, 0x03FC, 0x03FC,
  226.    0xFF00, 0xFF00, 0x03FC, 0x03FC,
  227.    0xFF00, 0xFF00, 0x03FC, 0x03FC,
  228.    0xFF00, 0xFFFF, 0xFFFC, 0x03FC,
  229.    0xFF00, 0xFFFF, 0xFFFC, 0x03FC,
  230.    0xFF00, 0xFFFF, 0xFFFC, 0x03FC,
  231.    0xFF00, 0xFFFF, 0xFFFC, 0x03FC,
  232.    0xFF00, 0x0000, 0x0000, 0x03FC,
  233.    0xFF00, 0x0000, 0x0000, 0x03FC,
  234.    0xFF00, 0x0000, 0x0000, 0x03FC,
  235.    0xFF00, 0x0000, 0x0000, 0x03FC,
  236.    0xFFFF, 0xFFFF, 0xFFFF, 0xFFFC,
  237.    0xFFFF, 0xFFFF, 0xFFFF, 0xFFFC,
  238.    0xFFFF, 0xFFFF, 0xFFFF, 0xFFFC,
  239.    0xFFFF, 0xFFFF, 0xFFFF, 0xFFFC,   /* Plane 2, line 31. */
  240.  
  241.    0xFFFF, 0xFFFF,   0xFFFF, 0xFFFC, /* Plane 3, line 1. */
  242.    0xFFFF, 0xFFFF,   0xFFFF, 0xFFFC,
  243.    0xFFFF, 0xFFFF,   0xFFFF, 0xFFFC,
  244.    0xFFFF, 0xFFFF,   0xFFFF, 0xFFFC,
  245.    0xFFFF, 0xFFFF,   0xFFFF, 0xFFFC,
  246.    0xFFFF, 0xFFFF,   0xFFFF, 0xFFFC,
  247.    0xFFFF, 0xFFFF,   0xFFFF, 0xFFFC,
  248.    0xFFFF, 0xFFFF,   0xFFFF, 0xFFFC,
  249.    0xFFFF, 0x0000,   0x0003, 0xFFFC,
  250.    0xFFFF, 0x0000,   0x0003, 0xFFFC,
  251.    0xFFFF, 0x0000,   0x0003, 0xFFFC,
  252.    0xFFFF, 0x0000,   0x0003, 0xFFFC,
  253.    0xFFFF, 0x0000,   0x0003, 0xFFFC,
  254.    0xFFFF, 0x0000,   0x0003, 0xFFFC,
  255.    0xFFFF, 0x0000,   0x0003, 0xFFFC,
  256.    0xFFFF, 0x0000,   0x0003, 0xFFFC,
  257.    0xFFFF, 0x0000,   0x0003, 0xFFFC,
  258.    0xFFFF, 0x0000,   0x0003, 0xFFFC,
  259.    0xFFFF, 0x0000,   0x0003, 0xFFFC,
  260.    0xFFFF, 0x0000,   0x0003, 0xFFFC,
  261.    0xFFFF, 0x0000,   0x0003, 0xFFFC,
  262.    0xFFFF, 0x0000,   0x0003, 0xFFFC,
  263.    0xFFFF, 0x0000,   0x0003, 0xFFFC,
  264.    0xFFFF, 0xFFFF,   0xFFFF, 0xFFFC,
  265.    0xFFFF, 0xFFFF,   0xFFFF, 0xFFFC,
  266.    0xFFFF, 0xFFFF,   0xFFFF, 0xFFFC,
  267.    0xFFFF, 0xFFFF,   0xFFFF, 0xFFFC,
  268.    0xFFFF, 0xFFFF,   0xFFFF, 0xFFFC,
  269.    0xFFFF, 0xFFFF,   0xFFFF, 0xFFFC,
  270.    0xFFFF, 0xFFFF,   0xFFFF, 0xFFFC,
  271.    0xFFFF, 0xFFFF,   0xFFFF, 0xFFFC   /* Plane 3, line 31. */
  272. };
  273. USHORT *BobImage_chip = 0;
  274.  
  275. /* These are for my custom screen. */
  276. struct Screen *screen = NULL;
  277. struct NewScreen ns = {
  278.    0, 0,      /* Start position. */
  279.    SBMWIDTH, SBMHEIGHT, SBMDEPTH,   /* Width, height, depth. */
  280.    0, 0,      /* Default detail pen, block pen. */
  281.    NULL,      /* Viewing mode. */
  282.    CUSTOMSCREEN | CUSTOMBITMAP,      /* Screen type. DBL BUF */
  283.    &TestFont,      /* Font to use. */
  284.    NULL,      /* No default title. */
  285.    NULL,      /* No pointer to additional gadgets. */
  286.    NULL         /* No pointer to CustomBitMap. */
  287. };
  288.  
  289. /* These are for my window. */
  290. struct Window *window = NULL;
  291. struct NewWindow nw = {
  292.    0, 0,      /* Start position. */
  293.    SBMWIDTH, SBMHEIGHT,   /* Width, height. */
  294.    0, 0,      /* Detail pen, block pen. */
  295.    CLOSEWINDOW,      /* IDCMP flags. */
  296.    WINDOWCLOSE | BORDERLESS,      /* Flags. */
  297.    NULL,      /* No pointer to FirstGadget. */
  298.    NULL,      /* No pointer to first CheckMark. */
  299.    NULL,      /* No default Title. */
  300.    NULL,      /* No pointer to Screen. */
  301.    NULL,      /* No pointer to BitMap. */
  302.    0, 0,      /* MinWidth, MinHeight (not used). */
  303.    SBMWIDTH, SBMHEIGHT,   /* MaxWidth, MaxHeight (not used). */
  304.    CUSTOMSCREEN      /* Screen type. */
  305. };
  306.  
  307. /*******************************************************************************
  308.  * This will be called if a sprite collision with the border is detected.
  309.  */
  310.  
  311. borderPatrol(s, b)
  312. struct VSprite *s;
  313. int b;
  314. {
  315.    register struct vInfo *info;
  316.  
  317.    info = &s->VUserExt;
  318.    if (b & (TOPHIT | BOTTOMHIT))   /* Top/Bottom hit, change direction. */
  319.       info->vy = -(info->vy);
  320.    if (b & (LEFTHIT | RIGHTHIT))   /* Left/Right hit, change direction. */
  321.       info->vx = -(info->vx);
  322.  
  323. }
  324.  
  325. /*******************************************************************************
  326.  * Fun Starts.
  327.  */
  328.  
  329. main()
  330. {
  331.    SHORT i, j;
  332.  
  333.    /* Open libraries that will be used directly. */
  334.    if ((IntuitionBase = (struct IntuitionBase *)
  335.        OpenLibrary("intuition.library", LIBRARY_VERSION)) == 0) {
  336. #ifdef DEBUG
  337.       kprintf("Main: Can't open Intuition.\n");
  338. #endif
  339.       MyCleanup();
  340.       Exit(-1);
  341.    }
  342.  
  343.    if ((GfxBase = (struct GfxBase *)
  344.        OpenLibrary("graphics.library", LIBRARY_VERSION)) == 0) {
  345. #ifdef DEBUG
  346.       kprintf("Main: Can't open Graphics.\n");
  347. #endif
  348.       MyCleanup();
  349.       Exit(-1);
  350.    }
  351.  
  352.    /*******************************************************************************
  353.  * DBL BUF
  354.     */
  355.    for(j=0; j<2; j++) {
  356.       if ((MyBitMapPtrs[j] = (struct BitMap *)
  357.           AllocMem(sizeof(struct BitMap), MEMF_CHIP)) == 0) {
  358. #ifdef DEBUG
  359.          kprintf("Main: Can't allocate BitMap.\n");
  360. #endif
  361.          MyCleanup();
  362.          Exit(-1);
  363.       }
  364.       InitBitMap(MyBitMapPtrs[j], RBMDEPTH, RBMWIDTH, RBMHEIGHT);
  365.       for(i=0; i<RBMDEPTH; i++) {
  366.          if ((MyBitMapPtrs[j]->Planes[i] = (PLANEPTR)AllocRaster(RBMWIDTH,
  367.          RBMHEIGHT)) == 0) {
  368. #ifdef DEBUG
  369.             kprintf("Main: Can't allocate BitMaps' Planes.\n");
  370. #endif
  371.             MyCleanup();
  372.             Exit(-1);
  373.          }
  374.          BltClear(MyBitMapPtrs[j]->Planes[i], (RBMWIDTH / 8) * RBMHEIGHT, 1);
  375.       }
  376.    }
  377.    ns.CustomBitMap = MyBitMapPtrs[0]; /* !! */
  378.    screen->RastPort.Flags = DBUFFER;
  379.  
  380.    /* Open My Very Own Screen. */
  381.    if ((screen = (struct Screen *)OpenScreen(&ns)) == 0) {
  382. #ifdef DEBUG
  383.       kprintf("Main: Can't open Screen.\n");
  384. #endif
  385.       MyCleanup();
  386.       Exit(-1);
  387.    }
  388.  
  389.    /* Now get that flashing title bar off the display. DBL BUF */
  390.    /*
  391.       screen->ViewPort.RasInfo->RxOffset = 5;
  392.       screen->ViewPort.RasInfo->RyOffset = 5;
  393.    */
  394.  
  395.    /* Set screens' colors (Could've used LoadRGB4()). */
  396.    SetRGB4(&screen->ViewPort, 00, 00, 00, 00);
  397.    SetRGB4(&screen->ViewPort, 01, 15, 00, 00);
  398.    SetRGB4(&screen->ViewPort, 02, 00, 15, 00);
  399.    SetRGB4(&screen->ViewPort, 03, 00, 00, 15);
  400.    SetRGB4(&screen->ViewPort, 04, 15, 15, 00);
  401.    SetRGB4(&screen->ViewPort, 05, 15, 00, 15);
  402.    SetRGB4(&screen->ViewPort, 06, 08, 15, 15);
  403.    SetRGB4(&screen->ViewPort, 07, 15, 11, 00);
  404.    SetRGB4(&screen->ViewPort, 08, 05, 13, 00);
  405.    SetRGB4(&screen->ViewPort, 09, 14, 03, 00);
  406.    SetRGB4(&screen->ViewPort, 10, 15, 02, 14);
  407.    SetRGB4(&screen->ViewPort, 11, 15, 13, 11);
  408.    SetRGB4(&screen->ViewPort, 12, 12, 09, 08);
  409.    SetRGB4(&screen->ViewPort, 13, 11, 11, 11);
  410.    SetRGB4(&screen->ViewPort, 14, 07, 13, 15);
  411.    SetRGB4(&screen->ViewPort, 15, 15, 15, 15);
  412.  
  413.    nw.Screen = screen;
  414.  
  415.    if ((window = (struct Window *)OpenWindow(&nw)) == 0) {
  416. #ifdef DEBUG
  417.       kprintf("Main: Can't open Window.\n");
  418. #endif
  419.       MyCleanup();
  420.       Exit(-1);
  421.    }
  422.  
  423.    /*****************************************************************************
  424.    * Now that the screen envirionment is set up, It's time to set up the
  425.       * gels system.
  426.       */
  427.  
  428.    /* ReadyGels is in GelTools(). */
  429.    if (ReadyGels(&GInfo, &screen->RastPort) != 0) {
  430. #ifdef DEBUG
  431.       kprintf("Main: ReadyGels failed.\n");
  432. #endif
  433.       MyCleanup();
  434.       Exit(-1);
  435.    }
  436.  
  437.    SetCollision(0, borderPatrol, &GInfo);
  438.  
  439.    /* Copy Images to chip memory. */
  440.    if (!InitImages()) {
  441. #ifdef DEBUG
  442.       kprintf("Main: InitImages() failed.\n");
  443. #endif
  444.       MyCleanup();
  445.       Exit(-1);
  446.    }
  447.  
  448.    /*****************************************************************************
  449.    * System is set up, now set up each Gel.
  450.       */
  451.  
  452.    /* First use the routines in geltools to get the sprite. */
  453.    for(i = 0; i < NSPRITES; i++) {
  454.       if ((VSprites[i] = (struct VSprite *)MakeVSprite(VSPRITEHEIGHT,
  455.       VSpriteImage_chip, &MyVSpriteColors[0], i*6, (i*8)+10,
  456.       VSPRITEWIDTH,  VSPRITEDEPTH, VSPRITE)) == 0) {
  457. #ifdef DEBUG
  458.          kprintf("Main: MakeVSprite failed.\n");
  459. #endif
  460.          MyCleanup();
  461.          Exit(-1);
  462.       }
  463.  
  464.       VSprites[i]->VUserExt.id = i;
  465.  
  466.    }
  467.  
  468.    /* First use the routines in geltools to get the bob. */
  469.    for(i = 0; i < NBOBS; i++) {
  470.       if ((Bobs[i] = (struct Bob *)MakeBob(BOBWIDTH, BOBHEIGHT, BOBDEPTH,
  471.       BobImage_chip, 0x0F, 0x00, (i*6), (i*8)+10,
  472.       SAVEBACK | OVERLAY)) == 0) {
  473. #ifdef DEBUG
  474.          kprintf("Main: MakeBob failed.\n");
  475. #endif
  476.          MyCleanup();
  477.          Exit(-1);
  478.       }
  479.  
  480.       Bobs[i]->BobVSprite->VUserExt.id = i;
  481.  
  482.       /* DBL BUF */
  483.       if ((Bobs[i]->DBuffer = (struct DBufPacket *)AllocMem (sizeof(struct
  484.           DBufPacket), MEMF_CHIP)) == 0) {
  485. #ifdef DEBUG
  486.          kprintf("Main: Can't allocate double buffers' packet for a bob.\n");
  487. #endif
  488.          MyCleanup();
  489.          Exit(-1);
  490.       }
  491.       if ((Bobs[i]->DBuffer->BufBuffer = (WORD *)AllocMem (sizeof(SHORT) *
  492.           ((BOBWIDTH+15)/16) * BOBHEIGHT * BOBDEPTH, MEMF_CHIP)) == 0) {
  493. #ifdef DEBUG
  494.          kprintf("Main: Can't allocate double buffer for a bob.\n");
  495. #endif
  496.          MyCleanup();
  497.          Exit(-1);
  498.       }
  499.       AddBob(Bobs[i], &screen->RastPort);
  500.  
  501.       /* The following relies on the fact that AddBob sets the before
  502.              * and after pointers to 0, so the first before and last after.
  503.              * are left alone.
  504.              * Earlier bob has higher priority, thus this bob'll be drawn
  505.              * AFTER that one, thus this bob will appear on top of all earlier
  506.              * ones. One could set the bobs to be drawn in any order by rearranging
  507.              * these pointers.
  508.              */
  509.       if (i > 0) {
  510.          Bobs[i]->After = Bobs[i-1];
  511.          Bobs[i]->After->Before = Bobs[i];
  512.       }
  513.    }  /* End of for. */
  514.  
  515.    /*****************************************************************************
  516.    * Hey, wow, everything opened, and allocated, and initialized! Whew.
  517.       */
  518. Bobs[0]->BobVSprite->X=50;
  519. Bobs[0]->BobVSprite->Y=25;
  520. Bobs[1]->BobVSprite->X=200;
  521. Bobs[1]->BobVSprite->Y=100;
  522. DrawGels();
  523.    for (;;) {
  524.  
  525.       while (MyIntuiMessage = (struct IntuiMessage *)
  526.           GetMsg(window->UserPort))
  527.          switch (MyIntuiMessage->Class) {
  528.          case CLOSEWINDOW:
  529.             ReplyMsg(MyIntuiMessage);
  530.             MyCleanup();
  531.             Exit(TRUE);
  532.             break;
  533.          default:
  534.             ReplyMsg(MyIntuiMessage);
  535.             break;
  536.          }
  537.    }
  538.  
  539. /*******************************************************************************
  540.  * DrawGels part of loop.
  541.  */
  542.  
  543. DrawGels()
  544. {
  545.  
  546.    SortGList(&screen->RastPort);        /* Put the list in order. */
  547. /*  DoCollision(&screen->RastPort);    Collision routines may called now. */
  548.    DrawGList(&screen->RastPort,&screen->ViewPort);      /* Draw 'em. */
  549.    screen->ViewPort.RasInfo->BitMap = MyBitMapPtrs[ToggleFrame];   /* DBL BUF */
  550.    WaitTOF();                           /* When the beam hits the top... */
  551.    MakeScreen(screen);                  /* Tell intuition to do it's stuff. */
  552.    RethinkDisplay();                    /* Does a MrgCop & LoadView. */
  553.    ToggleFrame ^=1;                     /* DBL BUF */
  554.    screen->RastPort.BitMap = MyBitMapPtrs[ToggleFrame];         /* DBL BUF */
  555. }
  556.  
  557. /*******************************************************************************
  558.  * This will be called in case of error, or when main is done.
  559.  */
  560.  
  561. MyCleanup()
  562. {
  563.    short i, j;
  564.  
  565.    for (i=0; i < NBOBS; i++) {
  566.       if (Bobs[i] != NULL) {
  567.          DeleteGel(Bobs[i]->BobVSprite);
  568.       }
  569.    }
  570.    for (i=0; i<NSPRITES; i++)
  571.    {
  572.       if (VSprites[i] != NULL)
  573.       {
  574.          DeleteGel(VSprites[i]);
  575.       }
  576.    }
  577.    PurgeGels(&GInfo);
  578.    FreeImages();
  579.    if (window != NULL)
  580.       CloseWindow(window);
  581.    if (screen != NULL)
  582.       CloseScreen(screen);
  583.  
  584.    /* DBL BUF */
  585.    for(j=0; j<2; j++) {
  586.       if (MyBitMapPtrs[j] != NULL) {
  587.          for(i=0; i<RBMDEPTH; i++) {
  588.             if (MyBitMapPtrs[j]->Planes[i] != 0)
  589.                FreeRaster(MyBitMapPtrs[j]->Planes[i], RBMWIDTH, RBMHEIGHT);
  590.          }
  591.          FreeMem(MyBitMapPtrs[j], sizeof(struct BitMap));
  592.       }
  593.    }
  594.  
  595.    if (GfxBase != NULL)
  596.       CloseLibrary(GfxBase);
  597.    if (IntuitionBase != NULL)
  598.       CloseLibrary(IntuitionBase);
  599. }
  600.  
  601. InitImages()
  602. {
  603.    extern USHORT *VSpriteImage_chip;
  604.    extern USHORT *BobImage_chip;
  605.    int i;
  606.  
  607.    if ((VSpriteImage_chip = (USHORT *)
  608.        AllocMem(sizeof(VSpriteImage), MEMF_CHIP)) == 0) {
  609. #ifdef DEBUG
  610.       kprintf("InitImages: No Memory for VSpriteImage.\n");
  611. #endif
  612.       return(FALSE);
  613.    }
  614.    if ((BobImage_chip = (USHORT *)
  615.        AllocMem(sizeof(BobImage), MEMF_CHIP)) == 0) {
  616. #ifdef DEBUG
  617.       kprintf("InitImages: No Memory for BobImage.\n");
  618. #endif
  619.       return(FALSE);
  620.    }
  621.    for(i=0; i<24; i++)
  622.       VSpriteImage_chip[i] = VSpriteImage[i];
  623.    for(i=0; i<496; i++)
  624.       BobImage_chip[i] = BobImage[i];
  625.    return(TRUE);
  626. }
  627.  
  628. FreeImages()
  629. {
  630.    extern USHORT *VSpriteImage_chip;
  631.    extern USHORT *BobImage_chip;
  632.  
  633.    if (VSpriteImage_chip != 0)
  634.       FreeMem(VSpriteImage_chip, sizeof(VSpriteImage));
  635.    if (BobImage_chip != 0)
  636.       FreeMem(BobImage_chip, sizeof(BobImage));
  637. }
  638.  
  639.  
  640.  
  641.  
  642.  
  643.