SHARE
TWEET

[RMXP] Advanced Title 2.0

ForeverZer0 May 21st, 2011 245 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  2. # Zer0 Advanced Title
  3. # Author: ForeverZer0
  4. # Version: 2.0
  5. # Date: 10.03.2010
  6. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  7. # Version History
  8. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  9. #  Version 1.0 (3.14.2010)
  10. #  - Original write
  11. #
  12. #  Version 1.1 (3.18.2010)
  13. #  - Fixed a bug that would crash the game if you tried to return to the Title
  14. #    Screen from the load screen when using the Load Transition.
  15. #
  16. #  Version 1.2 (3.21.2010)
  17. #  - Added a part to pre-cache all the bitmaps before the animation begins,
  18. #    which should drastically reduce the possibility of lagging.
  19. #
  20. #  Version 2.0 (10.03.2010)
  21. #  - Totally re-written from scratch.
  22. #  - Eliminated the unprofessional 'flicker' that would occur if the database
  23. #    had an image defined for the title graphic.
  24. #  - Improved performance, compatibility, overview, and configurability.
  25. #  - Added Features:
  26. #     - More options to how animations operate, with easier configuration.
  27. #     - Added scene linker to easily add new commands to the title window.
  28. #     - Added config to work with custom save systems.
  29. #     - Add option to display text on the background.
  30. #     - Window appearance can now be easily changed.
  31. #
  32. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  33. #
  34. # Compatibility:
  35. #   - Should be compatible with just about anything other than scripts that
  36. #     add animation, etc. to the Title screen
  37. #   - Compatible with SDK
  38. #
  39. # Explanation:
  40. #   This system will allow you alter the title screen and add some different
  41. #   effects that are not normally available.
  42. #
  43. # Features:
  44. #   - Animated Title
  45. #   - Easy display of picture on screen and/or over animation
  46. #   - Random Title Screen each load
  47. #   - Transition Effect on loading saved games
  48. #   - Weather/Fog Effects
  49. #   - BGS and SFX
  50. #   - Window configuration.
  51. #
  52. # Instructions:
  53. #  - All the below configurable values can be set to nil to disable the feature
  54. #    with the exception of SAVE_DATA. It is already configured to the default
  55. #    system so leave it alone if you are not using a custom save system.
  56. #  - If using the animated title, all pictures need to be named exactly the
  57. #    the same, but have a different number at the end. The numbers should be
  58. #    consecutive and in the order that the animation should follow. The first
  59. #    image should be 0. (Ex. pic0, pic1, pic2, pic3, etc.)
  60. #  - Configuration is below. Individual explanation for the settings is in
  61. #    their respective sections. All Graphics, Fogs, SFX, BGS, etc. that you use
  62. #    need to be in their normal folders.
  63. #
  64. #:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:
  65.  
  66.   $zer0_adv_title = 2.0
  67.  
  68. #===============================================================================
  69. # ** Scene_Title
  70. #===============================================================================
  71.  
  72. class Scene_Title
  73. #=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
  74. #                           BEGIN CONFIGURATION
  75. #=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
  76.  
  77.   ANIMATED = ['Globe ', 40, 4]
  78.   # ['FILENAME', NUMBER_IMAGES, SPEED]
  79.    ANIMATION_TYPE = 0
  80.    # 0 = Do not loop. Run through images and stop on last one.
  81.    # 1 = Changes back to first image after running course, then repeats.
  82.    # 2 = Cycles backwards to the first image after running course, then repeats.
  83.    # 3 = Continually shift through all the files in "Titles" folder randomly.
  84.    CHANGE_SE = nil
  85.    # ['FILENAME', VOLUME, PITCH]
  86.    # Sound effect played when the image changes.
  87.    
  88.   RANDOM_BACKGROUNDS = true
  89.   # Uses a random image for the title each load if ANIMATED is nil. There is no
  90.   # need to configure the graphics. Any/all images from the "Titles" folder will
  91.   # be used.
  92.  
  93.   WEATHER = nil # [1, 20]
  94.   # [TYPE, POWER]
  95.   # Weather effect to be used on title screen.
  96.  
  97.   FOG = nil # ['001-Fog01', 0, 2, -2, 3, 60]
  98.   # ['FILENAME', HUE, X-SPEED, Y-SPEED, ZOOM, OPACITY]
  99.   # Fog to be displayed on the title screen.
  100.  
  101.   BGS = nil # ['032-Switch01', 100, 100]
  102.   # ['FILENAME', VOLUME, PITCH]
  103.   # Background sound to be played during title.
  104.  
  105.   PIC = ['Title Pic', 0, 0, 3001, 0, true, 2]
  106.   # ['NAME', X, Y, Z, OPACITY, FADE-IN?, FADE-IN SPEED]
  107.   # Picture to be displayed on title screen.
  108.    
  109.   SAVE_DATA = ['Save', '.rxdata', 4, '']
  110.   # ['SAVENAMES', 'SAVE_EXTENSION', SAVE_NUMBER, SAVE_DIRECTORY]
  111.   # If you are using a custom save system that alters the name of the save files,
  112.   # extension, or number of possible save files, configure this to match.
  113.   # DO NOT SET THIS VALUE TO NIL!
  114.  
  115.   LOAD_OUT = ['010-Random02', 60, 40]
  116.   LOAD_IN = ['012-Random04', 60, 40]
  117.   # ['TRANSITION NAME', DURATION, VAGUE]
  118.   # Transitions used from the load screen, and when game starts. Can use both or
  119.   # only one.
  120.  
  121.   TEXT = ["Zer0 Advanced Title v.#$zer0_adv_title", 8, 460, 'Arial Black', 18]
  122.   # ['STRING', X, Y, FONTNAME, FONTSIZE]
  123.   # Have text be displayed on the images such as the version number, etc.
  124.    TEXT_COLOR = Color.new(255, 113, 12, 255)
  125.    # [RED, GREEN, BLUE, ALPHA]
  126.    # Color used for the text if being used. White is default.
  127.    
  128.   WINDOW_DATA = [512, 352, 255, 128, false]
  129.   # [X, Y, OPACITY, WIDTH, SHOW_WINDOWSKIN?]
  130.   # Coordinates used for the main window. Default settings will be used if nil.
  131.   COMMANDS = ['New Game', 'Continue', 'Options']
  132.   # Strings used for the commands on the title screen. Omitting the third item
  133.   # in the array will also effectively get rid of the "Shutdown" option that
  134.   # many do not like for its uselessness.
  135.    
  136.   def _SCENE_LINK(command_index)
  137.     # Configure here any scenes you would like to link to the Title screen. You
  138.     # must first configure the name of the command in COMMANDS. After that, just
  139.     # fill in the name of the scene for the proper index. Any command index left
  140.     # undefined will be assumed to be a 'Shutdown' option.
  141.    
  142.     # ex.   when 2 then Scene_MyOptions
  143.    
  144.     # Will make the third command (index starts at 0) start the defined scene.
  145.     # Do not configue anything for index 0 or 1. It will not work. They are
  146.     # reserved for 'New Game' and 'Continue'.
  147.    
  148.     return case command_index
  149.     when 2 then Scene_End
  150.     end
  151.   end
  152.  
  153. #=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
  154. #                           END CONFIGURATION
  155. #=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
  156.  
  157.   def main
  158.     # If battle test
  159.     if $BTEST
  160.       battle_test
  161.       return
  162.     end
  163.     # Load database
  164.     $data_actors        = load_data('Data/Actors.rxdata')
  165.     $data_classes       = load_data('Data/Classes.rxdata')
  166.     $data_skills        = load_data('Data/Skills.rxdata')
  167.     $data_items         = load_data('Data/Items.rxdata')
  168.     $data_weapons       = load_data('Data/Weapons.rxdata')
  169.     $data_armors        = load_data('Data/Armors.rxdata')
  170.     $data_enemies       = load_data('Data/Enemies.rxdata')
  171.     $data_troops        = load_data('Data/Troops.rxdata')
  172.     $data_states        = load_data('Data/States.rxdata')
  173.     $data_animations    = load_data('Data/Animations.rxdata')
  174.     $data_tilesets      = load_data('Data/Tilesets.rxdata')
  175.     $data_common_events = load_data('Data/CommonEvents.rxdata')
  176.     $data_system        = load_data('Data/System.rxdata')
  177.     # Create an instance of Game_System and a few other instance variables
  178.     $game_system, @sprites, @bitmaps = Game_System.new, [], []
  179.     # Create list of filenames of images found in Titles directory.
  180.     @files = Dir.entries('Graphics/Titles').find_all {|file|
  181.       ['.png', '.jpg'].include?(File.extname(file)) }
  182.     # Play BGS if defined.
  183.     # Stop playing ME and BGS (for when returning to title from game)
  184.     Audio.me_stop
  185.     if BGS != nil
  186.       $game_system.bgs_play(RPG::AudioFile.new(BGS[0], BGS[1], BGS[2]))
  187.     end
  188.     # Play title BGM
  189.     $game_system.bgm_play($data_system.title_bgm)
  190.     # Prepare bitmap(s) for the backgound graphic.
  191.     if ANIMATED != nil
  192.       if ANIMATION_TYPE != 3
  193.         (0...ANIMATED[1]).each {|i|
  194.           # Pre-cache the graphics now to prevent lag during animation.
  195.           @bitmaps[i] = RPG::Cache.title("#{ANIMATED[0]}#{i}") }
  196.       else
  197.         @files.each {|file| @bitmaps.push(RPG::Cache.title(file)) }
  198.       end
  199.       @count, @index, @reverse = 0, 0, false
  200.       # Create the audio file for later use if needed.
  201.       if CHANGE_SE != nil
  202.         @se = RPG::AudioFile.new(CHANGE_SE[0], CHANGE_SE[1], CHANGE_SE[2])
  203.       end
  204.     elsif RANDOM_BACKGROUNDS
  205.       # Cache a random image from the array.
  206.       @bitmaps.push(RPG::Cache.title(@files[rand(@files.size)]))
  207.     else
  208.       # Else use the bitmap defined in the database.
  209.       @bitmaps.push(RPG::Cache.title($data_system.title_name))
  210.     end
  211.     # Create weather sprite if needed.
  212.     if WEATHER != nil
  213.       @weather = RPG::Weather.new
  214.       @weather.type, @weather.max = WEATHER[0], WEATHER[1]
  215.       @sprites.push(@weather)
  216.     end
  217.     # Create Fog sprite if needed.
  218.     if FOG != nil
  219.       @fog = Plane.new
  220.       @fog.bitmap = RPG::Cache.fog(FOG[0], FOG[1])
  221.       @fog.z, @fog.opacity = 3000, FOG[5]
  222.       @fog.zoom_x = @fog.zoom_y = FOG[4]
  223.     end
  224.     # Create picture graphic if needed.
  225.     if PIC != nil
  226.       @picture = Sprite.new
  227.       @picture.bitmap = RPG::Cache.picture(PIC[0])
  228.       @picture.x, @picture.y, @picture.z = PIC[1], PIC[2], PIC[3]
  229.       @picture.opacity = PIC[4]
  230.       @sprites.push(@picture)
  231.     end
  232.     # Draw text on background image(s) if configured.
  233.     if TEXT != nil
  234.       @bitmaps.each {|bitmap|
  235.         bitmap.font.name, bitmap.font.size = TEXT[3], TEXT[4]
  236.         if TEXT_COLOR.is_a?(Color)
  237.           bitmap.font.color = TEXT_COLOR
  238.         end
  239.         bitmap.draw_text(TEXT[1], TEXT[2], 640, TEXT[4]+8, TEXT[0])
  240.       }
  241.     end
  242.     # Set graphic to background.
  243.     @background = Sprite.new
  244.     @background.bitmap = @bitmaps[0]
  245.     # Create command window.
  246.     commands = COMMANDS == nil ? ['New Game', 'Continue', 'Shutdown'] : COMMANDS
  247.     if WINDOW_DATA != nil
  248.       @command_window = Window_Command.new(WINDOW_DATA[3], commands)
  249.       @command_window.back_opacity = WINDOW_DATA[2]
  250.       @command_window.x, @command_window.y = WINDOW_DATA[0], WINDOW_DATA[1]
  251.       unless WINDOW_DATA[4]
  252.         @command_window.opacity = 0
  253.       end
  254.     else
  255.       @command_window = Window_Command.new(192, commands)
  256.       @command_window.y, @command_window.back_opacity = 288, 160
  257.       @command_window.x = 320 - @command_window.width / 2
  258.     end
  259.     # Determine if any save files exist.
  260.     filenames = []
  261.     (1..SAVE_DATA[2]).each {|i|
  262.       filenames.push("#{SAVE_DATA[3]}#{SAVE_DATA[0]}#{i}#{SAVE_DATA[1]}") }
  263.     @continue_enabled = filenames.any? {|filename| File.exist?(filename) }
  264.     # Disable 'Continue' if no save files are found.
  265.     if @continue_enabled
  266.       @command_window.index = 1
  267.     else
  268.       @command_window.disable_item(1)
  269.     end
  270.     @sprites.push(@command_window, @background)
  271.     # Transition the graphics.
  272.     Graphics.transition
  273.     # Main loop
  274.     loop { Graphics.update; Input.update; update; break if $scene != self }
  275.     # Prepare for transition.
  276.     Graphics.freeze
  277.     Audio.bgs_stop
  278.     # Dispose the bitmaps, sprites, etc.
  279.     (@sprites + @bitmaps).each {|object| object.dispose }
  280.     @fog.dispose if @fog != nil
  281.     # Clear Cache to free the graphics from the memory.
  282.     RPG::Cache.clear
  283.   end
  284.   #-----------------------------------------------------------------------------
  285.   def update
  286.     # Update the sprites.
  287.     @sprites.each {|sprite| sprite.update }
  288.     # Scroll fog if needed.
  289.     if @fog != nil
  290.       @fog.ox += FOG[2]
  291.       @fog.oy += FOG[3]
  292.     end
  293.     # Update picture if needed.
  294.     if @picture != nil && @picture.opacity != 255 && PIC[5]
  295.       @picture.opacity += PIC[6]
  296.     end
  297.     # Update animation if needed.
  298.     if ANIMATED != nil
  299.       @count += 1
  300.       if @count == ANIMATED[2]
  301.         case ANIMATION_TYPE
  302.         when 0 # No looping
  303.           @index += 1
  304.         when 1 # Re-Start
  305.           @index = (@index + 1) % ANIMATED[1]
  306.         when 2 # Reverse Cycle
  307.           @index += @reverse ? -1 : 1
  308.           # Change reverse flag when needed.
  309.           if @index == 0
  310.             @reverse = false
  311.           elsif @index == ANIMATED[1]
  312.             @reverse = true
  313.           end
  314.         when 3 # Random Image
  315.           old = @index
  316.           @index = rand(@bitmaps.size)
  317.           # Ensure images don't repeat consecutively.
  318.           @index += 1 if old == @index
  319.         end
  320.         # Make sure bitmap index stays within permissible range.
  321.         @index = [[@index, 0].max, ANIMATED[1]-1].min
  322.         # Alter the image to the new bitmap.
  323.         @background.bitmap = @bitmaps[@index]
  324.         # Play the change SE if needed.
  325.         if @se != nil
  326.           $game_system.se_play(@se)
  327.         end
  328.         # Reset count.
  329.         @count = 0
  330.       end
  331.     end
  332.     # If C button was pressed
  333.     if Input.trigger?(Input::C)
  334.       # Branch by command window cursor position
  335.       case @command_window.index
  336.       when 0 then command_new_game
  337.       when 1 then command_continue
  338.       else
  339.         scene = _SCENE_LINK(@command_window.index)
  340.         scene == nil ? command_shutdown : $scene = scene.new
  341.       end
  342.     end
  343.   end
  344. end
  345.  
  346. #===============================================================================
  347. # ** Scene_Load
  348. #===============================================================================
  349.  
  350. class Scene_Load < Scene_File
  351.  
  352.   alias zer0_adv_title_main main
  353.   def main
  354.     zer0_adv_title_main
  355.     # Only if next scene is Scene_Map.
  356.     if $scene.is_a?(Scene_Map)
  357.       # Set data in local variables.
  358.       tran_out, tran_in = Scene_Title::LOAD_OUT, Scene_Title::LOAD_IN
  359.       folder = 'Graphics/Transitions/'
  360.       # Play "out" transition if so configured.
  361.       if tran_out != nil
  362.         Graphics.transition(tran_out[1], folder + tran_out[0], tran_out[2])
  363.         Graphics.freeze
  364.       end
  365.       # Play "in" transition if so configured.
  366.       if tran_in != nil
  367.         # Create an instance of the map sprite.
  368.         map = Spriteset_Map.new
  369.         Graphics.transition(tran_in[1], folder + tran_in[0], tran_in[2])
  370.         Graphics.freeze
  371.         # Dispose sprite.
  372.         map.dispose
  373.       end
  374.     end
  375.   end
  376. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top