Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #==============================================================================#
- # ♥ Icon Animation
- #==============================================================================#
- # // • Created By : IceDragon (rpgmakervxace.com)
- # // • Modified By : IceDragon (rpgmakervxace.com)
- # // • Data Created : 03/10/2012
- # // • Data Modified : 03/10/2012
- # // • Version : 1.0
- #==============================================================================#
- # ● Change Log
- # ♣ 03/10/2012 V1.0
- # Started & Finished
- #==============================================================================#
- class Sprite::Icon < Sprite_Base
- attr_reader :icon_index
- def initialize( viewport=nil, icon_index=0 )
- super( viewport )
- @icon_index = icon_index
- self.bitmap = iconset
- update_icon()
- end
- def iconset
- Cache.system( "Iconset" )
- end
- def icon_index=( icon_index )
- @icon_index = icon_index
- self.bitmap = iconset
- update_icon()
- end
- def update_icon()
- self.src_rect.set( @icon_index % 16 * 24, @icon_index / 16 * 24, 24, 24 )
- end
- end
- class Cube
- attr_accessor :x, :y, :z
- attr_accessor :width, :length, :height
- def initialize(*args)
- set(*args)
- end
- def set( x=0, y=0, z=0, width=0, height=0, length=0 )
- self.x, self.y, self.z = x, y, z
- self.width, self.length, self.height = width, length, height
- end
- def set2( x=0, y=0, z=0, width=0, length=0, height=0 )
- self.x, self.y, self.z = x, y, z
- self.width, self.length, self.height = width, length, height
- end
- def to_a
- return self.x, self.y, self.z, self.width, self.height, self.length
- end
- def empty
- set()
- end
- end
- module Handler ; end
- class Handler::SpriteEquip
- attr_reader :subject
- def initialize(subject)
- @subject = subject
- @cube = Cube.new(0,0,0,24,24,0) # // Width, Height aren't used yet
- reset()
- end
- def reset()
- self.ox,self.oy = 0, 0
- self.icon_index = 0
- self.angle_abs = 0
- self.opacity = 255
- self.visible = false
- end
- attr_accessor :ox, :oy
- attr_accessor :icon_index
- attr_accessor :angle_abs
- attr_accessor :opacity
- attr_accessor :visible
- def subject_angle()
- case @subject.direction
- when 2
- 0
- when 4
- -90
- when 6
- 90
- when 8
- 180 # // Err why? pole... thats why
- else
- 0
- end
- end
- def angle
- angle_abs + subject_angle
- end
- def auto_oxy()
- self.ox, self.oy = 24, 24
- end
- def auto_xyz()
- h = (@subject.height * 0.8).to_i
- case @subject.direction
- when 2
- self.x, self.y = 8, h
- self.z = 1
- when 4
- self.x, self.y = 8, h
- self.z = -1
- when 6
- self.x, self.y = @subject.width-8, h
- self.z = 1
- when 8
- self.x, self.y = @subject.width-8, h
- self.z = -1
- end
- end
- def x
- @cube.x
- end
- def y
- @cube.y
- end
- def z
- @cube.z
- end
- def width
- @cube.width
- end
- def height
- @cube.height
- end
- def x=(n)
- @cube.x = n
- end
- def y=(n)
- @cube.y = n
- end
- def z=(n)
- @cube.z = n
- end
- def width=(n)
- @cube.width = n
- end
- def height=(n)
- @cube.height = n
- end
- # / Actual Sprite x, y, z
- def screen_x
- @subject.x + self.x - 16
- end
- def screen_y
- @subject.y + self.y - 32
- end
- def screen_z
- @subject.z + self.z
- end
- ACTIONS = {}
- ACTIONS["basicattack"] = proc do |hnd|
- hnd.auto_oxy()
- hnd.auto_xyz()
- hnd.visible = true
- base_angle = 30
- hnd.icon_index = hnd.subject.weapon_icon
- for i in 0..90
- hnd.angle_abs = base_angle + i
- Fiber.yield if i % 9 == 0 # // 10 frames
- end
- hnd.visible = false
- end
- def do_action(&action)
- reset()
- @fiber = Fiber.new { call_action(&action) }
- end
- def call_action(&action)
- action.call(self)
- @fiber = nil
- end
- def update()
- @fiber.resume if(@fiber)
- end
- def busy?()
- !(@fiber).nil?()
- end
- def wait(n)
- n.times do Fiber.yield ; end
- end
- end
- class Sprite::WeaponIcon < Sprite::Icon
- def initialize(viewport,subject)
- super(viewport)
- @subject = subject # // Handler::SpriteEquip*
- pre_init()
- update()
- end
- def pre_init()
- end
- def update()
- super()
- self.x = @subject.screen_x
- self.y = @subject.screen_y
- self.z = @subject.screen_z
- self.ox = @subject.ox
- self.oy = @subject.oy
- self.angle = @subject.angle
- self.opacity = @subject.opacity
- self.visible = @subject.visible
- change_icon_index(@subject.icon_index)
- end
- def change_icon_index(n)
- self.icon_index = n unless(self.icon_index==n)
- end
- end
- # //
- class Game_Battler
- def weapon_icon
- 0
- end
- end
- class Game_Actor
- def weapon_icon
- w,=weapons.compact(); w ? w.icon_index : super()
- end
- end
- class Game_Enemy
- ENEMY_WEAPON_ICON = {}
- # // enemy_id
- ENEMY_WEAPON_ICON[1] = 144 # // Axe ...
- def weapon_icon
- ENEMY_WEAPON_ICON[@enemy_id] || super()
- end
- end
- class Sprite_Character
- alias :icon_anim_initialize :initialize
- def initialize(*args,&block)
- icon_anim_initialize(*args,&block)
- @equip_handle = Handler::SpriteEquip.new(self)
- @equip_sprite = Sprite::WeaponIcon.new(self.viewport,@equip_handle)
- end
- attr_reader :equip_handle
- alias :es_viewport_s :viewport=
- def viewport=(*args,&block)
- es_viewport_s(*args,&block)
- @equip_sprite.viewport = self.viewport
- end
- def direction
- @character.direction
- end
- alias :es_update :update
- def update(*args,&block)
- es_update(*args,&block)
- @equip_handle.update() if(@equip_handle)
- @equip_sprite.update() if(@equip_sprite)
- end
- def weapon_icon()
- @battler.weapon_icon
- end
- end
- class Scene_Battle
- alias :es_show_attack_animation :show_attack_animation
- def show_attack_animation(targets)
- sprite = @subject.battle_sprite
- sprite.equip_handle.do_action(&Handler::SpriteEquip::ACTIONS["basicattack"])
- update_for_wait() while(sprite.equip_handle.busy?())
- es_show_attack_animation(targets)
- end
- end
- #=■==========================================================================■=#
- # // ● End of File ● // #
- #=■==========================================================================■=#
Advertisement
Add Comment
Please, Sign In to add comment