Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. # =============================================================================
  2. # TheoAllen - Character Animation Loop
  3. # Version : 1.0
  4. # Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com
  5. # (This script documentation is written in informal indonesian language)
  6. # =============================================================================
  7. ($imported ||= {})[:Theo_CharAnimloop] = true
  8. # =============================================================================
  9. # Change Logs:
  10. # -----------------------------------------------------------------------------
  11. # 2014.02.12 - Finished script
  12. # =============================================================================
  13. =begin
  14.  
  15.   -----------------------------------------------------------------------------
  16.   Perkenalan :
  17.   Script ini ngebikin kamu bisa ngeplay animasi looping pada karakter yang ada
  18.   di map.
  19.  
  20.   -----------------------------------------------------------------------------
  21.   Cara penggunaan :
  22.   Pasang script ini di bawah material namun di atas main
  23.   Gunakan script call seperti ini pada set move route
  24.  
  25.   animloop(id)
  26.   animloop(id, mirror)
  27.   animloop(id, mirror, rate)
  28.  
  29.   Ganti id dengan id animasi dalam database.
  30.   Ganti mirror dengan true atawa false. Nilai defaultnya adalah false
  31.   Ganti rate dengan angka 1 - 4. Semakin kecil semakin cepat gerakan
  32.   animasinya. Nilai defaultnya adalah 3
  33.  
  34.   Untuk ngehentiin animasi cukup dengan tulis
  35.   end_animloop
  36.  
  37.   -----------------------------------------------------------------------------
  38.   Terms of use :
  39.   Credit gw, TheoAllen. Kalo semisal u bisa ngedit2 script gw trus jadi lebih
  40.   keren, terserah. Ane bebasin. Asal ngga ngeklaim aja. Kalo semisal mau
  41.   dipake buat komersil, jangan lupa, gw dibagi gratisannya.    
  42.  
  43. =end
  44. # =============================================================================
  45. # Tidak ada konfigurasi. Jangan sentuh apapun di bawah ini
  46. # =============================================================================
  47. class Game_Character
  48.   attr_accessor :animloop_id
  49.   attr_accessor :animloop_mirror
  50.   attr_accessor :animloop_rate
  51.  
  52.   alias theo_animloop_id_init initialize
  53.   def initialize
  54.     theo_animloop_id_init
  55.     init_animloop_members
  56.   end
  57.  
  58.   def init_animloop_members
  59.     @animloop_id = 0
  60.     @animloop_mirror = false
  61.     @animloop_rate = 3
  62.   end
  63.  
  64.   def animloop(id, mirror = false, rate = 3)
  65.     @animloop_id = id
  66.     @animloop_mirror = mirror
  67.     @animloop_rate = rate
  68.   end
  69.  
  70.   def end_animloop
  71.     init_animloop_members
  72.   end
  73.  
  74. end
  75. # -----------------------------------------------------------------------------
  76. # Pseudo Sprite for animation
  77. # -----------------------------------------------------------------------------
  78. class Char_Animloop < Sprite_Base  
  79.   attr_reader :char_sprite
  80.  
  81.   def initialize(char_sprite)
  82.     super(char_sprite.viewport)
  83.     @char_sprite = char_sprite
  84.     update_all
  85.   end
  86.  
  87.   def update_all
  88.     src_rect.set(char_sprite.src_rect)
  89.     self.ox = char_sprite.ox
  90.     self.oy = char_sprite.oy
  91.     last_x = char_sprite.x - self.x
  92.     last_y = char_sprite.y - self.y
  93.     move_animation(last_x, last_y)
  94.     self.x = char_sprite.x
  95.     self.y = char_sprite.y
  96.     self.z = char_sprite.z
  97.   end
  98.  
  99.   def update
  100.     super
  101.     update_all
  102.     setup_animation
  103.   end
  104.  
  105.   def setup_animation
  106.     if !animation? && character.animloop_id != 0
  107.       @anim_id = character.animloop_id
  108.       start_animation($data_animations[@anim_id], character.animloop_mirror)
  109.     end
  110.   end
  111.  
  112.   def character
  113.     char_sprite.character
  114.   end
  115.  
  116.   def end_animation
  117.     if character.animloop_id == @anim_id
  118.       @ani_duration = @animation.frame_max * @ani_rate + 1
  119.     # Revert back
  120.     elsif character.animloop_id != @anim_id && character.animloop_id != 0
  121.       @anim_id = character.animloop_id
  122.       start_animation($data_animations[@anim_id], character.animloop_mirror)
  123.     # Change animation  
  124.     else
  125.       @anim_id = 0
  126.       super
  127.     # End animation
  128.     end
  129.   end
  130.  
  131.   def move_animation(dx, dy)
  132.     if @animation && @animation.position != 3
  133.       @ani_ox += dx
  134.       @ani_oy += dy
  135.       @ani_sprites.each do |sprite|
  136.         sprite.x += dx
  137.         sprite.y += dy
  138.       end
  139.     end
  140.   end
  141.  
  142.   def set_animation_rate
  143.     @ani_rate = character.animloop_rate
  144.   end
  145.  
  146. end
  147.  
  148. class Sprite_Character
  149.  
  150.   alias theo_animloop_id_init initialize
  151.   def initialize(*args)
  152.     theo_animloop_id_init(*args)
  153.     @sprite_animloop = Char_Animloop.new(self)
  154.   end
  155.  
  156.   alias theo_animloop_id_update update
  157.   def update
  158.     theo_animloop_id_update
  159.     @sprite_animloop.update if @sprite_animloop
  160.   end
  161.  
  162.   alias theo_animloop_id_dispose dispose
  163.   def dispose
  164.     theo_animloop_id_dispose
  165.     @sprite_animloop.dispose
  166.   end
  167.  
  168. end