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

  1.  
  2. #include <intuition/intuition.h>
  3. #include <graphics/sprite.h>
  4. #include <math.h>
  5. #include "easysound.c"
  6. #include "easysound.h"
  7. #include "spriteDATA.c"
  8. #include "askc"
  9. #include "titlec"
  10. #include "stripc"
  11. #include "mainaskc"
  12. #include "infoc"
  13. #include "rightc"
  14. #include "leftc"
  15. #include "letsgoc"
  16.  
  17. #define HEIGHT 200
  18. #define WIDTH 320
  19. #define DEPTH 5
  20.  
  21. struct Window *win;
  22. struct Screen *scr;
  23. struct IntuitionBase *IntuitionBase;
  24. struct GfxBase *GfxBase;
  25. struct ViewPort *vp;
  26. struct RastPort *rp;
  27. struct IntuiMessage *message;
  28.  
  29. USHORT class;
  30. USHORT code;
  31.  
  32. struct NewScreen ns =
  33. { 0,0,WIDTH,HEIGHT,5,0,1,NULL,  /* View modes */
  34.   CUSTOMSCREEN,  /* Screen type */
  35.   NULL,          /* Font */
  36.   NULL,NULL,NULL          /* CustomBitmap */  };
  37.  
  38. struct NewWindow nw =
  39. { 0,0,WIDTH,HEIGHT,0,1,MOUSEBUTTONS+RAWKEY,  /* IDCMP flags */
  40.   ACTIVATE|BORDERLESS|RMBTRAP, /* Flags */
  41.   NULL,NULL,NULL,  /* Gadget,Checkmark,Name */
  42.   NULL,NULL,  /* Screen,BitMap */
  43.   WIDTH,HEIGHT,100,100,  /* Max Width,Height, Min Width,Height */
  44.   CUSTOMSCREEN  };
  45.  
  46. int loc[40][12],blue_ball;
  47.  
  48. struct SimpleSprite left_arrow = {
  49. left_arrow_data,15,15,200,3 };
  50.  
  51. struct SimpleSprite right_arrow = {
  52. right_arrow_data,15,15,200,3 };
  53.  
  54. int connect;  /*  This is a variable of how many circles the user wishes to 
  55.                   connect so they win the game */
  56. CPTR boing;
  57.  
  58. UWORD chip dummydata[] = { 0x0000,0x0000,0x0000,0x0000,0x0000,0x0000 };
  59.  
  60. void _main()
  61. {
  62. int dum;
  63.  
  64. Open_Stuff();
  65.  
  66. if((GetSprite(&left_arrow,2))!=2)  die("   I CAN GET SPRITE #2, SO I AM EXITING.");
  67. if((GetSprite(&right_arrow,3))!=3) die("   I CAN GET SPRITE #3, SO I AM EXITING.");
  68.  
  69. MoveSprite(0,&left_arrow,8,184);   
  70. MoveSprite(0,&right_arrow,286,184); /* These are the arrows */
  71.  
  72. Init_Screen();
  73.  
  74. while(1)
  75.  {
  76.  ClearRASTPORT();
  77.  ClearLOCS();
  78.  DrawImage(rp,&mainask,76,81);
  79.  dum=1;
  80.    while(dum)
  81.    {  
  82.    while((connect=idcmpch())==0);
  83.    if(connect==0x19)
  84.    { dum=0; CirclesUp(); }
  85.       else if(connect==0x10) die("");
  86.          else if(connect==0x17) { dum=0; DisplayINFO(); }
  87.    }
  88. }
  89. die("");
  90. }
  91.  
  92. DisplayINFO()
  93. {
  94. DrawImage(rp,&info,37,62);
  95. while(idcmpch()!=0x45);
  96. return(1);
  97. }
  98.  
  99. WriteNumber()
  100. {
  101. char dum2[20];
  102. SetAPen(rp,29);
  103. sprintf(dum2,"%d",connect);
  104. Move(rp,215,50);
  105. Text(rp,dum2,strlen(dum2));
  106. return(1);
  107. }
  108.  
  109. CirclesUp()
  110. {
  111. int xpos,incr,dummy=1,input,player,player2,c=0,v,r;
  112. int xpos2;
  113.  
  114. ClearRASTPORT();
  115. ClearLOCS();
  116. DrawImage(rp,&ask_image,52,106);  
  117. while(dummy)
  118.    {
  119.    while((connect=idcmpch())==0);
  120.    if(connect<=7&&connect>=3) dummy=0; 
  121.    }
  122. WriteNumber();
  123. ClearRASTPORT();
  124.  
  125. DrawImage(rp,&letsgo,105,120);
  126. Delay(75);
  127. ClearRASTPORT();
  128.  
  129. while(1)
  130.    {
  131.       v=rand()%777;  
  132.       if(v%2==1)  /*  This is the side which the circle flys in */
  133.       { xpos=0; incr=6; } 
  134.       else { xpos=288; incr=-6; }
  135.       if(++c%2==0)   
  136.         { player=0x64; player2=-1; ball2.PlanePick=4; }
  137.         else { player=0x65; player2=0x68; ball2.PlanePick=8; }
  138. dummy=1;
  139.       if(rand()%25==0) 
  140.         { blue_ball=1;  ball2.PlanePick=16; }
  141.         else blue_ball=0;
  142.         while(dummy)
  143.         {
  144.         xpos+=incr;
  145.         xpos2=xpos;
  146.         if(xpos2%12!=0) xpos2+=incr;  
  147.         DrawImage(rp,&ball2,xpos,186);
  148.         input=idcmpch();
  149.         if(input==player||input==player2)
  150.         if(blue_ball==1)
  151.                 {
  152.                 if(xpos%12==0) { up2(xpos); dummy=0; }
  153.                 else { xpos+=incr; DrawImage(rp,&ball2,xpos,186); up2(xpos); dummy=0; }
  154.                 }
  155.                 else
  156.                 if(loc[(xpos2-12)/12][9]==0)   
  157.                 {
  158.                 if(xpos%12==0) { r=up(xpos2,c%2+1); dummy=0; }
  159.                 else { xpos+=incr; DrawImage(rp,&ball2,xpos2,186); r=up(xpos2,c%2+1); dummy=0; }
  160.                 }
  161.         if(r==5||input==0x45) return(1);
  162.         if(xpos<=16&&incr==-6) dummy=0;
  163.            else if(xpos>=272&&incr==6) dummy=0;
  164.         WaitTOF();
  165.         }
  166.    ball2.PlanePick=0x00;
  167.    DrawImage(rp,&ball2,xpos,186);
  168.    }
  169. return(1);
  170. }
  171.  
  172. int up(int where,int who) /* This function sends an ordinary ball up */
  173. {
  174. int y,w,stop,up,across,max;
  175. int gameover;
  176.  
  177. for(w=0;w<12;w++)
  178.    if(loc[(where-12)/12][w]==0)
  179.    {
  180.    stop=w;
  181.    loc[(where-12)/12][w]=who;
  182.    w=13;
  183.    }
  184.  
  185. across=(where-12)/12;
  186. up=stop;
  187.  
  188. w=60+(stop*12);
  189.  
  190. where+=7;
  191.  
  192. ball.PlanePick=ball2.PlanePick;
  193.  
  194. for(y=186;y>w;y--)
  195.    DrawImage(rp,&ball,where,y);
  196.  
  197. StopSound(RIGHT0);
  198. if(boing) PlaySound(boing,MAXVOLUME,RIGHT0,NORMALRATE,1);
  199.  
  200. max=how_many(across,up,who);
  201. if(max>=connect) { gameover=1; AWinner(who); } else gameover=0;
  202.  
  203. if(gameover) return(5); else return(2);
  204. }
  205.  
  206.  
  207.  
  208. AWinner(int w)
  209. {
  210. if(w==1) DrawImage(rp,&left,65,156);
  211.    else DrawImage(rp,&right,65,156);
  212. while(idcmpch()!=0x45);
  213. return(1);
  214. }
  215.  
  216. int how_many(int across,int up,int person)
  217. {    /* This function returns the maximum number of circles of the colour
  218.         just shot up either diagonally,horizontally or vertically. */
  219. int n1,n2,n3,n4;
  220. int dummy,c1,c2,max;
  221. int a,u;
  222.  
  223. a=across; u=up; dummy=1; c1=0;
  224.  
  225. while(dummy)
  226.    {
  227.       if(a==0) dummy=0;
  228.       else {
  229.       --a;
  230.       if(loc[a][u]==person) c1++;
  231.       else dummy=0;
  232.       }
  233.    }
  234.  
  235. a=across; u=up; dummy=1; c2=0;
  236.  
  237. while(dummy)
  238.    {
  239.       if(a==39) dummy=0;
  240.       else {
  241.       ++a;
  242.       if(loc[a][u]==person) c2++;
  243.       else dummy=0;
  244.       }
  245.    }
  246.  
  247. n1=c1+1+c2;
  248.  
  249. a=across; u=up; dummy=1; c1=0;
  250.  
  251. while(dummy)
  252.    {
  253.       if(u==0) dummy=0;
  254.       else {
  255.       --u;
  256.       if(loc[a][u]==person) c1++;
  257.       else dummy=0;
  258.       }
  259.    }
  260.  
  261. a=across; u=up; dummy=1; c2=0;
  262.  
  263. while(dummy)
  264.    {
  265.       if(u==11) dummy=0;
  266.       else {
  267.       ++u;
  268.       if(loc[a][u]==person) c2++;
  269.       else dummy=0;
  270.       }
  271.    }
  272.  
  273. n2=c1+1+c2;
  274.  
  275. a=across; u=up; dummy=1; c1=0;
  276.  
  277. while(dummy)
  278.    {
  279.       if(u==0||a==0) dummy=0;
  280.       else {
  281.       --u; --a;
  282.       if(loc[a][u]==person) c1++;
  283.       else dummy=0;
  284.       }
  285.    }
  286.  
  287. a=across; u=up; dummy=1; c2=0;
  288.  
  289. while(dummy)
  290.    {
  291.       if(u==39||a==11) dummy=0;
  292.       else {
  293.       ++u; ++a;
  294.       if(loc[a][u]==person) c2++;
  295.       else dummy=0;
  296.       }
  297.    }
  298.  
  299. n3=1+c1+c2;
  300.  
  301. a=across; u=up; dummy=1; c1=0;
  302.  
  303. while(dummy)
  304.    {
  305.       if(a==39||u==0) dummy=0;
  306.       else {
  307.       a++; --u;
  308.       if(loc[a][u]==person) c1++;
  309.       else dummy=0;
  310.       }
  311.    }
  312.  
  313. a=across; u=up; dummy=1; c2=0;
  314.  
  315. while(dummy)
  316.    {
  317.       if(a==39||u==11) dummy=0;
  318.       else {
  319.       --a; ++u;
  320.       if(loc[a][u]==person) c2++;
  321.       else dummy=0;
  322.       }
  323.    }
  324.  
  325. n4=c1+1+c2;
  326.  
  327. if(n1>n2) max=n1; else max=n2;
  328. if(max<n3) max=n3;
  329. if(max<n4) max=n4;  
  330.  
  331. /*  n1 is the value of how many circles where found horizontally from the
  332.     circle that was just sent up.
  333.     n2 is the value of how many circles where found vertically 
  334.     n3 & n4 is the value of how many circles where found diagonally 
  335.     AND finally max contains the largest of these 4 values */
  336.  
  337. return(max);
  338. }
  339.  
  340. up2(int where)   /*  This function sends a blue ball up! */
  341. {
  342. int y;
  343. where+=7;
  344.  
  345. for(y=1;y<12;y++)
  346.    loc[(where-12)/12][y]=0;
  347. loc[(where-12)/12][0]=5;
  348.  
  349. ball.PlanePick=ball2.PlanePick;
  350.  
  351. for(y=186;y>60;y--)
  352.    DrawImage(rp,&ball,where,y);
  353.  
  354. StopSound(RIGHT0);
  355. if(boing) PlaySound(boing,MAXVOLUME,RIGHT0,NORMALRATE,1);
  356.  
  357. return(TRUE);
  358. }
  359.  
  360. ClearRASTPORT()
  361. {
  362. struct Image i = {
  363. 0,0,277,150,0,NULL,0,0,NULL };
  364. DrawImage(rp,&i,18,61);
  365. return(8);
  366. }      
  367.  
  368. Init_Screen()
  369. {
  370. int sec,micros;
  371.  
  372. ClearRASTPORT();
  373. CurrentTime(&sec,µs);
  374. srand(sec*9999+micros);
  375.  
  376. SetRGB4(vp,1,0xD,0xD,0);
  377. SetRGB4(vp,2,0xB,0,0);
  378. SetRGB4(vp,3,0,0xB,0);
  379. SetRGB4(vp,4,15,0,0);
  380. SetRGB4(vp,5,4,4,4);
  381. SetRGB4(vp,6,8,8,8);
  382. SetRGB4(vp,7,0xC,0xC,0xC);
  383.  
  384. SetRGB4(vp,8,0,15,0);
  385. SetRGB4(vp,16,0,0,15);
  386. SetRGB4(vp,29,13,13,13);
  387. SetRGB4(vp,30,13,13,4);
  388.  
  389. DrawImage(rp,&title,0,0);
  390. DrawImage(rp,&strip,4,61);
  391. DrawImage(rp,&strip,295,61);     
  392.  
  393. boing=PrepareSound("boing");
  394.  
  395. SetPointer(win,dummydata,1,1,0,0);
  396.  
  397. return(TRUE);
  398. }
  399.  
  400. ClearLOCS()
  401. {
  402. int a,b;
  403. for(a=0;a<40;a++)
  404.  for(b=0;b<12;b++)
  405.    loc[a][b]=0;
  406. return(1);
  407. }     
  408.  
  409.  
  410. /*************************************************************************/
  411. /*************************************************************************/
  412. /*************************************************************************/
  413. /***************************                      ************************/
  414. /***************************    Functions....     ************************/
  415. /***************************                      ************************/
  416. /*************************************************************************/
  417. /*************************************************************************/
  418. /*************************************************************************/
  419.  
  420. int idcmpch()
  421. {
  422.         if(win->UserPort->mp_SigBit)
  423.         if(message=(struct IntuiMessage *)GetMsg(win->UserPort))
  424.         {
  425.         class=message->Class;
  426.         code=message->Code;
  427.         ReplyMsg((struct IntuiMessage *)message);
  428.            switch(class)
  429.               {
  430.               case MOUSEBUTTONS:
  431.                    return((int)0x68);
  432.               case RAWKEY:
  433.                    return((int)code);
  434.               }
  435.         }
  436. return(0);  /* Nothing interesting! */
  437. }
  438.  
  439.  
  440.  
  441. Open_Stuff()
  442. {
  443.  
  444. void *OpenLibrary();
  445. struct Window *OpenWindow();
  446. struct Screen *OpenScreen();
  447.  
  448. if(!(IntuitionBase=(struct IntuitionBase *)OpenLibrary("intuition.library",0)))
  449.    die("Can't open intuition.library");
  450.  
  451. if(!(GfxBase=(struct GfxBase *)OpenLibrary("graphics.library",0)))
  452.    die("Can't open graphics library");
  453.  
  454.  
  455. if((scr=OpenScreen(&ns))==NULL)
  456. die("");
  457.  
  458. nw.Screen=scr;
  459.  
  460. if(!(win=(struct Window *)OpenWindow(&nw)))
  461.    die("");
  462.  
  463. rp=win->RPort;
  464. vp=&scr->ViewPort;
  465.  
  466. SetRGB4(vp,0,0,0,0);
  467.  
  468. return(TRUE);
  469.  
  470. }
  471.  
  472.  
  473. die(s)
  474. char *s[];
  475. {
  476. char Alert[300];
  477. register int loop;
  478.  
  479. if(strlen(s)!=0) /* Display alert if s isn't NULL */
  480.    {
  481.    memset((void *)Alert,0,sizeof(Alert));
  482.    strcat(Alert,s);
  483.    strcat(Alert,"       Press either mouse button to continue.");
  484.    loop=strlen(s);
  485.    Alert[0]=0; Alert[1]=32; Alert[2]=16;
  486.    Alert[loop+2]='\0'; Alert[loop+3]=TRUE;
  487.    Alert[loop+4]=0; Alert[loop+5]=32; Alert[loop+6]=32;
  488.    Alert[loop+45]='\0'; Alert[loop+46]=FALSE;
  489.    DisplayAlert(RECOVERY_ALERT,Alert,48);
  490.    }
  491.  
  492. if((left_arrow.num)!=-1) FreeSprite(left_arrow.num);
  493. if((right_arrow.num)!=-1) FreeSprite(right_arrow.num);
  494.  
  495. StopSound(RIGHT0);
  496. if(boing) RemoveSound(boing);
  497.  
  498. if(win) CloseWindow(win);
  499. if(scr) CloseScreen(scr);
  500. if(GfxBase) CloseLibrary(GfxBase);
  501. if(IntuitionBase) CloseLibrary(IntuitionBase);
  502. exit();
  503. return(TRUE);
  504. }
  505.  
  506.  
  507.