home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / Arashi 1.1 / Game Source / jaf src / old.Flashmain.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-15  |  8.5 KB  |  506 lines  |  [TEXT/KAHL]

  1. /*
  2. **  Titleanimation && Highscorelists. Main program
  3. **  Flashing effects, etc.        //Jaf © copyright 1991
  4. **
  5. */
  6.  
  7.  
  8. #include "Palettes.h"
  9. #include "VA.h"
  10. #include "STORM.h"
  11. #include "Shuddup.h"
  12. #include "Flash.h"
  13. #include "Retrace.h"
  14. #include "VAInternal.h"
  15. #include "PlayOptions.h"
  16. #include "GamePause.h"
  17. #include "demomain.h"
  18.  
  19.  
  20. #define MAXINTENSITY 65535
  21. #define NEWINTENSITY 32767
  22. #define    DELAYTIME 110 
  23. #define LONGDELAY 300
  24.  
  25. /* not checked if this is the max */
  26. #define LIGHTNINGMALLOC 200
  27.  
  28. /* GLOBALS */
  29.  
  30.     
  31. extern int Characters[];
  32.  
  33. int        MainStage;
  34. int        SpecialEvent;
  35.  
  36. int        MaxScale;
  37.  
  38. long    intensity;
  39. int        lightninghit;
  40. long     loop;
  41. long     Phaze;
  42. int        BoxActive;
  43. int        FireworksActive;
  44.  
  45. Rect    Zoom;
  46.  
  47. int        *px;
  48. int        *py;
  49. int        *ls;
  50. int        *le;
  51.  
  52. int        maxsegments;
  53. int        block,blockspeed;
  54. int        discharge;
  55.  
  56. Handle            ColorHandle;
  57. VAColorInfo        *Col;
  58.  
  59. extern    EventRecord        Event;
  60.  
  61. long    PlayGame(long HighScore,int Options);
  62.  
  63. void    DoCompleteGame()
  64. {
  65.     long            score;
  66.  
  67.     score = PlayGame(0,NormalPlay);
  68.     if((score != -1)) 
  69.     {    Highscores(score);
  70.         MainStage = 16;
  71.         SpecialEvent = DELAY;
  72.         loop = -DELAYTIME;
  73.         VAEraseBuffer();
  74.         HighMain();
  75.     }
  76.     else
  77.     {
  78.         SpecialEvent = 0;
  79.         MainStage = 0;
  80.         loop = 0;
  81.     }
  82. }
  83.  
  84. void main() 
  85. {
  86.  
  87.     long            endtime;
  88.     int                Done;
  89.     
  90.     
  91.     if(StormStart())
  92.         return;
  93.  
  94.         
  95.     ThisLevel.lvNext = 1;
  96.     STLoadLevel();
  97.     
  98.     InitScale();
  99.  
  100.     randSeed=Ticks;
  101.  
  102.     ColorHandle=GetResource('CLOT',1002);
  103.     DetachResource(ColorHandle);
  104.     HLock(ColorHandle);
  105.  
  106.     Col=(VAColorInfo *) *ColorHandle;
  107.         (*Col)[8].red=65535;
  108.         (*Col)[8].blue=0;
  109.         (*Col)[8].green=0;
  110.     VASetColors(ColorHandle);
  111.  
  112.     VA.FrameSpeed=3;
  113.     Done = 0;
  114.     SpecialEvent = 0;
  115.     MainStage = 0;
  116.     loop = 0;
  117.     
  118.     do {
  119.         GameEvent();
  120.         switch(Event.what) {
  121.             case keyDown:
  122.             case autoKey:
  123.                     switch(Event.message & 0xFF)
  124.                     {    case 'q':
  125.                         case 'Q':
  126.                         case 27:
  127.                         case 13:     Done = 1;
  128.                                     break;
  129.                         case 'p':
  130.                         case 'P':
  131.                                     GamePause(TitlesRunning);
  132.                                     break;
  133. #define TEST_DEMO_GAME
  134. #ifdef TEST_DEMO_GAME
  135.                         case ',':
  136.                                     RecordDemoGame();
  137.                                     break;
  138.                         case '.':
  139.                                     PlayDemoGame();
  140.                                     break;
  141. #endif
  142.                         default:
  143.                                     DoCompleteGame();
  144.                                     break;
  145.                     }
  146.                     break;
  147.             case mouseUp:
  148.                     DoCompleteGame();
  149.                     break;
  150.         }
  151.         MainTitle();
  152.         VAStep();
  153.     } while(!Done);
  154.     
  155.     VACatchUp();
  156.     VACloseFractalLines();
  157.     VAStep();
  158.     CloseSoundKit();    
  159.     VAClose();
  160.     
  161.      ResetGestalt(); 
  162.      ReplaceASHI();
  163. }
  164.     
  165. void MainTitle()
  166. {
  167.     switch(SpecialEvent) {
  168.         case DELAY:
  169.             loop=loop+5;
  170.             if(loop>=DELAYTIME) {
  171.                 loop = 0;
  172.                 SpecialEvent=NOEVENT;
  173.             }
  174.             if(FireworksActive) {
  175.                 loop=loop-4;
  176.                 if(!(((unsigned int)Random()) % 9))
  177.                     Firework();
  178.             }
  179.             if(BoxActive)
  180.                 DrawBox(); 
  181.             break;
  182.         case LIGHTNING:
  183.             DrawLightning();
  184.             break;
  185.         case LOGOSTART:
  186.             titlemain(ARASHIPICT, HORIZONTAL);  /*  */
  187.             VASetColors(ColorHandle);
  188.             SpecialEvent = NOEVENT;
  189.             break;
  190.         case ZOOMSTART:
  191.             DrawZoomer(); 
  192.             break;
  193.             
  194.         case NOEVENT:
  195.         default:
  196.             switch(MainStage) {
  197.                 case 0:
  198.                     BoxActive=0;
  199.                     FireworksActive=0;
  200.                     Erase(VA.frame.left,VA.frame.top,VA.frame.right,VA.frame.bottom);
  201.                     SpecialEvent = DELAY;
  202.                     break;        
  203.                 case 1:
  204.                     Lightning();
  205.                     break;
  206.                 case 2:
  207.                     HitBlast();
  208.                     titlemain(ARASHIPICT, HORIZONTAL);  /*  */
  209.                     VASetColors(ColorHandle);
  210.                     SpecialEvent = DELAY;
  211.                     break;
  212.                 case 4:
  213.                     Lightning();
  214.                     break;
  215.                 case 5:
  216.                     HitBlast();
  217.                     PlayDemoGame();
  218.                     VAEraseBuffer();
  219.                     VASetColors(GetResource('CLOT',1002));
  220.                     VAStep();
  221.                     break;                    
  222.                 case 6:
  223.                     /* initial Rect */
  224.                     Zoom.left=(VA.frame.left+VA.frame.right/12);
  225.                     Zoom.right=(VA.frame.right-VA.frame.right/12);
  226.                     Zoom.top=(VA.frame.top+VA.frame.bottom/12);
  227.                     Zoom.bottom=(VA.frame.bottom-VA.frame.bottom/12);
  228.                     InitZoomer();
  229.                     break;
  230.                 case 7:
  231.                     Text(0,BG2);
  232.                     SpecialEvent = DELAY;
  233.                     break;
  234.                 case 8:
  235.                     Text(0,255);
  236.                     InitZoomer();
  237.                     break;
  238.                 case 9:
  239.                     Text(1,BG2);
  240.                     SpecialEvent = DELAY;
  241.                     break;
  242.                 case 10:
  243.                     Text(1,255);    
  244.                     InitZoomer();
  245.                     break;    
  246.                 case 11:
  247.                     Text(2,BG2);
  248.                     SpecialEvent = DELAY;
  249.                     break;    
  250.                 case 12:
  251.                     Text(2,255);
  252.                     InitZoomer();
  253.                     break;
  254.                 case 13:
  255.                     Text(3,BG2);
  256.                     SpecialEvent = DELAY;
  257.                     break;
  258.                 case 14:
  259.                     Text(3,255);
  260.                     InitZoomer();
  261.                     break;
  262.                 case 15:
  263.                     HighMain();
  264.                     SpecialEvent = DELAY;
  265.                     FireworksActive = 1;                    
  266.                     break;
  267.                 case 16:
  268.                     BoxActive=0;
  269.                     FireworksActive=0;
  270.                     Erase(VA.frame.left,VA.frame.top,VA.frame.right,VA.frame.bottom);
  271.                     break;
  272.             }
  273.             MainStage++;
  274.             if(MainStage==17)
  275.                 MainStage=0; 
  276.             break;
  277.     }
  278. }
  279.  
  280. void InitZoomer() 
  281. {
  282.     SpecialEvent=ZOOMSTART;
  283.      BoxActive=1;
  284.     DrawZoomer();                    /* in RectZoom.c */
  285. }    
  286.  
  287. /* gets the maximum scale to print the STORM logo */
  288. InitScale()
  289. {
  290.     int scale;
  291.  
  292.     scale = 50;
  293.     while((100+scale*41)>VA.frame.right || (100+scale*8)>VA.frame.bottom)
  294.         scale--;
  295.     MaxScale = scale;
  296. }
  297.  
  298. int Getfontscale()
  299. {
  300.     return MaxScale/6;
  301. }
  302.  
  303. void Erase(x1,y1,x2,y2)
  304. int x1,y1,x2,y2;
  305. {
  306.     Rect eraser;
  307.     eraser.top = y1;
  308.     eraser.bottom = y2;
  309.     eraser.left = x1;
  310.     eraser.right = x2;
  311.     PmBackColor(BGC);
  312.     EraseRect(&eraser);
  313. }
  314.  
  315. #define    RETURN_CHAR    13
  316. void Text(number, color)
  317. int    number;
  318. int    color;
  319. {
  320.     int        x,y,i;
  321.     int     len;
  322.     Handle    TextHand;
  323.     char    *str,*Text;
  324.     
  325.     TextHand=GetResource('TEXT',128+number);
  326.     HLock(TextHand);
  327.     x = Zoom.left+MaxScale;
  328.     y = Zoom.top+2*MaxScale;
  329.  
  330.     VA.segmscale = Getfontscale();
  331.     VA.color=color;
  332.  
  333.     Text=(char *)*TextHand;
  334.     len=GetHandleSize(TextHand);
  335.     
  336.     str = Text;
  337.     for(i=0;i<len;i++) {
  338.         if(*(str++) == RETURN_CHAR) {
  339.             if(Text<str-1) {
  340.                 VAMoveTo(x,y);
  341.                 VADrawText(Text,0,str-Text-1);
  342.                 if(VA.segmscale>=2) {
  343.                     VAMoveTo(x+1,y);
  344.                     VADrawText(Text,0,str-Text-1);
  345.                 }
  346.             }
  347.             y+=VA.segmscale * 10;
  348.             Text=str;
  349.         }
  350.     }
  351. }
  352.  
  353. void ClearText() {
  354.     Erase(VA.frame.left,VA.frame.top ,VA.frame.right,VA.frame.bottom);
  355. }
  356.  
  357. void InitializeLightning()
  358. {    
  359.     int        segment,current;
  360.     int        hitground,forkedlast,forkprob;
  361.     int        i;
  362.  
  363.     px = (int *) NewPtr(sizeof(int) * LIGHTNINGMALLOC);
  364.     py = (int *) NewPtr(sizeof(int) * LIGHTNINGMALLOC);
  365.     ls = (int *) NewPtr(sizeof(int) * LIGHTNINGMALLOC);
  366.     le = (int *) NewPtr(sizeof(int) * LIGHTNINGMALLOC);
  367.     
  368.     for(i=0;i<LIGHTNINGMALLOC;i++) {
  369.         px[i]=0;py[i]=0;
  370.         ls[i]=0;le[i]=0;
  371.     }
  372.     segment=1;
  373.     current=0;
  374.     px[0]=VA.frame.right/2;
  375.     py[0]=-20;
  376.     ls[0]=0;le[0]=0;
  377.     hitground=0;forkedlast=1;
  378.     forkprob=15;
  379.     while(!hitground) {
  380.         ls[segment]=current;
  381.         le[segment]=segment;
  382.         /* fork? */
  383.         if(Random()%forkprob==0 && !forkedlast) {
  384.             current--;
  385.             forkedlast = 1;
  386.             forkprob+=150;
  387.         }
  388.         else {
  389.             forkedlast = 0;
  390.             forkprob-=1;
  391.             if(forkprob<5)
  392.                 forkprob=5;
  393.         }
  394.         if(Random()%2) {
  395.             /* right-side */
  396.             px[ls[segment]]=px[ls[current]]+2+((unsigned int)Random())%30;
  397.             py[ls[segment]]=py[ls[current]]+20+((unsigned int)Random())%10;
  398.             if(py[ls[segment]]>VA.frame.bottom)
  399.                 hitground=1;
  400.         }
  401.         else {
  402.             /* left-side */
  403.             px[ls[segment]]=px[ls[current]]-2-((unsigned int)Random())%30;
  404.             py[ls[segment]]=py[ls[current]]+20+((unsigned int)Random())%10;
  405.             if(py[ls[segment]]>VA.frame.bottom)
  406.                 hitground=1;
  407.         }
  408.         segment++;
  409.         current++;
  410.     }
  411.     ls[segment]=0;
  412.     le[segment]=0;
  413.     maxsegments=segment;
  414. }
  415.  
  416. void Lightning()
  417. {            
  418.     InitializeLightning();
  419.     SpecialEvent = LIGHTNING;
  420.     discharge = 0;
  421.     lightninghit = 0;
  422.     intensity = 0;
  423.     block = 10;
  424.     blockspeed = maxsegments/8+1;
  425.     DrawLightning();
  426. }
  427.  
  428. void DrawLightning()
  429. {
  430.     if(intensity || !lightninghit) {
  431.         if(!lightninghit) {
  432.             block+=blockspeed;
  433.             }
  434.         else {
  435.             if(discharge<maxsegments) {
  436.                 discharge+=blockspeed;
  437.             }
  438.         }
  439.         LightningEffect();
  440.         FlashEffect();
  441.     }
  442.     else 
  443.         SpecialEvent = 0;
  444. }
  445.  
  446. void LightningEffect()
  447. {
  448.     int i;
  449.  
  450.     VA.color=2;
  451.     
  452.     for(i=discharge;i<block;i++) {
  453.         if (i<maxsegments && px[le[i]] !=0 && px[ls[i]] !=10 && py[le[i]]!=0) {
  454.             VAMoveTo(px[ls[i]],py[ls[i]]);
  455.             VASafeLineTo(px[le[i]],py[le[i]]);
  456.             }
  457.         else {
  458.             if(!lightninghit) 
  459.                 intensity+=MAXINTENSITY;
  460.             lightninghit=1;
  461.             }
  462.         }
  463.  
  464.     for(i=discharge;i<block;i++) {
  465.         if(px[ls[i]]!=0) {
  466.             px[ls[i]]=px[ls[i]]+Random()%4;
  467.             py[ls[i]]=py[ls[i]]+Random()%4;
  468.         }
  469.     }
  470. }
  471.     
  472. void FlashEffect()
  473. {
  474.     if(intensity > MAXINTENSITY)
  475.         intensity=MAXINTENSITY;
  476.  
  477.     (*Col)[9].red=intensity/2;
  478.     (*Col)[9].blue=intensity;
  479.     (*Col)[9].green=intensity/2;
  480.         
  481.     intensity= (intensity * 2)/3;
  482.  
  483.     VASetColors(ColorHandle);
  484. }
  485.  
  486. void HitBlast()
  487. {
  488.     PlayA(Blast,999);
  489.     if(!PlayOptions->noLoudSounds)
  490.         PlayB(Blast,999);
  491.  
  492.     DisposPtr(px);
  493.     DisposPtr(py);
  494.     DisposPtr(ls);
  495.     DisposPtr(le);
  496. }
  497.  
  498. void DrawBox()
  499. {
  500.     VA.color=2;
  501.     VALine(Zoom.left,Zoom.top,Zoom.right,Zoom.top);
  502.     VALine(Zoom.left,Zoom.top,Zoom.left,Zoom.bottom);
  503.     VALine(Zoom.right,Zoom.bottom,Zoom.right,Zoom.top);
  504.     VALine(Zoom.right,Zoom.bottom,Zoom.left,Zoom.bottom);
  505. }
  506.