home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d5xx / d592 / star.lha / Star / star.c < prev    next >
C/C++ Source or Header  |  1992-01-31  |  5KB  |  225 lines

  1.  
  2.  
  3. #include <intuition/intuition.h>
  4. #include "star.h"
  5.  
  6. #define HEIGHT 400
  7. #define WIDTH 640
  8. #define DEPTH 4
  9.  
  10. struct Window *win;
  11. struct Screen *scr;
  12. struct IntuitionBase *IntuitionBase;
  13. struct GfxBase *GfxBase;
  14. struct ViewPort *vp;
  15. struct RastPort *rp;
  16. struct IntuiMessage *message;
  17.  
  18. USHORT class;
  19. USHORT code;
  20.  
  21. struct NewScreen ns =
  22. { 0,0,WIDTH,HEIGHT,DEPTH,0,1,HIRES+LACE,  /* View modes */
  23.   CUSTOMSCREEN,  /* Screen type */
  24.   NULL,          /* Font */
  25.   NULL,NULL,NULL          /* CustomBitmap */  };
  26.  
  27. struct NewWindow nw =
  28. { 0,0,WIDTH,HEIGHT,0,1,MOUSEBUTTONS,  /* IDCMP flags */
  29.   ACTIVATE|BORDERLESS|RMBTRAP, /* Flags */
  30.   NULL,NULL,NULL,  /* Gadget,Checkmark,Name */
  31.   NULL,NULL,  /* Screen,BitMap */
  32.   WIDTH,HEIGHT,100,100,  /* Max Width,Height, Min Width,Height */
  33.   CUSTOMSCREEN  };
  34.  
  35. int *values1,*values2,*values3; /* Declare 3 pointers to my 3 sets of points */
  36.  
  37. void _main()
  38. {
  39. int x,times=0;
  40.  
  41. Open_Stuff();
  42.  
  43. Init_Colour();
  44.  
  45.  
  46.  
  47. values1=Init_Values(30,30);
  48. values2=Init_Values(60,61);     /* Initialize 3 sets of points */
  49. values3=Init_Values(100,301);
  50.  
  51. if(values1==0 || values2==0 || values3==0)
  52.    die("   I can't allocate memory for my points!");
  53.  
  54. Clear_Rastport();
  55.  
  56. while(idcmpch()!=1)   /* Draw Stars until the user presses the LMB */
  57.    {
  58.    for(x=0;x<2;x++)
  59.    {
  60.    times++;
  61.   
  62.    SetAPen(rp,rand()%15+1);
  63.    Draw_Star(rp,values1,rand()%500+40,rand()%300+40,rand()%20+5);
  64.    
  65.    SetAPen(rp,rand()%15+1);
  66.    Draw_Star(rp,values2,rand()%500+70,rand()%260+70,rand()%40+10);
  67.  
  68.    SetAPen(rp,rand()%15+1);
  69.    Draw_Star(rp,values3,rand()%420+110,rand()%180+110,rand()%200+33);
  70.    
  71.    if(times==30) { times=0; Clear_Rastport(); }
  72.    }
  73.  
  74.    }
  75.  
  76.  
  77. die("");
  78. }
  79.  
  80. int Clear_Rastport()
  81. {
  82. struct Image dummy =
  83. { 0,0,WIDTH,HEIGHT,0,NULL,0,0,NULL };
  84. DrawImage(rp,&dummy,0,0);
  85. return(1);
  86. }
  87.  
  88. int Init_Colour()
  89. {
  90. int sec,micros;
  91.  
  92. SetRGB4(vp,1,15,0,0);
  93. SetRGB4(vp,2,15,0,0);
  94. SetRGB4(vp,3,15,15,0);
  95. SetRGB4(vp,4,0,15,15);
  96. SetRGB4(vp,5,15,0,15);
  97. SetRGB4(vp,6,15,15,15);
  98. SetRGB4(vp,7,0,0,15);
  99. SetRGB4(vp,8,15,15,0);
  100. SetRGB4(vp,9,6,15,6);
  101. SetRGB4(vp,10,15,3,3);
  102. SetRGB4(vp,11,15,3,9);
  103.  
  104. SetAPen(rp,11);
  105. Move(rp,220,200);
  106. Text(rp,"       STAR  V1.0",17);
  107. Move(rp,216,215);
  108. Text(rp,"      By Jason Lowe",19);
  109. Move(rp,215,230);
  110. SetAPen(rp,6);
  111. Text(rp,"    Calculating points",22);
  112. Move(rp,210,245);
  113. Text(rp,"  Left Mouse Button EXITS",25);
  114. Move(rp,210,260);
  115. SetAPen(rp,8);
  116. Text(rp,"  Source for this program",25);
  117. Move(rp,205,275);
  118. Text(rp,"is avalable from the author.",28);
  119. Move(rp,207,290);
  120. Text(rp,"   This program is 100% C.",26);
  121.  
  122. CurrentTime(&sec,µs);   /* Reseed the random number generator */
  123. srand(999*sec+micros);
  124.  
  125. return(1);
  126. }
  127.  
  128. /*************************************************************************/
  129. /*************************************************************************/
  130. /*************************************************************************/
  131. /***************************                      ************************/
  132. /***************************    Functions....     ************************/
  133. /***************************                      ************************/
  134. /*************************************************************************/
  135. /*************************************************************************/
  136. /*************************************************************************/
  137.  
  138. int idcmpch()
  139. {
  140.         if(win->UserPort->mp_SigBit)
  141.         if(message=(struct IntuiMessage *)GetMsg(win->UserPort))
  142.         {
  143.         class=message->Class;
  144.         code=message->Code;
  145.         ReplyMsg((struct IntuiMessage *)message);
  146.            switch(class)
  147.               {
  148.               case MOUSEBUTTONS:
  149.                    switch(code)
  150.                    {
  151.                    case SELECTDOWN:
  152.                    return(1);
  153.                    }
  154.               }
  155.         }
  156. return(0);  /* Nothing interesting! */
  157. }
  158.  
  159.  
  160.  
  161. Open_Stuff()
  162. {
  163.  
  164. void *OpenLibrary();
  165. struct Window *OpenWindow();
  166. struct Screen *OpenScreen();
  167.  
  168. if(!(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",0)))
  169.    die("Can't open intuition.library");
  170.  
  171. if(!(GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",0)))
  172.    die("Can't open graphics library");
  173.  
  174.  
  175. if((scr=OpenScreen(&ns))==NULL)
  176. ;
  177.  
  178. nw.Screen=scr;
  179.  
  180. if(!(win=(struct Window *)OpenWindow(&nw)))
  181.    die("Can't open window");
  182.  
  183. rp=win->RPort;
  184. vp=&scr->ViewPort;
  185.  
  186. SetRGB4(vp,0,0,0,0);
  187.  
  188. return(TRUE);
  189.  
  190. }
  191.  
  192.  
  193. int die(s)
  194. char *s[];
  195. {
  196. char Alert[300];
  197. register int loop;
  198.  
  199. if(strlen(s)!=0) /* Display alert if s isn't NULL */
  200.    {
  201.    memset((void *)Alert,0,sizeof(Alert));
  202.    strcat(Alert,s);
  203.    strcat(Alert,"       Press either mouse button to continue.");
  204.    loop=strlen(s);
  205.    Alert[0]=0; Alert[1]=32; Alert[2]=16;
  206.    Alert[loop+2]='\0'; Alert[loop+3]=TRUE;
  207.    Alert[loop+4]=0; Alert[loop+5]=32; Alert[loop+6]=32;
  208.    Alert[loop+45]='\0'; Alert[loop+46]=FALSE;
  209.    DisplayAlert(RECOVERY_ALERT,Alert,48);
  210.    }
  211.  
  212. if(values1) Free_Values(values1);
  213. if(values2) Free_Values(values2);
  214. if(values3) Free_Values(values3);
  215.  
  216. if(win) CloseWindow(win);
  217. if(scr) CloseScreen(scr);
  218. if(GfxBase) CloseLibrary(GfxBase);
  219. if(IntuitionBase) CloseLibrary(IntuitionBase);
  220. exit();
  221. return(1);
  222. }
  223.  
  224.  
  225.