# アイテム管理
ItemCollision = []

module ItemManager

  # 初期化
  def ItemManager.initAll
    # 全部のアイテム配列
    @objects = []
    ItemCollision.clear
  end

  # 全部のアイテムを移動
  def ItemManager.moveAll
    # 移動＆消えたときは配列から削除
    @objects.each do |t|
      t.move
    end
  end

  # 全部のアイテムを描画
  def ItemManager.drawAll
    # 描画
    @objects.each do |t|
      t.draw
    end
  end

  # オブジェクト配列を返す
  def ItemManager.objects
    @objects
  end

  # フラグがたっているオブジェクトを削除する
  def ItemManager.clear
    @objects.delete_if do |t|
      t.delflag
    end
  end
end


# ハート
class ItemHeart

  def ItemHeart.create(*arr)
    ItemManager.objects.push(ItemHeart.new(*arr))
  end

  def initialize(x, y)
    @x = x
    @y = y
    @speed = 1.5
    @delflag = false
    @animewait = 8
    @animecount = @animewait
    @anime = 10
    @rot = -12
    @rotcount = 10
    @rotflag = 1
    @collision = CollisionBox.new(self, IMAGE_life[0].x1, IMAGE_life[0].y1,
                                        IMAGE_life[0].x2, IMAGE_life[0].y2)
  end

  def move
    # 移動
    @x = @x - @speed

    # 画面外判定
    if @y >  480 then
      @delflag = true
      return
    end

    # アニメ処理
    @animecount = @animecount - 1
    if @animecount == 0 then
      @animecount = @animewait
      @anime = @anime + 1
      if @anime > 11 then
        @anime = 0
      end
    end

    if @rot == 14 or @rot == -14 then
      @rotcount = @rotcount - 1
      if @rotcount == 0 then
        @rotflag = - @rotflag
        @rotcount = 10
        @rot = @rot + @rotflag * 1
      end
    else
      @rot = @rot + @rotflag * 1
    end

    # あたり判定範囲設定
    @collision.set(@x, @y)
    ItemCollision.push(@collision)
  end

  def hit(opponent)
    SE_LifeUp.play
    opponent.hp = opponent.hp + 5
    OtherLifeUpEffect.create
    OtherLifeUp.create
    @delflag = true
  end

  def draw
    # アイテムを描画する
    temp = @anime < 4 ? @anime : 0
    Window.drawEx(@x, @y + @rot.abs/2.0, IMAGE_life[temp], :angle => @rot, :centerx => 10, :centery => 30, :z => 6)
    Window.draw(@x-13 + Math.cos(TO_RADIAN * (@rot-90)) * 30, @y-12 + @rot.abs/2.0, IMAGE_lifekira[@anime % 2], 6.1)
    
  end

attr_accessor :delflag
end


# 音符
class ItemNote

  def ItemNote.create(*arr)
    ItemManager.objects.push(ItemNote.new(*arr))
  end

  def initialize(x, y)
    @x = x
    @y = y
    @speed = 1.5
    @delflag = false
    @animewait = 8
    @animecount = @animewait
    @anime = 10
    @rot = -12
    @rotcount = 10
    @rotflag = 1
    @collision = CollisionBox.new(self, IMAGE_note[0].x1, IMAGE_note[0].y1,
                                        IMAGE_note[0].x2, IMAGE_note[0].y2)
  end

  def move
    # 移動
    @x = @x - @speed

    # 画面外判定
    if @y >  480 then
      @delflag = true
      return
    end

    # アニメ処理
    @animecount = @animecount - 1
    if @animecount == 0 then
      @animecount = @animewait
      @anime = @anime + 1
      if @anime > 11 then
        @anime = 0
      end
    end

    if @rot == 14 or @rot == -14 then
      @rotcount = @rotcount - 1
      if @rotcount == 0 then
        @rotflag = - @rotflag
        @rotcount = 10
        @rot = @rot + @rotflag * 1
      end
    else
      @rot = @rot + @rotflag * 1
    end

    # あたり判定範囲設定
    @collision.set(@x, @y)
    ItemCollision.push(@collision)

  end

  def hit(opponent)
    SE_LifeUp.play
    OtherAddOption.create
    if $saru != nil and $saru.option.size < 4 then
      OptionKozaru.create
    end
    @delflag = true
  end

  def draw
    # アイテムを描画する
    temp = @anime < 4 ? @anime : 0
    Window.drawEx(@x, @y + @rot.abs/2.0, IMAGE_note[temp], :angle => @rot, :centerx => 10, :centery => 30, :z => 6)
    Window.draw(@x-6 + Math.cos(TO_RADIAN * (@rot-90)) * 30, @y-8 + @rot.abs/2.0, IMAGE_onpukira[@anime % 2], 6.1)
  end

attr_accessor :delflag
end







