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