Advertisement
ZoriaRPG

Zig-Zag Weapon Script v0.2

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