class Sprite_CastTimer < Sprite_Base
  attr_accessor :chara
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize(viewport , chara)
    super(viewport)
    @tile_map_width = 32
    @tile_map_height = 32
    @chara = nil
    @cw = 0
    @ch = 0
    @width = 64
    @height = 8
    @chara = chara
    @color = chara.cast_color || $cast_color
    set_bitmap
    update
  end

  #--------------------------------------------------------------------------
  # ● フレーム更新
  #--------------------------------------------------------------------------
  def update
    super
    update_position
    
    set_bitmap
    if !@chara || @chara.rest_cast_time <= 0
      self.visible = false 
    else
      self.visible = true
    end  
  end

  def make_Bitmap
    value = @width * @chara.rest_cast_time / @chara.cast_time
    bitmap = Bitmap.new(@width , @height) 
    bitmap.fill_rect(Rect.new(0 ,0, value,@height), @color) 

    return bitmap
  end  
 
  def set_bitmap
    return unless @chara  
    return unless @chara.cast_time > 0
    self.bitmap = make_Bitmap 
  end  
  #--------------------------------------------------------------------------
  # ● 位置の更新
  #--------------------------------------------------------------------------
  def update_position
    return unless @chara
    self.x = @chara.screen_x - @tile_map_width 
    self.y = @chara.screen_y + 1
    self.z = 300
  end
end