IceDragon200

Weapon Icon Animation 4 Jet's Front View

Mar 10th, 2012
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 6.47 KB | None | 0 0
  1. #==============================================================================#
  2. # ♥ Icon Animation
  3. #==============================================================================#
  4. # // • Created By    : IceDragon (rpgmakervxace.com)
  5. # // • Modified By   : IceDragon (rpgmakervxace.com)
  6. # // • Data Created  : 03/10/2012
  7. # // • Data Modified : 03/10/2012
  8. # // • Version       : 1.0
  9. #==============================================================================#
  10. # ● Change Log
  11. #     ♣ 03/10/2012 V1.0
  12. #         Started & Finished
  13. #==============================================================================#
  14. class Sprite::Icon < Sprite_Base
  15.   attr_reader :icon_index
  16.   def initialize( viewport=nil, icon_index=0 )
  17.     super( viewport )
  18.     @icon_index = icon_index
  19.     self.bitmap = iconset
  20.     update_icon()
  21.   end  
  22.   def iconset
  23.     Cache.system( "Iconset" )
  24.   end  
  25.   def icon_index=( icon_index )
  26.     @icon_index = icon_index
  27.     self.bitmap = iconset
  28.     update_icon()
  29.   end  
  30.   def update_icon()
  31.     self.src_rect.set( @icon_index % 16 * 24, @icon_index / 16 * 24, 24, 24 )
  32.   end  
  33. end
  34. class Cube
  35.   attr_accessor :x, :y, :z
  36.   attr_accessor :width, :length, :height
  37.   def initialize(*args)
  38.     set(*args)
  39.   end
  40.   def set( x=0, y=0, z=0, width=0, height=0, length=0 )
  41.     self.x, self.y, self.z = x, y, z
  42.     self.width, self.length, self.height = width, length, height
  43.   end
  44.   def set2( x=0, y=0, z=0, width=0, length=0, height=0 )
  45.     self.x, self.y, self.z = x, y, z
  46.     self.width, self.length, self.height = width, length, height
  47.   end
  48.   def to_a
  49.     return self.x, self.y, self.z, self.width, self.height, self.length
  50.   end  
  51.   def empty
  52.     set()
  53.   end  
  54. end
  55. module Handler ; end
  56. class Handler::SpriteEquip
  57.   attr_reader :subject
  58.   def initialize(subject)
  59.     @subject    = subject
  60.     @cube       = Cube.new(0,0,0,24,24,0) # // Width, Height aren't used yet
  61.     reset()
  62.   end  
  63.   def reset()
  64.     self.ox,self.oy = 0, 0
  65.     self.icon_index = 0
  66.     self.angle_abs  = 0
  67.     self.opacity    = 255
  68.     self.visible    = false
  69.   end  
  70.   attr_accessor :ox, :oy
  71.   attr_accessor :icon_index
  72.   attr_accessor :angle_abs
  73.   attr_accessor :opacity
  74.   attr_accessor :visible  
  75.   def subject_angle()
  76.     case @subject.direction
  77.     when 2
  78.       0
  79.     when 4
  80.       -90
  81.     when 6
  82.       90
  83.     when 8
  84.       180 # // Err why? pole... thats why
  85.     else
  86.       0
  87.     end  
  88.   end  
  89.   def angle
  90.     angle_abs + subject_angle
  91.   end  
  92.   def auto_oxy()
  93.     self.ox, self.oy = 24, 24
  94.   end  
  95.   def auto_xyz()
  96.     h = (@subject.height * 0.8).to_i
  97.     case @subject.direction
  98.     when 2
  99.       self.x, self.y = 8, h
  100.       self.z = 1
  101.     when 4  
  102.       self.x, self.y = 8, h
  103.       self.z = -1
  104.     when 6
  105.       self.x, self.y = @subject.width-8, h
  106.       self.z = 1
  107.     when 8
  108.       self.x, self.y = @subject.width-8, h
  109.       self.z = -1
  110.     end  
  111.   end
  112.   def x
  113.     @cube.x
  114.   end
  115.   def y
  116.     @cube.y
  117.   end
  118.   def z
  119.     @cube.z
  120.   end  
  121.   def width
  122.     @cube.width
  123.   end  
  124.   def height
  125.     @cube.height
  126.   end
  127.   def x=(n)
  128.     @cube.x = n
  129.   end  
  130.   def y=(n)
  131.     @cube.y = n
  132.   end  
  133.   def z=(n)
  134.     @cube.z = n
  135.   end  
  136.   def width=(n)
  137.     @cube.width = n
  138.   end  
  139.   def height=(n)
  140.     @cube.height = n
  141.   end
  142.   # / Actual Sprite x, y, z
  143.   def screen_x
  144.     @subject.x + self.x - 16
  145.   end
  146.   def screen_y
  147.     @subject.y + self.y - 32
  148.   end
  149.   def screen_z
  150.     @subject.z + self.z
  151.   end
  152.   ACTIONS = {}
  153.   ACTIONS["basicattack"] = proc do |hnd|
  154.     hnd.auto_oxy()
  155.     hnd.auto_xyz()
  156.     hnd.visible = true
  157.     base_angle  = 30
  158.     hnd.icon_index = hnd.subject.weapon_icon
  159.     for i in 0..90
  160.       hnd.angle_abs = base_angle + i
  161.       Fiber.yield if i % 9 == 0 # // 10 frames
  162.     end  
  163.     hnd.visible = false
  164.   end
  165.   def do_action(&action)
  166.     reset()
  167.     @fiber = Fiber.new { call_action(&action) }
  168.   end
  169.   def call_action(&action)
  170.     action.call(self)
  171.     @fiber = nil
  172.   end  
  173.   def update()
  174.     @fiber.resume if(@fiber)
  175.   end
  176.   def busy?()
  177.     !(@fiber).nil?()
  178.   end  
  179.   def wait(n)
  180.     n.times do Fiber.yield ; end
  181.   end  
  182. end  
  183. class Sprite::WeaponIcon < Sprite::Icon
  184.   def initialize(viewport,subject)
  185.     super(viewport)
  186.     @subject = subject # // Handler::SpriteEquip*
  187.     pre_init()
  188.     update()
  189.   end  
  190.   def pre_init()
  191.   end  
  192.   def update()
  193.     super()
  194.     self.x       = @subject.screen_x
  195.     self.y       = @subject.screen_y
  196.     self.z       = @subject.screen_z
  197.     self.ox      = @subject.ox
  198.     self.oy      = @subject.oy
  199.     self.angle   = @subject.angle
  200.     self.opacity = @subject.opacity
  201.     self.visible = @subject.visible
  202.     change_icon_index(@subject.icon_index)
  203.   end  
  204.   def change_icon_index(n)
  205.     self.icon_index = n unless(self.icon_index==n)
  206.   end  
  207. end
  208. # //
  209. class Game_Battler
  210.   def weapon_icon
  211.     0
  212.   end  
  213. end  
  214. class Game_Actor
  215.   def weapon_icon
  216.     w,=weapons.compact(); w ? w.icon_index : super()
  217.   end  
  218. end  
  219. class Game_Enemy
  220.   ENEMY_WEAPON_ICON = {}
  221.   # //         enemy_id
  222.   ENEMY_WEAPON_ICON[1] = 144 # // Axe ...
  223.   def weapon_icon
  224.     ENEMY_WEAPON_ICON[@enemy_id] || super()
  225.   end  
  226. end  
  227. class Sprite_Character
  228.   alias :icon_anim_initialize :initialize
  229.   def initialize(*args,&block)
  230.     icon_anim_initialize(*args,&block)
  231.     @equip_handle = Handler::SpriteEquip.new(self)
  232.     @equip_sprite = Sprite::WeaponIcon.new(self.viewport,@equip_handle)
  233.   end  
  234.   attr_reader :equip_handle
  235.   alias :es_viewport_s :viewport=
  236.   def viewport=(*args,&block)
  237.     es_viewport_s(*args,&block)
  238.     @equip_sprite.viewport = self.viewport
  239.   end  
  240.   def direction
  241.     @character.direction
  242.   end  
  243.   alias :es_update :update
  244.   def update(*args,&block)
  245.     es_update(*args,&block)
  246.     @equip_handle.update() if(@equip_handle)
  247.     @equip_sprite.update() if(@equip_sprite)
  248.   end  
  249.   def weapon_icon()
  250.     @battler.weapon_icon
  251.   end  
  252. end  
  253. class Scene_Battle
  254.   alias :es_show_attack_animation :show_attack_animation
  255.   def show_attack_animation(targets)
  256.     sprite = @subject.battle_sprite
  257.     sprite.equip_handle.do_action(&Handler::SpriteEquip::ACTIONS["basicattack"])
  258.     update_for_wait() while(sprite.equip_handle.busy?())
  259.     es_show_attack_animation(targets)
  260.   end
  261. end  
  262. #=■==========================================================================■=#
  263. #                           // ● End of File ● //                              #
  264. #=■==========================================================================■=#
Advertisement
Add Comment
Please, Sign In to add comment