Advertisement
ZoriaRPG

RandomHeader.zh

May 28th, 2017
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 30.14 KB | None | 0 0
  1. //-------------------------------//
  2. // The Random Header - v. 1.0    //
  3. //-------------------------------//
  4.  
  5. // -------- SETTINGS (edit these) -------- //
  6.  
  7. const int COMBO_AUTOWARP = 0; // Specify the first of four autowarp combos (A,B,C,D) for scriptWarp() and forceWarp()
  8.  
  9. // -------- GLOBAL VARIABLES AND CONSTANTS (do not edit!) -------- //
  10.  
  11. // Input constants for getItemInputSlot()
  12. const int INPUT_NONE = 0;
  13. const int INPUT_A = 1;
  14. const int INPUT_B = 2;
  15.  
  16. // New Combo Flag Variables
  17. const int CF_STEP = 200;
  18.  
  19. // -------- FUNCTIONS -------- //
  20.  
  21. // Function to move Link to an (X,Y) coordinate.
  22. // It pretty much combines Link->X and Link->Y into one command.
  23. void moveLink(int x, int y)
  24. {
  25.     Link->X = x;
  26.     Link->Y = y;
  27. }
  28.  
  29. // Initiate a preset sidewarp
  30. // 0 = A 1 = B 2 = C 3 = D
  31. // Note: Uses FFC 31.
  32. void forceWarp(int warpnum)
  33. {
  34.     ffc warp = Screen->LoadFFC(31);
  35.     warp->Data = COMBO_AUTOWARP + warpnum;
  36. }
  37.  
  38. // Sets then immediately initiates a side warp (0-3)
  39. // Don't do anything serious with the sidewarp you choose on the current screen.
  40. // Note: Uses FFC 31
  41. void scriptWarp(int dmap, int screen, int type, int warpnum)
  42. {
  43.     Screen->SetSideWarp(warpnum, screen, dmap, type);
  44.     ffc warp = Screen->LoadFFC(31);
  45.     warp->Data = COMBO_AUTOWARP + warpnum;
  46. }
  47. // This is an overload of the above that automatically chooses Sidewarp D.
  48. void scriptWarp(int dmap, int screen, int type)
  49. {
  50.     scriptWarp(dmap, screen, type, 3);
  51. }//!End scriptWarp
  52.  
  53. // A reorganization of Screen->SetSideWarp() because we are really picky
  54. void setSideWarp(int num, int dmap, int screen, int type)
  55. {
  56.     Screen->SetSideWarp(num, screen, dmap, type);
  57. }
  58.  
  59. // This function returns the slot an item is in
  60. int getItemInputSlot(int itemID)
  61. {
  62.     // If the item is in slot A
  63.     if(GetEquipmentA() == itemID)
  64.         return INPUT_A;
  65.     // Else if the item is in slot B
  66.     else if(GetEquipmentB() == itemID)
  67.         return INPUT_B;
  68.     // Else the item is not equipped
  69.     else
  70.         return INPUT_NONE;
  71. } //! End of int getItemInputSlot(int itemID)
  72.  
  73. // This function gathers the slot the item is in
  74. // and returns true or false for if that button
  75. // is currently being pressed by the player
  76. bool ifItemInput(int itemID)
  77. {
  78.     // Get the item slot the item is in
  79.     int itemSlot = getItemInputSlot(itemID);
  80.    
  81.     // If the player is pressing A and the item is in slot A
  82.     if(itemSlot == INPUT_A && Link->InputA)
  83.         return true;
  84.     // If the player is pressing B and the item is in slot B
  85.     else if(itemSlot == INPUT_B && Link->InputB)
  86.         return true;
  87.     // If the player is not pressing the item or if it is not equipped
  88.     else
  89.         return false;
  90. } //! End of bool ifItemInput(int itemID)
  91.  
  92. // This function gives Link an item.  If the function
  93. // is passed "true" for ifHoldUp, then it will force Link
  94. // to hold up the item.
  95. void giveItem(int itemID, bool ifHoldUp)
  96. {
  97.     // This creates a new item and places it over Link
  98.     item newItem = Screen->CreateItem(itemID);
  99.     newItem->HitWidth = 16; newItem->HitHeight = 16;
  100.     SetItemPickup(newItem, IP_HOLDUP, ifHoldUp);
  101.     newItem->X = Link->X; newItem->Y = Link->Y;
  102. } //! End of bool giveItem(int itemID, bool ifHoldUp)
  103.  
  104. // This function forces Link input.  Essentially,
  105. // it's an easier method of doing all of the Link->Input
  106. // variables and such.
  107. void setInput(bool up, bool down, bool left, bool right, bool a, bool b, bool l, bool r, bool map, bool start)
  108. {
  109.     Link->InputUp = up;
  110.     Link->InputDown = down;
  111.     Link->InputLeft = left;
  112.     Link->InputRight = right;
  113.     Link->InputA = a;
  114.     Link->InputB = b;
  115.     Link->InputL = l;
  116.     Link->InputR = r;
  117.     Link->InputMap = map;
  118.     Link->InputStart = start;
  119. }
  120.  
  121. // This creates an enemy at a random (non-solid) location on the screen
  122. void createEnemy(int enemyNum)
  123. {
  124.     // Essentially while you have not found a good place
  125.     while(true)
  126.     {
  127.         // Get a random location on the screen
  128.         int x = Rand(12) * 16 + 32;
  129.         int y = Rand(7) * 16 + 32;
  130.        
  131.         // Boolean for if the location is acceptable
  132.         bool ifLocationOkay = true;
  133.        
  134.         // Make sure the location isn't over Link
  135.         if(Distance(x, y, Link->X, Link->Y) < 16)
  136.             ifLocationOkay = false;
  137.            
  138.         // These next 5 things make sure that the location is not solid
  139.             if(Screen->isSolid(x, y))
  140.                 ifLocationOkay = false;
  141.                
  142.             if(Screen->isSolid(x+15, y))
  143.                 ifLocationOkay = false;
  144.                
  145.             if(Screen->isSolid(x, y+15))
  146.                 ifLocationOkay = false;
  147.                
  148.             if(Screen->isSolid(x+15, y+15))
  149.                 ifLocationOkay = false;
  150.                
  151.             if(Screen->isSolid(x+8, y+8))
  152.                 ifLocationOkay = false;
  153.         // End checking for solidity
  154.        
  155.         // Get the combo number and type of the location
  156.         int comboNum = ComboAt(x, y);
  157.         int comboType = Screen->ComboT[comboNum];
  158.        
  159.         // If the combo type is water or anything preventing enemies, the location is not okay
  160.         if(comboType == CT_WATER || comboType == CT_NOENEMY || comboType == CT_NOFLYZONE || comboType == CT_NOJUMPZONE)
  161.             ifLocationOkay = false;
  162.            
  163.         // Check if there is a no enemy combo flag on the location
  164.         if(Screen->ComboF[comboNum] == CF_NOENEMY)
  165.             ifLocationOkay = false;
  166.            
  167.         // If the location is acceptable, create the enemy there
  168.         if(ifLocationOkay)
  169.         {
  170.             CreateNPCAt(enemyNum, x, y);
  171.             break;
  172.         }
  173.     } //! End of while(true)
  174. } //! End of void createEnemy(int enemyNum)
  175.  
  176. //A shorthand way to get a combo cset on the current layer.
  177. //Layer 0 is the screen itself.
  178. int GetLayerComboC(int layer, int combo) {
  179.   if (layer==0)
  180.     return Screen->ComboC[combo];
  181.   else
  182.     return Game->GetComboCSet(Screen->LayerMap(layer), Screen->LayerScreen(layer), combo);
  183. }
  184.  
  185. //A shorthand way to set a combo cset on the current layer.
  186. //Layer 0 is the screen itself.
  187. void SetLayerComboC(int layer, int combo, int d) {
  188.   if (layer == 0)
  189.     Screen->ComboC[combo] = d;
  190.   else
  191.     Game->SetComboCSet(Screen->LayerMap(layer), Screen->LayerScreen(layer), combo, d);
  192. }
  193.  
  194. // Returns the opposite direction based upon Dir-> values
  195. // The oppositeDir in std.zh looked like it was for angles.
  196. int getOppositeDir(int dir)
  197. {
  198.     if(dir == DIR_UP)
  199.         return DIR_DOWN;
  200.     else if(dir == DIR_DOWN)
  201.         return DIR_UP;
  202.     else if(dir == DIR_LEFT)
  203.         return DIR_RIGHT;
  204.     else
  205.         return DIR_LEFT;
  206. }
  207.  
  208. // Function to see if an lweapon has hit a x, y location
  209. bool WeaponCollision(lweapon a, float x1, float y1, float x2, float y2)
  210. {
  211.     int ax = a->X + a->HitXOffset;
  212.     int ay = a->Y + a->HitYOffset;
  213.     return RectCollision(ax, ay, ax+a->HitWidth, ay+a->HitHeight, x1, y1, x2, y2);
  214. }
  215.  
  216. // Function to see if an eweapon has hit a x, y location
  217. bool WeaponCollision(eweapon a, float x1, float y1, float x2, float y2)
  218. {
  219.     int ax = a->X + a->HitXOffset;
  220.     int ay = a->Y + a->HitYOffset;
  221.     return RectCollision(ax, ay, ax+a->HitWidth, ay+a->HitHeight, x1, y1, x2, y2);
  222. }
  223.  
  224. // Function to return if an lweapon has hit a solid object
  225. bool WeaponSolidCollision(lweapon a)
  226. {
  227.     // Variables for the weapon edge locations
  228.    
  229.     bool ifMagic = a->ID == LW_MAGIC || a->ID == LW_REFMAGIC;
  230.    
  231.     // Grab the center of the item
  232.     int x = a->X + a->HitXOffset + a->HitWidth / 2;
  233.     int y = a->Y + a->HitYOffset + a->HitHeight / 2;
  234.    
  235.     // Loop through all locations and check if they're solid
  236.     if(Screen->isSolid(x, y))
  237.     {
  238.         // Grab the combo type of the location
  239.         int combo = Screen->ComboT[ComboAt(x, y)];
  240.            
  241.         if(combo == CT_HOOKSHOTONLY)
  242.             return false;
  243.         // If the wand item is magic
  244.         else if(ifMagic)
  245.         {
  246.             // If the combo type is NOT a mirror or prism, it hit a solid object
  247.             if(combo < 45 || combo > 49)
  248.                 return true;
  249.         }
  250.         // Else the spot is not magic, so it hit a solid object
  251.         else
  252.             return true;
  253.     }
  254.    
  255.     // The weapon did not hit a solid object
  256.     return false;
  257. }
  258.  
  259. // Function to return if an eweapon has hit a solid object
  260. bool WeaponSolidCollision(eweapon a)
  261. {
  262.     // Variables for the weapon edge locations
  263.    
  264.     bool ifMagic = a->ID == EW_MAGIC || a->ID == EW_WIND;
  265.    
  266.     // Grab the center of the item
  267.     int x = a->X + a->HitXOffset + a->HitWidth / 2;
  268.     int y = a->Y + a->HitYOffset + a->HitHeight / 2;
  269.    
  270.     // Loop through all locations and check if they're solid
  271.     if(Screen->isSolid(x, y))
  272.     {
  273.         // If the wand item is magic
  274.         if(ifMagic)
  275.         {
  276.             // Grab the combo type of the location
  277.             int combo = Screen->ComboT[ComboAt(x, y)];
  278.            
  279.             // If the combo type is NOT a mirror or prism, it hit a solid object
  280.             if(combo < 45 || combo > 49)
  281.                 return true;
  282.         }
  283.         // Else the spot is not magic, so it hit a solid object
  284.         else
  285.             return true;
  286.     }
  287.    
  288.     // The weapon did not hit a solid object
  289.     return false;
  290. }
  291.  
  292. // Function to get the direction clockwise to the given direction (only 4 main directions)
  293. int getClockwiseDir(int dir)
  294. {
  295.     return getClockwiseDir(dir, false);
  296. }
  297.  
  298. // Function to get the direction clockwise to the given direction
  299. int getClockwiseDir(int dir, bool eightDir)
  300. {
  301.     // If all 8 directions are needed
  302.     if(eightDir)
  303.     {
  304.         // Return the direction to the clockwise of the given direction
  305.         if(dir == DIR_UP)
  306.             return DIR_RIGHTUP;
  307.         else if(dir == DIR_RIGHTUP)
  308.             return DIR_RIGHT;
  309.         else if(dir == DIR_RIGHT)
  310.             return DIR_RIGHTDOWN;
  311.         else if(dir == DIR_RIGHTDOWN)
  312.             return DIR_DOWN;
  313.         else if(dir == DIR_DOWN)
  314.             return DIR_LEFTDOWN;
  315.         else if(dir == DIR_LEFTDOWN)
  316.             return DIR_LEFT;
  317.         else if(dir == DIR_LEFT)
  318.             return DIR_LEFTUP;
  319.         else
  320.             return DIR_UP;
  321.     }
  322.     // Else only the main 4 directions are needed
  323.     else
  324.     {
  325.         // Return the direction to the clockwise of the given direction
  326.         if(dir == DIR_UP)
  327.             return DIR_RIGHT;
  328.         else if(dir == DIR_RIGHT)
  329.             return DIR_DOWN;
  330.         else if(dir == DIR_DOWN)
  331.             return DIR_LEFT;
  332.         else
  333.             return DIR_UP;
  334.     }
  335. } //! End of int getClockwise(int dir, bool eightDir)
  336.  
  337. int getCounterClockwiseDir(int dir)
  338. {
  339.     return getCounterClockwiseDir(dir, false);
  340. }
  341.  
  342. // Function to get the direction clockwise to the given direction
  343. int getCounterClockwiseDir(int dir, bool eightDir)
  344. {
  345.     // If all 8 directions are needed
  346.     if(eightDir)
  347.     {
  348.         // Return the direction to the clockwise of the given direction
  349.         if(dir == DIR_UP)
  350.             return DIR_LEFTUP;
  351.         else if(dir == DIR_LEFTUP)
  352.             return DIR_LEFT;
  353.         else if(dir == DIR_LEFT)
  354.             return DIR_LEFTDOWN;
  355.         else if(dir == DIR_LEFTDOWN)
  356.             return DIR_DOWN;
  357.         else if(dir == DIR_DOWN)
  358.             return DIR_RIGHTDOWN;
  359.         else if(dir == DIR_RIGHTDOWN)
  360.             return DIR_RIGHT;
  361.         else if(dir == DIR_RIGHT)
  362.             return DIR_RIGHTUP;
  363.         else
  364.             return DIR_UP;
  365.     }
  366.     // Else only the main 4 directions are needed
  367.     else
  368.     {
  369.         // Return the direction to the clockwise of the given direction
  370.         if(dir == DIR_UP)
  371.             return DIR_LEFT;
  372.         else if(dir == DIR_LEFT)
  373.             return DIR_DOWN;
  374.         else if(dir == DIR_DOWN)
  375.             return DIR_RIGHT;
  376.         else
  377.             return DIR_UP;
  378.     }
  379. } //! End of int getClockwise(int dir, bool eightDir)
  380.  
  381. // This function checks if a location is walkable
  382. // As in, it's not solid and it's not water
  383. bool canWalk(float x, float y)
  384. {
  385.     // Check if the location is solid
  386.     if(Screen->isSolid(x, y))
  387.         return false;
  388.        
  389.     // Grab the combo locationj
  390.     int combo = ComboAt(x, y);
  391.    
  392.     // If the combo is water, return false
  393.     if(Screen->ComboT[combo] == CT_WATER)
  394.         return false;
  395.        
  396.     // Check if the location is out of bounds
  397.     if(x < 0 || x >= 256)
  398.         return false;
  399.        
  400.     if(y < 0 || y >= 176)
  401.         return false;
  402.        
  403.     // Else it's okay, so return true
  404.     return true;
  405. }
  406.  
  407. // Function to see if an x, y location is valid to walk on
  408. // x = x location
  409. // y = y location
  410. // fullTile = Whether a 16x16 area should be checked or the lower half (16x8) should be checked
  411.     // True = 16x16
  412.     // False = 16x8
  413. bool canWalk(float x, float y, bool fullTile)
  414. {
  415.     // If the full 16x16 grid needs to be checked
  416.     if(fullTile)
  417.     {
  418.         // Check all 4 corners of the grid and make sure they're not solid
  419.         if(canWalk(x, y) && canWalk(x + 8, y) && canWalk(x + 15, y)
  420.             && canWalk(x, y + 8) && canWalk(x + 15, y + 8)
  421.             && canWalk(x, y + 15) && canWalk(x + 8, y + 15) && canWalk(x + 15, y + 15))
  422.             // If they are not, return true
  423.             return true;
  424.         // Else one of the 4 corners of the grid is solid
  425.         else
  426.             // Return false
  427.             return false;
  428.     }
  429.     // Else the bottom half of the grid has to be checked
  430.     else
  431.     {
  432.         // Check all 4 corners of the grid and make sure they're not solid
  433.         if(canWalk(x, y + 8) && canWalk(x + 8, y + 8) && canWalk(x + 15, y + 8)
  434.             && canWalk(x, y + 15) && canWalk(x + 8, y + 15) && canWalk(x + 15, y + 15))
  435.             // If they are not, return truee
  436.             return true;
  437.         // Else one of the 4 corners of the bottom half of the grid is solid
  438.         else
  439.             return false;
  440.     }
  441. }
  442.  
  443. // Same as above, but checks a full rectangle
  444. bool canWalk(float x1, float y1, float x2, float y2)
  445. {
  446.     // Ensure (x1,y1) is the top left and (x2,y2) which
  447.     if(x1 > x2)
  448.     {
  449.         int temp = x1;
  450.         x1 = x2;
  451.         x2 = temp;
  452.     }
  453.    
  454.     if(y1 > y2)
  455.     {
  456.         int temp = y1;
  457.         y1 = y2;
  458.         y2 = temp;
  459.     }
  460.    
  461.     // Go through each
  462.     for(int x = x1; x < x2; x += 8)
  463.     {
  464.         if(!canWalk(x, y1))
  465.             return false;
  466.         if(!canWalk(x, y2))
  467.             return false;
  468.     }
  469.    
  470.     for(int y = y1; y < y2; y += 8)
  471.     {
  472.         if(!canWalk(x1, y))
  473.             return false;
  474.         if(!canWalk(x2, y))
  475.             return false;
  476.     }
  477.    
  478.     if(!canWalk(x2, y2))
  479.         return false;
  480.    
  481.     return true;
  482. }
  483.  
  484. // This is an extension of isWalkable to check for no enemy combos and flags
  485. // Set flying to true to ignore solidity and water, but also check for a no fly zone
  486. bool canWalkEnemy(float x, float y, bool flying)
  487. {
  488.     // Get the combo number and type of the location
  489.     int comboNum = ComboAt(x, y);
  490.     int comboType = Screen->ComboT[comboNum];
  491.    
  492.     // If the combo type is a no enemy combo
  493.     if(comboType == CT_NOENEMY)
  494.         return false;
  495.        
  496.     // If it is NOT a flying enemy and the combo is a no ground enemy zone
  497.     if(!flying && comboType == CT_NOGROUNDENEMY)
  498.         return false;
  499.        
  500.     // If it is a flying enemy and the combo is a no fly zone
  501.     if(flying && comboType == CT_NOFLYZONE)
  502.         return false;
  503.        
  504.     // Check if there is a no enemy combo flag on the location
  505.     if(Screen->ComboF[comboNum] == CF_NOENEMY)
  506.         return false;
  507.        
  508.     if(x < 0 || y < 0 || x > 256 || y > 168)
  509.         return false;
  510.        
  511.     if(flying)
  512.         return true;
  513.     else
  514.         return canWalk(x, y);
  515. }
  516.  
  517. // Function to see if an x, y location is valid to walk on
  518. // x = x location
  519. // y = y location
  520. // fullTile = Whether a 16x16 area should be checked or the lower half (16x8) should be checked
  521.     // True = 16x16
  522.     // False = 16x8
  523. bool canWalkEnemy(float x, float y, bool flying, bool fullTile)
  524. {
  525.     // If the full 16x16 grid needs to be checked
  526.     if(fullTile)
  527.     {
  528.         // Check all 4 corners of the grid and make sure they're not solid
  529.         if(canWalkEnemy(x, y, flying) && canWalkEnemy(x + 8, y, flying) && canWalkEnemy(x + 15, y, flying)
  530.             && canWalkEnemy(x, y + 8, flying) && canWalkEnemy(x + 15, y + 8, flying)
  531.             && canWalkEnemy(x, y + 15, flying) && canWalkEnemy(x + 8, y + 15, flying) && canWalkEnemy(x + 15, y + 15, flying))
  532.             // If they are not, return true
  533.             return true;
  534.         // Else one of the 4 corners of the grid is solid
  535.         else
  536.             // Return false
  537.             return false;
  538.     }
  539.     // Else the bottom half of the grid has to be checked
  540.     else
  541.     {
  542.         // Check all 4 corners of the grid and make sure they're not solid
  543.         if(canWalkEnemy(x, y + 8, flying) && canWalkEnemy(x + 8, y + 8, flying) && canWalkEnemy(x + 15, y + 8, flying)
  544.             && canWalkEnemy(x, y + 15, flying) && canWalkEnemy(x + 8, y + 15, flying) && canWalkEnemy(x + 15, y + 15, flying))
  545.             // If they are not, return truee
  546.             return true;
  547.         // Else one of the 4 corners of the bottom half of the grid is solid
  548.         else
  549.             return false;
  550.     }
  551. }
  552.  
  553. // Same as above, but checks a full rectangle
  554. bool canWalk(float x1, float y1, float x2, float y2, bool flying)
  555. {
  556.     // Ensure (x1,y1) is the top left and (x2,y2) which
  557.     if(x1 > x2)
  558.     {
  559.         int temp = x1;
  560.         x1 = x2;
  561.         x2 = temp;
  562.     }
  563.    
  564.     if(y1 > y2)
  565.     {
  566.         int temp = y1;
  567.         y1 = y2;
  568.         y2 = temp;
  569.     }
  570.    
  571.     // Go through each
  572.     for(int x = x1; x < x2; x += 8)
  573.     {
  574.         if(canWalkEnemy(x, y1, flying))
  575.             return false;
  576.         if(canWalkEnemy(x, y2, flying))
  577.             return false;
  578.     }
  579.    
  580.     for(int y = y1; y < y2; y += 8)
  581.     {
  582.         if(canWalkEnemy(x1, y, flying))
  583.             return false;
  584.         if(canWalkEnemy(x2, y, flying))
  585.             return false;
  586.     }
  587.    
  588.     if(canWalkEnemy(x2, y2, flying))
  589.         return false;
  590.    
  591.     return true;
  592. }
  593.  
  594. // Function to see if Link has hit a square
  595. bool LinkCollision(int x1, int y1, int x2, int y2)
  596. {
  597.     // Grab the bottom right of Link
  598.     int ax = Link->X + Link->HitXOffset;
  599.     int ay = Link->Y + Link->HitYOffset;
  600.  
  601.     // Check the collision
  602.     return RectCollision(ax, ay, ax+Link->HitWidth, ay+Link->HitHeight, x1, y1, x2, y2);
  603. }
  604.  
  605. // Quickly edit the appearance of a ffc
  606. //      Object is a reference to the ffc to edit.
  607. void editFFC(ffc object, int x, int y, int combo, int cset)
  608. {
  609.     object->X = x;
  610.     object->Y = y;
  611.     object->Data = combo;
  612.     object->CSet = cset;
  613. }
  614.  
  615. // Overload of the above that just edits the position
  616. void editFFC(ffc object, int x, int y)
  617. {
  618.     editFFC(object, x, y, object->Data, object->CSet);
  619. }
  620.  
  621. // Basic function to handle secret flags.  Returns true if a secret flag is activated
  622. // These are scripted mimics of the ZQuest secret combo flags, but have a bit more flexibility for scripting.
  623. bool checkCFlag(int x, int y, int x2, int y2, int flag)
  624. {
  625.     // Flag for regular arrows
  626.     if(flag == CF_ARROW)
  627.     {
  628.         // Loop through all weapons
  629.         for(int i = 1; i <= Screen->NumLWeapons(); i++)
  630.         {
  631.             lweapon current = Screen->LoadLWeapon(i);
  632.            
  633.             // Check if it's the right weapon
  634.             if(current->ID == LW_ARROW)
  635.             {
  636.                 // Check if there was a collision
  637.                 if(WeaponCollision(current, x, y, x2, y2))
  638.                 {
  639.                     current->DeadState = WDS_DEAD;
  640.                     return true;
  641.                 }
  642.             }
  643.         }
  644.        
  645.         // Else it didn't hit
  646.         return false;
  647.     }
  648.     // Flag for the bombs
  649.     else if(flag == CF_BOMB)
  650.     {
  651.         // Loop through all weapons
  652.         for(int i = 1; i <= Screen->NumLWeapons(); i++)
  653.         {
  654.             lweapon current = Screen->LoadLWeapon(i);
  655.            
  656.             // Check if it's the right weapon
  657.             if(current->ID == LW_BOMBBLAST)
  658.             {
  659.                 // Check if there was a collision
  660.                 if(WeaponCollision(current, x, y, x2, y2))
  661.                 {
  662.                     return true;
  663.                 }
  664.             }
  665.         }
  666.        
  667.         // Else it didn't hit
  668.         return false;
  669.     }
  670.     // Flag for the wand's magic
  671.     else if(flag == CF_WANDMAGIC)
  672.     {
  673.         // Loop through all weapons
  674.         for(int i = 1; i <= Screen->NumLWeapons(); i++)
  675.         {
  676.             lweapon current = Screen->LoadLWeapon(i);
  677.            
  678.             // Check if it's the right weapon
  679.             if(current->ID == LW_MAGIC)
  680.             {
  681.                 // Check if there was a collision
  682.                 if(WeaponCollision(current, x, y, x2, y2))
  683.                 {
  684.                     current->DeadState = WDS_DEAD;
  685.                     return true;
  686.                 }
  687.             }
  688.         }
  689.        
  690.         // Else it didn't hit
  691.         return false;
  692.     }
  693.     // Flag for a boomerang
  694.     else if(flag == CF_BRANG1 || flag == CF_BRANG2 || flag == CF_BRANG3)
  695.     {
  696.         // Loop through all weapons
  697.         for(int i = 1; i <= Screen->NumLWeapons(); i++)
  698.         {
  699.             lweapon current = Screen->LoadLWeapon(i);
  700.            
  701.             // Check if it's the right weapon
  702.             if(current->ID == LW_BRANG)
  703.             {
  704.                 // Check if there was a collision
  705.                 if(WeaponCollision(current, x, y, x2, y2))
  706.                 {
  707.                     current->DeadState = WDS_BOUNCE;
  708.                     return true;
  709.                 }
  710.             }
  711.         }
  712.        
  713.         // Else it didn't hit
  714.         return false;
  715.     }
  716.     // Flag for a sword
  717.     else if(flag == CF_SWORD1 || flag == CF_SWORD2 || flag == CF_SWORD3)
  718.     {
  719.         // Loop through all weapons
  720.         for(int i = 1; i <= Screen->NumLWeapons(); i++)
  721.         {
  722.             lweapon current = Screen->LoadLWeapon(i);
  723.            
  724.             // Check if it's the right weapon
  725.             if(current->ID == LW_SWORD)
  726.             {
  727.                 // Check if there was a collision
  728.                 if(WeaponCollision(current, x, y, x2, y2))
  729.                     return true;
  730.             }
  731.         }
  732.        
  733.         // Else it didn't hit
  734.         return false;
  735.     }
  736.     // Flag for a hookshot
  737.     else if(flag == CF_HOOKSHOT)
  738.     {
  739.         // Loop through all weapons
  740.         for(int i = 1; i <= Screen->NumLWeapons(); i++)
  741.         {
  742.             lweapon current = Screen->LoadLWeapon(i);
  743.            
  744.             // Check if it's the right weapon
  745.             if(current->ID == LW_HOOKSHOT)
  746.             {
  747.                 // Check if there was a collision
  748.                 if(WeaponCollision(current, x, y, x2, y2))
  749.                 {
  750.                     current->DeadState = WDS_BOUNCE;
  751.                     return true;
  752.                 }
  753.             }
  754.         }
  755.        
  756.         // Else it didn't hit
  757.         return false;
  758.     }
  759.     // Flag for a hammer
  760.     else if(flag == CF_HAMMER)
  761.     {
  762.         // Loop through all weapons
  763.         for(int i = 1; i <= Screen->NumLWeapons(); i++)
  764.         {
  765.             lweapon current = Screen->LoadLWeapon(i);
  766.            
  767.             // Check if it's the right weapon
  768.             if(current->ID == LW_HAMMER)
  769.             {
  770.                 // Check if there was a collision
  771.                 if(WeaponCollision(current, x, y, x2, y2))
  772.                 {
  773.                     current->DeadState = WDS_DEAD;
  774.                     return true;
  775.                 }
  776.             }
  777.         }
  778.        
  779.         // Else it didn't hit
  780.         return false;
  781.     }
  782.     // Flag for any weapon
  783.     else if(flag == CF_STRIKE)
  784.     {
  785.         // Loop through all weapons
  786.         for(int i = 1; i <= Screen->NumLWeapons(); i++)
  787.         {
  788.             lweapon current = Screen->LoadLWeapon(i);
  789.            
  790.             if(current->ID == LW_SPARKLE) continue;
  791.             if(current->ID == LW_FIRESPARKLE) continue;
  792.             if(current->ID == LW_BOMB) continue;
  793.             if(current->ID == LW_SBOMB) continue;
  794.             if(current->ID == LW_BAIT) continue;
  795.             if(current->DeadState > 0 && current->ID != LW_BRANG) continue;
  796.             if(!current->CollDetection) continue;
  797.            
  798.             if(WeaponCollision(current, x, y, x2, y2))
  799.             {
  800.                 if(current->ID == LW_BRANG || current->ID == LW_HOOKSHOT)
  801.                     current->DeadState = WDS_BOUNCE;
  802.                 else
  803.                     current->DeadState = WDS_DEAD;
  804.                 return true;
  805.             }
  806.         }
  807.        
  808.         // Else it didn't hit
  809.         return false;
  810.     }
  811.     // Flag for a Link step switch
  812.     else if(flag == CF_STEP)
  813.     {
  814.         x = Floor(x / 16) * 16;
  815.         y = Floor(y / 16) * 16;
  816.        
  817.         // If the distance from the switch to Link is <= 4 pixels
  818.         if(Distance(Link->X, Link->Y, x, y) <= 6)
  819.             return true;
  820.     }
  821.    
  822.     return false;
  823. }//! End of bool checkCFlag(int x, int y, int x2, int y2, int flag)
  824.  
  825. // Function for a 16x16 secret flag
  826. bool checkCFlag(int x, int y, int flag)
  827. {
  828.     // Check the given 16x16 span for the flag
  829.     return checkCFlag(x+2, y+2, x+13, y+13, flag);
  830. }
  831.  
  832. // Function for a FFC secret flag
  833. bool checkCFlag(ffc object, int flag)
  834. {
  835.     // Check the span of the ffc for the flag
  836.     return checkCFlag(object->X+2, object->Y+2, object->X+object->EffectWidth-3, object->Y+object->EffectHeight-3, flag);
  837. }
  838.  
  839. // Function for an eweapon secret flag
  840. bool checkCFlag(eweapon object, int flag)
  841. {
  842.     // Check the span of the eweapon for the flag
  843.     int ax = object->X + object->HitXOffset;
  844.     int ay = object->Y + object->HitYOffset;
  845.  
  846.     return checkCFlag(ax, ay, ax+object->HitWidth, ay+object->HitHeight, flag);
  847. }
  848.  
  849. // Function for an npc secret flag
  850. bool checkCFlag(npc object, int flag)
  851. {
  852.     // Check the span of the eweapon for the flag
  853.     int ax = object->X + object->HitXOffset;
  854.     int ay = object->Y + object->HitYOffset;
  855.  
  856.     return checkCFlag(ax+2, ay+2, ax+object->HitWidth-3, ay+object->HitHeight-3, flag);
  857. }
  858.  
  859. // Function to wait until a secret flag happens in a rectangle
  860. void waitUntilCFlag(int x1, int y1, int x2, int y2, int flag)
  861. {
  862.     while(!checkCFlag(x1, y1, x2, y2, flag))
  863.         Waitframe();
  864. }
  865.  
  866. // Function to wait until a secret flag happens in a 16x16 location
  867. void waitUntilCFlag(int x, int y, int flag)
  868. {
  869.     while(!checkCFlag(x, y, flag))
  870.         Waitframe();
  871. }
  872.  
  873. // Function to wait until a secret flag happens on a FFC
  874. void waitUntilCFlag(ffc object, int flag)
  875. {
  876.     while(!checkCFlag(object, flag))
  877.         Waitframe();
  878. }
  879.  
  880. // Normal CFlag function on a rectangle that will wait until one happens, then activate secrets
  881. void CFlag(int x1, int y1, int x2, int y2, int flag, bool SFX)
  882. {
  883.     // Wait until the location was hit
  884.     waitUntilCFlag(x1, y1, x2, y2, flag);
  885.    
  886.     // Activate secrets
  887.     Screen->TriggerSecrets();
  888.    
  889.     // If requested, play the normal secret SFX
  890.     if(SFX)
  891.         Game->PlaySound(SFX_SECRET);
  892. }
  893.  
  894. // Normal CFlag function on combo that will wait until one happens, then activate secrets
  895. void CFlag(int x, int y, int flag, bool SFX)
  896. {
  897.     // Wait until the location was hit
  898.     waitUntilCFlag(x, y, flag);
  899.    
  900.     // Activate secrets
  901.     Screen->TriggerSecrets();
  902.    
  903.     // If requested, play the normal secret SFX
  904.     if(SFX)
  905.         Game->PlaySound(SFX_SECRET);
  906. }
  907.  
  908. // Normal CFlag function on combo that will wait until one happens, then activate secrets
  909. void CFlag(ffc object, int flag, bool SFX)
  910. {
  911.     // Wait until the location was hit
  912.     waitUntilCFlag(object, flag);
  913.    
  914.     // Activate secrets
  915.     Screen->TriggerSecrets();
  916.    
  917.     // If requested, play the normal secret SFX
  918.     if(SFX)
  919.         Game->PlaySound(SFX_SECRET);
  920. }
  921.  
  922. // Checks if the given direction is the only direction being pressed.
  923. bool isOnlyDirection(int direction)
  924. {
  925.     int directions = 0;
  926.     // Add up the directions with an offset of 1 (so that Up registers as something)
  927.     if(Link->InputUp)
  928.         directions += DIR_UP + 1;
  929.     if(Link->InputDown)
  930.         directions += DIR_DOWN + 1;
  931.     if(Link->InputLeft)
  932.         directions += DIR_LEFT + 1;
  933.     if(Link->InputRight)
  934.         directions += DIR_RIGHT + 1;
  935.        
  936.     // Remove offset and do final check...
  937.     if(directions - 1 == direction)
  938.         return true;
  939.     else
  940.         return false;
  941. }//!End isOnlyDirection
  942.  
  943. // Function to move a FFC in the direction of a radian angle
  944. void ffcAngularMovement(ffc theffc, float angle, int speed)
  945. {
  946.     // First find out the x and y unit circle values
  947.     int unitX = RadianCos(angle);
  948.     int unitY = RadianSin(angle);
  949.    
  950.     // Set the ffc's Vx and Vy to speed * unit circle value
  951.     theffc->Vx = unitX * speed;
  952.     theffc->Vy = unitY * speed;
  953. }
  954.  
  955. // Function to tell if Link is about to leave the screen
  956. bool leavingScreen()
  957. {
  958.     if(Link->X <= 1 && Link->InputLeft)
  959.         return true;
  960.     else if(Link->Y <= 1 && Link->InputUp)
  961.         return true;
  962.     else if(Link->X >= 239 && Link->InputRight)
  963.         return true;
  964.     else if(Link->Y >= 159 && Link->InputDown)
  965.         return true;
  966.     else
  967.         return false;
  968. }
  969.  
  970. // Function to see if a box has collided with a line
  971. bool lineBoxCollision(int lineX1, int lineY1, int lineX2, int lineY2, int boxX1, int boxY1, int boxX2, int boxY2, int boxBorder)
  972. {
  973.     // Shrink down the box for the border
  974.     boxX1 += boxBorder; boxY1 += boxBorder;
  975.     boxX2 -= boxBorder; boxY2 -= boxBorder;
  976.    
  977.     // If the line isn't vertical
  978.     if(lineX2!=lineX1)
  979.     {
  980.        
  981.         float i0 = (boxX1 - lineX1)/(lineX2-lineX1);
  982.         float i1 = (boxX2 - lineX1)/(lineX2-lineX1);
  983.        
  984.         float yA = lineY1 + i0*(lineY2-lineY1);
  985.         float yB = lineY1 + i1*(lineY2-lineY1);
  986.        
  987.        
  988.         if(Max(boxX1, boxX2) >= Min(lineX1, lineX2) && Min(boxX1, boxX2) <= Max(lineX1, lineX2) &&
  989.             Max(boxY1, boxY2) >= Min(lineY1, lineY2) && Min(boxY1, boxY2) <= Max(lineY1, lineY2))
  990.         {
  991.             if(Min(boxY1, boxY2) > Max(yA, yB) || Max(boxY1, boxY2) < Min(yA, yB))
  992.                 return false;
  993.             else
  994.                 return true;
  995.         }
  996.         else
  997.             return false;
  998.     }
  999.     // If the line is vertical
  1000.     else if(lineX1 >= boxX1 && lineX1 <= boxX2)
  1001.     {
  1002.         // Basically we need to find the top and bottom y values of the line to check for intersection
  1003.         float lineYMin = lineY1;
  1004.         float lineYMax = lineY2;
  1005.        
  1006.         if(lineYMin > lineYMax)
  1007.         {
  1008.             lineYMin = lineY2;
  1009.             lineYMax = lineY1;
  1010.         }
  1011.        
  1012.         // If either point intersects
  1013.         if((boxY1 >= lineYMin && boxY1 <= lineYMax) || (boxY2 >= lineYMin && boxY2 <= lineYMax))
  1014.             return true;
  1015.     }
  1016.    
  1017.     return false;
  1018. } //! End of lineBoxCollision
  1019.  
  1020. // Function to get the difference between two angles
  1021. float angleDifference(float angle1, float angle2)
  1022. {
  1023.     // Get the difference between the two angles
  1024.     float dif = angle2 - angle1;
  1025.    
  1026.     // Compensate for the difference being outside of normal bounds
  1027.     if(dif >= PI)
  1028.         dif -= 2 * PI;
  1029.     else if(dif <= -1 * PI)
  1030.         dif += 2 * PI;
  1031.        
  1032.     return dif;
  1033. }
  1034.  
  1035. // Function to get the difference between two angles
  1036. float angleDifferenceDegrees(float angle1, float angle2)
  1037. {
  1038.     RadtoDeg(angleDifference(DegtoRad(angle1), DegtoRad(angle2)));
  1039. }
  1040.  
  1041. // Function to tell if a location is inside the screen
  1042. bool inScreen(int x, int y)
  1043. {
  1044.     return (x >= 0 && x < 256 && y >= 0 && y < 168);
  1045. }
  1046.  
  1047. // This function draws a particular string with a border around it
  1048. void drawStringBordered(int layer, int x, int y, int font, int textColor, int borderColor, int alignment, int text, int opacity)
  1049. {
  1050.     Screen->DrawString(layer, x-1, y-1, font, borderColor, -1, alignment, text, opacity);
  1051.     Screen->DrawString(layer, x, y-1, font, borderColor, -1, alignment, text, opacity);
  1052.     Screen->DrawString(layer, x+1, y-1, font, borderColor, -1, alignment, text, opacity);
  1053.     Screen->DrawString(layer, x-1, y, font, borderColor, -1, alignment, text, opacity);
  1054.     Screen->DrawString(layer, x+1, y, font, borderColor, -1, alignment, text, opacity);
  1055.     Screen->DrawString(layer, x-1, y+1, font, borderColor, -1, alignment, text, opacity);
  1056.     Screen->DrawString(layer, x, y+1, font, borderColor, -1, alignment, text, opacity);
  1057.     Screen->DrawString(layer, x+1, y+1, font, borderColor, -1, alignment, text, opacity);
  1058.     Screen->DrawString(layer, x, y, font, textColor, -1, alignment, text, opacity);
  1059. }
  1060.  
  1061. void drawIntegerBordered(int layer, int x, int y, int font, int textColor, int borderColor, int number, int opacity)
  1062. {
  1063.     Screen->DrawInteger(layer, x-1, y-1, font, borderColor, -1, -1, -1, number, 0, opacity);
  1064.     Screen->DrawInteger(layer, x, y-1, font, borderColor, -1, -1, -1, number, 0, opacity);
  1065.     Screen->DrawInteger(layer, x+1, y-1, font, borderColor, -1, -1, -1, number, 0, opacity);
  1066.     Screen->DrawInteger(layer, x-1, y, font, borderColor, -1, -1, -1, number, 0, opacity);
  1067.     Screen->DrawInteger(layer, x+1, y, font, borderColor, -1, -1, -1, number, 0, opacity);
  1068.     Screen->DrawInteger(layer, x-1, y+1, font, borderColor, -1, -1, -1, number, 0, opacity);
  1069.     Screen->DrawInteger(layer, x, y+1, font, borderColor, -1, -1, -1, number, 0, opacity);
  1070.     Screen->DrawInteger(layer, x+1, y+1, font, borderColor, -1, -1, -1, number, 0, opacity);
  1071.     Screen->DrawInteger(layer, x, y, font, textColor, -1, -1, -1, number, 0, opacity);
  1072. }
  1073.  
  1074. void drawCharacterBordered(int layer, int x, int y, int font, int textColor, int borderColor, int glyph, int opacity){
  1075.     Screen->DrawCharacter(layer, x-1, y-1, font, borderColor, -1, -1, -1, glyph, opacity);
  1076.     Screen->DrawCharacter(layer, x, y-1, font, borderColor, -1, -1, -1, glyph, opacity);
  1077.     Screen->DrawCharacter(layer, x+1, y-1, font, borderColor, -1, -1, -1, glyph, opacity);
  1078.     Screen->DrawCharacter(layer, x-1, y, font, borderColor, -1, -1, -1, glyph, opacity);
  1079.     Screen->DrawCharacter(layer, x+1, y, font, borderColor, -1, -1, -1, glyph, opacity);
  1080.     Screen->DrawCharacter(layer, x-1, y+1, font, borderColor, -1, -1, -1, glyph, opacity);
  1081.     Screen->DrawCharacter(layer, x, y+1, font, borderColor, -1, -1, -1, glyph, opacity);
  1082.     Screen->DrawCharacter(layer, x+1, y+1, font, borderColor, -1, -1, -1, glyph, opacity);
  1083.     Screen->DrawCharacter(layer, x, y, font, textColor, -1, -1, -1, glyph, opacity);
  1084. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement