Advertisement
neonblack

Anni Batt Script V1.0 (vx)

Mar 21st, 2012
1,828
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 7.46 KB | None | 0 0
  1. ###--------------------------------------------------------------------------###
  2. #  Animated Battler Graphic script                                             #
  3. #  Version 1.0                                                                 #
  4. #                                                                              #
  5. #      Credits:                                                                #
  6. #  Original code by: Neonblack                                                 #
  7. #  Modified by:                                                                #
  8. #                                                                              #
  9. #  This work is licensed under the Creative Commons Attribution-NonCommercial  #
  10. #  3.0 Unported License. To view a copy of this license, visit                 #
  11. #  http://creativecommons.org/licenses/by-nc/3.0/.                             #
  12. #  Permissions beyond the scope of this license are available at               #
  13. #  http://cphouseset.wordpress.com/liscense-and-terms-of-use/.                 #
  14. #                                                                              #
  15. #      Contact:                                                                #
  16. #  NeonBlack - neonblack23@live.com (e-mail) or "neonblack23" on skype         #
  17. ###--------------------------------------------------------------------------###
  18.  
  19. ###--------------------------------------------------------------------------###
  20. #      Revision information:                                                   #
  21. #  V1.0 - 11.27.2011                                                           #
  22. #   Wrote and debugged main script                                             #
  23. ###--------------------------------------------------------------------------###
  24.  
  25. ###--------------------------------------------------------------------------###
  26. #      Compatibility:                                                          #
  27. #  Alias       - Game_Enemy:  initialize                                       #
  28. #                Scene_Title:  load_bt_database, load_database                 #
  29. #  Overwrites  - Sprite_Battler:  update_battler_bitmap                        #
  30. #  New Objects - Game_Enemy: ani_frames, z_size                                #
  31. #                Sprite_Battler: animated_sprite_bitmap                        #
  32. #                Scene_Title: load_cp_ani_cache                                #
  33. ###--------------------------------------------------------------------------###
  34.  
  35. ###--------------------------------------------------------------------------###
  36. #      Instructions:                                                           #
  37. #  Place this script in the "Materials" section of the scripts above main.     #
  38. #  This script is plug and play and needs no modding to work.  Some monster    #
  39. #  commands are available below and described in some detail.                  #
  40. #                                                                              #
  41. #      Commands:                                                               #
  42. #  sprite[x:y]  - Used to define an animations sheet.  Place this command in   #
  43. #                 the description box of whatever monster you want to change.  #
  44. #                 Change "x" to the filename for the animation sheet.          #
  45. #                 Change "y" to the number of frames contained in the sheet.   #
  46. #                                                                              #
  47. #                 Example: "sprite[Gallade:10]                                 #
  48. #                          The monster graphic "Gallade" will be used and the  #
  49. #                          graphic will cycle through 10 stages of animation.  #
  50. #                                                                              #
  51. #      zoom[x]  - Change the size of the battler where "x" is the actual       #
  52. #                 pixel size.  For example, 100% zoome is just "1", 200% zoom  #
  53. #                 is "2", etc.  It is important to note that this command may  #
  54. #                 only be used on animated battlers.                           #
  55. ###--------------------------------------------------------------------------###
  56.  
  57.  
  58. ###--------------------------------------------------------------------------###
  59. #  The following lines are the actual core code of the script.  While you are  #
  60. #  certainly invited to look, modifying it may result in undesirable results.  #
  61. #  Modify at your own risk!                                                    #
  62. ###--------------------------------------------------------------------------###
  63.  
  64. class Game_Enemy < Game_Battler
  65.   alias cp_ani_initialize initialize unless $@
  66.   def initialize(index, enemy_id)
  67.     cp_ani_initialize(index, enemy_id)
  68.     @ani_frames = enemy.ani_frames
  69.     @z_size = enemy.z_size
  70.   end
  71.     ####-------------------------------------------------
  72.     #New objects used to properly call the new variables.
  73.   def ani_frames
  74.     return @ani_frames
  75.   end
  76.  
  77.   def z_size
  78.     return @z_size
  79.   end
  80. end
  81.  
  82. class Sprite_Battler < Sprite_Base
  83.   def update_battler_bitmap
  84.     @frame_count = 0 if @frame_count == nil
  85.     @frame_count += 1 if @ani_frames != 0
  86.     if @battler.battler_name != @battler_name or
  87.        @battler.battler_hue != @battler_hue or
  88.        @frame_count >= 4
  89.       @frame_count = 0
  90.       @ani_frames = @battler.ani_frames
  91.       @z_size = @battler.z_size
  92.       @battler_name = @battler.battler_name
  93.       @battler_hue = @battler.battler_hue
  94.       if @ani_frames == 0
  95.         self.bitmap = Cache.battler(@battler_name, @battler_hue)
  96.       else
  97.         self.bitmap = animated_sprite_bitmap
  98.       end
  99.       @width = bitmap.width
  100.       @height = bitmap.height
  101.       self.ox = @width / 2
  102.       self.oy = @height
  103.       if @battler.dead? or @battler.hidden
  104.         self.opacity = 0
  105.       end
  106.     end
  107.   end  
  108.     ####-----------------------------------------
  109.     #New object used to draw the animated sprite.
  110.   def animated_sprite_bitmap
  111.     @frame_set = -1 if @frame_set == nil
  112.     @frame_set += 1
  113.     @frame_set = 0 if @frame_set >= @ani_frames
  114.    
  115.     zi = @z_size
  116.     tempbat = Cache.battler(@battler_name, @battler_hue)
  117.     howide = tempbat.width / @ani_frames
  118.     temprec = Rect.new(@frame_set * howide, 0, howide, tempbat.height)
  119.     tempmap = Bitmap.new(tempbat.width / @ani_frames * zi, tempbat.height * zi)
  120.     tempmap.stretch_blt(tempmap.rect, tempbat, temprec)
  121.     return tempmap
  122.   end
  123. end
  124.  
  125. module CP
  126.   module REGEXP
  127.     module ENEMY
  128.       SPRITE = /sprite\[(\w+):(\d+)\]/i
  129.       ZSIZE = /zoom\[(\d+)\]/i
  130.     end
  131.   end
  132. end
  133.  
  134. class RPG::Enemy
  135.   attr_accessor :ani_frames
  136.   attr_accessor :z_size
  137.  
  138.   def cache_enemy_cp_ani
  139.     return if @cp_cached_enemy; @cp_cached_enemy = true
  140.     @ani_frames = 0
  141.     @z_size = 1
  142.     self.note.split(/[\r\n]+/).each { |line|
  143.       case line
  144.       when CP::REGEXP::ENEMY::SPRITE
  145.         @battler_name = $1.to_s
  146.         @ani_frames = $2.to_i
  147.       when CP::REGEXP::ENEMY::ZSIZE
  148.         @z_size = $1.to_i
  149.       end
  150.     }
  151.   end
  152. end
  153.  
  154. class Scene_Title < Scene_Base
  155.   alias cp_bt_load_database load_bt_database unless $@
  156.   def load_bt_database
  157.     cp_bt_load_database
  158.     load_cp_ani_cache
  159.   end
  160.  
  161.   alias cp_ani_load_database load_database unless $@
  162.   def load_database
  163.     cp_ani_load_database
  164.     load_cp_ani_cache
  165.   end
  166.  
  167.   def load_cp_ani_cache
  168.     for obj in $data_enemies
  169.       next if obj == nil
  170.       obj.cache_enemy_cp_ani if obj.is_a?(RPG::Enemy)
  171.     end
  172.   end
  173. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement