# その他オブジェクト管理
module OtherManager

  # 初期化
  def OtherManager.initAll
    # 全部のそのた配列
    @objects = []
  end

  # 全部のそのたを移動
  def OtherManager.moveAll
    # 移動
    @objects.hs_each(:move)
  end

  # 全部のそのたを描画
  def OtherManager.drawAll
    # 描画
    @objects.hs_each(:draw)
  end

  def OtherManager.objects
    @objects
  end

  # フラグがたっているオブジェクトを削除する
  def OtherManager.clear
    @objects.hs_delete_if(:delflag)
  end

end


# やられたおばけ
class OtherObakeKO

  def self.create(*arr)
    OtherManager.objects.push(self.new(*arr))
  end

  def initialize(x, y, scale)
    @x = x
    @y = y
    @scale = scale
    @rot = 0
    temp = rand(60) + 270
    @dx = Math.cos(TO_RADIAN * temp) * 8
    @dy = Math.sin(TO_RADIAN * temp) * 8
    @delflag = false
    @alpha = 256
  end

  def move
    # 移動
    @x = @x + @dx
    @y = @y + @dy
    @dy = @dy + 0.2

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

    # 透明化
    @alpha = @alpha - 3
    if @alpha < 0 then
      @delflag = true
      return
    end

    # 回転
    @rot = @rot + 20
    if @rot > 359 then
      @rot = @rot - 360
    end
  end

  def draw
    Window.drawEx(@x, @y, IMAGE_obakehit, :angle => @rot, :scalex => @scale, :alpha => @alpha, :z => 5)
  end

  attr_accessor :delflag
end


# やられたぼす
class OtherObakeBoss

  def self.create(*arr)
    OtherManager.objects.push(self.new(*arr))
  end

  def initialize(x, y)
    @x = x
    @y = y
    @rot = 0
    temp = rand(60) + 270
    @dx = Math.cos(TO_RADIAN * temp) * 8
    @dy = Math.sin(TO_RADIAN * temp) * 8
    @delflag = false
    @alpha = 256
  end

  def move
    # 移動
    @x = @x + @dx
    @y = @y + @dy
    @dy = @dy + 0.2

    # 画面外判定
    if @y >  480  or @x >  640  then
      @delflag = true
      BgGameOver.create(210, 170)
      return
    end

    # 透明化
    @alpha = @alpha - 3
    if @alpha < 0 then
      @delflag = true
      BgGameOver.create(210, 170)
      return
    end

    # 回転
    @rot = @rot + 20
    if @rot > 359 then
      @rot = @rot - 360
    end
  end

  def draw
    Window.drawEx(@x, @y, IMAGE_boss, :angle => @rot, :alpha => @alpha, :z => 5)
  end

  attr_accessor :delflag
end


# やられこうもり
class OtherBatKO

  def self.create(*arr)
    OtherManager.objects.push(self.new(*arr))
  end

  def initialize(x, y)
    @x = x
    @y = y
    @bx = x
    @angle = 90
    @delflag = false
    @alpha = 255
    @count = 60
  end

  def move
    # 移動
    @bx = @bx - 0.5
    @y = @y + 2

    @x = @bx + Math.cos(TO_RADIAN * @angle) * 15
    
    @count -= 1
    if @count < 0 then
      @alpha -= 5
    end

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

    # 回転
    @angle = @angle + 8
    if @angle > 359 then
      @angle = @angle - 360
    end
  end

  def draw
    Window.drawEx(@x, @y, IMAGE_batdead, :scaley => -1, :alpha => @alpha, :z => 5)
  end

  attr_accessor :delflag
end


# やられジャック
class OtherJackKO

  def self.create(*arr)
    OtherManager.objects.push(self.new(*arr))
  end

  def initialize(x, y)
    @x = x
    @y = y
    @rot = 0
    temp = rand(60) + 270
    @dx = Math.cos(TO_RADIAN * temp) * 8
    @dy = Math.sin(TO_RADIAN * temp) * 8
    @delflag = false
  end

  def move
    # 移動
    @x = @x + @dx
    @y = @y + @dy
    @dy = @dy + 0.2

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

    # 回転
    @rot = @rot + 20
    if @rot > 359 then
      @rot = @rot - 360
    end
  end

  def draw
    Window.drawRot(@x, @y, IMAGE_jack2, @rot, nil, nil, 5)
  end

  attr_accessor :delflag
end


# やられ魔女
class OtherMajoKO

  def self.create(*arr)
    OtherManager.objects.push(self.new(*arr))
  end

  def initialize(x, y)
    @x = x
    @y = y
    @dy = -4
    @delflag = false
  end

  def move
    # 移動
    @y = @y + @dy
    @dy = @dy + 0.2

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

  end

  def draw
    Window.draw(@x, @y, IMAGE_majo3, 5)
  end

  attr_accessor :delflag
end


# やられうさぎ
class OtherUsagiKO

  def self.create(*arr)
    OtherManager.objects.push(self.new(*arr))
  end

  def initialize(x, y)
    @x = x
    @y = y
    @dy = -4
    @delflag = false
  end

  def move
    # 移動
    @y = @y + @dy
    @dy = @dy + 0.2

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

  end

  def draw
    Window.draw(@x, @y, IMAGE_usagihit, 5)
  end

  attr_accessor :delflag
end


# うき
class OtherUki

  def self.create(*arr)
    OtherManager.objects.push(self.new(*arr))
  end

  def initialize(x, y)
    @x = x + 32
    @y = y - 32
    @count = 20
    @delflag = false
  end

  def move
    @count = @count - 1
    if @count == 0 then
      @delflag = true
    end
  end

  def draw
    Window.draw(@x, @y, IMAGE_uki, 3)
  end

  attr_accessor :delflag
end


# 消えるさるたま
class OtherSarutama

  def self.create(*arr)
    OtherManager.objects.push(self.new(*arr))
  end

  def initialize(x, y, scale)
    @x = x
    @y = y
    @count = scale
    @angle = 0
    @delflag = false
  end

  def move
    @x = @x + 0.5
    @count = @count - 1
    if @count == 0 then
      @delflag = true
      return
    end

    # 画像回転
    @angle = @angle + 10
    if @angle > 359 then
      @angle = @angle - 360
    end
  end

  def draw
    Window.drawEx(@x, @y, IMAGE_sarutamadel, :angle => @angle, :scalex => @count / 40.0, :scaley => @count / 40.0, :z => 3)
  end

attr_accessor :delflag

end


# しにさる
class OtherSaruDead

  def self.create(*arr)
    OtherManager.objects.push(self.new(*arr))
  end

  def initialize(x, y)
    @x = x
    @y = y
    @count = 180
    @angle = 0
    @delflag = false
  end

  def move
    @y = @y - 0.5
    @count = @count - 1
    if @count == 0 then
      $zanki = $zanki - 1
      if $zanki > 0 then
        SaruManager.create
      else
        BgGameOver.create(210, 170)
      end
      @delflag = true
      return
    end

    # 画像回転
    @angle = @angle + 20
    if @angle > 359 then
      @angle = @angle - 360
    end
  end

  def draw
    Window.drawRot(@x, @y, IMAGE_saru01, @angle, nil, nil, 10)
  end

attr_accessor :delflag

end


# きらきら
class OtherKirakira

  def self.create(*arr)
    OtherManager.objects.push(self.new(*arr))
  end

  def initialize(x, y)
    @x = x
    @y = y
    @angle = rand(360)
    @delflag = false
    @alpha = 128 + rand(128)
  end

  def move
    @alpha = @alpha - 16
    if @alpha <= 0 then
      @delflag = true
    end
  end

  def draw
    Window.drawEx(@x, @y, IMAGE_tekitama3p, :alpha=>@alpha, :angle=>@angle, :z=>6)
  end

attr_accessor :delflag

end


# 回復文字
class OtherLifeUp

  def self.create(*arr)
    OtherManager.objects.push(self.new(*arr))
  end

  def initialize
    @y = -30
    @alpha = 255
  end

  def move
    if $saru == nil then
      @delflag = true
      return
    end

    @alpha = @alpha - 3
    if @alpha < 0 then
      @delflag = true
    end

    @y = @y - 0.3

  end

  def draw
    if $saru != nil then
      Window.drawAlpha($saru.x, $saru.y + @y, IMAGE_LIFEUP, @alpha, 6)
    end
  end

attr_accessor :delflag

end


# Optionの文字
class OtherAddOption

  def self.create(*arr)
    OtherManager.objects.push(self.new(*arr))
  end

  def initialize
    @y = -30
    @alpha = 255
  end

  def move
    if $saru == nil then
      @delflag = true
      return
    end

    @alpha = @alpha - 3
    if @alpha < 0 then
      @delflag = true
    end

    @y = @y - 0.3

  end

  def draw
    if $saru != nil then
      Window.drawAlpha($saru.x - 15, $saru.y + @y, IMAGE_ADDOPTION, @alpha, 6)
    end
  end

attr_accessor :delflag

end


# 爆発
class OtherBomber

  def self.create(*arr)
    OtherManager.objects.push(self.new(*arr))
  end

  def initialize(x, y)
    @x = x
    @y = y
    @delflag = false
    @anime = 0
    @animewait = 10
    @animecount = @animewait
    @count = 20
  end

  def move
    @animecount = @animecount - 1
    if @animecount == 0 then
      @animecount = @animewait
      @anime = 1 - @anime
    end

    @count = @count - 1
    if @count == 0 then
      @delflag = true
    end

  end

  def draw
    Window.draw(@x, @y, IMAGE_bomber[@anime], 9)
  end

attr_accessor :delflag

end


# てきクラス（おばけ工場）
class OtherHaka

  def self.create(*arr)
    OtherManager.objects.push(self.new(*arr))
  end

  def initialize(x, y)
    @x = x
    @y = y
    @delflag = false
    @count = 100
  end

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

    # 画面外判定
    if @x <= -IMAGE_hakaDestroy.width then
      @delflag = true
    end

  end

  def draw
    @count -= 1
    if @count < 0 then
      Window.draw(@x, @y, IMAGE_hakaDestroy, 5.9)
    else
      Window.draw(@x + Math.cos(TO_RADIAN * @count * 60) * 5, @y, IMAGE_hakadhit, 5.9)
    end
    if @count == 0 then
      OtherMoku.create(@x, @y, 180, IMAGE_moku)
      OtherMoku.create(@x, @y, 220, IMAGE_moku2)
      OtherMoku.create(@x, @y, 260, IMAGE_moku)
      OtherMoku.create(@x, @y, 300, IMAGE_moku2)
      OtherMoku.create(@x, @y, 340, IMAGE_moku)
    end
    
    
  end

# クラス外に公開する変数
attr_accessor :delflag

end


# うさ星エフェクト
class OtherUsaStar

  def self.create(*arr)
    OtherManager.objects.push(self.new(*arr))
  end

  def initialize(x, y, angle, speed)
    @x = x
    @y = y
    @count = 40
    @alpha = 255
    @dx = Math.cos(TO_RADIAN * angle) * speed
    @dy = Math.sin(TO_RADIAN * angle) * speed
  end

  def move
    @x += @dx
    @y += @dy

    @count -= 1

    if @count < 0 then
      @alpha = @alpha - 16
      if @alpha <= 0 then
        @delflag = true
      end
    end
  end

  def draw
    Window.drawAlpha(@x, @y, IMAGE_usatama2, @alpha, 6)
  end

attr_accessor :delflag

end


# 煙
class OtherMoku

  def self.create(*arr)
    OtherManager.objects.push(self.new(*arr))
  end

  def initialize(x, y, angle, image)
    @x = x + 20
    @y = y + 70
    @count = 40
    @alpha = 255
    @dx = Math.cos(TO_RADIAN * angle)
    @dy = Math.sin(TO_RADIAN * angle)
    @image = image
  end

  def move
    @x += @dx
    @y += @dy

    @count -= 1

    if @count < 0 then
      @alpha = @alpha - 16
      if @alpha <= 0 then
        @delflag = true
      end
    end
  end

  def draw
    Window.drawAlpha(@x, @y, @image, @alpha, 6)
  end

attr_accessor :delflag

end
