daily pastebin goal
23%
SHARE
TWEET

LinkDeath.zh

ZoriaRPG Aug 19th, 2017 (edited) 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Custom Link Death Animation
  2. //ZoriaRPG
  3.  
  4. int LinkInvisibleEvents[20]; //An array to store the conditions that cause Link to be invisible.
  5. //THese could all be binary flags in one array index, but that is *potentially* slower.
  6. const int INVIS_DYING = 1; //an invisible cause condition.
  7.  
  8. const int FFC_LINK_DEATH_DATA = 100; //Freeze all, except ffcs.
  9.  
  10. const int SFX_DEATH = 0; //Death Sound
  11.  
  12. const int MUS_DEATH_STRING = 1000; //String ID of Death Music Filename
  13. const int MUS_DEATH_TRK = 1; //Track of  enhanced music file to play.
  14. const int MIDI_DEATH = 50; //Fallback MIDI if the music file is missing, or corrupt.
  15.  
  16. const int DEATH_ANIM_DUR = 3; //cycles of frames * number_of * this, so 3 == 240 frames.
  17. const int DEATH_ANIM_FRAMES_PER_TILE = 10; //The number of frames each tile state of the death animation is sequentially drawn.
  18. const int DEATH_ANIM_TILE_BASE = 12000; //The base tile of the death sequece/
  19. const int DEATH_ANIM_TILE_NUMBER_OF = 8; //8 tiles?
  20.  
  21. const int DEATH_RECT_LAYER = 7; //Should be 7.
  22. const int DEATH_RECT_X = 0; const int DEATH_RECT_X2 = 256;
  23. const int DEATH_RECT_Y = 0; const int DEATH_RECT_Y2 = 176;
  24. const int DEATH_RECT_COLOUR = 0x01; //Set colour here.
  25. const int DEATH_RECT_SCALE = 100;
  26. const int DEATH_RECT_RX = 0; const int DEATH_RECT_RY = 0; const int DEATH_RECT_RANGLE = 0;
  27. const int DEATH_RECT_OPACITY = 64;
  28.  
  29. const int DEATH_LINK_LAYER = 7; //Should be 7 and enqueued to draw over the fade rect.
  30.  
  31. const int SPRITE_DEATH_WINK_OUT = 70; //Weapon Sprite of Death Wink Out
  32.  
  33. const int LINK_CONTINUE_HEALTH_PERCENT = 100; //Percentage of HP to restore on death
  34. const int LINK_CONTINUE_MAGIC_PERCENT = 100; //Percentage of MP to restore on death
  35.  
  36. //IsInvisible(LinkInvisibleEvents);
  37. void IsInvisible(int ptr){
  38.     for ( int q = SizeOfArray(ptr); q > 0; q-- ){
  39.         if ( ptr[q] ) Link->Invisible = true;
  40.         return;
  41.     }
  42.     Link->Invisible = false;
  43. }
  44.  
  45. //Sets a single invisible cause condition.
  46. void IsInvisible(int ptr, int indx, bool state){
  47.     if ( state ) ptr[indx] = 1;
  48.     else ptr[indx] = 0;
  49. }
  50.  
  51. //Checks if a specific source for invisibility is enabled.
  52. bool IsInvisible(int ptr, int indx){
  53.     return (ptr[indx] != 0);
  54. }
  55.  
  56. //Sets Link as Not Invisible, disabling all Invis Flags
  57. void NotInvisible(int ptr){
  58.     for ( int q = SizeOfArray(ptr); q > 0; q-- ){
  59.         ptr[q] = 0;
  60.     }
  61.     Link->Invisible = false;
  62. }
  63.  
  64.  
  65. //Link Death Animation Sequence
  66. ffc script FFC_LinKDeath{
  67.    
  68.     //Play the death music.
  69.     int mus[200]; //change filename as needed.
  70.     Game->GetMessage(MUS_DEATH_STRING, mus);
  71.     for ( int q = 199; q > 0; q-- ) {
  72.         if ( mus[q] == ' ' ) mus[q] = 0; //Trim the trailing spaces.
  73.         else break;
  74.     }
  75.     if ( !Game->PlayEnhancedMusic(mus,MUS_TRK_DEATH) ) { //if the enhance music file is absent,
  76.         Game->PlayMIDI(MIDI_DEATH); //play the fallthrough midi.
  77.     }
  78.     int til[4]; //Array to hold animation variables.
  79.     til[0] = DEATH_ANIM_TILE_BASE;
  80.     //til[1] = 0; // count
  81.     til[2] = 1; //layers
  82.     til[3] = 128; //Link death tile opacity
  83.    
  84.     for ( int q = ( DEATH_ANIM_DUR * DEATH_ANIM_FRAMES_PER_TILE * DEATH_ANIM_TILE_NUMBER_OF ) ; q > 0; q-- ) {
  85.         //Fade to Red
  86.         if ( q % ( DEATH_ANIM_DUR * DEATH_ANIM_FRAMES_PER_TILE ) == 0 ) {
  87.             tile[2]++; //Every leg of the process, add another layer to the red fade.
  88.         }
  89.         for ( int w = til[2]; w > 0; w-- ) {
  90.             Screen->Rectangle(
  91.                 //Red or other fade colour rect.
  92.                 DEATH_RECT_LAYER, DEATH_RECT_X, DEATH_RECT_Y, DEATH_RECT_X2, DEATH_RECT_Y2,
  93.                 DEATH_RECT_COLOUR, DEATH_RECT_SCALE,
  94.                 DEATH_RECT_RX, DEATH_RECT_RY, DEATH_RECT_RANGLE,
  95.                 true, DEATH_RECT_OPACITY       
  96.             );
  97.         }
  98.         if ( q % DEATH_ANIM_FRAMES_PER_TILE == 0 ) til[1]++; //Increment the tile used by the draw.
  99.         if ( til[1] >= DEATH_ANIM_TILE_NUMBER_OF ) til[1] = 0; //or reset and rollover to base tile.
  100.         if ( q <= DEATH_ANIM_FRAMES_PER_TILE * DEATH_ANIM_TILE_NUMBER_OF ) til[3] = 64; //Fade Link
  101.         //Draw Link Spinning
  102.         //This, alternatively, could be a weapon sprite, however, that still requires drawing the
  103.         //weapon tile to the proper layer, and in the correct enqueueing order.
  104.         Screen->DrawTile   
  105.         (   DEATH_LINK_LAYER, Link->X, Link->Y,
  106.             DEATH_ANIM_TILE_BASE + til[1], 1, 1,
  107.             DEATH_ANIM_TILE_CSET, -1, -1,
  108.             0, 0, 0,
  109.             0,
  110.             true, til[3]
  111.         );
  112.         Waitframe(); continue();
  113.     }
  114.     //Draw Win Out Sprite
  115.     lweapon dsprite = Screen->CreateLWeapon(LW_SPARKLE);
  116.     dsprite->HitYOffset = -1000;
  117.     dsprite->X = Link->X;
  118.     dsprite->Y = Link->Y;
  119.    
  120.     //Do menu here.
  121.     int choice = DeathMenu();
  122.     if ( choice == 1 ) {
  123.         //Quit
  124.         Game->End();
  125.     }
  126.     if ( choice == 2 ) {
  127.         //Save
  128.         Game->Save();
  129.         Game->End();
  130.     }
  131.     if ( choice == 3 ) {
  132.         //Continue
  133.         //Needs custom reload function **callback signal** to the global active script.
  134.     }
  135. }
  136.  
  137. //The menu function ( template, at this time ).
  138. int DeathMenu(){
  139.     int choice;
  140.     //Draw the menu here. Are you using Tango?
  141.    
  142.     return choice;
  143.    
  144. }
  145.  
  146. //Mandatory to clear some variables on reload.
  147. global script OnContinue(){
  148.     void run(){
  149.         Resume_Ghost_ZH();
  150.         NotInvisible(LinkInvisibleEvents);
  151.     }
  152.    
  153. }
  154.  
  155. //Called if Link factually dies, and we want to run the custom death sequence.
  156. void LinKDeath(){
  157.     Suspend_Ghost_ZH();
  158.     ffc f; int ff[]="FFC_LinKDeath";
  159.     Link->HP = Lin->MaxHP;
  160.     for ( int q = 32; q > 1; q-- ) {
  161.         f = Screen->LoadFFC(q);
  162.         if ( q->Data == 0 ) {
  163.             if ( q->Script == 0 ) {
  164.                 f-Data = FFC_LINK_DEATH_DATA;
  165.                 f->Script = Game->GetFFCScript(ff);
  166.             }
  167.         }
  168.     }
  169. }
  170.  
  171. //Call before Waitdraw
  172. void DoDeath(){
  173.     if ( Link->HP <= 0 ) { LinkDeath(); }
  174. }
  175.  
  176.  
  177.  
  178. //Example structure and procedure for a continue game function.
  179. //This clearly would never compile as-is.  --Lazy
  180. void ContinueGame(){
  181.     Screen->Rectangle(//black)]
  182.     OpeningWipe();
  183.     Link->HP = ( Link->MaxHP / 100 ) * LINK_CONTINUE_HEALTH_PERCENT;
  184.     Link->MP = ( Link->MaxMP / 100 ) * LINK_CONTINUE_MAGIC_PERCENT;
  185.     Link->Warp(LastEntranceDMap,LastEntranceScreen);
  186. }
RAW Paste Data
Top