#============================================================================== # ■ Numset #------------------------------------------------------------------------------ #  定数全般のモジュールです。 #============================================================================== module Numset WEATHER_MAX = 40 # 天候画像の最大表示数 end #============================================================================== # ■ RPG::Weather #------------------------------------------------------------------------------ #  天候を扱うクラスです。 #============================================================================== module RPG class Weather #-------------------------------------------------------------------------- # ● 構造体 #-------------------------------------------------------------------------- # 順にファイル名、X移動ピクセル、Y移動ピクセル、不透明度変化、表示時間 Type = Struct.new("Type", :name, :bitmap, :vektor_x, :vektor_y, :vektor_alpha, :duration) @weathers = [] @weathers.push(Type.new("rain", nil, -2, 16, 8, 24)) @weathers.push(Type.new("storm", nil, -8, 16, 12, 16)) @weathers.push(Type.new("snow", nil, -2, 8, 8, 24)) #-------------------------------------------------------------------------- # ● 公開インスタンス変数 #-------------------------------------------------------------------------- attr_reacer :types attr_reader :max attr_reader :ox attr_reader :oy #-------------------------------------------------------------------------- # ● オブジェクト初期化 #-------------------------------------------------------------------------- def initialize(viewport = nil) @type = 0 @max = 0 @ox = 0 @oy = 0 @sprites = [] @types = Array.new(@weathers.size){0} @durations = Array.new(40){0} for weather in @weathers weather.bitmap = RPG::Cache.picture(weather.name) end for i in 0...Numset::WEATHER_MAX sprite = Sprite.new(viewport) sprite.z = 0 sprite.visible = false sprite.opacity = 0 @sprites.push(sprite) end end def dispose @sprites.each{|sprite| sprite.dispose} end def type=(size) return if @type == type @type = type - 1 if @weathers[type] != nil bitmap = @weathers[type].bitmap else bitmap = nil end for i in 0...Numset::WEATHER_MAX sprite = @sprites[i] sprite.visible = (i <= @max) sprite.bitmap = bitmap end end def ox=(ox) return if @ox == ox @ox = ox @sprites.each{|sprite| sprite.ox = @ox} end def oy=(oy) return if @oy == oy @oy = oy @sprites.each{|sprite| sprite.oy = @oy} end def max=(max) return if @max == max; @max = [[max, 0].max, Numset::WEATHER_MAX].min (0...Numset::WEATHER_MAX).each{|i| @sprites[i].visible = (i <= @max)} end def update return if @type == 0 for i in 0...@max sprite = @sprites[i] if @weathers[@type - 1] != nil base = @weathers[@type - 1] sprite.x += base.vektor_x sprite.y += base.vektor_y sprite.opacity -= base.vektor_alpha @durations[i] -= 1 if base.name =~ /@(\d+)@(\d+)$/ if ((base.duration - @durations[i]) % $2.to_i) == 0 sprite.src_rect.width = sprite.bitmap.width / $1.to_i sprite.src_rect.x = (sprite.src_rect.x + sprite.src_rect.width) % sprite.bitmap.width end end x = sprite.x - @ox y = sprite.y - @oy if @durations[i] == 0 sprite.x = rand(800) - 50 + @ox sprite.y = rand(800) - 200 + @oy sprite.z = sprite.y + 180 - @oy sprite.opacity = 255 @durations[i] = base.duration end end end end end