Advertisement
ZoriaRPG

Zig-Zag Weapon Script

Mar 18th, 2019
348
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.21 KB | None | 0 0
  1. //Zig-Zag Weapon pattern.
  2. //ZoriaRPG, 18th March, 2019
  3.  
  4. eweapon script eZigZagwhoneedssine
  5. {
  6.     void run(int dist, int speed)
  7.     {
  8.         int frame = 1;
  9.         int baseline;
  10.         dist = (dist < 1) ? 12 : dist;
  11.         speed = (speed < 1) ? 1 : speed;
  12.         //initial direction from baseline
  13.         bool initial = ( Rand(0,1) ) ? true : false;
  14.         switch(this->Dir)
  15.         {
  16.             case DIR_UP: baseline = this->X+(this->TileWidth*0.5); break;
  17.             case DIR_LEFT: baseline = this->Y+(this->TileHeight*0.5); break;
  18.             case DIR_DOWN: baseline = this->X+(this->TileWidth*0.5)+1; break;
  19.             case DIR_RIGHT: baseline = this->Y+(this->TileHeight*0.5)+1; break;
  20.                
  21.         }
  22.         while(this->isValid())
  23.         {
  24.             ++frame;
  25.             switch(this->Dir)
  26.             {
  27.                 case DIR_UP:
  28.                 case DIR_DOWN:
  29.                 {
  30.                     if ( initial )
  31.                     {
  32.                         if ( !(frame%speed) )
  33.                         {
  34.                             if ((baseline - this->X) < dist )
  35.                             {
  36.                                 --this->X;
  37.                             }
  38.                             else initial = !initial;
  39.                         }
  40.                     }
  41.                     else
  42.                     {
  43.                         if ( !(frame%speed) )
  44.                         {
  45.                             if ( (this->X - baseline) < dist )
  46.                             {
  47.                                 ++this->X;
  48.                             }
  49.                             else initial = !initial;
  50.                         }
  51.                     }
  52.                     break; 
  53.                 }
  54.                
  55.                 case DIR_LEFT:
  56.                 case DIR_RIGHT:
  57.                 {
  58.                     if ( initial )
  59.                     {
  60.                         if ( !(frame%speed) )
  61.                         {
  62.                             if ((baseline - this->Y) < dist )
  63.                             {
  64.                                 --this->Y;
  65.                             }
  66.                             else initial = !initial;
  67.                         }
  68.                     }
  69.                     else
  70.                     {
  71.                         if ( !(frame%speed) )
  72.                         {
  73.                             if ( (this->Y - baseline) < dist )
  74.                             {
  75.                                 ++this->Y;
  76.                             }
  77.                             else initial = !initial;
  78.                         }
  79.                     }
  80.                     break; 
  81.                 }
  82.             }
  83.             Waitframe();
  84.         }
  85.     }
  86. }
  87.  
  88.  
  89. lweapon script lZigZagwhoneedssine
  90. {
  91.     void run(int dist, int speed)
  92.     {
  93.         int frame = 1;
  94.         int baseline;
  95.         dist = (dist < 1) ? 12 : dist;
  96.         speed = (speed < 1) ? 1 : speed;
  97.         //initial direction from baseline
  98.         bool initial = ( Rand(0,1) ) ? true : false;
  99.         switch(this->Dir)
  100.         {
  101.             case DIR_UP: baseline = this->X+(this->TileWidth*0.5); break;
  102.             case DIR_LEFT: baseline = this->Y+(this->TileHeight*0.5); break;
  103.             case DIR_DOWN: baseline = this->X+(this->TileWidth*0.5)+1; break;
  104.             case DIR_RIGHT: baseline = this->Y+(this->TileHeight*0.5)+1; break;
  105.                
  106.         }
  107.         while(this->isValid())
  108.         {
  109.             ++frame;
  110.             switch(this->Dir)
  111.             {
  112.                 case DIR_UP:
  113.                 case DIR_DOWN:
  114.                 {
  115.                     if ( initial )
  116.                     {
  117.                         if ( !(frame%speed) )
  118.                         {
  119.                             if ((baseline - this->X) < dist )
  120.                             {
  121.                                 --this->X;
  122.                             }
  123.                             else initial = !initial;
  124.                         }
  125.                     }
  126.                     else
  127.                     {
  128.                         if ( !(frame%speed) )
  129.                         {
  130.                             if ( (this->X - baseline) < dist )
  131.                             {
  132.                                 ++this->X;
  133.                             }
  134.                             else initial = !initial;
  135.                         }
  136.                     }
  137.                     break; 
  138.                 }
  139.                
  140.                 case DIR_LEFT:
  141.                 case DIR_RIGHT:
  142.                 {
  143.                     if ( initial )
  144.                     {
  145.                         if ( !(frame%speed) )
  146.                         {
  147.                             if ((baseline - this->Y) < dist )
  148.                             {
  149.                                 --this->Y;
  150.                             }
  151.                             else initial = !initial;
  152.                         }
  153.                     }
  154.                     else
  155.                     {
  156.                         if ( !(frame%speed) )
  157.                         {
  158.                             if ( (this->Y - baseline) < dist )
  159.                             {
  160.                                 ++this->Y;
  161.                             }
  162.                             else initial = !initial;
  163.                         }
  164.                     }
  165.                     break; 
  166.                 }
  167.             }
  168.             Waitframe();
  169.         }
  170.     }
  171. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement