#============================================================================== # ■ Numset #------------------------------------------------------------------------------ #  定数を扱うモジュールです。 #============================================================================== module Numset DOUBLE_SPEED = false # 二倍速判定 end #============================================================================== # ■ RPG::Sprite #------------------------------------------------------------------------------ #  アニメーションの管理を行うクラスです。 #============================================================================== 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 = [] @_blink = false @_animation = [] @_animation_hit = [] if Game_Battler.method_defined?("animation_critical") @_animation_critical = [] end @_animation_sprites = [] @_animation_duration = [] @_loop_animation = [] @_loop_animation_index = [] @_loop_animation_sprites = [] end def dispose dispose_damage (0...@_animation.size).each{|a| dispose_animation(a)} (0...@_loop_animation.size).each{|a| dispose_loop_animation(a)} super end def animation(animation, hit, critical = false) return if animation == nil @_animation.push(animation) @_animation_hit.push(hit) if Game_Battler.method_defined?("animation_critical") @_animation_critical.push(critical) end @_animation_duration.push(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.push([]) max = 0 for a in animation.frames max = [max, a.cell_max].max end if animation.position != 3 or not @@_animations.include?(animation) for i in 0..max sprite = ::Sprite.new(self.viewport) sprite.bitmap = bitmap sprite.visible = false @_animation_sprites.last.push(sprite) end unless @@_animations.include?(animation) @@_animations.push(animation) end end update_animation(@_animation.size - 1) end def loop_animation(animation) return if @_loop_animation.include?(animation) or animation == nil @_loop_animation.push(animation) @_loop_animation_index.push(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.push([]) @_loop_animation_index.push(0) max = 0 for a in animation.frames max = [max, a.cell_max].max end for i in 0..max sprite = ::Sprite.new(self.viewport) sprite.bitmap = bitmap sprite.visible = false @_loop_animation_sprites.last.push(sprite) end update_loop_animation(@_loop_animation.size - 1) end def dispose_animation(id) if @_animation_sprites[id] != nil sprite = @_animation_sprites[id][0] if sprite != nil @@_reference_count[sprite.bitmap] -= 1 end for sprite in @_animation_sprites[id] sprite.dispose end @_animation_duration.delete_at(id) @_animation_sprites.delete_at(id) @_animation_hit.delete_at(id) if Game_Battler.method_defined?("animation_critical") @_animation_critical.delete_at(id) end @_animation.delete_at(id) end end def dispose_loop_animation(id) if @_loop_animation_sprites[id] != nil sprite = @_loop_animation_sprites[id][0] if sprite != nil @@_reference_count[sprite.bitmap] -= 1 end for sprite in @_loop_animation_sprites[id] sprite.dispose end @_loop_animation_sprites.delete_at(id) @_loop_animation_index.delete_at(id) @_loop_animation.delete_at(id) end end def effect? return true if @_whiten_duration > 0 return true if @_appear_duration > 0 return true if @_escape_duration > 0 return true if @_collapse_duration > 0 return true if @_damage_duration > 0 for i in 0...@_animation_duration.size return true if @_animation_duration[i] > 0 end return false 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 != [] if Numset::DOUBLE_SPEED or (Graphics.frame_count % 2 == 0) for a in 0...@_animation.size @_animation_duration[a] -= 1 update_animation(a) end end end if @_loop_animation != [] if Numset::DOUBLE_SPEED or (Graphics.frame_count % 2 == 0) for a in 0...@_loop_animation.size update_loop_animation(a) @_loop_animation_index[a] += 1 @_loop_animation_index[a] %= @_loop_animation[a].frame_max end 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(id) if @_animation_duration[id] > 0 frame_index = @_animation[id].frame_max - @_animation_duration[id] cell_data = @_animation[id].frames[frame_index].cell_data position = @_animation[id].position animation_set_sprites(@_animation_sprites[id], cell_data, position) for timing in @_animation[id].timings if timing.frame == frame_index if Game_Battler.method_defined?("animation_critical") animation_process_timing(timing, @_animation_hit[id], @_animation_critical[id]) else animation_process_timing(timing, @_animation_hit[id]) end end end else dispose_animation(id) end end def update_loop_animation(id) frame_index = @_loop_animation_index[id] cell_data = @_loop_animation[id].frames[frame_index].cell_data position = @_loop_animation[id].position animation_set_sprites(@_loop_animation_sprites[id], cell_data, position) for timing in @_loop_animation[id].timings if timing.frame == frame_index animation_process_timing(timing, true) end end end def animation_set_sprites(sprites, cell_data, position) for i in 0...sprites.size 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 = 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 sprite.x += cell_data[i, 1] sprite.y += cell_data[i, 2] 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] sprite.mirror = (cell_data[i, 5] == 1) sprite.opacity = cell_data[i, 6] * self.opacity / 255.0 sprite.blend_type = cell_data[i, 7] end end def x=(x) sx = x - self.x if sx != 0 for a in 0...@_animation.size if @_animation_sprites[a] != nil for i in 0..@_animation_sprites[a].size @_animation_sprites[a][i].x += sx end end end for a in 0...@_loop_animation.size if @_loop_animation_sprites[a] != nil for i in 0...@_loop_animation_sprites[a].size @_loop_animation_sprites[a][i].x += sx end end end end super end def y=(y) sy = y - self.y if sy != 0 for a in 0...@_animation.size if @_animation_sprites[a] != nil for i in 0...@_animation_sprites[a].size @_animation_sprites[a][i].y += sy end end end for a in 0...@_loop_animation.size if @_loop_animation_sprites[a] != nil for i in 0...@_loop_animation_sprites[a].size @_loop_animation_sprites[a][i].y += sy end end end end super end end end #============================================================================== # ■ Game_Battler (分割定義 1) #------------------------------------------------------------------------------ #  バトラーを扱うクラスです。このクラスは Game_Actor クラスと Game_Enemy クラ # スのスーパークラスとして使用されます。 #============================================================================== class Game_Battler #-------------------------------------------------------------------------- # ● ステートアニメID集 #-------------------------------------------------------------------------- def state_animation_ids result = [] @states.each{|s| unless result.include?($data_states[s].animation_id) result.push($data_states[s].animation_id) end } result.delete(0) if result != [] return result end end #============================================================================== # ■ Sprite_Battler #------------------------------------------------------------------------------ #  バトラー表示用のスプライトです。Game_Battler クラスのインスタンスを監視し、 # スプライトの状態を自動的に変化させます。 #============================================================================== class Sprite_Battler < RPG::Sprite #-------------------------------------------------------------------------- # ● オブジェクト初期化 # viewport : ビューポート # battler : バトラー (Game_Battler) #-------------------------------------------------------------------------- alias :base_initialize :initialize def initialize(viewport, battler = nil) base_initialize(viewport, battler) @battler_states = [] end #-------------------------------------------------------------------------- # ● アニメーション #-------------------------------------------------------------------------- def animation(animation, hit, critical = false) if Game_Battler.method_defined?("index2") @battler.index2 = @_animation_sprites.size end super(animation, hit, critical) end #-------------------------------------------------------------------------- # ● フレーム更新 #-------------------------------------------------------------------------- def update super # バトラーが nil の場合 if @battler == nil self.bitmap = nil loop_animation(nil) return end # ファイル名か色相が現在のものと異なる場合 if @battler.battler_name != @battler_name or @battler.battler_hue != @battler_hue # ビットマップを取得、設定 @battler_name = @battler.battler_name @battler_hue = @battler.battler_hue self.bitmap = RPG::Cache.battler(@battler_name, @battler_hue) @width = bitmap.width @height = bitmap.height self.ox = @width / 2 self.oy = @height # 戦闘不能または隠れ状態なら不透明度を 0 にする if @battler.dead? or @battler.hidden self.opacity = 0 end end # アニメーション ID が現在のものと異なる場合 if @battler_states != @battler.state_animation_ids @battler.state_animation_ids.each{|s| loop_animation($data_animations[s]) if not @battler_states.include?(s) } @battler_states.each{|s| dispose_loop_animation(@_loop_animation.index($data_animations[s])) if not @battler.state_animation_ids.include?(s) } @battler_states = @battler.state_animation_ids end # 表示されるべきアクターの場合 if @battler.is_a?(Game_Actor) and @battler_visible # メインフェーズでないときは不透明度をやや下げる if $game_temp.battle_main_phase self.opacity += 3 if self.opacity < 255 else self.opacity -= 3 if self.opacity > 207 end end # 明滅 if @battler.blink blink_on else blink_off end # 不可視の場合 unless @battler_visible # 出現 if not @battler.hidden and not @battler.dead? and (@battler.damage == nil or @battler.damage_pop) appear @battler_visible = true end end # 可視の場合 if @battler_visible # 逃走 if @battler.hidden $game_system.se_play($data_system.escape_se) escape @battler_visible = false end # 白フラッシュ if @battler.white_flash whiten @battler.white_flash = false end # アニメーション if @battler.animation_id != 0 animation = $data_animations[@battler.animation_id] if Game_Battler.method_defined?("animation_critical") animation(animation, @battler.animation_hit, @battler.animation_critical) else animation(animation, @battler.animation_hit) end @battler.animation_id = 0 end # ダメージ if @battler.damage_pop damage(@battler.damage, @battler.critical) @battler.damage = nil @battler.critical = false @battler.damage_pop = false end # コラプス if @battler.damage == nil and @battler.dead? if @battler.is_a?(Game_Enemy) $game_system.se_play($data_system.enemy_collapse_se) else $game_system.se_play($data_system.actor_collapse_se) end collapse @battler_visible = false end end # スプライトの座標を設定 self.x = @battler.screen_x self.y = @battler.screen_y self.z = @battler.screen_z end end