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