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 / jam src / STSpikes.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-14  |  8.0 KB  |  421 lines  |  [TEXT/KAHL]

  1. /*/
  2.      Project Arashi: STSpikes.c
  3.      Major release: Version 1.1d2, 9/5/95
  4.  
  5.      Last modification: Monday, December 14, 1992, 22:04
  6.      Created: Friday, March 24, 1989, 13:07
  7.  
  8.      Copyright © 1989-1992, Juri Munkki
  9. /*/
  10.  
  11. #include "VA.h"
  12. #include "STORM.h"
  13.  
  14. extern    Shot    shots[];
  15. extern    int        shotcount;
  16. extern    Player    Hero;
  17.  
  18. #define    SPIKERSPEED            (ThisLevel.spSpeed)
  19. #define    SPIKERTOP            (ThisLevel.spTop)
  20. #define    SPIKERCOLOR            (ThisLevel.spColor[0])
  21. #define    PLASMASPEED            (ThisLevel.spPlSpeed)
  22. #define    PLASMAPRIMECOLOR    (ThisLevel.spColor[1])
  23. #define    PLASMASECCOLOR        (ThisLevel.spColor[2])
  24. #define    PLASMARANGE            5
  25. #define    SPIKEHITDROP        (ThisLevel.shPower)
  26.  
  27. typedef struct
  28. {    int        top;
  29.     IFixed    ball;
  30.     Fixed    direction;
  31.     IFixed    plasma;
  32. }    Spiker;
  33.  
  34.             Spiker    *Spikers;
  35. static        int        SpikeRotAngle,SpikeUpdate;
  36.  
  37.  
  38. void    DrawSpiker(cx,cy,size,angle)
  39. register    int        cx,cy,size,angle;
  40. {
  41.     register    int        dx,dy,i;
  42.     
  43.     VA.color=SPIKERCOLOR;
  44.  
  45.     size>>=2;
  46.     dx=(size * Cosins[angle])/256;
  47.     dy=(size * Sins[angle]  )/256;
  48.  
  49.     for(i=0;i<5;i++)
  50.     {    angle+=(ANGLES/5);
  51.         if(angle>=ANGLES)    angle-=ANGLES;
  52.         VAMoveTo(cx+dx,cy+dy);
  53.         dx=(size * Cosins[angle])/256;
  54.         dy=(size * Sins[angle]  )/256;
  55.         VALineTo(cx+dx,cy+dy);
  56.     }
  57. }
  58.  
  59.  
  60. void    DrawPlasma(lane,level)
  61. int        lane,level;
  62. {
  63.     register        int        dx,dy,x,y,angle,i;
  64.                     long    size;
  65.  
  66.     size=ww.unitlen[level];
  67.  
  68.     x=ww.xc[lane][level];
  69.     y=ww.yc[lane][level];
  70.  
  71.     angle=(level*21+ANGLES) % ANGLES;
  72.  
  73.     VAMoveTo(x,y);
  74.     for(i=0;i<3;i++)
  75.     {    angle+=ANGLES/3;
  76.         if(angle>=ANGLES)    angle-=ANGLES;
  77.     
  78.         dx = (Cosins[angle]*size)>>10;
  79.         dy = (Sins[angle]*size)>>10;
  80.         VA.color=PLASMAPRIMECOLOR;
  81.         VASafeLineTo(x+dx,y+dy);
  82.         VA.color=PLASMASECCOLOR;
  83.         VASafeSpot(x-(dx>>1),y-(dy>>1));
  84.     }
  85. }
  86.  
  87. void    ChangeSpike(lane,level)
  88. int        lane,level;
  89. {
  90.     register    int        x,y,soff,scol,sfield;
  91.  
  92.     soff=VA.offset;
  93.     sfield=VA.field;
  94.     scol=VA.color;
  95.     VA.field=1;
  96.     VA.offset=0;
  97.  
  98.     if(Spikers[lane].top<DEPTH)
  99.     {    VA.color=1;
  100.         x=ww.xc[lane][Spikers[lane].top];
  101.         y=ww.yc[lane][Spikers[lane].top];
  102.  
  103.         VAStaticLine(x,y,ww.xc[lane][DEPTH],ww.yc[lane][DEPTH]);
  104.     }
  105.     Spikers[lane].top=level;
  106.  
  107.     if(level<DEPTH)
  108.     {    VA.color=0;
  109.         VAStaticLine(    ww.xc[lane][level],
  110.                     ww.yc[lane][level],
  111.                     ww.xc[lane][DEPTH],
  112.                     ww.yc[lane][DEPTH]);
  113.     }
  114.     VA.field=sfield;
  115.     VA.offset=soff;
  116.     VA.color=scol;
  117. }
  118. void    DrawSpike(lane)
  119. int        lane;
  120. {
  121.     register    int        x,y,level,soff,scol,sfield;
  122.  
  123.     soff=VA.offset;
  124.     sfield=VA.field;
  125.     scol=VA.color;
  126.     VA.field=1;
  127.     VA.offset=0;
  128.  
  129.     VA.color=0;
  130.     level=Spikers[lane].top;
  131.     if(level<DEPTH)
  132.     {    VAStaticLine(    ww.xc[lane][level],
  133.                     ww.yc[lane][level],
  134.                     ww.xc[lane][DEPTH],
  135.                     ww.yc[lane][DEPTH]);
  136.     }
  137.     VA.field=sfield;
  138.     VA.offset=soff;
  139.     VA.color=scol;
  140. }
  141.  
  142. void    DropSpike(lane)
  143. register    int        lane;
  144. {
  145.     register    int        x,y;
  146.     register    int        soff,scol,sfield;
  147.     
  148.     soff=VA.offset;
  149.     sfield=VA.field;
  150.     scol=VA.color;
  151.     VA.field=1;
  152.     VA.offset=0;
  153.     
  154.     x=ww.xc[lane][Spikers[lane].top-Hero.flydepth];
  155.     y=ww.yc[lane][Spikers[lane].top-Hero.flydepth];
  156.  
  157.     VAExplosion(x,y,Spikers[lane].top>DEPTH/2 ? 0 : 1 ,5);
  158.     IncreaseScore(ThisLevel.spSpikePoints);
  159.  
  160.     if(Hero.flydepth)
  161.     {    Spikers[lane].top+=SPIKEHITDROP;
  162.         
  163.         if(Spikers[lane].top>=DEPTH)
  164.         {    Spikers[lane].top=DEPTH+999;
  165.         }
  166.     }
  167.     else
  168.     {    VA.color=1;
  169.         VAStaticLine(x,y,ww.xc[lane][DEPTH],ww.yc[lane][DEPTH]);
  170.         
  171.         VA.color=0;
  172.     
  173.         Spikers[lane].top+=SPIKEHITDROP;
  174.         if(Spikers[lane].top>=DEPTH)
  175.         {    Spikers[lane].top=DEPTH+999;
  176.         }
  177.         else
  178.         {    VAStaticLine(    ww.xc[lane][Spikers[lane].top],
  179.                         ww.yc[lane][Spikers[lane].top],
  180.                         ww.xc[lane][DEPTH],
  181.                         ww.yc[lane][DEPTH]);
  182.         }
  183.     }
  184.  
  185.     VA.field=sfield;
  186.     VA.offset=soff;
  187.     VA.color=scol;
  188. }
  189. void    KillSpiker(lane)
  190. register    int        lane;
  191. {
  192.     register    int        x,y;
  193.  
  194.     if(Spikers[lane].direction && (Spikers[lane].ball.i < DEPTH))
  195.     {    x=ww.xc[lane][Spikers[lane].ball.i];
  196.         y=ww.yc[lane][Spikers[lane].ball.i];
  197.         VAExplosion(x,y,Spikers[lane].ball.i>DEPTH/2 ? 1:2,0);
  198.         PlayB(Dziung,0);
  199.         IncreaseScore(ThisLevel.spPoints);
  200.         Spikers[lane].direction=0;
  201.     }
  202. }
  203.  
  204. void    BlowPlasma(lane)
  205. register    int        lane;
  206. {
  207.     VAExplosion(ww.xc[lane][Spikers[lane].plasma.i]+1,
  208.                 ww.yc[lane][Spikers[lane].plasma.i]+1,
  209.                 1,
  210.                 PLASMASECCOLOR);
  211.     PlayB(Dziung,0);
  212.     IncreaseScore(ThisLevel.spPlPoints);
  213.     Spikers[lane].plasma.i= DEPTH+1;
  214.  
  215. }
  216. void    SpikeShotTests()
  217. {
  218.     register    int        i;
  219.     register    Shot    *shp;
  220.     register    int        shotlevel;
  221.  
  222.     if(Hero.superzapping==1 && Hero.flydepth==0)
  223.     {    for(i=0;i<ww.numsegs;i++)
  224.         {    if(Spikers[i].ball.i<DEPTH)        KillSpiker(i);
  225.             if(Spikers[i].plasma.i<DEPTH)    BlowPlasma(i);
  226.         }
  227.     }
  228.  
  229.     shp=shots;
  230.     for(i=0;i<shotcount;i++)
  231.     {    shotlevel=shp->level+Hero.flydepth;
  232.         if(shotlevel>Spikers[shp->lane].top)
  233.         {    
  234.             if(shotlevel<=DEPTH)
  235.                 DropSpike(shp->lane);    
  236.             
  237.             if(shotlevel>Spikers[shp->lane].ball.i)
  238.                 KillSpiker(shp->lane);
  239.             *shp--=shots[--shotcount];
  240.             i--;
  241.         }
  242.         else if(Hero.flydepth==0)
  243.         {    if(shotlevel>Spikers[shp->lane].plasma.i)
  244.             {    ExplodeShot(shp->lane,shotlevel);
  245.                 BlowPlasma(shp->lane);
  246.                 *shp--=shots[--shotcount];
  247.                 i--;
  248.             }
  249.         }
  250.         shp++;
  251.     }
  252. }
  253.  
  254. void    UpdateSpikes()
  255. {
  256.     register    int        i,j,k;
  257.     
  258.     SpikeRotAngle+=5;
  259.     
  260.     if(SpikeRotAngle < 40)
  261.     {    if(++SpikeUpdate >= ww.numsegs)
  262.             SpikeUpdate=0;
  263.         if(Spikers[SpikeUpdate].top < DEPTH )
  264.             DrawSpike(SpikeUpdate);
  265.     }
  266.     if(SpikeRotAngle>=ANGLES) SpikeRotAngle-=ANGLES;
  267.     
  268.     VA.color=0;
  269.     for(i=0;i<ww.numsegs;i++)
  270.     {    j=Spikers[i].top;
  271.         if ((j == DEPTH) && (Spikers[i].direction > 0)) /* This tells when a Spiker */
  272.         {                        /* reaches the bottom.  Generate a Tanker? */
  273.         }
  274.         
  275.         if(Spikers[i].direction)
  276.         {    Spikers[i].ball.f+=Spikers[i].direction;
  277.             k = Spikers[i].ball.i;
  278.             
  279.             if(k<=SPIKERTOP)
  280.             {    Spikers[i].direction = SPIKERSPEED;    /* Spiker at top, turning around */
  281.             }
  282.             else
  283.             {    if(k>=DEPTH) Spikers[i].direction= 0;
  284.             }
  285.             
  286.             if(k<j)
  287.             {    j=k;
  288.                 ChangeSpike(i,j);
  289.             }
  290.             
  291.             if(Spikers[i].direction)
  292.             {    DrawSpiker(ww.xc[i][k],ww.yc[i][k],ww.unitlen[k],SpikeRotAngle);
  293.             }
  294.             
  295.             Spikers[i].ball.i = k;
  296.         }
  297.         else
  298.         {    if(VAPosRandom()<ThisLevel.spProb)
  299.             {    Spikers[i].direction= -SPIKERSPEED;
  300.                 Spikers[i].ball.i=DEPTH;
  301.                 if(Spikers[i].plasma.i>DEPTH && ThisLevel.spPlasma)
  302.                 {
  303.                     Spikers[i].plasma.i=DEPTH;
  304.                 }
  305.             }
  306.         }
  307.         if(Spikers[i].plasma.i<=DEPTH)
  308.         {    Spikers[i].plasma.f-=PLASMASPEED;
  309.  
  310.             DrawPlasma(i,Spikers[i].plasma.i);
  311.             if(Spikers[i].plasma.i<0)
  312.             {    PlayB(Whiz,0);
  313.                 Spikers[i].plasma.i=DEPTH+1;
  314.                 Hero.lanestat[i]|=PlasMask;
  315.             }
  316.             else
  317.             {    if(Spikers[i].plasma.i<PLASMARANGE)
  318.                     Hero.lanestat[i]|=PlasMask;
  319.             }
  320.         }
  321.  
  322.         if(j<DEPTH)
  323.         {    VA.color=ThisLevel.spColor[1];
  324.             VAPixel(ww.xc[i][j],ww.yc[i][j]);
  325.         }
  326.     }
  327.     SpikeShotTests();
  328. }
  329. void    InitSpikes()
  330. {
  331.     register    int        i;
  332.     register    int        soff,scol,sfield;
  333.  
  334.     SpikeRotAngle=0;
  335.     SpikeUpdate=0;
  336.  
  337.     soff=VA.offset;
  338.     sfield=VA.field;
  339.     scol=VA.color;
  340.  
  341.     VA.color=0;
  342.     VA.field=1;
  343.     VA.offset=0;
  344.     
  345.     for(i=0;i<ww.numsegs;i++)
  346.     {    Spikers[i].direction=0;
  347.         Spikers[i].plasma.i=DEPTH+1;    /*    No plasma flying    */
  348.  
  349.         if(ThisLevel.spStart>=0)
  350.             Spikers[i].top=ThisLevel.spStart;
  351.  
  352.         if(Spikers[i].top<DEPTH)
  353.             VAStaticLine(    ww.xc[i][DEPTH],ww.yc[i][DEPTH],
  354.                             ww.xc[i][Spikers[i].top],ww.yc[i][Spikers[i].top]);
  355.     }
  356.     
  357.     ThisLevel.spStart= -1;
  358.  
  359.     VA.field=sfield;
  360.     VA.offset=soff;
  361.     VA.color=scol;
  362. }
  363.  
  364. void    RedrawSpikes()
  365. {
  366.     register    int        i,level;
  367.  
  368.     VA.field=1;
  369.     VA.offset=0;
  370.     
  371.     for(i=0;i<ww.numsegs;i++)
  372.     {    level=Spikers[i].top;
  373.         if(level<DEPTH)
  374.         {    VAStaticLine(    ww.xc[i][DEPTH],ww.yc[i][DEPTH],
  375.                             ww.xc[i][level],ww.yc[i][level]);
  376.         }
  377.         Spikers[i].direction=0;
  378.     }
  379. }
  380.  
  381. void    FlySpikes(color)
  382. int        color;
  383. {
  384.                 Rect    toclip;
  385.     register    int        toplevel,botlevel;
  386.     register    int        i;
  387.  
  388.     SpikeShotTests();
  389.  
  390.     botlevel=DEPTH-Hero.flydepth;
  391.  
  392.     for(i=0;i<ww.numsegs;i++)
  393.     {    toplevel=Spikers[i].top-Hero.flydepth;
  394.         if(toplevel<=ZOOMDEPTH)
  395.             toplevel=ZOOMDEPTH+1;
  396.     
  397.         if(toplevel < botlevel)
  398.         {    if(toplevel <= 0)
  399.             {    Hero.lanestat[i] |= SpikeMask;
  400.             }
  401.             
  402.             toclip.left=ww.xc[i][botlevel];
  403.             toclip.top=ww.yc[i][botlevel];
  404.             toclip.right=ww.xc[i][toplevel];
  405.             toclip.bottom=ww.yc[i][toplevel];
  406.         
  407.             VA.color=ThisLevel.spColor[1];
  408.             VASafePixel(toclip.right,toclip.bottom);
  409.  
  410.             VA.color=color;
  411.             if(VAClip(&toclip))
  412.             {    VALine(toclip.left,toclip.top,toclip.right,toclip.bottom);
  413.             }
  414.         }
  415.     }
  416. }
  417.  
  418. void    AllocSpikers()
  419. {
  420.     Spikers=(Spiker *)NewPtr(sizeof(Spiker)*MAXSEGS);    
  421. }