IceDragon200

[IEI]CharacterMultiFrames

May 21st, 2012
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 3.22 KB | None | 0 0
  1. #==============================================================================#
  2. # ♥ IEI - Character Multi Frames
  3. #==============================================================================#
  4. # // • Created By    : IceDragon
  5. # // • Data Created  : 05/21/2012
  6. # // • Data Modified : 05/21/2012
  7. # // • Version       : 0.1
  8. #==============================================================================#
  9. # -- This is a BETA script, and is therefore not final
  10. # put #[number_of_columns,number_of_rows] in a filename to modify its
  11. # default frame progression
  12. # EG.
  13. #   $Actor4#[12,8].png
  14. # --
  15. # To modify the frame order simply change use a 'script' command
  16. # in a 'move route'
  17. #   self.anime_style = n
  18. #   n is:
  19. #     0 - Ping Pong, 1 - Forward, 2 - Reverse, 3 - Random
  20. # --
  21. ($imported||={})["IEI::CharacterMultiFrame"] = 0x01000
  22. #==============================================================================#
  23. # ♥ Game_Character
  24. #==============================================================================#
  25. class Game_Character
  26.   def pattern_frames
  27.     @pattern_frames ||= begin
  28.       n = @character_name.match(/\#\[(\d+),(\d+)\]/)||[nil,3,4]
  29.       n[1,2].collect{|s|s.to_i}
  30.     end
  31.   end
  32.   def update_anime_pattern
  33.     if @last_char_name != @character_name
  34.       @defpattern_a = @pattern_frames = nil
  35.       @last_char_name = @character_name
  36.     end  
  37.     if !@step_anime && @stop_count > 0
  38.       @pattern = @original_pattern
  39.     else
  40.       @pattern = (@pattern + 1) % (pattern_frames[0] + anime_frame_add)
  41.     end
  42.   end
  43.   def anime_frame_add
  44.     return 1 if anime_style == 0
  45.     0
  46.   end  
  47.   # // 0 - Ping Pong, 1 - Forward, 2 - Reverse, 3 - Random
  48.   def anime_style
  49.     @anime_style ||= 0
  50.   end
  51.   attr_writer :anime_style
  52.   def anime_pattern
  53.     case anime_style
  54.     when 0 ;
  55.       (@defpattern_a||=((0...pattern_frames[0]).to_a+(1...(pattern_frames[0]-1)).to_a.reverse))[@pattern]
  56.     when 1 ; @pattern
  57.     when 2 ; pattern_frames[0] - @pattern
  58.     when 3 ; rand(pattern_frames[0])
  59.     end
  60.   end
  61. end
  62. #==============================================================================#
  63. # ♥ Sprite_Character
  64. #==============================================================================#
  65. class Sprite_Character
  66.   def set_character_bitmap
  67.     self.bitmap = Cache.character(@character_name)
  68.     sign = @character_name[/^[\!\$]./]
  69.     hfrms, vfrms = @character ? @character.pattern_frames : [3,4]
  70.     if sign && sign.include?('$')
  71.       @cw = bitmap.width / hfrms
  72.       @ch = bitmap.height / vfrms
  73.     else
  74.       @cw = bitmap.width / (hfrms * 4)
  75.       @ch = bitmap.height / (vfrms * 2)
  76.     end
  77.     self.ox = @cw / 2
  78.     self.oy = @ch
  79.   end
  80.   def update_src_rect
  81.     if @tile_id == 0
  82.       index = @character.character_index
  83.       pattern = @character.anime_pattern #< 3 ? @character.pattern : 1
  84.       hfrms, vfrms = @character.pattern_frames
  85.       sx = (index % 4 * hfrms + pattern) * @cw
  86.       sy = (index / 4 * vfrms + (@character.direction - 2) / 2) * @ch
  87.       self.src_rect.set(sx, sy, @cw, @ch)
  88.     end
  89.   end
  90. end
  91. #==============================================================================#
  92. # EOF
  93. #==============================================================================#
Advertisement
Add Comment
Please, Sign In to add comment