Advertisement
ZoriaRPG

Custom F6 and Game Over Screens [2.55]

Oct 24th, 2018
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 10.78 KB | None | 0 0
  1. ///////////////////////////////////////
  2. /// Custom Game Over and F6 Screens ///
  3. /// v1.3 for ZC 2.55                ///
  4. /// 24th October, 2018              ///
  5. /// By: ZoriaRPG                    ///
  6. ///////////////////////////////////////
  7.  
  8.  
  9. import "std.zh"
  10.  
  11. typedef const int define;
  12. typedef const int config;
  13.  
  14. define ON = 1;
  15. define OFF = 0;
  16.  
  17. script typedef ffc namespace;
  18.  
  19. namespace script F6
  20. {
  21. define SELECTION_SAVE = 1;
  22. define SELECTION_RETRY = 2;
  23. define SELECTION_CANCEL = 3;
  24.    
  25. config F6MIDI = -3;
  26.    
  27.     void run(){}
  28.     const int FREEZE = 504; //Freeze Combo
  29.     void freeze(int state)
  30.     {
  31.         ffc f = Screen->LoadFFC(32);
  32.         if ( state ) f->Data = FREEZE;
  33.         else f->Data = 0;
  34.     }
  35.        
  36.     //if ( F6.press() ) { F6.optiona(); }
  37.     bool press()
  38.     {
  39.         TraceS("User pressed F6"); TraceNL();
  40.         if ( Input->ReadKey[46+6] ) return true;
  41.         return false;
  42.     }
  43.     void draw() { gameover.draw(true); }
  44.     int choice() { return gameover.get_choice(); }
  45.    
  46.     void options()
  47.     {
  48.         Game->DisableActiveSubscreen = true;
  49.         freeze(ON);
  50.         int oldmidi = Game->GetMIDI();
  51.         Game->PlayMIDI(F6MIDI);
  52.         while(menu())
  53.         {
  54.             draw();
  55.             Waitdraw();
  56.             Waitframe();
  57.         }
  58.         Game->PlayMIDI(oldmidi);
  59.         freeze(OFF);
  60.        
  61.         Link->PressStart = false; Link->InputStart = false;
  62.        
  63.     }
  64.    
  65.     bool menu()
  66.     {
  67.         int sel = choice();
  68.         switch(sel)
  69.         {
  70.             case SELECTION_SAVE:
  71.             {
  72.                 Game->Save(); return false;
  73.             }
  74.             case SELECTION_RETRY:
  75.             {
  76.                 freeze(OFF);
  77.                 Game->End(); return false;
  78.             }
  79.             case SELECTION_CANCEL:
  80.             {
  81.                 return false;
  82.             }
  83.         }
  84.         return true;
  85.     }
  86.    
  87. }
  88.  
  89. namespace script gameover
  90. {
  91.     // Sounds and MIDIs
  92. config SFX_WINKOUT          = 38; //Sound to play during wink-out animation.
  93. config SFX_LINKDEATH            = 28; //Sound to play when Link dies.
  94. config SFX_GAMEOVERSCREEN_CURSOR    = 6;  //Sound to play when the player moves the game over cursor.
  95. config SFX_GAMEOVERSCREEN_SELECTION     = 44; //Sound to play when the user selects a game over menu option.
  96. config MIDI_GAMEOVER            = -4; //MIDI to play on Game Over screen.
  97.     //Defaults: -3 is the internal Game Over, -2 is Level 9, -1 is Overworld
  98.  
  99. // Sprites (Weapons/Misc)
  100. config SPR_DEATH        = 88; //Sprite of Link Spinning
  101. config SPR_DEATH_WINKOUT    = 89; //Sprite of wink-out
  102. // Sprite Timing
  103. config END_DEATH_SPIN       = 40; //Frames to display death spin animation.
  104. config END_WINKOUT      = 10; //Frames to display wink-out animation.
  105.  
  106. // Other Graphics and Colours
  107. config TILE_SAVECURSOR      = 20;
  108. config TILE_SAVECURSOR_CSET     = 1;    //CSet for minitile cursor.
  109. config BLACK            = 0x0F; //Black in the current palette
  110. config RED          = 0x93; //Red in the current palette
  111. config WHITE            = 0x01; //White in the current palette
  112.  
  113. // Menu Object Positions and Settings
  114. config DONT_SAVE_X      = 102; //X position of the RETRY string.
  115. config SAVE_X           = 102; //X position of the SAVE string.
  116. config DONT_SAVE_Y      = 68;  //Y position of the RETRY string.
  117. config CANCEL_Y         = 68+14;  //Y position of the RETRY string.
  118. config SAVE_Y           = 54;  //X position of the SAVE string.
  119. config CURSOR_OFFSET        = 26;  //X offset of the cursor from the text.
  120.  
  121. //Global Variables and Arrays
  122.  
  123. //Indices for values[]
  124. define MENU_SEL_STATE       = 0; //The current selected menu option.
  125. define MENU_SEL_POS_X       = 1; //Stores where to draw menu selector.
  126. define MENU_SEL_POS_Y       = 2; //Stores where to draw menu selector.
  127. define DEATH_LX         = 3; //Cache of Link's last X position before death.
  128. define DEATH_LY         = 4; //Cache of Link's last Y position before death.
  129. define DEATHFRAME       = 5; //Timer for death animations.
  130. define QUIT             = 6; //The game 'QUIT' type, SAVE or RETRY
  131.  
  132. //gameover.QUIT Types
  133. define quitSAVE         = 1;
  134. define quitRETRY        = 2;
  135.  
  136. //Menu Selection types
  137. define SELECTION_SAVE       = 1;
  138. define SELECTION_RETRY      = 2;
  139. define SELECTION_CANCEL     = 3;
  140.  
  141.     int values[8] = {1,SAVE_Y,DONT_SAVE_Y, 0,0};
  142.     void run(){}
  143.     bool check()
  144.     {
  145.         if ( Link->HP < 1 )
  146.         {
  147.             Link->HP = 1;
  148.             Link->Invisible = true;
  149.             Link->CollDetection = false;
  150.             values[DEATH_LX] = Link->X;
  151.             values[DEATH_LY] = Link->Y;
  152.             return true;
  153.         }
  154.         return false;
  155.     }
  156.     void clean_up()
  157.     {
  158.         int q;
  159.         if ( Screen->NumNPCs() )
  160.         {
  161.             for ( q = Screen->NumNPCs(); q > 0; --q )
  162.             {
  163.                 npc n = Screen->LoadNPC(q); Remove(n);
  164.             }
  165.         }
  166.         if ( Screen->NumLWeapons() )
  167.         {
  168.             for ( q = Screen->NumLWeapons(); q > 0; --q )
  169.             { lweapon n = Screen->LoadLWeapon(q); Remove(n); }
  170.         }
  171.         if ( Screen->NumEWeapons() )
  172.         {
  173.             for ( q = Screen->NumEWeapons(); q > 0; --q )
  174.             { eweapon n = Screen->LoadEWeapon(q); Remove(n); }
  175.         }
  176.         if ( Screen->NumItems() )
  177.         {
  178.             for ( q = Screen->NumItems(); q > 0; --q )
  179.             { item n = Screen->LoadItem(q); Remove(n); }
  180.         }
  181.         //clear all ffcs
  182.         for ( q = 1; q < 33; ++q )
  183.         {
  184.             ffc f = Screen->LoadFFC(q);
  185.             f->Data = 0; f->Script = 0;
  186.         }
  187.     }
  188.     void draw(bool cancel)
  189.     {
  190.         //Draw black background with Rectangle()
  191.         Screen->Rectangle(5,0,0,256,256,BLACK,100, 0,0,0,true,128);
  192.         if ( !cancel )
  193.         {
  194.             if ( values[MENU_SEL_STATE] )
  195.             {
  196.                 //int ss1[]="Drawing cursor and text.";
  197.                 //TraceS(ss1);
  198.                 Screen->FastTile(6,SAVE_X-CURSOR_OFFSET, SAVE_Y, TILE_SAVECURSOR, TILE_SAVECURSOR_CSET,128);
  199.                 //draw strings, red for selected
  200.                 Screen->DrawString(6,SAVE_X,SAVE_Y,0,RED, -1,0,"SAVE",128);
  201.                 Screen->DrawString(6,DONT_SAVE_X,DONT_SAVE_Y,0,WHITE, -1,0,"RETRY",128);
  202.             }
  203.             else
  204.             {
  205.                 //Draw cursor
  206.                 Screen->FastTile(6,DONT_SAVE_X-CURSOR_OFFSET, DONT_SAVE_Y, TILE_SAVECURSOR, TILE_SAVECURSOR_CSET,128);
  207.                 //draw strings, red for selected
  208.                 Screen->DrawString(6,SAVE_X,SAVE_Y,0,WHITE, -1,0,"SAVE",128);
  209.                 Screen->DrawString(6,DONT_SAVE_X,DONT_SAVE_Y,0,RED, -1,0,"RETRY",128);
  210.             }
  211.         }
  212.         else
  213.         {
  214.             switch(values[MENU_SEL_STATE])
  215.             {
  216.                
  217.                
  218.                 case SELECTION_SAVE:
  219.                 {
  220.                     //int ss1[]="Drawing cursor and text.";
  221.                     //TraceS(ss1);
  222.                     Screen->FastTile(6,SAVE_X-CURSOR_OFFSET, SAVE_Y, TILE_SAVECURSOR, TILE_SAVECURSOR_CSET,128);
  223.                     //draw strings, red for selected
  224.                     Screen->DrawString(6,SAVE_X,SAVE_Y,0,RED, -1,0,"SAVE",128);
  225.                     Screen->DrawString(6,DONT_SAVE_X,DONT_SAVE_Y,0,WHITE, -1,0,"RETRY",128);
  226.                     Screen->DrawString(6,DONT_SAVE_X,CANCEL_Y,0,WHITE, -1,0,"CANCEL",128);
  227.                     break;
  228.                 }
  229.                 case SELECTION_RETRY:
  230.                 {
  231.                     //Draw cursor
  232.                     Screen->FastTile(6,DONT_SAVE_X-CURSOR_OFFSET, DONT_SAVE_Y, TILE_SAVECURSOR, TILE_SAVECURSOR_CSET,128);
  233.                     //draw strings, red for selected
  234.                     Screen->DrawString(6,SAVE_X,SAVE_Y,0,WHITE, -1,0,"SAVE",128);
  235.                     Screen->DrawString(6,DONT_SAVE_X,DONT_SAVE_Y,0,RED, -1,0,"RETRY",128);
  236.                     Screen->DrawString(6,DONT_SAVE_X,CANCEL_Y,0,WHITE, -1,0,"CANCEL",128);
  237.                     break;
  238.                 }
  239.                 case SELECTION_CANCEL:
  240.                 {
  241.                     //Draw cursor
  242.                     Screen->FastTile(6,DONT_SAVE_X-CURSOR_OFFSET, CANCEL_Y, TILE_SAVECURSOR, TILE_SAVECURSOR_CSET,128);
  243.                     //draw strings, red for selected
  244.                     Screen->DrawString(6,SAVE_X,SAVE_Y,0,WHITE, -1,0,"SAVE",128);
  245.                     Screen->DrawString(6,DONT_SAVE_X,DONT_SAVE_Y,0,WHITE, -1,0,"RETRY",128);
  246.                     Screen->DrawString(6,DONT_SAVE_X,CANCEL_Y,0,RED, -1,0,"CANCEL",128);
  247.                     break;
  248.                 }
  249.                 default: break;
  250.                
  251.             }
  252.            
  253.         }
  254.     }
  255.     bool choice()
  256.     {
  257.         if ( Link->PressDown || Link->PressUp )
  258.         {
  259.             values[MENU_SEL_STATE] = Cond(values[MENU_SEL_STATE],0,1);
  260.             Game->PlaySound(SFX_GAMEOVERSCREEN_CURSOR);
  261.             return true;
  262.         }
  263.        
  264.         if ( Link->PressStart )
  265.         {
  266.             Game->PlaySound(SFX_GAMEOVERSCREEN_SELECTION);
  267.             if ( values[MENU_SEL_STATE] ) values[QUIT] = quitSAVE;
  268.             else values[QUIT] = quitRETRY; //no save
  269.             return false;
  270.         }
  271.         return true;
  272.     }
  273.    
  274.    
  275.     int get_choice()
  276.     {
  277.         if ( Link->PressDown )
  278.         {
  279.             Game->PlaySound(SFX_GAMEOVERSCREEN_CURSOR);
  280.             switch(values[MENU_SEL_STATE])
  281.             {
  282.                 case SELECTION_SAVE: //save
  283.                     ++values[MENU_SEL_STATE]; break;
  284.                 case SELECTION_RETRY: //retry
  285.                     ++values[MENU_SEL_STATE]; break;
  286.                 case SELECTION_CANCEL: //3
  287.                     values[MENU_SEL_STATE] = 1; break;
  288.                 default: //cance;
  289.                     values[MENU_SEL_STATE] = 0; break;
  290.             }
  291.         }
  292.         if ( Link->PressUp )
  293.         {
  294.             Game->PlaySound(SFX_GAMEOVERSCREEN_CURSOR);
  295.             switch(values[MENU_SEL_STATE])
  296.             {
  297.                 case 1: //save
  298.                     values[MENU_SEL_STATE] = 3; break;
  299.                 case 2: //retry
  300.                     --values[MENU_SEL_STATE] ; break;
  301.                 case SELECTION_CANCEL: //3
  302.                     --values[MENU_SEL_STATE] ; break;
  303.                 default: //cance;
  304.                     values[MENU_SEL_STATE] = 0; break;
  305.             }
  306.         }      
  307.        
  308.         if ( Link->PressStart )
  309.         {
  310.             Game->PlaySound(SFX_GAMEOVERSCREEN_SELECTION);
  311.             int ret = values[MENU_SEL_STATE];
  312.             values[MENU_SEL_STATE] = 1;
  313.             return ret;
  314.         }
  315.     }
  316.     void animation()
  317.     {
  318.     if ( values[DEATHFRAME] == 0 ) Game->PlaySound(SFX_LINKDEATH);
  319.         lweapon death = Screen->CreateLWeapon(LW_SPARKLE);
  320.        
  321.         death->UseSprite(SPR_DEATH);
  322.         death->X = values[DEATH_LX];
  323.         death->Y = values[DEATH_LY];
  324.  
  325.         while ( values[DEATHFRAME] < END_DEATH_SPIN )
  326.         {
  327.             ++values[DEATHFRAME];
  328.             //spin Link around by drawing his tiles, then make the wink out.
  329.             NoAction(); Waitdraw(); Waitframe();
  330.         }
  331.         Remove(death);
  332.         Game->PlaySound(SFX_WINKOUT);
  333.         lweapon death2 = Screen->CreateLWeapon(LW_SPARKLE);
  334.         death2->UseSprite(SPR_DEATH_WINKOUT);
  335.         death2->X = values[DEATH_LX];
  336.         death2->Y = values[DEATH_LY];
  337.         while ( values[DEATHFRAME] < END_DEATH_SPIN+END_WINKOUT )
  338.         {
  339.             ++values[DEATHFRAME];
  340.             //wink-out
  341.             NoAction();  Waitdraw(); Waitframe();
  342.         }
  343.         Remove(death2);
  344.     }
  345. }
  346.  
  347.  
  348. //Global Active Script
  349. global script noF6
  350. {
  351.     void run()
  352.     {
  353.         while(true)
  354.         {
  355.             //Normal pre-waitdraw functions go here.
  356.        
  357.             //UpdateGhostZH1();
  358.            
  359.             //Put any health refull code above this!
  360.             //Run the check to see if Link is dying...
  361.             if ( F6.press() ) { Game->DisableActiveSubscreen = false; F6.options(); }
  362.             if ( gameover.check() ) break; //LAST before Waitdraw()
  363.             Waitdraw();
  364.            
  365.             //Normal post-waitdraw functions go here.
  366.            
  367.             //UpdateGhostZH2();
  368.            
  369.             Waitframe();
  370.         }
  371.         while(!gameover.values[gameover.QUIT])
  372.         {
  373.             //gameover.values[gameover.DEATH_LX] = Link->X;
  374.             //gameover.values[gameover.DEATH_LY] = Link->Y;
  375.             //Set game music to a silent MIDI.
  376.  
  377.             Link->HP = Link->MaxHP;
  378.             Link->Invisible = true;
  379.             Link->CollDetection = false;
  380.             //Clean up screen objects
  381.             gameover.clean_up();
  382.             //Do Link Death animation
  383.             gameover.animation();
  384.            
  385.             bool menu = true;
  386.             Game->PlayMIDI(gameover.MIDI_GAMEOVER);//Play game over midi.
  387.             Game->DisableActiveSubscreen = true;   
  388.            
  389.             while(menu) //menu loop
  390.             {
  391.                 //    GAME OVER SCREEN
  392.                 gameover.draw(false);
  393.                 menu = gameover.choice();
  394.                 Waitdraw();
  395.                 Waitframe();
  396.             }
  397.             Waitdraw(); Waitframe();
  398.         }
  399.         if ( gameover.values[gameover.QUIT] == gameover.quitSAVE )
  400.         {
  401.             ++Game->NumDeaths;
  402.             Game->Save();
  403.             Game->End();
  404.         }
  405.         else Game->End(); //Retry
  406.     }
  407. }
  408.  
  409. global script OnExit
  410. {
  411.     void run()
  412.     {
  413.         Link->Invisible = false;
  414.     }
  415. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement