
class Sprite_PinBall < Sprite_Base

  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #--------------------------------------------------------------------------
  def initialize(viewport, ball_name , ball_index , pinball)
    super(viewport)
    @ball_name = ball_name
    @ball_index = ball_index
    @pinball = pinball
    @cw = 0
    @ch = 0
    
    set_ball_bitmap
    update_src_rect
    update
  end

  #--------------------------------------------------------------------------
  # ● フレーム更新
  #--------------------------------------------------------------------------
  def update
    super
    update_position
  end


  #--------------------------------------------------------------------------
  # ● ボールのビットマップを設定
  #--------------------------------------------------------------------------
  def set_ball_bitmap
    self.bitmap = Cache.character(@ball_name)
    sign = @ball_name[/^[\!\$]./]
    if sign && sign.include?('$')
      @cw = bitmap.width / 3
      @ch = bitmap.height / 4
    else
      @cw = bitmap.width / 12
      @ch = bitmap.height / 8
    end
    self.ox = @cw / 2
    self.oy = @ch
  end
  #--------------------------------------------------------------------------
  # ● 転送元矩形の更新
  #--------------------------------------------------------------------------
  def update_src_rect
    index = @character_index
    pattern = 0 
    sx = (@ball_index % 4 * 3 + pattern) * @cw
    sy = (@ball_index / 4 * 4 ) * @ch
    self.src_rect.set(sx, sy, @cw , @ch)
  end
  #--------------------------------------------------------------------------
  # ● 位置の更新
  #--------------------------------------------------------------------------
  def update_position
    return unless @pinball
    self.x = @pinball.x 
    self.y = @pinball.y 
    self.z = 300
  end



end
