TheoAllen

Theo - Animated Battleback

Oct 28th, 2013
515
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 5.58 KB | None | 0 0
  1. # =============================================================================
  2. # TheoAllen - Animated Battleback
  3. # Version : 1.0b
  4. # Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com
  5. # (This script documentation is written in informal indonesian language)
  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.   Perkenalan :
  18.   ------------------------------------------------------------------------
  19.   Pengen battleback kamu bisa gerak? Well, mungkin script ini bisa mewujudkan
  20.   impianmu. Semoga saja :D
  21.  
  22.   ------------------------------------------------------------------------
  23.   Cara penggunaan :
  24.   ------------------------------------------------------------------------
  25.   Pasang script ini dibawah material namun diatas main
  26.   Buat folder "AnimBattleBack" di dalam folder Graphics.
  27.  
  28.   Siapkan gambar background untuk battleback dengan format nama
  29.   "namafile_01.png". Siapkan gambar berikutnya untuk frame animasi setelahnya
  30.   dan namakan dengan "namafile_02.png". Dan seterusnya. Kamu boleh memasukkan
  31.   frame animasi sebanyak yang kamu mau. Dan perlu diingat, jangan lupa dengan
  32.   nomor frame belakang tersebut ("_02.png" dst ...)
  33.  
  34.   Untuk menggunakan animated battleback pada map tertentu, gunakan notetag
  35.   <anim bb: key_animasi> dimana "key_animasi" adalah "key" yang berada pada
  36.   konfigurasi dibawah. Perlu diingat, penulisan "key_animasi" pada notetag
  37.   tidak perlu disertai kutip
  38.  
  39.   ------------------------------------------------------------------------
  40.   Terms of use :
  41.   ------------------------------------------------------------------------
  42.   Credit gw, TheoAllen. Kalo semisal u bisa ngedit2 script gw trus jadi lebih
  43.   keren, terserah. Ane bebasin. Asal ngga ngeklaim aja. Kalo semisal mau
  44.   dipake buat komersil, jangan lupa, gw dibagi gratisannya.
  45.  
  46. =end
  47. # =============================================================================
  48. # Konfigurasi
  49. # =============================================================================
  50. module Theo
  51.   module AnimBB
  52.   # --------------------------------------------------------------------------
  53.   # Animated Battleback Database
  54.   # --------------------------------------------------------------------------
  55.   # Paduan konfigurasi :
  56.   #
  57.   # Key     --> Kata kunci untuk dipergunakan dalam notetag di map properties
  58.   # Nama    --> Nama untuk file gambar (tanpa disertai "_01")
  59.   # Frame   --> Frame maksimal gambar. Misalnya animasi framenya ada 20
  60.   # Rate    --> Refresh rate. Makin kecil, gambar akan makin cepet gerak
  61.   # --------------------------------------------------------------------------
  62.     List = {
  63.   # "Key"     => ["Nama"      , Frame, Rate],
  64.     "mansion" => ["mansion"   ,     8,    4],
  65.     "dtown"   => ["deserttown",     7,   10],
  66.  
  67.   # Tambahin sendiri  
  68.     } # <-- Jangan disentuh!
  69.    
  70.   end
  71. end
  72. # =============================================================================
  73. # Akhir dari konfigurasi
  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