Ocedic

OC Animated Title 1.0

Apr 17th, 2013
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 12.18 KB | None | 0 0
  1. # *****************************************************************************
  2. #
  3. # OC ANIMATED TITLE SCREEN
  4. # Author: Ocedic
  5. # Site: http://ocedic.wordpress.com/
  6. # Version: 1.0
  7. # Last Updated: 3/16/13
  8. #
  9. # Updates:
  10. # 1.0 - First release
  11. #
  12. # *****************************************************************************
  13.  
  14. $imported = {} if $imported.nil?
  15. $imported["OC-AnimatedTitleLayers"] = true
  16.  
  17. #==============================================================================
  18. # ▼ Introduction
  19. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  20. # This script allows you to create a custom title screen with moving, animated
  21. # layers.
  22. #==============================================================================
  23. # ▼ Instructions
  24. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  25. # Place this script above Main and customize options in the configuration
  26. # section. Files must be have a "-x" after their name, where x is their frame
  27. # number. For example, if you have a layer called "dog.png" with 3 frames of
  28. # animation, each file must be named "dog-1.png", "dog-2.png" and "dog-3.png"
  29. # respectively. Since all layers have at least one frame, even if you aren't
  30. # using animation for that layer the file must have a "-1" after it.
  31. #
  32. # See demo for further
  33. #==============================================================================
  34. # ▼ Compatibility
  35. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  36. # This script may not be compatible with other scripts that affect the title
  37. # scene.
  38. #==============================================================================
  39. # ▼ Terms of Use
  40. # =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  41. # Can be freely used and modified in non-commercial projects. Proper attribution
  42. # must be given to Ocedic, and this header must be preserved.
  43. # For commercial terms, see here: https://ocedic.wordpress.com/terms-of-use/
  44. #==============================================================================
  45.  
  46. #==============================================================================
  47. # ■ Configuration
  48. #------------------------------------------------------------------------------
  49. #  Change customizable settings here
  50. #==============================================================================
  51.  
  52. module OC
  53.   module TITLE
  54.  
  55. #==============================================================================
  56. # * Layers Path *
  57. #------------------------------------------------------------------------------
  58. #   The folder in which custom layers are stored.
  59. #==============================================================================
  60.  
  61.     LAYERS_PATH = "Graphics/TitleLayers/"
  62.    
  63. #==============================================================================
  64. # * Layer Speed *
  65. #------------------------------------------------------------------------------
  66. #   The speed at which the layers will move into position.
  67. #==============================================================================
  68. # * Update Frequency *
  69. #------------------------------------------------------------------------------
  70. #   How often the layers will update position and zoom. This variable is an
  71. #   update every x frames. This means that a higher number will slow the speed.
  72. #==============================================================================
  73. # * Focus Zoom *
  74. #------------------------------------------------------------------------------
  75. #   The amount of zoom on the focus entry. A higher number is greater zoom.
  76. #==============================================================================
  77. # * Zoom Speed *
  78. #------------------------------------------------------------------------------
  79. #   The speed at which the focus entry zooms in. Recommended to keep it at a
  80. #   multiple of 0.004. A higher number is higher zoom speed.
  81. #==============================================================================
  82.     LAYER_SPEED = 2      # Default 2
  83.     UPDATE_FREQ = 2      # Default 2
  84.     FOCUS_ZOOM  = 1.3    # Default 1.3
  85.     ZOOM_SPEED  = 0.004  # Default 0.004
  86.        
  87. #==============================================================================
  88. # * Title Layers *
  89. #------------------------------------------------------------------------------
  90. #   Manage all of your layers in this array. To add a new layer, copy one of
  91. #   the elements. "Filename" is the name of the graphic file.
  92. #   "Z-index" is how it will be displayed relative to other layers. The higher
  93. #   the z-index, the closer to the foreground it is.
  94. #   "Position" is the final x and y coordinates of the image.
  95. #   "Frames" is the number of frames of animation for the layer. For file naming
  96. #   instructions, see above.
  97. #   "Refresh" is the refresh rate of the layer. A lower number gives a faster
  98. #   animation.
  99. #   "Blend" is the blending mode that the bitmap will use. 0 is normal, 1 is
  100. #   additive, 2 is subtractive.
  101. #   "Entry" is the type of entry effect the layer uses. There are a number of
  102. #   pre-defined entries:
  103. #   :origin - The layer appears as is at the position
  104. #   :focus - The layer zooms in by the focus zoom above
  105. #   :left - The layer comes in from the left and moves to position
  106. #   :right - The layer comes in from the right and moves to position
  107. #
  108. #==============================================================================
  109.     LAYERS = [
  110.  
  111. #     ["filename",  z-index,  position,  entry,  frames,  refresh,  blend],
  112.       ["mansion",   0,        0,0,      :focus,   1,      0,        0],
  113.       ["gatel",     5,     -50,40,       :left,   4,     10,        0],
  114.       ["gater",    10,      50,40,      :right,   1,      0,        0],
  115.       ["smoke",    15,      0,-60,     :bottom,   4,      5,        0],
  116.        
  117.     ]  # Don't delete this
  118.    
  119.   end #TITLE
  120. end #OC
  121.  
  122. #==============================================================================
  123. # ■ End of Configuration
  124. #==============================================================================
  125.  
  126. #==============================================================================
  127. # ■ New Class: Sprite_Layer
  128. #==============================================================================
  129.  
  130. class Sprite_Layer < Sprite_Base
  131.  
  132. #==============================================================================
  133. # * Accessors *
  134. #==============================================================================
  135.   attr_accessor :target_x
  136.   attr_accessor :target_y
  137.   attr_accessor :filename
  138.   attr_accessor :frames
  139.   attr_accessor :refresh
  140.  
  141. #==============================================================================
  142. # * Alias: Initialize *
  143. #==============================================================================
  144.   alias oc_sprite_layer_initialize_2nols initialize
  145.   def initialize(viewport = nil)
  146.     oc_sprite_layer_initialize_2nols
  147.     @filename = nil
  148.     @frames = 0
  149.     @refresh = 0
  150.     @target_x = 0
  151.     @target_y = 0
  152.     @target_zoom = 1.0
  153.     @entry = nil
  154.     @current_frame = 1     # Current frame of animation loaded
  155.   end
  156.  
  157. #==============================================================================
  158. # * New Method: Set Initial Position *
  159. #==============================================================================
  160.   def set_initial_pos(entry)
  161.     case entry
  162.     when :origin
  163.       self.x = @target_x
  164.       self.y = @target_y
  165.       @entry = :origin
  166.     when :focus
  167.       @target_zoom = OC::TITLE::FOCUS_ZOOM
  168.       @entry = :focus
  169.     when :left
  170.       self.x = -Graphics.width / 3
  171.       self.y = @target_y
  172.       @entry = :left
  173.     when :right
  174.       self.x = Graphics.width / 3
  175.       self.y = @target_y
  176.       @entry = :right
  177.     when :top
  178.       self.x = @target_x
  179.       self.y = -Graphics.height / 3
  180.       @entry = :top
  181.     when :bottom
  182.       self.x = @target_x
  183.       self.y = Graphics.height / 3
  184.       @entry = :bottom
  185.     end
  186.   end
  187.  
  188. #==============================================================================
  189. # * New Method: Change Frame *
  190. #==============================================================================  
  191.   def change_frame(id)
  192.     filename = @filename + "-" + id.to_s
  193.     self.bitmap = Cache.load_bitmap(OC::TITLE::LAYERS_PATH, filename)
  194.   end
  195.  
  196. #==============================================================================
  197. # * New Method: Update Layer *
  198. #==============================================================================
  199.   def update_layer
  200.     @update_timer ||= 0
  201.     @update_timer += 1
  202.     update_position if @update_timer % OC::TITLE::UPDATE_FREQ == 0 &&
  203.                        ((((self.x != @target_x) || (self.y != @target_y)) &&
  204.                        @entry != :focus) || (self.zoom_x != @target_zoom))
  205.     @update_refresh ||= 0
  206.     @update_refresh += 1
  207.     update_animation if @frames > 1 && @update_refresh % @refresh == 0
  208.   end
  209.  
  210. #==============================================================================
  211. # * New Method: Update Position *
  212. #==============================================================================
  213.   def update_position
  214.     case @entry
  215.     when :focus
  216.       self.zoom_x += [OC::TITLE::ZOOM_SPEED, @target_zoom - self.zoom_x].min
  217.       self.zoom_y += [OC::TITLE::ZOOM_SPEED, @target_zoom - self.zoom_y].min
  218.       self.x -= OC::TITLE::ZOOM_SPEED / 0.004
  219.       self.y -= OC::TITLE::ZOOM_SPEED / 0.004
  220.     when :left
  221.       self.x += [OC::TITLE::LAYER_SPEED, @target_x - x].min
  222.     when :right
  223.       self.x -= [OC::TITLE::LAYER_SPEED, x - @target_x].min
  224.     when :top
  225.       self.y += [OC::TITLE::LAYER_SPEED, @target_y - y].min
  226.     when :bottom
  227.       self.y -= [OC::TITLE::LAYER_SPEED, y - @target_y].min
  228.     end
  229.   end
  230.  
  231. #==============================================================================
  232. # * New Method: Update Animation *
  233. #==============================================================================
  234.   def update_animation
  235.     if @current_frame < @frames
  236.       @current_frame += 1
  237.     else
  238.       @current_frame = 1
  239.     end
  240.     change_frame(@current_frame)
  241.   end
  242.  
  243. end #class sprite_layer
  244.  
  245. #==============================================================================
  246. # ■ Scene_Title
  247. #==============================================================================
  248.  
  249. class Scene_Title < Scene_Base
  250.  
  251. #==============================================================================
  252. # * Overwrite: Start *
  253. #==============================================================================
  254.   def start
  255.     super
  256.     SceneManager.clear
  257.     Graphics.freeze
  258.     @layers = Array.new
  259.     @fogs = Array.new
  260.     load_layers
  261.     create_command_window
  262.     play_title_music
  263.   end  
  264.  
  265. #==============================================================================
  266. # * Overwrite: Update Basic *
  267. #==============================================================================
  268.   def update_basic
  269.     super
  270.     @layers.each do |layer|
  271.       layer.update_layer
  272.     end
  273.   end
  274.  
  275. #==============================================================================
  276. # * New Method: Load Layers *
  277. #------------------------------------------------------------------------------
  278. #   Loads all layers defined in the LAYERS array into an array of sprite layers
  279. #   that we can manage and manipulate
  280. #==============================================================================
  281.   def load_layers
  282.     i = 0
  283.     OC::TITLE::LAYERS.each do |layer|
  284.       @layers << Sprite_Layer.new
  285.       @layers[i].filename = layer[0]
  286.       @layers[i].frames = layer[5]
  287.       @layers[i].refresh = layer[6]
  288.       filename = layer[0] + "-1"
  289.       @layers[i].bitmap = Cache.load_bitmap(OC::TITLE::LAYERS_PATH, filename)
  290.       @layers[i].blend_type = layer[7]
  291.       @layers[i].z = layer[1]
  292.       @layers[i].target_x = layer[2]
  293.       @layers[i].target_y = layer[3]
  294.       @layers[i].set_initial_pos(layer[4])
  295.       i += 1
  296.     end
  297.   end
  298.  
  299. #==============================================================================
  300. # * Overwrite: Terminate *
  301. #==============================================================================
  302.   def terminate
  303.     super
  304.     SceneManager.snapshot_for_background
  305.     @layers.each do |layer|
  306.       layer.dispose
  307.     end
  308.   end
  309.  
  310. end #class scene_title
Advertisement
Add Comment
Please, Sign In to add comment