home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Games / Arashi 1.1.1 / source code / Game Source / jaf src / Flashmain.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-31  |  8.6 KB  |  511 lines  |  [TEXT/KAHL]

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