Advertisement
ZoriaRPG

ZScript: Z3 Style Magic Mirror (v0.1.3, Compiles)

Nov 22nd, 2016
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 12.88 KB | None | 0 0
  1. ///////////////////////
  2. /// Z3 Magic Mirror ///
  3. /// v0.1.4          ///
  4. /// 22-Nov-2016     ///
  5. /// By: ZoriaRPG    ///
  6. ///////////////////////////////////////
  7. /// Partial Rewrite of the Original ///
  8. /// WarpFunctions.zh b1.1 from 2014 ///
  9. /// originally made by request for  ///
  10. /// Obderhode and used in the quest ///
  11. /// 'The Three Whistles'            ///
  12. ///////////////////////////////////////
  13.  
  14. //! To-Do
  15. //! Add in freeze flas and ghost suspension
  16.  
  17. /// Global Array
  18. int Mirror[214747];
  19.  
  20. const int TEST_MIRROR_SPARKLE = 1;
  21. const int MIRROR_SPARKLE_BEFORE_WAITDRAW = 1;
  22.  
  23. //Options
  24. const int WARP_RETURNS_ON_INJURY        = 1;
  25. const int MIRROR_RETURNS_TO_DUNGEON_ENTRANCE    = 1; //This requires placing a warp return square on dungeon entrance screens.
  26.  
  27. const int POST_WARP_LINK_IS_INVINCIBLE      = 1;     //If se tto '1', Link->CollDetection will be disabled for a number of
  28.                         //frames equal to:
  29.  
  30. const int WARP_INVULNERABILITY_FRAMES       = 90; //Number of frames that Link is invulnerable after warping.
  31.  
  32. //!! Caution: This may conflict with other items that grant invulnerability!
  33.  
  34.  
  35. ///Constants for Array Indices of Mirror[]
  36.  
  37. const int IS_WARPING        = 0;
  38. const int AFTER_WARP        = 1;
  39. const int RETURN_WARP       = 2;
  40. const int AFTER_RETURN_WARP     = 3;
  41.  
  42. const int WARP_SPARKLE          = 10;
  43. const int WARP_SPARKLE_DMAP         = 11;
  44. const int WARP_SPARKLE_SCREEN       = 12;
  45. const int WARP_SPARKLE_X        = 13;
  46. const int WARP_SPARKLE_Y        = 14;
  47. const int WARP_SPARKLE_RETURN_DMAP  = 15;
  48.  
  49. const int WARP_LINK_X           = 20;
  50. const int WARP_LINK_Y           = 21;
  51. const int WARP_LINK_Z           = 22;
  52. const int WARP_LINK_HP          = 23;
  53. const int WARP_LINK_TEMP_INVULNERABILITY = 24;
  54.  
  55. const int MIRROR_SPARKLE_COMBO_FRAME = 30; //Mirror array index
  56.  
  57.  
  58. //Settings
  59.  
  60. //Sounds
  61. const int SFX_WARP_ERROR    = 0;
  62. const int SFX_WARP      = 16;
  63. const int SFX_WARP_DUNGEON  = 16;
  64.  
  65. const int WARP_WAVE_DUR     = 100; //Duration of warp wavy animation (overworld)
  66. const int WARP_WAVE_DUR_DUNGEON = 100; //Duration of warp wavy animation (inside dungeons)
  67.  
  68. const int WARP_DUR      = 60;
  69. const int WARP_CIRCLE_COLOUR    = 5;
  70. const int POST_WARP_DELAY   = 15;
  71.  
  72.  
  73. //Mirror Sparkle Settings
  74. const int CMB_WARP_SPARKLE      = 0; // COmbo of sparkle or other warp return effect.
  75.  
  76. const int MIRROR_SPARKLE_COMBO      = 1000;
  77. const int MIRROR_SPARKLE_COMBO_LAYER    = 2;
  78. const int MIRROR_SPARKLE_COMBO_W    = 1;
  79. const int MIRROR_SPARKLE_COMBO_H    = 1;
  80. const int MIRROR_SPARKLE_COMBO_CSET     = 0;
  81. const int MIRROR_SPARKLE_COMBO_XSCALE   = -1;
  82. const int MIRROR_SPARKLE_COMBO_YSCALE   = -1;
  83. const int MIRROR_SPARKLE_COMBO_RX   = 0;
  84. const int MIRROR_SPARKLE_COMBO_RY   = 0;
  85. const int MIRROR_SPARKLE_COMBO_RANGLE   = 0;
  86.  
  87. const int MIRROR_SPARKLE_COMBO_FLIP     = 0;
  88. const int MIRROR_SPARKLE_COMBO_OPACITY  = 64;
  89.  
  90. const int MIRROR_SPARKLE_COMBO_NUM_FRAMES = 4;
  91. const int MIRROR_SPARKLE_COMBO_INIT_FRAME = 1;
  92.  
  93.  
  94.  
  95.  
  96. //Accessors
  97. int IsWarping(){ return Mirror[IS_WARPING]; }
  98. void IsWarping(bool state){ if ( state ) Mirror[IS_WARPING] = 1; else Mirror[IS_WARPING] = 0; }
  99.  
  100. int AfterWarp(){ return Mirror[AFTER_WARP]; }
  101. void AfterWarp(bool state){ if ( state ) Mirror[AFTER_WARP] = 1; else Mirror[AFTER_WARP] = 0; }
  102.  
  103. int IsReturnWarping(){ return Mirror[RETURN_WARP]; }
  104. void IsReturnWarping(bool state){ if ( state ) Mirror[RETURN_WARP] = 1; else Mirror[RETURN_WARP] = 0; }
  105.  
  106. int AfterReturnWarp(){ return Mirror[AFTER_RETURN_WARP]; }
  107. void AfterReturnWarp(bool state){ if ( state ) Mirror[AFTER_RETURN_WARP] = 1; else Mirror[AFTER_RETURN_WARP] = 0; }
  108.  
  109. int WarpSparkle(){ return Mirror[WARP_SPARKLE]; }
  110. void WarpSparkle(bool state){ if ( state ) Mirror[WARP_SPARKLE] = 1; else Mirror[WARP_SPARKLE] = 0; }
  111.  
  112. int WarpSparkleReturn(){ return Mirror[WARP_SPARKLE_RETURN_DMAP]; }
  113. void WarpSparkleReturn(int dmap){ Mirror[WARP_SPARKLE_RETURN_DMAP] = dmap; }
  114.  
  115. int WarpSparkleDMap(){ return Mirror[WARP_SPARKLE_DMAP]; }
  116. void WarpSparkleDMap(int dmap){ Mirror[WARP_SPARKLE_DMAP] = dmap; }
  117.  
  118. int WarpSparkleX(){ return Mirror[WARP_SPARKLE_X]; }
  119. void WarpSparkleX(int x){ Mirror[WARP_SPARKLE_X] = x; }
  120.  
  121. int WarpSparkleY(){ return Mirror[WARP_SPARKLE_X]; }
  122. void WarpSparkleY(int y){ Mirror[WARP_SPARKLE_X] = y; }
  123.  
  124. int WarpSparkleScreen(){ return Mirror[WARP_SPARKLE_SCREEN]; }
  125. void WarpSparkleScreen(int screen){ Mirror[WARP_SPARKLE_SCREEN] = screen; }
  126.  
  127.  
  128. //Functions
  129.  
  130. //Checks the present DMap and returns irts counterpart.
  131. //!! You must set up the arrays inside this function, for it to work.
  132. int GetOtherworldlyDMap(int dmap){
  133.     int q[4];
  134.     int LightWorldDMaps[]={1,2,3,4,5}; //Populate these two arrays with the IDs of your light and dark world dmaps
  135.     int DarkWorldDMaps[]={6,7,8,9,10}; //in matched pairs.
  136.     for ( q[0] = 0; q[0] < SizeOfArray(LightWorldDMaps); q[0]++ ) {
  137.         q[1] = LightWorldDMaps[ q[0] ];
  138.         q[2] = DarkWorldDMaps[ q[0] ];
  139.         if ( dmap == q[1] ) return DarkWorldDMaps[ q[0] ];
  140.         if ( dmap == q[2] ) return LightWorldDMaps[ q[0] ];
  141.     }
  142.     return -1;
  143. }
  144.  
  145. //Returns if the present dmap is a dark world dmap
  146. //!! You must set up the arrays inside this function, for it to work.
  147. bool IsDarkWorld(){
  148.     int DarkWorldDMaps[]={6,7,8,9,10};
  149.     for ( int q = 0; q < SizeOfArray(DarkWorldDMaps); q++ ) {
  150.         if ( Game->GetCurDMap() == DarkWorldDMaps[q] ) return true;
  151.     }
  152.     return false
  153. }
  154.  
  155. //Generates coordinates for the warp return sparkle.
  156. //this is set when we use the mirror.
  157. void SetWarpReturn(){
  158.     WarpSparkle(true);
  159.     WarpSparkleX(Link->X);
  160.     WarpSparkleY(Link->Y);
  161.     WarpSparkleDMap( GetOtherworldlyDMap( Game->GetCurDMap() ) );
  162.     WarpSparkleScreen(Game->GetCurScreen());
  163.     WarpSparkleReturn(Game->GetCurDMap());
  164. }
  165.  
  166. //Removes the warp sparkle, after using it.
  167. void ClearWarpSparkle(){
  168.     WarpSparkle(false);
  169.     WarpSparkleX(-100);
  170.     WarpSparkleY(-100);
  171.     WarpSparkleDMap(-1);
  172.     WarpSparkleScreen(-1);
  173.     WarpSparkleReturn(-1);
  174. }
  175.  
  176. //Returns if Link is in a dungeon based on the array dungeonDMaps[]
  177. //!! You must set up the array inside this function, for it to work.
  178. bool IsDungeonDMap(){
  179.     int dungeonDMaps[]={20,21,22};//List all dungeon DMaps here
  180.     for ( int q = 0; q < SizeOfArray(dungeonDMaps); q++ ) {
  181.         if ( Game->GetCurDMap() == dungeonDMaps[q] ) return true;
  182.         return false;
  183.     }
  184. }
  185.  
  186. //Returns if the warp destination is solid, prior to warping.
  187. bool WarpDestSolid(int x, int y, int screen, int map){
  188.     return ( Game->GetComboSolid(map, screen, ComboAt(x,y)) );
  189. }
  190.    
  191. //! Main Functions to Call before Waitdraw()
  192.  
  193. //Handles the initial warp routines.
  194. void MirrorWarpLink() {
  195.     if ( IsWarping() ){
  196.         Mirror[WARP_LINK_X] = Link->X;
  197.         Mirror[WARP_LINK_Y] = Link->Y;
  198.         Mirror[WARP_LINK_Z] = Link->Z;
  199.         Mirror[WARP_LINK_HP] = Link->HP;
  200.         NoAction();
  201.         Game->PlaySound(SFX_WARP);
  202.         Screen->Wavy = WARP_WAVE_DUR;
  203.         //Freeze all enemies and ghost scripts
  204.         for(int q = WARP_WAVE_DUR + POST_WARP_DELAY; q > 0; q--){
  205.             NoAction();
  206.             Waitframe();
  207.         }
  208.         //resume npcs and ghost scripts
  209.         Link->PitWarp(GetOtherworldlyDMap(Game->GetCurDMap()), Game->GetCurScreen());
  210.         IsWarping(false);
  211.         AfterWarp(true);
  212.     }
  213.    
  214.     if (IsReturnWarping() ){
  215.         Mirror[WARP_LINK_HP] = Link->HP;
  216.         Link->X = WarpSparkleX();
  217.         Link->Y = WarpSparkleY();
  218.         NoAction();
  219.         Game->PlaySound(SFX_WARP);
  220.         Screen->Wavy = WARP_WAVE_DUR;
  221.         //Freeze all enemies and ghost scripts
  222.         for(int q = WARP_WAVE_DUR + POST_WARP_DELAY; q > 0; q--){
  223.             NoAction();
  224.             Waitframe();
  225.         }
  226.         //resume npcs and ghost scripts
  227.         Link->PitWarp(WarpSparkleReturn(), WarpSparkleScreen());
  228.         IsReturnWarping(false);
  229.         AfterReturnWarp(true);
  230.     }
  231. }
  232.  
  233. //Post-warp cleanup, and bounce.
  234. void WarpFinish() {
  235.     if (AfterWarp()){
  236.         if ( Link->Action == LA_GOTHURTLAND || Link->Action == LA_GOTHURTWATER ) Link->HitDir = -1;
  237.         //SetWarpReturn();
  238.         //If the destination is solid, send Link back.
  239.         if ( Screen->ComboS[ ComboAt(Link->X, Link->Y) ] ) {
  240.             Game->PlaySound(SFX_WARP);
  241.             Screen->Wavy = WARP_WAVE_DUR;
  242.             //freeze all enemies and ghost scripts.
  243.             for (int q = WARP_WAVE_DUR + POST_WARP_DELAY; q > 0; q--){
  244.                 NoAction();
  245.                 Waitframe();
  246.             }
  247.             //resume npcs and ghost scripts
  248.             Link->X = Mirror[WARP_LINK_X];
  249.             Link->Y = Mirror[WARP_LINK_Y];
  250.             Link->PitWarp(WarpSparkleReturn(), Game->GetCurScreen());
  251.             AfterWarp(false);
  252.         }
  253.         if ( Link->HP < Mirror[WARP_LINK_HP] && WARP_RETURNS_ON_INJURY) { //If Link is injured, send him back.
  254.             Link->HP = Mirror[WARP_LINK_HP];
  255.             Game->PlaySound(SFX_WARP);
  256.             Screen->Wavy = WARP_WAVE_DUR;
  257.             //freeze all enemies and ghost scripts.
  258.             for(int q = WARP_WAVE_DUR + POST_WARP_DELAY; q > 0; q--){
  259.                 NoAction();
  260.                 Waitframe();
  261.             }
  262.             //resume npcs and ghost scripts
  263.             Link->X = Mirror[WARP_LINK_X];
  264.             Link->Y = Mirror[WARP_LINK_Y];
  265.             Link->PitWarp(WarpSparkleReturn(), Game->GetCurScreen());
  266.  
  267.             Link->X = Mirror[WARP_LINK_X];
  268.             Link->Y = Mirror[WARP_LINK_Y];
  269.             Link->HP = Mirror[WARP_LINK_HP];
  270.             AfterWarp(false);
  271.         }
  272.         else {
  273.             Mirror[WARP_INVULNERABILITY_FRAMES] = WARP_INVULNERABILITY_FRAMES;
  274.         }
  275.     }
  276.    
  277.     if (AfterReturnWarp()){
  278.         if ( Link->Action == LA_GOTHURTLAND || Link->Action == LA_GOTHURTWATER ) Link->HitDir = -1;
  279.         ClearWarpSparkle();
  280.         Mirror[WARP_INVULNERABILITY_FRAMES] = WARP_INVULNERABILITY_FRAMES;
  281.         AfterReturnWarp(false);
  282.            
  283.     }
  284.    
  285.     if ( POST_WARP_LINK_IS_INVINCIBLE ) {
  286.         if ( Mirror[WARP_INVULNERABILITY_FRAMES] ) {
  287.             Link->CollDetection = false;
  288.             Mirror[WARP_INVULNERABILITY_FRAMES]--;
  289.         }
  290.         if ( !Mirror[WARP_INVULNERABILITY_FRAMES] ) Link->CollDetection = true;
  291.     }
  292. }
  293.  
  294.  
  295. //Creates the mirror return sparkle.
  296. void MirrorSparkle(){
  297.     if ( Game->GetCurDMap() == WarpSparkleDMap() && Game->GetCurScreen() == WarpSparkleScreen() ) {
  298.         Screen->DrawCombo(  MIRROR_SPARKLE_COMBO_LAYER, WarpSparkleX(), WarpSparkleY(),
  299.             MIRROR_SPARKLE_COMBO, MIRROR_SPARKLE_COMBO_H, MIRROR_SPARKLE_COMBO_W, MIRROR_SPARKLE_COMBO_CSET,
  300.             MIRROR_SPARKLE_COMBO_XSCALE, MIRROR_SPARKLE_COMBO_YSCALE, MIRROR_SPARKLE_COMBO_RX,
  301.             MIRROR_SPARKLE_COMBO_RY, MIRROR_SPARKLE_COMBO_RANGLE, Mirror[MIRROR_SPARKLE_COMBO_FRAME],
  302.             MIRROR_SPARKLE_COMBO_FLIP, true, MIRROR_SPARKLE_COMBO_OPACITY) ; //Mirror sparkle
  303.        
  304.         //Reduce the frames
  305.         if ( Mirror[MIRROR_SPARKLE_COMBO_FRAME] >= MIRROR_SPARKLE_COMBO_NUM_FRAMES ) Mirror[MIRROR_SPARKLE_COMBO_FRAME] = MIRROR_SPARKLE_COMBO_INIT_FRAME;
  306.         else Mirror[MIRROR_SPARKLE_COMBO_FRAME]++;
  307.            
  308.         if ( RectCollision( Mirror[WARP_SPARKLE_X], Mirror[WARP_SPARKLE_Y], Mirror[WARP_SPARKLE_X]+16, Mirror[WARP_SPARKLE_Y]+16, Link->X+Link->HitXOffset+Link->DrawXOffset, Link->Y+Link->HitYOffset+Link->DrawYOffset, Link->X+Link->HitXOffset+Link->DrawXOffset+Link->HitWidth, Link->Y+Link->HitYOffset+Link->DrawYOffset+Link->HitHeight)
  309.             || Distance(CenterLinkX(), CenterLinkY(), Mirror[WARP_SPARKLE_X]+8, Mirror[WARP_SPARKLE_Y]+8) < 8)
  310.         {
  311.             //Reurn Link via the portal
  312.             if ( !Mirror[WARP_INVULNERABILITY_FRAMES] ) IsReturnWarping(true);
  313.         }
  314.     }
  315. }
  316.  
  317. void TestSparkle(){
  318.     Screen->DrawCombo(  MIRROR_SPARKLE_COMBO_LAYER, WarpSparkleX(), WarpSparkleY(),
  319.             MIRROR_SPARKLE_COMBO, MIRROR_SPARKLE_COMBO_H, MIRROR_SPARKLE_COMBO_W, MIRROR_SPARKLE_COMBO_CSET,
  320.             MIRROR_SPARKLE_COMBO_XSCALE, MIRROR_SPARKLE_COMBO_YSCALE, MIRROR_SPARKLE_COMBO_RX,
  321.             MIRROR_SPARKLE_COMBO_RY, MIRROR_SPARKLE_COMBO_RANGLE, Mirror[MIRROR_SPARKLE_COMBO_FRAME],
  322.             MIRROR_SPARKLE_COMBO_FLIP, true, MIRROR_SPARKLE_COMBO_OPACITY) ; //Mirror sparkle
  323.        
  324.         //Reduce the frames
  325.         if ( Mirror[MIRROR_SPARKLE_COMBO_FRAME] >= MIRROR_SPARKLE_COMBO_NUM_FRAMES ) Mirror[MIRROR_SPARKLE_COMBO_FRAME] = MIRROR_SPARKLE_COMBO_INIT_FRAME;
  326.         else Mirror[MIRROR_SPARKLE_COMBO_FRAME]++;
  327. }
  328.  
  329.  
  330. /// Items
  331.  
  332. item script Mirror{
  333.     void run(){
  334.         if ( IsDungeonDMap() && MIRROR_RETURNS_TO_DUNGEON_ENTRANCE ) {
  335.             //Warp to dungeon entrance.
  336.             Game->PlaySound(SFX_WARP_DUNGEON);
  337.             Screen->Wavy = WARP_WAVE_DUR_DUNGEON;
  338.             Link->Warp(Game->GetCurDMap(), Game->DMapContinue[Game->GetCurDMap()]);
  339.         }
  340.         else {
  341.             if ( IsDarkWorld() )
  342.                 SetWarpReturn();
  343.                 IsWarping(true);
  344.             //Warp to other world
  345.             if ( !IsDarkWorld() && SFX_WARP_ERROR ) Game->PlaySound(SFX_WARP_ERROR);
  346.         }
  347.     }
  348. }
  349.  
  350. //Global Script Example
  351.  
  352. global script Z3_Mirror{
  353.     void run(){
  354.         while(true){
  355.             MirrorWarpLink();
  356.             WarpFinish();
  357.             if ( TEST_MIRROR_SPARKLE ) TestSparkle();
  358.             if ( MIRROR_SPARKLE_BEFORE_WAITDRAW ) MirrorSparkle();
  359.             Waitdraw();
  360.             if ( !MIRROR_SPARKLE_BEFORE_WAITDRAW ) MirrorSparkle();
  361.             Waitframe();
  362.         }
  363.     }
  364. }
  365.  
  366. //Deprecated
  367.  
  368. //bool TouchingSolid(int x, int y) {
  369.   //  if ( Screen->isSolid(x,y) ||
  370.   //  Screen->isSolid(x + SOLIDITY_CHECK_DISTANCE, y) ||
  371.   //  Screen->isSolid(x + SOLIDITY_CHECK_DISTANCE, y+SOLIDITY_CHECK_DISTANCE) ||
  372.   //  Screen->isSolid(x + SOLIDITY_CHECK_DISTANCE, y-SOLIDITY_CHECK_DISTANCE) ||
  373.   //  Screen->isSolid(x - SOLIDITY_CHECK_DISTANCE, y) ||
  374.   //  Screen->isSolid(x - SOLIDITY_CHECK_DISTANCE, y+SOLIDITY_CHECK_DISTANCE) ||
  375.   //  Screen->isSolid(x - SOLIDITY_CHECK_DISTANCE, y-SOLIDITY_CHECK_DISTANCE) ) {
  376.   //      return true;
  377.   //  }
  378.   //  else {
  379.    //     return false;
  380.   //  }
  381. //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement