Guest User

RM VX ACE - Animated Title Screen

a guest
Apr 29th, 2015
205
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #==============================================================================
  2. # ** Title_Sunbeam
  3. #------------------------------------------------------------------------------
  4. #  This class performs the sunbeam processing for the title screen.
  5. #==============================================================================
  6.  
  7. class Title_Sunbeam
  8.   #--------------------------------------------------------------------------
  9.   # * Object Initialization
  10.   #--------------------------------------------------------------------------
  11.   def initialize(index)
  12.     # Set management variables
  13.     @frame_duration        = rand(120)
  14.     @opacity               = rand(30) + 20
  15.     @opacity_target        = rand(30) + 10
  16.     @opacity_target_target = rand(50) + 10
  17.     # Load the bitmap
  18.     image = Bitmap.new("Graphics/System/Sunbeam_" + index.to_s)
  19.     # Set up the sprite
  20.     @image = Sprite.new()
  21.     @image.bitmap = image
  22.     @image.visible = true
  23.     @image.x = 0
  24.     @image.y = 0
  25.     @image.z = 1
  26.     @image.opacity = @opacity
  27.   end
  28.   #--------------------------------------------------------------------------
  29.   # * Free
  30.   #--------------------------------------------------------------------------
  31.   def dispose
  32.     # Dispose of the bitmap
  33.     @image.bitmap.dispose() if !@image.bitmap.disposed?()
  34.     # Dispose of the sprite
  35.     @image.dispose() if !@image.disposed?()
  36.   end
  37.   #--------------------------------------------------------------------------
  38.   # * Frame Update
  39.   #--------------------------------------------------------------------------
  40.   def update
  41.     # If the frame count has run out
  42.     if (@frame_duration <= 0)
  43.       # Set the new target opacity and timing, then return
  44.       @frame_duration        = 50
  45.       @opacity_target_target = rand(125) + rand(25) + 10
  46.       return
  47.     end
  48.     # Update the image opacity target
  49.     d = @frame_duration
  50.     @opacity_target = (@opacity_target * (d - 1) + @opacity_target_target) / d
  51.     # Decrement the frame duration
  52.     @frame_duration -= 1
  53.     # Update the image opacity
  54.     d = 30
  55.     @opacity = (@opacity * (d - 1) + @opacity_target) / d
  56.     @image.opacity = @opacity
  57.   end
  58. end
  59.  
  60. #==============================================================================
  61. # ** Title_Dot
  62. #------------------------------------------------------------------------------
  63. #  This class performs the dot processing for the title screen.
  64. #==============================================================================
  65.  
  66. class Title_Dot
  67.   #--------------------------------------------------------------------------
  68.   # * Object Initialization
  69.   #--------------------------------------------------------------------------
  70.   def initialize
  71.     # Set management variables
  72.     @x_target_duration       = rand(120)
  73.     @x_target_target         = (rand(624) - 40)
  74.     @y_target_duration       = rand(120)
  75.     @y_target_target         = (rand(496) - 40)
  76.     @x                       = (rand(624) - 40)
  77.     @x_target                = (rand(624) - 40)
  78.     @y                       = (rand(496) - 40)
  79.     @y_target                = (rand(496) - 40)
  80.     @opacity_target_duration = rand(120)
  81.     @opacity_target_target   = (rand(200) + 20)
  82.     @opacity                 = (rand(150) + 20)
  83.     @opacity_target          = (rand(150) + 20)
  84.     @zoom_target_duration    = rand(120).to_f
  85.     @zoom_target_target      = (rand(99).to_f + 1.0) /  100.0
  86.     @zoom                    = (rand(99).to_f + 1.0) /  100.0
  87.     @zoom_target             = (rand(99).to_f + 1.0) /  100.0
  88.     # Load the bitmap
  89.     image = Bitmap.new("Graphics/System/Glowy_Dot")
  90.     # Set up the sprite
  91.     @image = Sprite.new()
  92.     @image.bitmap = image
  93.     @image.visible = true
  94.     @image.x = @x
  95.     @image.y = @y
  96.     @image.z = 30
  97.     @image.opacity = @opacity
  98.     @image.zoom_x  = @zoom
  99.     @image.zoom_y  = @zoom
  100.   end
  101.   #--------------------------------------------------------------------------
  102.   # * Free
  103.   #--------------------------------------------------------------------------
  104.   def dispose
  105.     # Dispose of the bitmap
  106.     @image.bitmap.dispose() if !@image.bitmap.disposed?()
  107.     # Dispose of the sprite
  108.     @image.dispose() if !@image.disposed?()
  109.   end
  110.   #--------------------------------------------------------------------------
  111.   # * Frame Update
  112.   #--------------------------------------------------------------------------
  113.   def update
  114.     update_opacity_target()
  115.     update_zoom_target()
  116.     update_x_target()
  117.     update_y_target()
  118.     update_opacity()
  119.     update_zoom()
  120.     update_x()
  121.     update_y()
  122.   end
  123.   #--------------------------------------------------------------------------
  124.   # * Frame Update (Opacity Target)
  125.   #--------------------------------------------------------------------------
  126.   def update_opacity_target
  127.     # If the frame count has run out
  128.     if (@opacity_target_duration <= 0)
  129.       # Set the new target opacity and timing, then return
  130.       @opacity_target_duration = 120
  131.       @opacity_target_target = (rand(200) + 20)
  132.       return
  133.     end
  134.     # Update the image opacity target
  135.     d = @opacity_target_duration
  136.     @opacity_target = (@opacity_target * (d - 1) + @opacity_target_target) / d
  137.     # Decrement the frame duration
  138.     @opacity_target_duration -= 1
  139.   end
  140.   #--------------------------------------------------------------------------
  141.   # * Frame Update (Opacity)
  142.   #--------------------------------------------------------------------------
  143.   def update_opacity
  144.     # Update the image opacity
  145.     d = 120
  146.     @opacity = (@opacity * (d - 1) + @opacity_target) / d
  147.     @image.opacity = @opacity
  148.   end
  149.   #--------------------------------------------------------------------------
  150.   # * Frame Update (Zoom Target)
  151.   #--------------------------------------------------------------------------
  152.   def update_zoom_target
  153.     # If the frame count has run out
  154.     if (@zoom_target_duration <= 0)
  155.       # Set the new target zoom and timing, then return
  156.       @zoom_target_duration = 120.0
  157.       @zoom_target_target = (rand(99).to_f + 1.0) /  100.0
  158.       return
  159.     end
  160.     # Update the image zoom target
  161.     d = @zoom_target_duration
  162.     @zoom_target = (@zoom_target * (d - 1.0) + @zoom_target_target) / d
  163.     # Decrement the frame duration
  164.     @zoom_target_duration -= 1
  165.   end
  166.   #--------------------------------------------------------------------------
  167.   # * Frame Update (Zoom)
  168.   #--------------------------------------------------------------------------
  169.   def update_zoom
  170.     # Update the image zoom
  171.     d = 120.0
  172.     @zoom = (@zoom * (d - 1.0) + @zoom_target) / d
  173.     @image.zoom_x = @zoom
  174.     @image.zoom_y = @zoom
  175.   end
  176.   #--------------------------------------------------------------------------
  177.   # * Frame Update (X Target)
  178.   #--------------------------------------------------------------------------
  179.   def update_x_target
  180.     # If the frame count has run out
  181.     if (@x_target_duration <= 0)
  182.       # Set the new target x and timing, then return
  183.       @x_target_duration = 120
  184.       @x_target_target = (rand(624) - 40)
  185.       return
  186.     end
  187.     # Update the image x target
  188.     d = @x_target_duration
  189.     @x_target = (@x_target * (d - 1.0) + @x_target_target) / d
  190.     # Decrement the frame duration
  191.     @x_target_duration -= 1
  192.   end
  193.   #--------------------------------------------------------------------------
  194.   # * Frame Update (Y Target)
  195.   #--------------------------------------------------------------------------
  196.   def update_y_target
  197.     # If the frame count has run out
  198.     if (@y_target_duration <= 0)
  199.       # Set the new target y and timing, then return
  200.       @y_target_duration = 120
  201.       @y_target_target = (rand(496) - 40)
  202.       return
  203.     end
  204.     # Update the image y target
  205.     d = @y_target_duration
  206.     @y_target = (@y_target * (d - 1.0) + @y_target_target) / d
  207.     # Decrement the frame duration
  208.     @y_target_duration -= 1
  209.   end
  210.   #--------------------------------------------------------------------------
  211.   # * Frame Update (X Position)
  212.   #--------------------------------------------------------------------------
  213.   def update_x
  214.     # Update the image x
  215.     d = 120
  216.     @x = (@x * (d - 1.0) + @x_target) / d
  217.     @image.x = @x
  218.   end
  219.   #--------------------------------------------------------------------------
  220.   # * Frame Update (Y Position)
  221.   #--------------------------------------------------------------------------
  222.   def update_y
  223.     # Update the image y
  224.     d = 120
  225.     @y = (@y * (d - 1.0) + @y_target) / d
  226.     @image.y = @y
  227.   end
  228. end
  229.  
  230. #==============================================================================
  231. # ** Scene_Title
  232. #------------------------------------------------------------------------------
  233. #  This class performs the title screen processing.
  234. #==============================================================================
  235.  
  236. class Scene_Title < Scene_Base
  237.   #--------------------------------------------------------------------------
  238.   # * Start Processing
  239.   #--------------------------------------------------------------------------
  240.   def start
  241.     super
  242.     SceneManager.clear
  243.     Graphics.freeze
  244.     create_background
  245.     create_foreground
  246.     create_sunbeams
  247.     create_dots
  248.     create_command_window
  249.     play_title_music
  250.   end
  251.   #--------------------------------------------------------------------------
  252.   # * Frame Update
  253.   #--------------------------------------------------------------------------
  254.   def update
  255.     # Call the parent method
  256.     super
  257.     # Iterate through the list of sunbeams
  258.     for sunbeam in @sunbeams
  259.       # Update the sunbeam
  260.       sunbeam.update()
  261.     end
  262.     # Iterate through the list of dots
  263.     for dot in @dots
  264.       # Update the dot
  265.       dot.update()
  266.     end
  267.   end
  268.   #--------------------------------------------------------------------------
  269.   # * Get Transition Speed
  270.   #--------------------------------------------------------------------------
  271.   def transition_speed
  272.     return 20
  273.   end
  274.   #--------------------------------------------------------------------------
  275.   # * Termination Processing
  276.   #--------------------------------------------------------------------------
  277.   def terminate
  278.     super
  279.     SceneManager.snapshot_for_background
  280.     dispose_background
  281.     dispose_foreground
  282.     dispose_sunbeams
  283.     dispose_dots
  284.   end
  285.   #--------------------------------------------------------------------------
  286.   # * Create Background
  287.   #--------------------------------------------------------------------------
  288.   def create_background
  289.     @sprite1 = Sprite.new
  290.     @sprite1.bitmap = Cache.title1($data_system.title1_name)
  291.     @sprite2 = Sprite.new
  292.     @sprite2.bitmap = Cache.title2($data_system.title2_name)
  293.     @sprite2.z = 50
  294.     center_sprite(@sprite1)
  295.     center_sprite(@sprite2)
  296.   end
  297.   #--------------------------------------------------------------------------
  298.   # * Create Foreground
  299.   #--------------------------------------------------------------------------
  300.   def create_foreground
  301.     @foreground_sprite = Sprite.new
  302.     @foreground_sprite.bitmap = Bitmap.new(Graphics.width, Graphics.height)
  303.     @foreground_sprite.z = 100
  304.     draw_game_title if $data_system.opt_draw_title
  305.   end
  306.   #--------------------------------------------------------------------------
  307.   # * Create Sunbeams
  308.   #--------------------------------------------------------------------------
  309.   def create_sunbeams
  310.     # Initialize the sunbeam array
  311.     @sunbeams = []
  312.     # Iterate through the list of sunbeams
  313.     for i in 0...5
  314.       # Create the sunbeam graphic and add it to the array
  315.       @sunbeams.push(Title_Sunbeam.new(i + 1))
  316.     end
  317.   end
  318.   #--------------------------------------------------------------------------
  319.   # * Create Dots
  320.   #--------------------------------------------------------------------------
  321.   def create_dots
  322.     # Initialize the dot array
  323.     @dots = []
  324.     # Iterate through the list of sunbeams
  325.     for i in 0...100
  326.       # Create the sunbeam graphic and add it to the array
  327.       @dots.push(Title_Dot.new())
  328.     end
  329.   end
  330.   #--------------------------------------------------------------------------
  331.   # * Draw Game Title
  332.   #--------------------------------------------------------------------------
  333.   def draw_game_title
  334.     @foreground_sprite.bitmap.font.size = 48
  335.     rect = Rect.new(0, 0, Graphics.width, Graphics.height / 2)
  336.     @foreground_sprite.bitmap.draw_text(rect, $data_system.game_title, 1)
  337.   end
  338.   #--------------------------------------------------------------------------
  339.   # * Free Background
  340.   #--------------------------------------------------------------------------
  341.   def dispose_background
  342.     @sprite1.bitmap.dispose
  343.     @sprite1.dispose
  344.     @sprite2.bitmap.dispose
  345.     @sprite2.dispose
  346.   end
  347.   #--------------------------------------------------------------------------
  348.   # * Free Foreground
  349.   #--------------------------------------------------------------------------
  350.   def dispose_foreground
  351.     @foreground_sprite.bitmap.dispose
  352.     @foreground_sprite.dispose
  353.   end
  354.   #--------------------------------------------------------------------------
  355.   # * Free Sunbeams
  356.   #--------------------------------------------------------------------------
  357.   def dispose_sunbeams
  358.     # Iterate through the list of sunbeams
  359.     for sunbeam in @sunbeams
  360.       # Dispose of the sunbeam
  361.       sunbeam.dispose
  362.     end
  363.     # Clear the list of sunbeams
  364.     @sunbeams.clear
  365.   end
  366.   #--------------------------------------------------------------------------
  367.   # * Free Dots
  368.   #--------------------------------------------------------------------------
  369.   def dispose_dots
  370.     # Iterate through the list of sunbeams
  371.     for dot in @dots
  372.       # Dispose of the sunbeam
  373.       dot.dispose
  374.     end
  375.     # Clear the list of sunbeams
  376.     @dots.clear
  377.   end
  378.   #--------------------------------------------------------------------------
  379.   # * Move Sprite to Screen Center
  380.   #--------------------------------------------------------------------------
  381.   def center_sprite(sprite)
  382.     sprite.ox = sprite.bitmap.width / 2
  383.     sprite.oy = sprite.bitmap.height / 2
  384.     sprite.x = Graphics.width / 2
  385.     sprite.y = Graphics.height / 2
  386.   end
  387.   #--------------------------------------------------------------------------
  388.   # * Create Command Window
  389.   #--------------------------------------------------------------------------
  390.   def create_command_window
  391.     @command_window = Window_TitleCommand.new
  392.     @command_window.set_handler(:new_game, method(:command_new_game))
  393.     @command_window.set_handler(:continue, method(:command_continue))
  394.     @command_window.set_handler(:shutdown, method(:command_shutdown))
  395.   end
  396.   #--------------------------------------------------------------------------
  397.   # * Close Command Window
  398.   #--------------------------------------------------------------------------
  399.   def close_command_window
  400.     @command_window.close
  401.     update until @command_window.close?
  402.   end
  403.   #--------------------------------------------------------------------------
  404.   # * [New Game] Command
  405.   #--------------------------------------------------------------------------
  406.   def command_new_game
  407.     DataManager.setup_new_game
  408.     close_command_window
  409.     fadeout_all
  410.     $game_map.autoplay
  411.     SceneManager.goto(Scene_Map)
  412.   end
  413.   #--------------------------------------------------------------------------
  414.   # * [Continue] Command
  415.   #--------------------------------------------------------------------------
  416.   def command_continue
  417.     close_command_window
  418.     SceneManager.call(Scene_Load)
  419.   end
  420.   #--------------------------------------------------------------------------
  421.   # * [Shut Down] Command
  422.   #--------------------------------------------------------------------------
  423.   def command_shutdown
  424.     close_command_window
  425.     fadeout_all
  426.     SceneManager.exit
  427.   end
  428.   #--------------------------------------------------------------------------
  429.   # * Play Title Screen Music
  430.   #--------------------------------------------------------------------------
  431.   def play_title_music
  432.     $data_system.title_bgm.play
  433.     RPG::BGS.stop
  434.     RPG::ME.stop
  435.   end
  436. end
RAW Paste Data