Advertisement
ZoriaRPG

Pushblock.zs

Nov 7th, 2018
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.97 KB | None | 0 0
  1.  
  2. script typedef ffc namespace;
  3. typedef const int define;
  4. typedef const int config;
  5.  
  6. namespace script blocks
  7. {
  8.     define MAX = 32;
  9.     define X = 0;
  10.     define Y = 1;
  11.     define COMBO = 3;
  12.     define CSET = 4;
  13.     define OPACITY = 5;
  14.     define DIR = 6;
  15.     define LAST = 7;
  16.     define CurNum = LAST*MAX; //EXTRA 1
  17.     define PushClock = CurNum+1; //EXTRA 2
  18.     define LastLinkX = CurNum+2; //EXTRA 2
  19.     define LastLinkY = CurNum+3; //EXTRA 2
  20.    
  21.     define LAYER = 4;
  22.    
  23.     define EXTRA = 2; //
  24.    
  25.     define ABOVE = -1;
  26.     define BELOW = 1;
  27.     define LEFT = 0.1;
  28.     define RIGHT = -0.1;
  29.    
  30.     //call at the end of every frame
  31.     void storeLink()
  32.     {
  33.         positions[LastLinkX] = Link->X;
  34.         positions[LastLinkY] = Link->Y;
  35.     }
  36.    
  37.     int positions[MAX*LAST+EXTRA];
  38.     void run(){} //automatic
  39.    
  40.     int create(int x, int y, int cmb, int cset)
  41.     {
  42.         int id = ++positions[CurNum];
  43.         if ( id >= MAX ) return -1;
  44.         positions[id*LAST] = x;
  45.         positions[id*LAST+Y] = y;
  46.         positions[id*LAST+DIR] = -1;
  47.         positions[id*LAST+COMBO] = combo;
  48.         positions[id*LAST+CSET] = cset;
  49.         positions[id*LAST+OPACITY] = 128;
  50.         return id;
  51.     }
  52.     void draw()
  53.     {
  54.         int pos[MAX*5]; int w;
  55.         for ( int q = 0; q < CurNum; += LAST ) //load combo information to an array
  56.         {
  57.             pos[w] = positions[q];
  58.             pos[w+1] = positions[q+1];
  59.             pos[w+2] = positions[q+2];
  60.             pos[w+3] = positions[q+3];
  61.             pos[w+4] = positions[q+4];
  62.             w += 5;
  63.         }
  64.         Screen->DrawCombos(LAYER, pos);
  65.     }
  66.    
  67.     //0 not touchimg, otherwise, return id +1
  68.     int touching()
  69.     {
  70.         for ( int q = 0; q < positions[CurNum]; q += LAST )
  71.         {
  72.             //check relative Link coordinates
  73.             switch(Link->Dir)
  74.             {
  75.                 case DIR_UP:
  76.                 {
  77.                     if ( Below(positions[id*LAST+Y]) )
  78.                     {
  79.                         if ( DistY(positions[id*LAST+Y]) <= 8 ) //overlap
  80.                         {
  81.                             if ( DistX(positions[id*LAST] <= 16 )
  82.                             {
  83.                                 return ((q/LAST)+1)*BELOW;
  84.                             }
  85.                             return 0;
  86.                         }
  87.                         return 0;
  88.                     }
  89.                     return 0;
  90.                    
  91.                 }
  92.                 case DIR_DOWN:
  93.                 {
  94.                     if ( Above(positions[id*LAST+Y]) )
  95.                     {
  96.                         if ( DistY(positions[id*LAST+Y]) <= 16 ) //overlap
  97.                         {
  98.                             if ( DistX(positions[id*LAST] <= 16 )
  99.                             {
  100.                                 ((q/LAST)+1)*ABOVE;
  101.                             }
  102.                             return 0;
  103.                         }
  104.                         return 0;
  105.                     }
  106.                     return 0;
  107.                    
  108.                 }
  109.                 case DIR_LEFT:
  110.                 {
  111.                     if ( LeftOf(positions[id*LAST]) )
  112.                     {
  113.                         if ( DistY(positions[id*LAST+Y]) <= 16 ) //overlap
  114.                         {
  115.                             if ( DistX(positions[id*LAST] <= 16 )
  116.                             {
  117.                                 ((q/LAST)+1)*LEFT;
  118.                             }
  119.                             return 0;
  120.                         }
  121.                         return 0;
  122.                     }
  123.                     return 0;
  124.                    
  125.                 }
  126.                 case DIR_RIGHT:
  127.                 {
  128.                     if ( RightOf(positions[id*LAST]) )
  129.                     {
  130.                         if ( DistY(positions[id*LAST+Y]) <= 8 ) //overlap
  131.                         {
  132.                             if ( DistX(positions[id*LAST] <= 16 )
  133.                             {
  134.                                 ((q/LAST)+1)*RIGHT;
  135.                             }
  136.                             return 0;
  137.                         }
  138.                         return 0;
  139.                     }
  140.                     return 0;
  141.                    
  142.                 }
  143.                 default: return 0;
  144.             }
  145.            
  146.     }
  147.        
  148.     dwfine PushTHRESHOLD = 28; //frames
  149.     bool pushing()
  150.     {
  151.         int id = touching();
  152.         if (!id) return false; //abort
  153.         int pushdir;
  154.         if ( id < 0 )
  155.         {
  156.             if ( !(id << 0) ) //decimal
  157.             {
  158.                 pushdir = DIR_LEFT;
  159.             }
  160.             else pushdir = DIR_DOWN;
  161.         }
  162.         else
  163.         {
  164.             if ( !(id << 0) ) //decimal
  165.             {
  166.                 pushdir = DIR_RIGHT;
  167.             }
  168.             else pushdir = DIR_UP;
  169.         }
  170.         switch(pushdir)
  171.         {
  172.             case DIR_LEFT:
  173.             {
  174.                 if ( Input->Hold[CB_LEFT] )
  175.                 {
  176.                     positions[id*LAST+DIR] = pushdir;
  177.                     ++positions[PushClock];
  178.                     Link->X = positions[LastLinkX]; //Hold Link in place
  179.                     //Don't allow knockback through a block
  180.                     if ( Link->HitDir == DIR_LEFT )
  181.                     {
  182.                         Link->HitDir = -1;
  183.                     }
  184.                     break;
  185.                 }
  186.                 else if ( Input->Press[CB_LEFT] )
  187.                 {
  188.                     Link->X = positions[LastLinkX]; //Hold Link in place
  189.                     //Don't allow knockback through a block
  190.                     if ( Link->HitDir == DIR_LEFT )
  191.                     {
  192.                         Link->HitDir = -1;
  193.                     }
  194.                     break;
  195.                 }
  196.                 else
  197.                 {
  198.                     //Don't allow knockback through a block
  199.                     if ( Link->HitDir == DIR_LEFT )
  200.                     {
  201.                         Link->HitDir = -1;
  202.                     }
  203.                     positions[id*LAST+DIR] = -1;
  204.                     positions[PushClock] = 0;
  205.                     break;
  206.                 }
  207.             }
  208.             case DIR_RIGHT:
  209.             {
  210.                 if ( Input->Hold[CB_RIGHT] )
  211.                 {
  212.                     positions[id*LAST+DIR] = pushdir;
  213.                     ++positions[PushClock];
  214.                     Link->X = positions[LastLinkX]; //Hold Link in place
  215.                     //Don't allow knockback through a block
  216.                     if ( Link->HitDir == DIR_RIGHT )
  217.                     {
  218.                         Link->HitDir = -1;
  219.                     }
  220.                     break;
  221.                 }
  222.                 else if ( Input->Press[CB_RIGHT] )
  223.                 {
  224.                     Link->X = positions[LastLinkX]; //Hold Link in place
  225.                     //Don't allow knockback through a block
  226.                     if ( Link->HitDir == DIR_RIGHT )
  227.                     {
  228.                         Link->HitDir = -1;
  229.                     }
  230.                     break;
  231.                 }
  232.                 else
  233.                 {
  234.                     //Don't allow knockback through a block
  235.                     if ( Link->HitDir == DIR_RIGHT )
  236.                     {
  237.                         Link->HitDir = -1;
  238.                     }
  239.                     positions[id*LAST+DIR] = -1;
  240.                     positions[PushClock] = 0;
  241.                     break;
  242.                 }
  243.             }
  244.             case DIR_DOWN:
  245.             {
  246.                 if ( Input->Hold[CB_DOWN] )
  247.                 {
  248.                     positions[id*LAST+DIR] = pushdir;
  249.                     ++positions[PushClock];
  250.                     Link->X = positions[LastLinkX]; //Hold Link in place
  251.                     //Don't allow knockback through a block
  252.                     if ( Link->HitDir == DIR_DOWN )
  253.                     {
  254.                         Link->HitDir = -1;
  255.                     }
  256.                     break;
  257.                 }
  258.                 else if ( Input->Press[CB_DOWN] )
  259.                 {
  260.                     Link->X = positions[LastLinkX]; //Hold Link in place
  261.                     //Don't allow knockback through a block
  262.                     if ( Link->HitDir == DIR_DOWN )
  263.                     {
  264.                         Link->HitDir = -1;
  265.                     }
  266.                     break;
  267.                 }
  268.                 else
  269.                 {
  270.                     //Don't allow knockback through a block
  271.                     if ( Link->HitDir == DIR_DOWN )
  272.                     {
  273.                         Link->HitDir = -1;
  274.                     }
  275.                     positions[id*LAST+DIR] = -1;
  276.                     positions[PushClock] = 0;
  277.                     break;
  278.                 }
  279.             }
  280.             case DIR_UP:
  281.             {
  282.                 if ( Input->Hold[CB_UP] )
  283.                 {
  284.                     positions[id*LAST+DIR] = pushdir;
  285.                     ++positions[PushClock];
  286.                     Link->X = positions[LastLinkX]; //Hold Link in place
  287.                     //Don't allow knockback through a block
  288.                     if ( Link->HitDir == DIR_UP )
  289.                     {
  290.                         Link->HitDir = -1;
  291.                     }
  292.                     break;
  293.                 }
  294.                 else if ( Input->Press[CB_UP] )
  295.                 {
  296.                     Link->X = positions[LastLinkX]; //Hold Link in place
  297.                     //Don't allow knockback through a block
  298.                     if ( Link->HitDir == DIR_UP )
  299.                     {
  300.                         Link->HitDir = -1;
  301.                     }
  302.                     break;
  303.                 }
  304.                 else
  305.                 {
  306.                     //Don't allow knockback through a block
  307.                     if ( Link->HitDir == DIR_UP )
  308.                     {
  309.                         Link->HitDir = -1;
  310.                     }
  311.                     positions[id*LAST+DIR] = -1;
  312.                     positions[PushClock] = 0;
  313.                     break;
  314.                 }
  315.             }
  316.        
  317.         }
  318.         if ( positions[PushClock] > 0 )
  319.         {
  320.             if ( positions[PushClock] > PushTHRESHOLD )
  321.             {
  322.                 return push(id); //we push the block
  323.             }
  324.             else
  325.             {
  326.                 return linkpush(); //we do the pushing anim
  327.             }
  328.         }
  329.         else return false; //no
  330.     }
  331.    
  332.     config TRIGGER = CT_SCRIPT_10;
  333.     config TRIGGER_SENS = 6;
  334.    
  335.     //pixel-precise triggers with very flexible sensitivity
  336.     bool on_trigger(int id)
  337.     {
  338.         int cx = positions[id*LAST];
  339.         int cy = positions[id*LAST+Y];
  340.         for ( int q = TRIGGER_SENS*-1; q <= TRIGGER_SENS; ++q ) //13*13 checks? Bleah.
  341.         {
  342.             for ( int w = TRIGGER_SENS*-1; w <= TRIGGER_SENS; ++w )
  343.             {
  344.                 if ( Screen->ComboT[ComboAt((cx+8-q), (cy-8+w))] == TRIGGER ) return true;
  345.             }
  346.         }
  347.         return false;
  348.     }
  349.    
  350.     config PushSFX = 63;
  351.     config PushPixels = 8; //half tghe size of PushBlockAnimDur
  352.     config PushBlockAnimDur = 16; //frames during which the block and Link move forward
  353.    
  354.     //movement of the block
  355.     bool push(id)
  356.     {
  357.        
  358.         //determine block direction
  359.         int timer = 0;
  360.         if (!timer) ////play the push sound
  361.             //while(timer)
  362.         //change to apecial Link sprite using ScriptTile
  363.         //every 2 frames, move the block forward one pixel until it has moved PushPixels pixels
  364.         //waitframe
  365.        
  366.         return true; //when done
  367.        
  368.        
  369.     }
  370.    
  371.     bool linkpush()
  372.     {
  373.         //while positions[PushClock] < PushTHRESHOLD
  374.         //hold Link in place
  375.         //use Link->\scriptTile to create a custom sprite inside
  376.         //switch(Link->Dir)
  377.        
  378.         return true; //when done
  379.     }
  380.            
  381.  
  382. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement