ZoriaRPG

ZScript Boomerang and Hookshot Key and Item Pickup

Apr 15th, 2021 (edited)
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.21 KB | None | 0 0
  1. /// v5
  2. /// Functions to grab, or drag keys, or items in lists back to Link; or give instantly to Link,
  3. /// when touched by a hookshot, or boomerang:
  4.  
  5. /// Default function uses only keys, and level keys as objects to collect with these weapons.
  6. /// Other versions accept args to do any of the following:
  7.  
  8. /// Return the item matching coordinates of lweapon each frame.
  9. /// ( May be unsafe? Will item return to its position if Link doesn;t take it? it ...should. )
  10. /// Give the item directly to Link (instantaneous)
  11. /// Hold the item overhead (bool holdUpItem).
  12. /// Accept an array (int list) listing other itemd to give when a brang or hookshot touches them; obeys the same physics defined by bool instantaneous, and bool holdUpItem.
  13.  
  14. const int SFX_HOLDTOHAND = 20;
  15.  
  16. //Drags keys back to Link, if touched by a boomerang, or hookshot.  Call every frame before Waitdraw();
  17.  
  18. void BrangKey_Drag(int holdUpItem)
  19. {
  20.     holdUpItem = Clamp(holdUpItem,0,2);
  21.     for ( int q = Screen->NumLWeapons(); q > 0; --q )
  22.     {
  23.         lweapon w = Screen->LoadLWeapon(q);
  24.         if ( w->ID == LW_BRANG || w->ID == LW_HOOKSHOT )
  25.         {
  26.             for ( int e = Screen->NumItems(); e > 0; --e )
  27.             {
  28.                 item a = Screen->LoadItem(e);
  29.                 if ( Collision (w,a) )
  30.                 {
  31.                     if ( a->ID == I_KEY ||  a->ID == I_LEVELKEY)
  32.                     {
  33.                         w->DeadState = WDS_BOUNCE; //Starts return anim for boomerang, or hookshot.
  34.                         //Bouncing must precede item movement.
  35.                         if ( a->isValid() )
  36.                         {
  37.                             a->Z = 0;
  38.                             a->X = w->X;
  39.                             a->Y = w->Y; //Drag the item back to Link.
  40.                             if ( holdUpItem )
  41.                             {
  42.                                 if ( a->Y == Link->Y )
  43.                                 {
  44.                                     if ( a->X == Link->X )
  45.                                     {
  46.                                         Link->Action = LA_HOLD1LAND+(holdUpItem-1); //Hold item over head.
  47.                                         Game->PlaySound(SFX_HOLDTOHAND);
  48.                                         Link->HeldItem = a->ID;
  49.                                     }
  50.                                 }
  51.                             }
  52.                            
  53.                         }
  54.                     }
  55.                    
  56.                     else continue;
  57.                 }
  58.             }
  59.         }
  60.     }
  61. }
  62.  
  63. //instantly gives Link the item.
  64. void BrangKey_Instant(int holdUpItem)
  65. {
  66.     holdUpItem = Clamp(holdUpItem,0,2);
  67.     for ( int q = Screen->NumLWeapons(); q > 0; --q )
  68.     {
  69.         lweapon w = Screen->LoadLWeapon(q);
  70.         if ( w->ID == LW_BRANG || w->ID == LW_HOOKSHOT )
  71.         {
  72.             for ( int e = Screen->NumItems(); e > 0; --e )
  73.             {
  74.                 item a = Screen->LoadItem(e);
  75.                 if ( Collision (w,a) )
  76.                 {
  77.                     if ( a->ID == I_KEY || a->ID == I_LEVELKEY )
  78.                     {
  79.                         w->DeadState = WDS_BOUNCE; //Starts return anim for boomerang, or hookshot.
  80.                         //Bouncing must precede item movement.
  81.                         if ( a->isValid() )
  82.                         {
  83.                             a->Z = Link->Z;
  84.                             a->X = Link->X;
  85.                             a->Y = Link->Y; //Drag the item back to Link.
  86.                             if ( holdUpItem )
  87.                             {
  88.                                 Link->Action = LA_HOLD1LAND+(holdUpItem-1); //Hold item over head.
  89.                                 Game->PlaySound(SFX_HOLDTOHAND);
  90.                                 Link->HeldItem = a->ID;
  91.                             }
  92.                         }
  93.                     }
  94.                    
  95.                     else continue;
  96.                 }
  97.             }
  98.         }
  99.     }
  100. }
  101.  
  102.  
  103.  
  104.  
  105. //Drags keys, or anything on specified array of items back to link if touched by a boomerang, or hookshot.
  106. void BrangPickup_Drag(int list, int holdUpItem)
  107. {
  108.     holdUpItem = Clamp(holdUpItem,0,2);
  109.     for ( int q = Screen->NumLWeapons(); q > 0; --q )
  110.     {
  111.         lweapon w = Screen->LoadLWeapon(q);
  112.         if ( w->ID == LW_BRANG || w->ID == LW_HOOKSHOT )
  113.         {
  114.             for ( int e = Screen->NumItems(); e > 0; --e )
  115.             {
  116.                 item a = Screen->LoadItem(e);
  117.                 if ( Collision (w,a) )
  118.                 {
  119.                     for ( int r = SizeOfArray(list); r >=0; --r )
  120.                     {
  121.                         if ( a->ID == list[r] )
  122.                         {
  123.                             w->DeadState = WDS_BOUNCE; //Starts return anim for boomerang, or hookshot.
  124.                             //Bouncing must precede item movement.
  125.                             if ( a->isValid() )
  126.                             {
  127.                                 a->Z = 0;
  128.                                 a->X = w->X;
  129.                                 a->Y = w->Y;
  130.                                 if ( holdUpItem )
  131.                                 {
  132.                                     if ( a->Y == Link->Y )
  133.                                     {
  134.                                         if ( a->X == Link->X )
  135.                                         {
  136.                                             Link->Action = LA_HOLD1LAND+(holdUpItem-1); //Hold item over head.
  137.                                             Game->PlaySound(SFX_HOLDTOHAND);
  138.                                             Link->HeldItem = a->ID;
  139.                                         }
  140.                                     }
  141.                                 }
  142.                             }
  143.                         }
  144.                     }
  145.                 }
  146.             }
  147.         }
  148.     }
  149. }
  150.  
  151.  
  152.  
  153. //Drags keys, or anything on specified array of items back to link if touched by a boomerang, or hookshot.
  154. void BrangPickup_Instant(int list, int holdUpItem)
  155. {
  156.     holdUpItem = Clamp(holdUpItem,0,2);
  157.     for ( int q = Screen->NumLWeapons(); q > 0; --q )
  158.     {
  159.         lweapon w = Screen->LoadLWeapon(q);
  160.         if ( w->ID == LW_BRANG || w->ID == LW_HOOKSHOT )
  161.         {
  162.             for ( int e = Screen->NumItems(); e > 0; --e )
  163.             {
  164.                 item a = Screen->LoadItem(e);
  165.                 if ( Collision (w,a) )
  166.                 {
  167.                     for ( int r = SizeOfArray(list); r >= 0; --r )
  168.                     {
  169.                         if ( a->ID == list[r] )
  170.                         {
  171.                             w->DeadState = WDS_BOUNCE; //Starts return anim for boomerang, or hookshot.
  172.                             //Bouncing must precede item movement.
  173.                             if ( a->isValid() )
  174.                             {
  175.                                 a->Z = 0;
  176.                                 a->X = Link->X;
  177.                                 a->Y = Link->Y; //Give the item directly to Link
  178.                                 if ( holdUpItem )
  179.                                 {
  180.                                     Link->Action = LA_HOLD1LAND+(holdUpItem-1); //Hold item over head.
  181.                                     Game->PlaySound(SFX_HOLDTOHAND);
  182.                                     Link->HeldItem = a->ID;
  183.                                 }
  184.                             }
  185.                         }
  186.                     }
  187.                 }
  188.             }
  189.         }
  190.     }
  191. }
  192.  
  193. //! TEST GLOBAL ACTIVE
  194. global script test_brangkey5
  195. {
  196.     void run()
  197.     {
  198.         while(1)
  199.         {
  200.             BrangKey_Instant(1);
  201.             Waitdraw();
  202.             Waitframe();
  203.         }
  204.     }
  205. }
  206.  
  207. // SCREEN SPECIFIC FFCs
  208. ffc script test_brangkey5_ffc
  209. {
  210.     void run()
  211.     {
  212.         while(1)
  213.         {
  214.             BrangKey_Instant(1);
  215.             Waitframe();
  216.         }
  217.     }
  218. }
  219.  
  220.  
  221. ////////////////////
  222. /// Item Pick-Up ///
  223. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
  224. /// This script creates an FFC, that gives Link a key, and clears the FFC if the FFC is touched by the      ///
  225. /// boomerang, or the hookshot. This is useful if you want the boomerang/hookshot to pick up keys as in Z3, ///
  226. /// without also allowing them to pick up other special items (per quest rules for Z3 boomerang.            ///
  227. ///                                                                                                         ///
  228. /// Note: The pick-up is instantaneous, and does not need to wait for Link to touch the item.               ///
  229. //////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  230. /// RUN ON SCREEN INIT!                                                                                    ///
  231. /// D0: Set to 0 to give a normal key, or 1 to give a key specific to the level that the player is inside. ///
  232. ///     Set to a negative number to give  specific item, OTHER THAN a key.                                 ///
  233. /// D1: Set this to the Sound Effect to play on giving the player the item, from Quest->Audio->SFX Data.   ///
  234. /// D2: Set this to the 1 to hold the item with one hand, 2 to hold with 2 hands.                          ///
  235. /// D3: Screen->D[register] to use.                                                                        ///
  236. //////////////////////////////////////////////////////////////////////////////////////////////////////////////
  237.  
  238. ffc script Z3_Key_Pickup
  239. {
  240.     void run(int level, int SFX, int holdUpItem, int reg)
  241.     {
  242.    
  243.         holdUpItem = Clamp(holdUpItem,0,2);
  244.         reg = Clamp(reg,0,7);
  245.         bool waiting = true;
  246.         while(waiting)
  247.         {
  248.             if ( Screen->D[reg] )
  249.             {   // If the FFC has already run on the screen
  250.                 this->Data = 0; //Remove sprite
  251.                 return; //Quit
  252.             }
  253.          
  254.             else
  255.             {
  256.                 for (int q = Screen->NumLWeapons(); q > 0; --q )
  257.                 {   // Loop through all LWeapons on screen.
  258.                     lweapon lw = Screen->LoadLWeapon(q);
  259.                     if ( lw->ID == LW_BRANG || lw->ID == LW_HOOKSHOT )
  260.                     {
  261.                         if (lw->CollDetection && Collision(this, lw))      // If the LWeapon is touching us.
  262.                         {
  263.                        
  264.                             waiting = false;
  265.                             if ( !level )
  266.                             {
  267.                                 ++Game->Counter[CR_KEYS];
  268.                                 Game->PlaySound(SFX);
  269.                                 Screen->D[reg] = 1;
  270.                                 if ( holdUpItem )
  271.                                 {
  272.                                     Link->Action = LA_HOLD1LAND+(holdUpItem-1); //Hold item over head.
  273.                                     Game->PlaySound(SFX_HOLDTOHAND);
  274.                                     Link->HeldItem = I_KEY;
  275.                                 }
  276.                                 this->Data = 0; //Remove sprite
  277.                                 return; //Quit
  278.                             }
  279.                             else if ( level > 0 )
  280.                             {
  281.                                 item levelKeyGiven = Screen->CreateItem(I_LEVELKEY);
  282.                                 levelKeyGiven->X = Link->X;
  283.                                 levelKeyGiven->Y = Link->Y;
  284.                                 levelKeyGiven->Z = Link->Z;
  285.                                 Game->PlaySound(SFX);
  286.                                 Screen->D[reg] = 1;
  287.                                 if ( holdUpItem )
  288.                                 {
  289.                                     Link->Action = LA_HOLD1LAND+(holdUpItem-1); //Hold item over head.
  290.                                     Game->PlaySound(SFX_HOLDTOHAND);
  291.                                     Link->HeldItem = I_LEVELKEY;
  292.                                 }
  293.                                 this->Data = 0; //Remove sprite
  294.                                 return; //Quit
  295.                             }
  296.                             else if ( level < 0 )
  297.                             {
  298.                                 item levelKeyGiven = Screen->CreateItem(-level);
  299.                                 if ( holdUpItem )
  300.                                 {
  301.                                     levelKeyGiven->Pickup |= IP_HOLDUP;
  302.                                 }
  303.                                 levelKeyGiven->X = Link->X;
  304.                                 levelKeyGiven->Y = Link->Y;
  305.                                 levelKeyGiven->Z = Link->Z;
  306.                                 Game->PlaySound(SFX);
  307.                                 Screen->D[reg] = 1;
  308.                                 this->Data = 0; //Remove sprite
  309.                                 return; //Quit
  310.                             }
  311.                         }
  312.                     }
  313.                 }
  314.                      
  315.                 Waitframe();
  316.             }
  317.         }
  318.     }
  319. }
  320.  
Add Comment
Please, Sign In to add comment