Code: |
module RPG class Sprite < ::Sprite @@_animations = [] @@_reference_count = {} 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 @_reverse = false @_option = 0 end def animation(animation, hit, reverse = false) dispose_animation @_animation = animation return if @_animation == nil @_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 unless @@_animations.include?(animation) @@_animations.push(animation) end end @_reverse = reverse split_list = animation.name.split('/') if split_list.length == 2 and split_list[0].length == 1 case split_list[0] when "R" @_option = 1 when "N" @_reverse = false when "M" @_option = 2 end end update_animation end def animation_set_sprites(sprites, cell_data, position) for i in 0..15 sprite = sprites[i] pattern = cell_data[i, 0] if sprite == nil or pattern == nil or pattern == -1 sprite.visible = false if sprite != nil next end sprite.visible = true sprite.src_rect.set(pattern % 5 * 192, pattern / 5 * 192, 192, 192) if position == 3 if self.viewport != nil sprite.x = self.viewport.rect.width / 2 sprite.y = self.viewport.rect.height - 160 else sprite.x = 320 sprite.y = 240 end else sprite.x = self.x - self.ox + self.src_rect.width / 2 sprite.y = self.y - self.oy + self.src_rect.height / 2 sprite.y -= self.src_rect.height / 4 if position == 0 sprite.y += self.src_rect.height / 4 if position == 2 end if @_reverse and position == 3 sprite.x = 620 - sprite.x sprite.y = 328 - sprite.y end if not @_reverse sprite.x += cell_data[i, 1] sprite.y += cell_data[i, 2] else sprite.x -= cell_data[i, 1] sprite.y -= cell_data[i, 2] end sprite.z = 2000 sprite.ox = 96 sprite.oy = 96 sprite.zoom_x = cell_data[i, 3] / 100.0 sprite.zoom_y = cell_data[i, 3] / 100.0 sprite.angle = cell_data[i, 4] if @_option == 1 and @_reverse sprite.angle += 180 end sprite.mirror = (cell_data[i, 5] == 1) if @_option == 2 and @_reverse sprite.mirror = (sprite.mirror == false) end sprite.opacity = cell_data[i, 6] * self.opacity / 255.0 sprite.blend_type = cell_data[i, 7] end end end end |