class Plane_Fog < Plane
attr_reader :fog_name # 雾 文件名
attr_reader :fog_hue # 雾 色相
attr_accessor :fog_blend_type # 雾 混合方式
attr_accessor :fog_zoom # 雾 放大率
attr_accessor :fog_sx
attr_accessor :fog_sy
def initialize(viewport, tileset_id)
super(viewport)
self.z = 3000
tileset = $data_tilesets[tileset_id]
self.change_fog(tileset.fog_name, tileset.fog_hue)
@fog_opacity = tileset.fog_opacity
@fog_blend_type = tileset.fog_blend_type
@fog_zoom = tileset.fog_zoom
@fog_sx = tileset.fog_sx
@fog_sy = tileset.fog_sy
# 初始化雾的各种信息
@fog_ox = 0
@fog_oy = 0
@fog_tone = Tone.new(0, 0, 0, 0)
@fog_tone_target = Tone.new(0, 0, 0, 0)
@fog_tone_duration = 0
@fog_opacity_duration = 0
@fog_opacity_target = 0
end
def dispose
super
end
#--------------------------------------------------------------------------
# ● 开始变更雾的色调
# tone : 色调
# duration : 时间
#--------------------------------------------------------------------------
def start_fog_tone_change(tone, duration)
@fog_tone_target = tone.clone
@fog_tone_duration = duration
if @fog_tone_duration == 0
@fog_tone = @fog_tone_target.clone
end
end
#--------------------------------------------------------------------------
# ● 开始变更雾的不透明度
# opacity : 不透明度
# duration : 时间
#--------------------------------------------------------------------------
def start_fog_opacity_change(opacity, duration)
@fog_opacity_target = opacity * 1.0
@fog_opacity_duration = duration
if @fog_opacity_duration == 0
@fog_opacity = @fog_opacity_target
end
end
def change_fog(name, hue)
# 雾与现在的情况有差异的情况下
if name != @fog_name || hue != @fog_hue
@fog_name = name
@fog_hue = hue
if self.bitmap != nil
@fog.bitmap.dispose
@fog.bitmap = nil
end
if @fog_name != ""
self.bitmap = RPG::Cache.fog(@fog_name, @fog_hue)
end
Graphics.frame_reset
end
end
def update
@fog_ox -= @fog_sx / 8.0
@fog_oy -= @fog_sy / 8.0
# 处理雾的色调变更
if @fog_tone_duration >= 1
d = @fog_tone_duration
target = @fog_tone_target
@fog_tone.red = (@fog_tone.red * (d - 1) + target.red) / d
@fog_tone.green = (@fog_tone.green * (d - 1) + target.green) / d
@fog_tone.blue = (@fog_tone.blue * (d - 1) + target.blue) / d
@fog_tone.gray = (@fog_tone.gray * (d - 1) + target.gray) / d
@fog_tone_duration -= 1
end
# 处理雾的不透明度变更
if @fog_opacity_duration >= 1
d = @fog_opacity_duration
@fog_opacity = (@fog_opacity * (d - 1) + @fog_opacity_target) / d
@fog_opacity_duration -= 1
end
# 刷新雾平面
self.zoom_x = @fog_zoom / 100.0
self.zoom_y = @fog_zoom / 100.0
self.opacity = @fog_opacity
self.blend_type = @fog_blend_type
self.ox = @fog_ox
self.oy = @fog_oy
self.tone = @fog_tone
end
end