Advertisement
ZoriaRPG

Basic Combo Collision

Jan 17th, 2018
451
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.12 KB | None | 0 0
  1. /// Combo Collision with Efficiency Improvements -Z
  2.  
  3. //Check for collision between ffc 'f' and a combo at location 'cmb'.
  4. bool Collision(int cmb, ffc f)
  5. {
  6.     int cx = ComboX(cmb);
  7.     int cy = ComboY(cmb);
  8.     return RectCollision( cx, cy, cx+16, cy+16, f->X, f->Y, f->X+f->EffectWidth, f->Y+f->EffectHeight );
  9. }
  10.  
  11. //Check for collision between lweapon 'l' and a combo at location 'cmb'.
  12. bool Collision(int cmb, lweapon l)
  13. {
  14.     int cx = ComboX(cmb);
  15.     int cy = ComboY(cmb);
  16.     return RectCollision( cx, cy, cx+16, cy+16, (l->X)+l->HitXOffset,  (l->Y)+l->HitYOffset+l, (l->X)+l->HitXOffset+l->HitWidth,  (l->Y)+l->HitYOffset+l->HitHeight);
  17. }
  18.  
  19. //Check for collision between eweapon 'l' and a combo at location 'cmb'.
  20. bool Collision(int cmb, eweapon l)
  21. {
  22.     int cx = ComboX(cmb);
  23.     int cy = ComboY(cmb);
  24.     return RectCollision( cx, cy, cx+16, cy+16, (l->X)+l->HitXOffset,  (l->Y)+l->HitYOffset+l, (l->X)+l->HitXOffset+l->HitWidth,  (l->Y)+l->HitYOffset+l->HitHeight);
  25. }
  26.  
  27.  
  28. //Check for collision between item 'l' and a combo at location 'cmb'.
  29. bool Collision(int cmb, item l)
  30. {
  31.     int cx = ComboX(cmb);
  32.     int cy = ComboY(cmb);
  33.     return RectCollision( cx, cy, cx+16, cy+16, (l->X)+l->HitXOffset,  (l->Y)+l->HitYOffset+l, (l->X)+l->HitXOffset+l->HitWidth,  (l->Y)+l->HitYOffset+l->HitHeight);
  34. }
  35.  
  36. //Check for collision between npc 'l' and a combo at location 'cmb'.
  37. bool Collision(int cmb, npc l)
  38. {
  39.     int cx = ComboX(cmb);
  40.     int cy = ComboY(cmb);
  41.     return RectCollision( cx, cy, cx+16, cy+16, (l->X)+l->HitXOffset,  (l->Y)+l->HitYOffset+l, (l->X)+l->HitXOffset+l->HitWidth,  (l->Y)+l->HitYOffset+l->HitHeight);
  42. }
  43.  
  44. //Check for collision between Link and a combo at location 'cmb'.
  45. bool Collision(int cmb)
  46. {
  47.     int cx = ComboX(cmb); int cy = ComboY(cmb);
  48.     if ( RectCollision( cx, cy, cx+16, cy+16, Link->X+Link->HitXOffset, Link->Y+Link->HitYOffset, Link->X+Link->HitXOffset+Link->HitWidth, Link->Y+Link->HitYOffset+Link->HitWidth) ) return true;
  49.     else if ( (Distance(CenterLinkX(), CenterLinkY(), cx+8, cy+8) < 8) ) return true;
  50.     return false;
  51. }
  52.  
  53.  
  54. //Constants for AdjacentCombo()
  55. //This now uses DIR_* constants, so you can do AdjacentCombo(cmb,Link->Dir)
  56. //Returns the Nth combo index of a combo based on a central point, and a direction.
  57. //For example, combo 22 + COMBO_UPRIGHT returns '7',
  58. //as combo 7 is to the upper-right of combo 22.
  59. int AdjacentCombo(int cmb, int dir)
  60. {
  61.     int combooffsets[13]={-0x10, 0x10, -1, 1, -0x11, -0x0F, 0x0F, 0x11};
  62.     if ( cmb % 16 == 0 ) combooffsets[9] = 1;
  63.     if ( (cmb & 15) == 1 ) combooffsets[10] = 1;
  64.     if ( cmb < 0x10 ) combooffsets[11] = 1; //if it's the top row
  65.     if ( cmb > 0x9F ) combooffsets[12] = 1; //if it's on the bottom row
  66.     if ( combooffsets[9] && ( dir == DIR_LEFT || dir == DIR_LEFTUP || dir == DIR_LEFTDOWN ) ) return 0; //if the left columb
  67.     if ( combooffsets[10] && ( dir == DIR_RIGHT || dir == DIR_RIGHTUP || dir == DIR_RIGHTDOWN ) ) return 0; //if the right column
  68.     if ( combooffsets[11] && ( dir == DIR_UP || dir == DIR_RIGHTUP || dir == DIR_LEFTUP ) ) return 0; //if the top row
  69.     if ( combooffsets[12] && ( dir == DIR_DOWN || dir == DIR_RIGHTDOWN || dir == DIR_LEFTDOWN ) ) return 0; //if the bottom row
  70.     else if ( cmb >= 0 && cmb <= 176 ) return cmb + combooffsets[dir];
  71.     else return -1;
  72. }  
  73.        
  74.  
  75.     ///March 2016
  76.    
  77. //! One of the following two AdjancentCombo(dist) functions is older, and bugged, and IDR which. I think it is the second one. -Z
  78.  
  79.  
  80. //Constants for AdjacentCombo()
  81. //This now uses DIR_* constants, so you can do AdjacentCombo(cmb,Link->Dir)
  82. //Returns the Nth combo index of a combo based on a central point, and a direction.
  83. //For example, combo 22 + COMBO_UPRIGHT returns '7',
  84. //as combo 7 is to the upper-right of combo 22.
  85. //dist is the number of combos away from cmb
  86.  
  87. //! rETURNS THE COMBO id OF A COMBO BASED ON A LOCATION, IN A GIVEM DIRECTION, n COMBOS AWAY.
  88.  
  89. int AdjacentCombo(int cmb, int dir, int dist){
  90.     int combooffsets[13]={-0x10, 0x10, -1, 1, -0x11, -0x0F, 0x0F, 0x11};
  91.     if ( cmb % 16 == 0 ) combooffsets[9] = 1;
  92.     if ( (cmb & 15) == 1 ) combooffsets[10] = 1;
  93.     if ( cmb < 0x10 ) combooffsets[11] = 1; //if it's the top row
  94.     if ( cmb > 0x9F ) combooffsets[12] = 1; //if it's on the bottom row
  95.     if ( combooffsets[9] && ( dir == CMB_LEFT || dir == CMB_UPLEFT || dir == CMB_DOWNLEFT || dir == CMB_LEFTUP ) ) return 0; //if the left columb
  96.     if ( combooffsets[10] && ( dir == CMB_RIGHT || dir == CMB_UPRIGHT || dir == CMB_DOWNRIGHT ) ) return 0; //if the right column
  97.     if ( combooffsets[11] && ( dir == CMB_UP || dir == CMB_UPRIGHT || dir == CMB_UPLEFT || dir == CMB_LEFTUP ) ) return 0; //if the top row
  98.     if ( combooffsets[12] && ( dir == CMB_DOWN || dir == CMB_DOWNRIGHT || dir == CMB_DOWNLEFT ) ) return 0; //if the bottom row
  99.     else if ( cmb >= 0 && cmb <= 176 ) {
  100.         int cmbs[2];//needs a for loop to ensure that t returns the most valid combo
  101.        
  102.         for ( cmbs[1] = 0; cmbs[1] < dist; cmbs[1]++ ) {
  103.             cmbs[0] = cmb;
  104.             cmb += (combooffsets[dir]);
  105.             if ( cmb < 0 || cmb > 175 ) return cmbs[0];
  106.             if ( cmb % 16 == 0 ) combooffsets[9] = 1;
  107.             if ( (cmb & 15) == 1 ) combooffsets[10] = 1;
  108.             if ( cmb < 0x10 ) combooffsets[11] = 1; //if it's the top row
  109.             if ( cmb > 0x9F ) combooffsets[12] = 1; //if it's on the bottom row
  110.             if ( combooffsets[9] && ( dir == CMB_LEFT || dir == CMB_UPLEFT || dir == CMB_DOWNLEFT || dir == CMB_LEFTUP ) ) return cmbs[0]; //if the left columb
  111.             if ( combooffsets[10] && ( dir == CMB_RIGHT || dir == CMB_UPRIGHT || dir == CMB_DOWNRIGHT ) ) return cmbs[0]; //if the right column
  112.             if ( combooffsets[11] && ( dir == CMB_UP || dir == CMB_UPRIGHT || dir == CMB_UPLEFT || dir == CMB_LEFTUP ) ) return cmbs[0]; //if the top row
  113.             if ( combooffsets[12] && ( dir == CMB_DOWN || dir == CMB_DOWNRIGHT || dir == CMB_DOWNLEFT ) ) return cmbs[0]; //if the bottom row
  114.            
  115.         }
  116.         return cmb;
  117.     }
  118.     else return -1;
  119. }  
  120.  
  121. int AdjacentCombo2(int cmb, int dir, int dist)
  122. {
  123.     int combooffsets[13]={-0x10, 0x10, -1, 1, -0x11, -0x0F, 0x0F, 0x11};
  124.     if ( cmb % 16 == 0 ) combooffsets[9] = 1;
  125.     if ( (cmb & 15) == 1 ) combooffsets[10] = 1;
  126.     if ( cmb < 0x10 ) combooffsets[11] = 1; //if it's the top row
  127.     if ( cmb > 0x9F ) combooffsets[12] = 1; //if it's on the bottom row
  128.     if ( combooffsets[9] && ( dir == DIR_LEFT || dir == DIR_LEFTUP || dir == DIR_LEFTDOWN ) ) {
  129.         return 0; //if the left columb
  130.     }
  131.     if ( combooffsets[10] && ( dir == DIR_RIGHT || dir == DIR_RIGHTUP || dir == DIR_RIGHTDOWN ) ) {
  132.         return 0; //if the left columb
  133.     }
  134.     if ( combooffsets[11] && ( dir == DIR_UP || dir == DIR_RIGHTUP || dir == DIR_LEFTUP ) ) {
  135.         return 0; //if the left columb
  136.     }
  137.     if ( combooffsets[12] && ( dir == DIR_DOWN || dir == DIR_RIGHTDOWN || dir == DIR_LEFTDOWN ) ) {
  138.         return 0; //if the left columb
  139.     }
  140.     int cmbs[2];//needs a for loop to ensure that t returns the most valid combo
  141.        
  142.     if ( cmb >= 0 && cmb < 176 )
  143.     {
  144.         cmbs[0] = cmb;
  145.         for ( cmbs[1] = 0; cmbs[1] < dist; ++cmbs[1] ) {
  146.             if ( dir == DIR_LEFT && ComboX(cmbs[0]) == 0 ) return cmbs[0];
  147.             if ( dir == DIR_RIGHT && ComboX(cmbs[0]) == 240 ) return cmbs[0];
  148.             if ( dir == DIR_UP && ComboY(cmbs[0]) == 0 ) return cmbs[0];
  149.             if ( dir == DIR_DOWN && ComboY(cmbs[0]) == 160 ) return cmbs[0];
  150.             cmbs[0] += (combooffsets[dir]);
  151.             if ( cmbs[0] < 0 || cmbs[0] > 175 ) return cmbs[0]; //Did I mean -1 here? -Z
  152.             if ( cmb % 16 == 0 ) combooffsets[9] = 1;
  153.             if ( (cmb & 15) == 1 ) combooffsets[10] = 1;
  154.             if ( cmb < 0x10 ) combooffsets[11] = 1; //if it's the top row
  155.             if ( cmb > 0x9F ) combooffsets[12] = 1; //if it's on the bottom row
  156.             if ( combooffsets[9] && ( dir == DIR_LEFT || dir == DIR_LEFTUP || dir == DIR_LEFTDOWN || dir == DIR_LEFTUP ) ) return cmbs[0]; //if the left columb
  157.             if ( combooffsets[10] && ( dir == DIR_RIGHT || dir == DIR_RIGHTUP || dir == DIR_RIGHTDOWN ) ) return cmbs[0]; //if the right column
  158.             if ( combooffsets[11] && ( dir == DIR_UP || dir == DIR_RIGHTUP || dir == DIR_LEFTUP || dir == DIR_LEFTUP ) ) return cmbs[0]; //if the top row
  159.             if ( combooffsets[12] && ( dir == DIR_DOWN || dir == DIR_RIGHTDOWN || dir == DIR_LEFTDOWN ) ) return cmbs[0]; //if the bottom row
  160.         }
  161.         return cmbs[0];
  162.     }
  163.     else return -1;
  164. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement