class RPG::Sprite < ::Sprite
def initialize(viewport = nil)
super(viewport)
@_whiten_duration = 0
@_appear_duration = 0
@_escape_duration = 0
@_collapse_duration = 0
@_damage_duration = 0
#@_animation_duration = 0
@_blink = false
@_animation = []
@_animation_hit = []
@_animation_duration = []
@_animation_sprites = []
@_loop_animation = []
@_loop_animation_sprites = []
@_loop_animation_index = []
end
def animation(animation, hit)
#dispose_animation
return if animation == nil
@_animation << animation
@_animation_hit << hit
@_animation_duration << animation.frame_max
animation_name = animation.animation_name
animation_hue = animation.animation_hue
bitmap = RPG::Cache.animation(animation_name, animation_hue)
if @@_reference_count.include?(bitmap)
@@_reference_count[bitmap] += 1
else
@@_reference_count[bitmap] = 1
end
_animation_sprites = []
if animation.position != 3 or not @@_animations.include?(animation)
for i in 0..15
sprite = ::Sprite.new(self.viewport)
sprite.bitmap = bitmap
sprite.visible = false
_animation_sprites.push(sprite)
end
@_animation_sprites << _animation_sprites
unless @@_animations.include?(animation)
@@_animations.push(animation)
end
end
update_animation
end
def loop_animation(animation)
return if animation == nil or @_loop_animation.include?(animation)
@_loop_animation << animation
@_loop_animation_index << 0
animation_name = animation.animation_name
animation_hue = animation.animation_hue
bitmap = RPG::Cache.animation(animation_name, animation_hue)
if @@_reference_count.include?(bitmap)
@@_reference_count[bitmap] += 1
else
@@_reference_count[bitmap] = 1
end
_loop_animation_sprites = []
for i in 0..15
sprite = ::Sprite.new(self.viewport)
sprite.bitmap = bitmap
sprite.visible = false
_loop_animation_sprites.push(sprite)
end
@_loop_animation_sprites << _loop_animation_sprites
update_loop_animation
end
def dispose_animation(v=nil)
for i in [email]0...@_animation_sprites.size[/email]
sprite = @_animation_sprites[i][0]
if sprite != nil
@@_reference_count[sprite.bitmap] -= 1
if @@_reference_count[sprite.bitmap] == 0
sprite.bitmap.dispose
end
end
for sprite in @_animation_sprites[i]
sprite.dispose
end
@_animation_sprites[i].clear
#@_animation_sprites.delete_at(i)
#@_animation.delete_at(i)
#@_animation_hit.delete_at(i)
#@_animation_duration.delete_at(i)
end
@_animation_sprites.clear
@_animation.clear
@_animation_hit.clear
@_animation_duration.clear
if v.nil?
@_animation_sprites = nil
@_animation = nil
@_animation_hit = nil
@_animation_duration = nil
end
end
def dispose_loop_animation(v=nil)
for i in [email]0...@_loop_animation_sprites.size[/email]
sprite = @_loop_animation_sprites[i][0]
if sprite != nil
@@_reference_count[sprite.bitmap] -= 1
if @@_reference_count[sprite.bitmap] == 0
sprite.bitmap.dispose
end
end
for sprite in @_loop_animation_sprites[i]
sprite.dispose
end
@_loop_animation_sprites[i].clear
#@_loop_animation_sprites.delete_at(i)
#@_loop_animation.delete_at(i)
#@_loop_animation_index.delete_at(i)
end
@_loop_animation_sprites.clear
@_loop_animation.clear
@_loop_animation_index.clear
if v.nil?
@_loop_animation = nil
@_loop_animation_sprites = nil
@_loop_animation_index = nil
end
end
def effect?
@_whiten_duration > 0 or
@_appear_duration > 0 or
@_escape_duration > 0 or
@_collapse_duration > 0 or
@_damage_duration > 0 or
@_animation_duration.size > 0
end
def update
super
if @_whiten_duration > 0
@_whiten_duration -= 1
self.color.alpha = 128 - (16 - @_whiten_duration) * 10
end
if @_appear_duration > 0
@_appear_duration -= 1
self.opacity = (16 - @_appear_duration) * 16
end
if @_escape_duration > 0
@_escape_duration -= 1
self.opacity = 256 - (32 - @_escape_duration) * 10
end
if @_collapse_duration > 0
@_collapse_duration -= 1
self.opacity = 256 - (48 - @_collapse_duration) * 6
end
if @_damage_duration > 0
@_damage_duration -= 1
case @_damage_duration
when 38..39
@_damage_sprite.y -= 4
when 36..37
@_damage_sprite.y -= 2
when 34..35
@_damage_sprite.y += 2
when 28..33
@_damage_sprite.y += 4
end
@_damage_sprite.opacity = 256 - (12 - @_damage_duration) * 32
if @_damage_duration == 0
dispose_damage
end
end
if @_animation.size > 0 and (Graphics.frame_count % 2 == 0)
for i in [email]0...@_animation_duration.size[/email]
@_animation_duration[i] -= 1
end
update_animation
end
if @_loop_animation.size > 0 and (Graphics.frame_count % 2 == 0)
update_loop_animation
for i in [email]0...@_loop_animation_index.size[/email]
@_loop_animation_index[i] += 1
@_loop_animation_index[i] %= @_loop_animation[i].frame_max
end
end
if @_blink
@_blink_count = (@_blink_count + 1) % 32
if @_blink_count < 16
alpha = (16 - @_blink_count) * 6
else
alpha = (@_blink_count - 16) * 6
end
self.color.set(255, 255, 255, alpha)
end
@@_animations.clear
end
def update_animation
for i in [email]0...@_animation_duration.size[/email]
if @_animation_duration[i] <= 0
@_animation_duration[i] = nil
sprite = @_animation_sprites[i][0]
if sprite != nil
@@_reference_count[sprite.bitmap] -= 1
if @@_reference_count[sprite.bitmap] == 0
sprite.bitmap.dispose
end
end
for sprite in @_animation_sprites[i]
sprite.dispose
end
@_animation_duration.delete_at(i)
@_animation_sprites.delete_at(i)
@_animation.delete_at(i)
return
end
frame_index = @_animation[i].frame_max - @_animation_duration[i]
cell_data = @_animation[i].frames[frame_index].cell_data
position = @_animation[i].position
animation_set_sprites(@_animation_sprites[i], cell_data, position)
for timing in @_animation[i].timings
if timing.frame == frame_index
animation_process_timing(timing, @_animation_hit)
end
end
#else
# dispose_animation
end
end
def update_loop_animation
for i in [email]0...@_loop_animation_index.size[/email]
frame_index = @_loop_animation_index[i]
cell_data = @_loop_animation[i].frames[frame_index].cell_data
position = @_loop_animation[i].position
animation_set_sprites(@_loop_animation_sprites[i], cell_data, position)
for timing in @_loop_animation[i].timings
if timing.frame == frame_index
animation_process_timing(timing, true)
end
end
end
end
def x=(x)
sx = x - self.x
if sx != 0
for each_sprites in [email]0...@_animation_sprites.size[/email]
for i in 0..15
@_animation_sprites[each_sprites][i].x += sx
end
end
for each_sprites in [email]0...@_loop_animation_sprites.size[/email]
for i in 0..15
@_loop_animation_sprites[each_sprites][i].x += sx
end
end
end
super
end
def y=(y)
sy = y - self.y
if sy != 0
for each_sprites in [email]0...@_animation_sprites.size[/email]
for i in 0..15
@_animation_sprites[each_sprites][i].y += sy
end
end
for each_sprites in [email]0...@_loop_animation_sprites.size[/email]
for i in 0..15
@_loop_animation_sprites[each_sprites][i].y += sy
end
end
end
super
end
end