#==============================================================================
# ■ New_Collapse vol.1.22
#------------------------------------------------------------------------------
# 08/02/06
#==============================================================================
module RPG
  class Sprite < ::Sprite
    #--------------------------------------------------------------------------
    # ■コラプス(再定義)
    #--------------------------------------------------------------------------
    def collapse
      # □バトラー画像の取得
      @_gf = RPG::Cache.battler(@battler.battler_name,@battler.battler_hue)
      # □ビットマップの再設定
      self.bitmap = Bitmap.new(@_gf.width,@_gf.height)
      self.bitmap.blt(0,0,@_gf,Rect.new(0,0,@_gf.width,@_gf.height))
      @_collapse_on = false
      @_opac = 0
      # □ブレントする色の設定
      #self.blend_type = 1
      #self.color.set(255,64,64,255)
      
      self.opacity = 255
      @_collapse_new = @_gf.height
      @_collapse_duration = 0
      @_whiten_duration = 0
      @_appear_duration = 0
      @_escape_duration = 0
    end
    #--------------------------------------------------------------------------
    # ■ 更新[F12]リセットバグ対策
    #--------------------------------------------------------------------------
    if !$@;alias hidesp_collapse_update update;end
    def update
      # □元の処理を実行
      hidesp_collapse_update
      if @_collapse_on != nil
        #…………………………………………………………………………………………………
        # ■コラプスの開始
        #…………………………………………………………………………………………………
        if @_collapse_new > 0
          @_collapse_on = true
          cn = @_gf.height
          py = 0
          opac_c = 0
          self.bitmap.clear
          # □上から徐々に透明度UP
          while cn > 0
            # □透明度が0になった場合、分岐の終了
            if opac_c >= 255
              break
            end
            self.bitmap.blt(0,py,@_gf,Rect.new(0,py,@_gf.width,1),255-opac_c)
            opac_c += (@_opac/2)
            cn -= 2
            py += 2
          end
          # □全体の透明度UP
          self.opacity -= @_opac
          if @_collapse_new % [@_gf.height/50,2].max == 0
            @_opac += 1
          end
          # □完全に消える速度
          @_collapse_new -= 1
          # □透明度が0になった場合、分岐の終了
          if self.opacity <= 0
            @_collapse_new = 0
          end
        #…………………………………………………………………………………………………
        # ■コラプスの終了
        #…………………………………………………………………………………………………
        elsif @_collapse_new <= 0 && @_collapse_on == true
          self.bitmap.clear
          self.opacity = 0
          @_opac = 0
          self.bitmap.blt(0,0,@_gf,Rect.new(0,0,@_gf.width,@_gf.height))
          @_collapse_on = nil
        end
      end
    end
  end
end