home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 255.lha / Maze / SpeedDemo.c < prev    next >
C/C++ Source or Header  |  1989-05-21  |  3KB  |  119 lines

  1. #include <libraries/dosextens.h>
  2. #include <intuition/intuition.h>
  3. #include <intuition/screens.h>
  4.  
  5. #define BITMAP
  6.  
  7. #include "maze.h"
  8.  
  9. /* Just change these defines for a new resolution */
  10. #define SCREENWIDTH  320
  11. #define SCREENHEIGHT 212
  12. #define VIEWMODE     NULL
  13.  
  14. struct NewScreen ns=
  15. {
  16.  0,0,SCREENWIDTH,SCREENHEIGHT,1,
  17.  1,0,
  18.  VIEWMODE,
  19.  CUSTOMSCREEN|SHOWTITLE,
  20.  NULL,
  21.  NULL,
  22.  NULL,
  23.  NULL
  24. };
  25. struct NewWindow nw=
  26. {
  27.  0,0,SCREENWIDTH,SCREENHEIGHT,
  28.  1,0,
  29.  VANILLAKEY|CLOSEWINDOW|GADGETUP,
  30.  BORDERLESS|NOCAREREFRESH|WINDOWCLOSE|ACTIVATE,
  31.  NULL, NULL,
  32.  "Maze Demo",/*NULL,*/
  33.  NULL, NULL, NULL,NULL,NULL,NULL,
  34.  CUSTOMSCREEN
  35. };
  36.  
  37. struct Library *GfxBase = NULL,*IntuitionBase = NULL;
  38. struct Screen *screen = NULL;
  39. struct Window *window = NULL;
  40. struct BitMap *bm;
  41. struct IntuiMessage *msg;
  42. ULONG  class;
  43. BOOL   WorkBench=NULL;
  44. void newmaze(),leave(),main();
  45.  
  46. void main(argc,argv)
  47. short argc;
  48. char argv[];
  49. {
  50.  if (!argc) WorkBench=TRUE;
  51.  if (!(IntuitionBase = (struct Library*) OpenLibrary("intuition.library",0L)))
  52.     leave("No Intuition Library");
  53.  if (!(GfxBase = (struct Library*) OpenLibrary("graphics.library",0L)))
  54.     leave("No Graphics Library");
  55.  
  56.  if (!(screen = (struct Screen*) OpenScreen(&ns)))
  57.     leave ("Can't open Screen");
  58.  
  59.  nw.Screen=screen;
  60.  if (!(window = (struct Window*) OpenWindow(&nw)))
  61.     leave("Can't open Window");
  62.  
  63.  SetRGB4(&screen->ViewPort,0,0,0,0);
  64.  SetRGB4(&screen->ViewPort,1,12,12,12);
  65.  bm = screen->ViewPort.RasInfo->BitMap;
  66.  
  67.  newmaze();
  68.  
  69.  for(;;)
  70.  {
  71.   WaitPort(window->UserPort);
  72.   if(msg=(struct IntuiMessage*)GetMsg(window->UserPort))
  73.   {
  74.    class=msg->Class;
  75.    ReplyMsg(msg);
  76.    switch(class)
  77.    {
  78.     case CLOSEWINDOW:
  79.      leave("");
  80.     case VANILLAKEY:
  81.      newmaze();
  82.    }
  83.   }
  84.  }
  85. }
  86. void leave(error)
  87. char *error;
  88. {
  89.  BPTR file;
  90.  
  91.  if(window)        CloseWindow(window);
  92.  if(screen)        CloseScreen(screen);
  93.  if(IntuitionBase) CloseLibrary(IntuitionBase);
  94.  if(GfxBase)       CloseLibrary(GfxBase);
  95.  
  96.  if (*error && WorkBench &&
  97.      (file=Open("con:20/70/400/60/Maze Demo",MODE_OLDFILE)))
  98.  {
  99.   Write(file,error,strlen(error));
  100.   Delay(200L);
  101.   Close(file);
  102.  }
  103.  else if (*error) printf("%s\n",error);
  104.  exit(0);
  105. }
  106.  
  107. void newmaze()
  108. {
  109.  BltClear (bm->Planes[0]+12*bm->BytesPerRow,  /*skip gadgets & title */
  110.            (bm->Rows-12)*bm->BytesPerRow,NULL);
  111.  
  112.  /* Get parameters from our BitMap,so we don't have to change them on
  113.     different resolutions */
  114.  if(!(maze(bm->BytesPerRow*8,bm->Rows-12,
  115.            bm->Planes[0]+12*bm->BytesPerRow)))
  116.    leave("Couldn't allocate Maze-Stack");
  117. }
  118.  
  119.