#============================================================================# XP Style Fog# v1.0 by Shaz#----------------------------------------------------------------------------# This is a simple port of XP's fog system.#----------------------------------------------------------------------------# To Install:# Copy and paste into a new script slot in Materials. This script aliases# existing methods, so can go below all other custom scripts.#----------------------------------------------------------------------------# To Use:# Create a Fogs folder inside your game's Graphics folder, and paste your# fog png files there## There are two ways of adding fog to a map:# 1. Set it in map notes - fog will be loaded when the map is loaded (all values # must be present)# <fog name hue opacity blend_type zoom speed-x speed-y># 2. via a Call Script command - fog will be added when the command is run# Call Script: $game_map.add_fog(name, hue, opacity, blend_type, zoom, # speed_x, speed_y)## Use the following two commands to make changes to fog# Call Script: $game_map.start_fog_tone_change(red, green, blue, gray, duration)# Call Script: $game_map.start_fog_opacity_change(opacity, duration)## You can also modify the $game_map fog attr_accessors individually via # Call Script commands.#----------------------------------------------------------------------------# Terms:# Use in free or commercial games# Credit Shaz#============================================================================module Cache #-------------------------------------------------------------------------- # * Get Fog #-------------------------------------------------------------------------- def self.fog(filename, hue) load_bitmap("Graphics/Fogs/", filename, hue) endendclass Game_Map #-------------------------------------------------------------------------- # * Public Instance Variables #-------------------------------------------------------------------------- attr_accessor :fog_name # fog file name attr_accessor :fog_hue # fog hue attr_accessor :fog_opacity # fog opacity level attr_accessor :fog_blend_type # fog blending method attr_accessor :fog_zoom # fog zoom rate attr_accessor :fog_sx # fog sx attr_accessor :fog_sy # fog sy attr_reader :fog_ox # fog x-coordinate starting point attr_reader :fog_oy # fog y-coordinate starting point attr_reader :fog_tone # fog color tone #-------------------------------------------------------------------------- # * Setup #-------------------------------------------------------------------------- alias shaz_fog_game_map_setup setup def setup(map_id) shaz_fog_game_map_setup(map_id) setup_fog setup_notes end #-------------------------------------------------------------------------- # * Setup Notes #-------------------------------------------------------------------------- def setup_notes @map.note.split(/[\r\n+]/).each do |line| case line when /<fog\s*(\w+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)\s*(\d+)>/i @fog_name = $1 @fog_hue = $2.to_i @fog_opacity = $3.to_i @fog_blend_type = $4.to_i # 0-normal, 1-add, 2-sub @fog_zoom = $5.to_i @fog_sx = $6.to_i @fog_sy = $7.to_i end end end #-------------------------------------------------------------------------- # * Setup Fog #-------------------------------------------------------------------------- def setup_fog @fog_name = "" @fog_hue = 0 @fog_opacity = 0 @fog_blend_type = 0 @fog_zoom = 0 @fog_sx = 0 @fog_sy = 0 @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 #-------------------------------------------------------------------------- # * Add Fog #-------------------------------------------------------------------------- def add_fog(name, hue = 90, opacity = 64, blend_type = 0, zoom = 200, sx = 0, sy = 0) @fog_name = name @fog_hue = hue @fog_opacity = opacity @fog_blend_type = blend_type @fog_zoom = zoom @fog_sx = sx @fog_sy = sy end #-------------------------------------------------------------------------- # * Start Changing Fog Color Tone # R, G, B, Gray : tone # duration : time #-------------------------------------------------------------------------- def start_fog_tone_change(red, green, blue, gray, duration) @fog_tone_target = Tone.new(red, green, blue, gray) @fog_tone_duration = duration if @fog_tone_duration == 0 @fog_tone = @fog_tone_target.clone end end #-------------------------------------------------------------------------- # * Start Changing Fog Opacity Level # opacity : opacity level # duration : time #-------------------------------------------------------------------------- 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 #-------------------------------------------------------------------------- # * Update Fog #-------------------------------------------------------------------------- def update_fog @fog_ox -= @fog_sx / 8.0 @fog_oy -= @fog_sy / 8.0 # Manage change in fog color tone 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 # Manage change in fog opacity level if @fog_opacity_duration >= 1 d = @fog_opacity_duration @fog_opacity = (@fog_opacity * (d - 1) + @fog_opacity_target) / d @fog_opacity_duration -= 1 end end #-------------------------------------------------------------------------- # * Frame Update # main: Interpreter update flag #-------------------------------------------------------------------------- alias shaz_fog_game_map_update update def update(main = false) shaz_fog_game_map_update(main) update_fog endend#==============================================================================# ** Spriteset_Map#------------------------------------------------------------------------------# This class brings together map screen sprites, tilemaps, etc. It's used# within the Scene_Map class.#==============================================================================class Spriteset_Map #-------------------------------------------------------------------------- # * Object Initialization #-------------------------------------------------------------------------- alias shaz_fog_spriteset_map_initialize initialize def initialize shaz_fog_spriteset_map_initialize create_fog update end #-------------------------------------------------------------------------- # * Create Fog #-------------------------------------------------------------------------- def create_fog @fog = Plane.new(@viewport1) @fog.z = 300 end #-------------------------------------------------------------------------- # * Free #-------------------------------------------------------------------------- alias shaz_fog_spriteset_map_dispose dispose def dispose dispose_fog shaz_fog_spriteset_map_dispose end #-------------------------------------------------------------------------- # * Free Fog #-------------------------------------------------------------------------- def dispose_fog @fog.bitmap.dispose if @fog.bitmap @fog.dispose end #-------------------------------------------------------------------------- # * Frame Update #-------------------------------------------------------------------------- alias shaz_fog_spriteset_map_update update def update update_fog shaz_fog_spriteset_map_update end #-------------------------------------------------------------------------- # * Update Fog #-------------------------------------------------------------------------- def update_fog return if !@fog if @fog_name != $game_map.fog_name or @fog_hue != $game_map.fog_hue @fog_name = $game_map.fog_name @fog_hue = $game_map.fog_hue if @fog.bitmap != nil @fog.bitmap.dispose @fog.bitmap = nil end if @fog_name != "" @fog.bitmap = Cache.fog(@fog_name, @fog_hue) end Graphics.frame_reset end @fog.zoom_x = $game_map.fog_zoom / 100.0 @fog.zoom_y = $game_map.fog_zoom / 100.0 @fog.opacity = $game_map.fog_opacity @fog.blend_type = $game_map.fog_blend_type @fog.ox = $game_map.display_x / 4 + $game_map.fog_ox @fog.oy = $game_map.display_y / 4 + $game_map.fog_oy @fog.tone = $game_map.fog_tone endend