Advertisement
ZoriaRPG

Game Over Menu v1.2 [2.55]

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