
class Spriteset_Weather

  attr_reader   :power                    # 強さ
  #--------------------------------------------------------------------------
  # ● オブジェクト初期化
  #--------------------------------------------------------------------------
  alias tako43weatherinitialize initialize
  def initialize(viewport = nil)
    tako43weatherinitialize(viewport)
    create_large_snow_bitmap
    create_rainRed_bitmap 
    create_rainBlack_bitmap 
    create_LL_snow_bitmap
    create_sand_bitmap

  end
  #--------------------------------------------------------------------------
  # ● メンバ変数の初期化
  #--------------------------------------------------------------------------
  alias tako3234initmembers init_members
  def init_members
    tako3234initmembers
    @sprites = []
  
  end
  #--------------------------------------------------------------------------
  # ● 解放
  #--------------------------------------------------------------------------
  alias tako43weatherdispose dispose
  def dispose
    tako43weatherdispose

    @rainRed_bitmap.dispose
    @snowL_bitmap.dispose 
    @snowLL_bitmap.dispose 
    @sand_bitmap.dispose
  end

  #--------------------------------------------------------------------------
  # ● 天候［大雪］のビットマップを作成
  #--------------------------------------------------------------------------
  def create_large_snow_bitmap
    @snowL_bitmap = Bitmap.new(8, 8)
    @snowL_bitmap.fill_rect(0, 1, 8, 6, particle_color2)
    @snowL_bitmap.fill_rect(1, 0, 6, 8, particle_color2)
    @snowL_bitmap.fill_rect(1, 2, 6, 4, particle_color1)
    @snowL_bitmap.fill_rect(2, 1, 4, 6, particle_color1)
  end    
  #--------------------------------------------------------------------------
  # ● 天候［大大雪］のビットマップを作成
  #--------------------------------------------------------------------------
  def create_LL_snow_bitmap
    @snowLL_bitmap = Bitmap.new(10, 10)
    @snowLL_bitmap.fill_rect(0, 1, 10, 8, particle_color2)
    @snowLL_bitmap.fill_rect(1, 0, 8, 10, particle_color2)
    @snowLL_bitmap.fill_rect(1, 2, 8, 6, particle_color1)
    @snowLL_bitmap.fill_rect(2, 1, 6, 8, particle_color1)
  end   
  #--------------------------------------------------------------------------
  # ● 天候［砂］のビットマップを作成
  #--------------------------------------------------------------------------
  def create_sand_bitmap
    @sand_bitmap = Bitmap.new(4, 6)
    sand_color = Color.new(255, 255, 200, 255)
    sand_color2 = Color.new(200, 100, 100, 255)
    @sand_bitmap.fill_rect(0, 0, 4, 4, sand_color)
    @sand_bitmap.fill_rect(0, 4, 4, 2, sand_color2)
  end     
     
  #--------------------------------------------------------------------------
  # ● 天候［赤雨］のビットマップを作成
  #--------------------------------------------------------------------------
  def create_rainRed_bitmap
    @rainRed_bitmap = Bitmap.new(7, 42)
    red_rain_color = Color.new(255, 0, 0, 192)
    7.times {|i| @rainRed_bitmap.fill_rect(6-i, i*6, 1, 6, red_rain_color) }
  end  
  #--------------------------------------------------------------------------
  # ● 天候［黒雨］のビットマップを作成
  #--------------------------------------------------------------------------
  def create_rainBlack_bitmap
    @rainBlack_bitmap = Bitmap.new(7, 42)
    rain_color = Color.new(0, 0, 0, 192)
    7.times {|i| @rainBlack_bitmap.fill_rect(6-i, i*6, 1, 6, rain_color) }
  end    


  #--------------------------------------------------------------------------
  # ● 画面の更新
  #--------------------------------------------------------------------------
  alias tako3232update_screen update_screen
  def update_screen
    if @type == :sandstorm
      @viewport.tone.set(-dimness / 2, -dimness, -dimness)
    else
      tako3232update_screen
    end  
    
  end
  #--------------------------------------------------------------------------
  # ● 暗さの取得
  #--------------------------------------------------------------------------
  def dimness
    return 0 if dimness_cancel?
    [(@power * 6).to_i,60].min 
  end
  #--------------------------------------------------------------------------
  # ● スプライトの更新*
  #--------------------------------------------------------------------------
  def update_sprite(sprite)
    sprite.ox = @ox
    sprite.oy = @oy
    case @type
    when :rain
      update_sprite_rain(sprite)
    when :storm
      update_sprite_storm(sprite)
    when :snow
      update_sprite_snow(sprite)
    else
      update_sprite_else(sprite)
   
      
    end
    create_new_particle(sprite) if sprite.opacity < 64
  end
  
  def update_sprite_else(sprite)
    if @type == :snowL  
      update_sprite_snowL(sprite)
    elsif @type == :snowLL  
      update_sprite_snowLL(sprite)   
    elsif @type == :brizard
      update_sprite_brizard(sprite) 
    elsif @type == :sanddust
      update_sprite_sanddust(sprite)       
    elsif @type == :sandstorm
      update_sprite_sandstorm(sprite)           
    elsif @type == :rainRed 
      update_sprite_rainRed(sprite)   
    elsif @type == :rainBlack
      update_sprite_rainBlack(sprite)          
    end
  end  
  
  def dimness_cancel?
    return true if @type == :sanddust
      
    return false
  end  
  
  #--------------------------------------------------------------------------
  # ● スプライトの更新［大きな雪］
  #--------------------------------------------------------------------------
  def update_sprite_snowL(sprite)
    sprite.bitmap = @snowL_bitmap
    sprite.x -= Math.sin(sprite.x ) * 4
    sprite.y += 2
    sprite.opacity -= 3
  end  
  #--------------------------------------------------------------------------
  # ● スプライトの更新［大きな雪］
  #--------------------------------------------------------------------------
  def update_sprite_snowLL(sprite)
    sprite.bitmap = @snowLL_bitmap
    sprite.x -= Math.sin(sprite.x ) * 4
    sprite.y += 2
    sprite.opacity -= 3
  end    
  
  #--------------------------------------------------------------------------
  # ● スプライトの更新［吹雪］
  #--------------------------------------------------------------------------
  def update_sprite_brizard(sprite)
    sprite.bitmap = @snow_bitmap
    sprite.x -= 7
    sprite.y += 2
    sprite.opacity -= 12
  end    
  #--------------------------------------------------------------------------
  # ● スプライトの更新［砂塵］
  #--------------------------------------------------------------------------
  def update_sprite_sanddust(sprite)
    sprite.bitmap = @sand_bitmap
    sprite.x -= 12
    sprite.y += 1
    sprite.opacity -= 12
  end      
  #--------------------------------------------------------------------------
  # ● スプライトの更新［砂嵐］
  #--------------------------------------------------------------------------
  def update_sprite_sandstorm(sprite)
    sprite.bitmap = @sand_bitmap
    sprite.x -= 12
    sprite.y += 1
    sprite.opacity -= 24
  end        
  #--------------------------------------------------------------------------
  # ● スプライトの更新［赤雨］
  #--------------------------------------------------------------------------
  def update_sprite_rainRed(sprite)
    sprite.bitmap = @rainRed_bitmap
    sprite.x -= 1
    sprite.y += 6
    sprite.opacity -= 12
  end     
  #--------------------------------------------------------------------------
  # ● スプライトの更新［黒雨］
  #--------------------------------------------------------------------------
  def update_sprite_rainBlack(sprite)
    sprite.bitmap = @rainBlack_bitmap
    sprite.x -= 1
    sprite.y += 6
    sprite.opacity -= 12
  end      


end
