TheoAllen

Theo - Animated Battleback (ENG)

Oct 28th, 2013
1,654
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.38 KB | None | 0 0
  1. # =============================================================================
  2. # TheoAllen - Animated Battleback
  3. # Version : 1.0b
  4. # Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com
  5. # (English Documentation)
  6. # =============================================================================
  7. ($imported ||= {})[:Theo_AnimBattleBack] = true
  8. # =============================================================================
  9. # Change Logs:
  10. # -----------------------------------------------------------------------------
  11. # 2014.07.15 - Fixed bug where you couldn't put unanimated battleback
  12. # 2013.10.28 - Finished script
  13. # =============================================================================
  14. =begin
  15.  
  16.   ------------------------------------------------------------------------
  17.   Introduction :
  18.   ------------------------------------------------------------------------
  19.   Want some animated battleback? Well, this script may grant your wish. I hope
  20.   so
  21.  
  22.   ------------------------------------------------------------------------
  23.   How to use :
  24.   ------------------------------------------------------------------------
  25.   Put this script below material but above main.
  26.   Create a folder inside folder Graphics. Name it "AnimBatleBack"
  27.  
  28.   Prepare the background image for battleback, name it with format
  29.   "filename_01.png". Prepare the next frame image and name it with
  30.   "filename_02.png". You may insert as many as you like. Remember to include
  31.   frame number in the image filename. ("_02.png _03.png" etc ...)
  32.  
  33.   In order to use animated battleback in a certain map, use a notetag
  34.   <anim bb: animaton_key> where "animation_key" is a "key" which located at
  35.   configuration below. Remember, the notetag doesn't require quotes ("") to
  36.   write. Just put <anim bb: your_key>
  37.  
  38.   ------------------------------------------------------------------------
  39.   Terms of use :
  40.   ------------------------------------------------------------------------
  41.   Credit me, TheoAllen. You are free to edit this script by your own. As long
  42.   as you don't claim it yours. For commercial purpose, don't forget to give me
  43.   a free copy of the game.
  44.  
  45. =end
  46. # =============================================================================
  47. # Configuration
  48. # =============================================================================
  49. module Theo
  50.   module AnimBB
  51.   # --------------------------------------------------------------------------
  52.   # Animated Battleback Database
  53.   # --------------------------------------------------------------------------
  54.   # Manuals :
  55.   #
  56.   # Key     --> A keyword that to be used in map notetag
  57.   # Name    --> Graphics file name (without "_01.png")
  58.   # Frame   --> Max frame for animation
  59.   # Rate    --> Refresh rate. The lower value, the faster animation will be
  60.   #             shown
  61.   # --------------------------------------------------------------------------
  62.     List = {
  63.   # "Key"     => ["Name"      , Frame, Rate],
  64.     "mansion" => ["mansion"   ,     8,    4],
  65.     "dtown"   => ["deserttown",     7,   10],
  66.  
  67.   # Add by yourself
  68.     } # <-- Don't touch at all cost!
  69.    
  70.   end
  71. end
  72. # =============================================================================
  73. # End of Configuration
  74. # =============================================================================
  75. class << Cache
  76.  
  77.   def animbattleback(filename, index)
  78.     file = filename + sprintf("_%02d", index)
  79.     load_bitmap("Graphics/AnimBattleBack/", file)
  80.   end
  81.  
  82. end
  83.  
  84. class Game_System
  85.   attr_accessor :anim_bb
  86.  
  87.   alias theo_animbb_init initialize
  88.   def initialize
  89.     theo_animbb_init
  90.     @anim_bb = ""
  91.   end
  92.  
  93. end
  94.  
  95. class Game_Map
  96.  
  97.   alias theo_animbb_setup setup
  98.   def setup(map_id)
  99.     theo_animbb_setup(map_id)
  100.     setup_animbb
  101.   end
  102.  
  103.   def setup_animbb
  104.     $game_system.anim_bb = ""
  105.     @map.note.split(/[\r\n]+/).each do |line|
  106.       if line =~ /<(?:anim bb|anim_bb):[ ]*(.+)>/i
  107.         $game_system.anim_bb = $1.to_s
  108.       end
  109.     end
  110.   end
  111.  
  112. end
  113.  
  114. class AnimBB < Sprite
  115.   attr_reader :name
  116.   attr_reader :index
  117.  
  118.   def initialize(viewport)
  119.     super(viewport)
  120.     init_member
  121.   end
  122.  
  123.   def init_member
  124.     @name = $game_system.anim_bb
  125.     @count = 0
  126.     @index = 1
  127.     refresh_bitmap
  128.   end
  129.  
  130.   def refresh_bitmap
  131.     if name.empty?
  132.       self.bitmap = Cache.empty_bitmap
  133.     else
  134.       self.bitmap = Cache.animbattleback(file, index)
  135.     end
  136.   end
  137.  
  138.   def file
  139.     Theo::AnimBB::List[name][0]
  140.   end
  141.  
  142.   def max_index
  143.     Theo::AnimBB::List[name][1]
  144.   end
  145.  
  146.   def rate
  147.     Theo::AnimBB::List[name][2]
  148.   end
  149.  
  150.   def need_refresh?
  151.     @count % rate == 0 && !name.empty?
  152.   end
  153.  
  154.   def change_index
  155.     @index += 1
  156.     if @index == max_index
  157.       @index = 1
  158.     end
  159.     refresh_bitmap
  160.   end
  161.  
  162.   def update
  163.     super
  164.     return if name.empty?
  165.     @count += 1
  166.     change_index if need_refresh?
  167.   end
  168.  
  169. end
  170.  
  171. class Spriteset_Battle
  172.  
  173.   alias theo_animbb_create_viewports create_viewports
  174.   def create_viewports
  175.     theo_animbb_create_viewports
  176.     create_animbb
  177.   end
  178.  
  179.   def create_animbb
  180.     @animbb = AnimBB.new(@viewport1)
  181.     @animbb.z = 5
  182.     center_sprite(@animbb)
  183.   end
  184.  
  185.   alias theo_animbb_update update
  186.   def update
  187.     theo_animbb_update
  188.     @animbb.update
  189.   end
  190.  
  191.   alias theo_animbb_dispose dispose
  192.   def dispose
  193.     theo_animbb_dispose
  194.     @animbb.dispose
  195.   end
  196.  
  197. end
Advertisement
Add Comment
Please, Sign In to add comment