Advertisement
ZoriaRPG

Game Over Menu v1.2 [2.50.x]

Oct 24th, 2018
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.11 KB | None | 0 0
  1. ///////////////////////////////
  2. /// Custom Game Over Screen ///
  3. /// v1.2 for ZC 2.50.x      ///
  4. /// 24th October, 2018      ///
  5. /// By: ZoriaRPG            ///
  6. //////////////////////////////////////
  7. /// Requested by: Korben on PureZC ///
  8. //////////////////////////////////////
  9.  
  10. import "std.zh"
  11.  
  12. // Sounds and MIDIs
  13. const int SFX_WINKOUT           = 38; //Sound to play during wink-out animation.
  14. const int SFX_LINKDEATH         = 28; //Sound to play when Link dies.
  15. const int SFX_GAMEOVERSCREEN_CURSOR     = 6;  //Sound to play when the player moves the game over cursor.
  16. const int SFX_GAMEOVERSCREEN_SELECTION  = 44; //Sound to play when the user selects a game over menu option.
  17. const int MIDI_GAMEOVER         = -4; //MIDI to play on Game Over screen.
  18.     //Defaults: -3 is the internal Game Over, -2 is Level 9, -1 is Overworld
  19.  
  20. // Sprites (Weapons/Misc)
  21. const int SPR_DEATH         = 88; //Sprite of Link Spinning
  22. const int SPR_DEATH_WINKOUT     = 89; //Sprite of wink-out
  23. // Sprite Timing
  24. const int END_DEATH_SPIN    = 40; //Frames to display death spin animation.
  25. const int END_WINKOUT       = 10; //Frames to display wink-out animation.
  26.  
  27. // Other Graphics and Colours
  28. const int TILE_SAVECURSOR   = 20;
  29. const int TILE_SAVECURSOR_CSET  = 1;    //CSet for minitile cursor.
  30. const int _COL_BLACK        = 0x0F; //Black in the current palette
  31. const int _COL_RED      = 0x93; //Red in the current palette
  32. const int _COL_WHITE        = 0x01; //White in the current palette
  33.  
  34. // Menu Object Positions and Settings
  35. const int DONT_SAVE_X       = 102; //X position of the RETRY string.
  36. const int SAVE_X        = 102; //X position of the SAVE string.
  37. const int DONT_SAVE_Y       = 68;  //Y position of the RETRY string.
  38. const int SAVE_Y        = 54;  //X position of the SAVE string.
  39. const int CURSOR_OFFSET     = 26;  //X offset of the cursor from the text.
  40.  
  41. //Global Variables and Arrays
  42. int gameover[8] = {1,SAVE_Y,DONT_SAVE_Y, 0,0};
  43. //Indices for gameover[]
  44. const int MENU_SEL_STATE    = 0; //The current selected menu option.
  45. const int MENU_SEL_POS_X    = 1; //Stores where to draw menu selector.
  46. const int MENU_SEL_POS_Y    = 2; //Stores where to draw menu selector.
  47. const int DEATH_LX      = 3; //Cache of Link's last X position before death.
  48. const int DEATH_LY      = 4; //Cache of Link's last Y position before death.
  49. const int DEATHFRAME        = 5; //Timer for death animations.
  50. const int QUIT          = 6; //The game 'QUIT' type, SAVE or RETRY
  51.  
  52.  
  53. //Quit Types
  54. const int quitSAVE = 1;
  55. const int quitRETRY = 2;
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62. global script noF6
  63. {
  64.     void run()
  65.     {
  66.         while(true)
  67.         {
  68.             //Normal pre-waitdraw functions go here.
  69.        
  70.             //UpdateGhostZH1();
  71.            
  72.             //Put any health refull code above this!
  73.             //Run the check to see if Link is dying...
  74.             if ( do_link_death_check() ) break; //LAST before Waitdraw()
  75.             Waitdraw();
  76.            
  77.             //Normal post-waitdraw functions go here.
  78.            
  79.             //UpdateGhostZH2();
  80.            
  81.             Waitframe();
  82.         }
  83.         while(!gameover[QUIT])
  84.         {
  85.             //gameover[DEATH_LX] = Link->X;
  86.             //gameover[DEATH_LY] = Link->Y;
  87.             //Set game music to a silent MIDI.
  88.  
  89.             Link->HP = Link->MaxHP;
  90.             Link->Invisible = true;
  91.             Link->CollDetection = false;
  92.             //Clean up screen objects
  93.             clean_up_all_screen_objects();
  94.             //Do Link Death animation
  95.             do_death_animation();
  96.            
  97.             bool menu = true;
  98.             Game->PlayMIDI(MIDI_GAMEOVER);//Play game over midi.
  99.                
  100.             while(menu) //menu loop
  101.             {
  102.                 Link->PressStart = false; //No active subscreen for 2.50
  103.                 Link->InputStart = false;
  104.        
  105.                 //    GAME OVER SCREEN
  106.                 draw_game_over_menu();
  107.                 menu = do_game_over_menu_choice();
  108.                 Waitdraw();
  109.                 Waitframe();
  110.             }
  111.             Waitdraw(); Waitframe();
  112.         }
  113.         if ( gameover[QUIT] == quitSAVE )
  114.         {
  115.             ++Game->NumDeaths;
  116.             Game->Save();
  117.             Game->End();
  118.         }
  119.         else Game->End(); //Retry
  120.     }
  121.     bool do_link_death_check()
  122.     {
  123.         if ( Link->HP < 1 )
  124.         {
  125.             Link->HP = 1;
  126.             Link->Invisible = true;
  127.             Link->CollDetection = false;
  128.             gameover[DEATH_LX] = Link->X;
  129.             gameover[DEATH_LY] = Link->Y;
  130.             return true;
  131.         }
  132.         return false;
  133.     }
  134.     void clean_up_all_screen_objects()
  135.     {
  136.         int q;
  137.         if ( Screen->NumNPCs() )
  138.         {
  139.             for ( q = Screen->NumNPCs(); q > 0; --q )
  140.             {
  141.                 npc n = Screen->LoadNPC(q); Remove(n);
  142.             }
  143.         }
  144.         if ( Screen->NumLWeapons() )
  145.         {
  146.             for ( q = Screen->NumLWeapons(); q > 0; --q )
  147.             { lweapon n = Screen->LoadLWeapon(q); Remove(n); }
  148.         }
  149.         if ( Screen->NumEWeapons() )
  150.         {
  151.             for ( q = Screen->NumEWeapons(); q > 0; --q )
  152.             { eweapon n = Screen->LoadEWeapon(q); Remove(n); }
  153.         }
  154.         if ( Screen->NumItems() )
  155.         {
  156.             for ( q = Screen->NumItems(); q > 0; --q )
  157.             { item n = Screen->LoadItem(q); Remove(n); }
  158.         }
  159.         //clear all ffcs
  160.         for ( q = 1; q < 33; ++q )
  161.         {
  162.             ffc f = Screen->LoadFFC(q);
  163.             f->Data = 0; f->Script = 0;
  164.         }
  165.     }
  166.     void draw_game_over_menu()
  167.     {
  168.         int sv[]="SAVE";
  169.         int dsv[]="RETRY";
  170.         //Draw black background with Rectangle()
  171.         Screen->Rectangle(5,0,0,256,256,_COL_BLACK,100, 0,0,0,true,128);
  172.  
  173.         if ( gameover[MENU_SEL_STATE] )
  174.         {
  175.             //int ss1[]="Drawing cursor and text.";
  176.             //TraceS(ss1);
  177.             Screen->FastTile(6,SAVE_X-CURSOR_OFFSET, SAVE_Y, TILE_SAVECURSOR, TILE_SAVECURSOR_CSET,128);
  178.             //draw strings, red for selected
  179.             Screen->DrawString(6,SAVE_X,SAVE_Y,0,_COL_RED, -1,0,sv,128);
  180.             Screen->DrawString(6,DONT_SAVE_X,DONT_SAVE_Y,0,_COL_WHITE, -1,0,dsv,128);
  181.         }
  182.         else
  183.         {
  184.             //Draw cursor
  185.             Screen->FastTile(6,DONT_SAVE_X-CURSOR_OFFSET, DONT_SAVE_Y, TILE_SAVECURSOR, TILE_SAVECURSOR_CSET,128);
  186.             //draw strings, red for selected
  187.             Screen->DrawString(6,SAVE_X,SAVE_Y,0,_COL_WHITE, -1,0,sv,128);
  188.             Screen->DrawString(6,DONT_SAVE_X,DONT_SAVE_Y,0,_COL_RED, -1,0,dsv,128);
  189.         }
  190.     }
  191.     bool do_game_over_menu_choice()
  192.     {
  193.         if ( Link->PressDown || Link->PressUp )
  194.         {
  195.             gameover[MENU_SEL_STATE] = Cond(gameover[MENU_SEL_STATE],0,1);
  196.             Game->PlaySound(SFX_GAMEOVERSCREEN_CURSOR);
  197.             return true;
  198.         }
  199.         //Screw it. This is why I added a way to disable the active subscreen to 2.55
  200.         //Global scripts DO NOT LIKE to block the active subscreen!
  201.         //if ( Link->PressStart )
  202.         if ( Link->PressA || Link->PressB )
  203.         {
  204.             //Link->PressStart = false;
  205.             //Link->InputStart = false;
  206.             Game->PlaySound(SFX_GAMEOVERSCREEN_SELECTION);
  207.             if ( gameover[MENU_SEL_STATE] ) gameover[QUIT] = quitSAVE;
  208.             else gameover[QUIT] = quitRETRY; //no save
  209.             return false;
  210.         }
  211.         return true;
  212.     }
  213.     void do_death_animation()
  214.     {
  215.     if ( gameover[DEATHFRAME] == 0 ) Game->PlaySound(SFX_LINKDEATH);
  216.         lweapon death = Screen->CreateLWeapon(LW_SPARKLE);
  217.        
  218.         death->UseSprite(SPR_DEATH);
  219.         death->X = gameover[DEATH_LX];
  220.         death->Y = gameover[DEATH_LY];
  221.  
  222.         while ( gameover[DEATHFRAME] < END_DEATH_SPIN )
  223.         {
  224.             ++gameover[DEATHFRAME];
  225.             //spin Link around by drawing his tiles, then make the wink out.
  226.             NoAction(); Waitdraw(); Waitframe();
  227.         }
  228.         Remove(death);
  229.         Game->PlaySound(SFX_WINKOUT);
  230.         lweapon death2 = Screen->CreateLWeapon(LW_SPARKLE);
  231.         death2->UseSprite(SPR_DEATH_WINKOUT);
  232.         death2->X = gameover[DEATH_LX];
  233.         death2->Y = gameover[DEATH_LY];
  234.         while ( gameover[DEATHFRAME] < END_DEATH_SPIN+END_WINKOUT )
  235.         {
  236.             ++gameover[DEATHFRAME];
  237.             //wink-out
  238.             NoAction();  Waitdraw(); Waitframe();
  239.         }
  240.         Remove(death2);
  241.     }
  242. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement