# ============================================================================= # TheoAllen - Fog Screen # Version : 2.0 # Contact : www.rpgmakerid.com (or) http://theolized.blogspot.com # (English documentation) # ============================================================================= ($imported ||={})[:Theo_FogScreen] = true # ============================================================================= # CHANGE LOGS: # ----------------------------------------------------------------------------- # 2013.08.24 - Rewrite script with very different workflows (v2.0) # - Multiple fogs support # - Now support very slow scrolling speed (sekitar 0.1) # - Fog not scrolled alongside player # - Now support battle fog # - Change map notetag # - Remove opacity variance # 2013.06.13 - Added global fog (v1.3) # - Added global disable switch # - Added specific disable switch # 2013.06.12 - Bugfix. Where fog isn't disposed when changing map # 2013.05.15 - Added blend type # - Added zoom # - Added opacity variance # 2013.05.09 - Started and Finished script (v1.0) # ============================================================================= =begin ----------------------------------------------------------------------------- Opening : This is a very different fog script than version 1.3. The usage and workflows are really not same. So, if you use my previous fog screen, you should remove and change to this one. I'm sorry if you need to re-setting from start ----------------------------------------------------------------------------- Introduction : This script simply displays for as RMXP have. ----------------------------------------------------------------------------- How to use : Put this script below material but above main Edit the database configurations for used fogs To display and remove fogs, make a script call. To display : add_fog(key) add_fog(key,fadein) To remove : delete_fog(key) delete_fog(key,fadeout) Note : - key is a hash key from fog database below. - fadein/fadeout is its fading speed. i.e if you set it to 5, then in every frame, its opacity will be increased by 5 until its max value which have you specified. If you ommit fadein/fadeout parameter, it will be instantly displayed - You can't call two or more fogs which has also same hash key. clear_fogs ^ If you want to clear all the fogs ----------------------------------------------------------------------------- Notetag : The notetag is quite simple. all you need it to put this notetag to map properties ----------------------------------------------------------------------------- Terms of use : Credit me, TheoAllen. You are free to edit this script by your own. As long as you don't claim it yours. For commercial purpose, don't forget to give me a free copy of the game. =end # ============================================================================= # Configuration : # ============================================================================= module THEO module Fog # ------------------------------------------------------------------------- # Include it in battle scene? # ------------------------------------------------------------------------- BattleFog = true # Set to true if you also want to display fogs in battle scene # ------------------------------------------------------------------------- # Fog Database List ~ # Level : Easy # ------------------------------------------------------------------------- # Configuration guides # # key => Hash key used to call your fog (In both script call and notetag) # name => Fog image filename that must be existed in Graphics/Pictures # opacity => For opacity (0 - 255) # speed_x => Horizontal scroll speed # speed_y => Vertical scroll speed # zoom_x => Horizontal zoom scale (1.0 is normal size) # zoom_y => Vertical zoom scale (1.0 is normal size) # ------------------------------------------------------------------------- List = { # "key" => ["name", opacity, speed_x, speed_y, zoom_x, zoom_y] "fog" => ["fog", 128, 0.2, 0.2, 1.0, 1.0], "cloud" => ["cloud", 90, -0.2, -0.2, 2.0, 2.0], "storm" => ["storm", 90, -2.0, 2.0, 1.0, 1.0], "leaf" => ["leaf", 90, 0, 0, 2.0, 2.0], # Add more } # <-- Don touch ~ ! # ------------------------------------------------------------------------- # Fog Extended Database List # Level : Hard # ------------------------------------------------------------------------- # There're more configurations besides those above. But it just optional. # For reason of neatness, I would like to split it up # # Configuration guide : # Start it by write like this. Key is a hash key, remember # fog = fog_data["key"] # # Then change the attributes : # fog = fog_data["fog"] # fog.name = "something" # fog.opacity = 100 # # Here is the list of the unlisted attributes beside the previous config # # fog.switch >> Switch ID. If the switch is turned ON, it will be invis # fog.blend_type >> Type of blending. Choose between 0 - 2 (default : 0) # fog.tone >> Same as tint screen. Fill it with Tone.new(R,G,B,Gray) # fog.z >> Z Coordinate. Greater value will displays the fog over # the other fogs. Default value is 250 # # For scale scroll # fog.scroll_scale_x >> Horizontal scale # fog.scroll_scale_y >> Vertical scale # # These are for scrolling scale. If you put them in 0.0, then the fog will # scrolled alongside the player, i.e the fog will followed the player. The # default value is 1.0 # ------------------------------------------------------------------------- def self.custom_fogs fog = fog_data["leaf"] fog.scroll_scale_x = 0.4 fog.scroll_scale_y = 0.4 fog = fog_data["rain1"] fog.blend_type = 1 fog = fog_data["rain2"] fog.blend_type = 2 end end end # ============================================================================= # End of config. You need scripting skill to edit below this line. # ============================================================================= module THEO module Fog def self.load_fogs List.each do |key,data| fog = fog_data[key] fog.name = data[0] fog.opacity = data[1] fog.speed_x = data[2] fog.speed_y = data[3] fog.zoom_x = data[4] fog.zoom_y = data[5] end end def self.fog_data $game_temp.fogs end end end # ============================================================================= # ▼ DataManager # ============================================================================= class << DataManager alias theo_fog_create_obj create_game_objects def create_game_objects theo_fog_create_obj THEO::Fog.load_fogs THEO::Fog.custom_fogs end end # ============================================================================= # ▼ DataFogs # ============================================================================= class DataFogs def initialize @data = {} end def [](key) @data[key] ||= Fog.new(key) end end # ============================================================================= # ▼ Fogs # ============================================================================= class Fog attr_accessor :key attr_accessor :name attr_accessor :opacity attr_accessor :speed_x attr_accessor :speed_y attr_accessor :zoom_x attr_accessor :zoom_y attr_accessor :scroll_scale_x attr_accessor :scroll_scale_y attr_accessor :blend_type attr_accessor :tone attr_accessor :switch attr_accessor :z def initialize(key) @key = key @name = "" @opacity = 255 @speed_x = 0.0 @speed_y = 0.0 @zoom_x = 1.0 @zoom_y = 1.0 @scroll_scale_x = 1.0 @scroll_scale_y = 1.0 @blend_type = 0 @tone = Tone.new @switch = 0 @z = 250 end def visible !$game_switches[@switch] end end # ============================================================================= # ▼ Game_Temp # ============================================================================= class Game_Temp attr_accessor :clear_fog attr_reader :fogs # -------------------------------------------------------------------------- # They said that too much global variables isn't good. So, I used an # instance variable to store my fogs database =P # -------------------------------------------------------------------------- alias theo_fog_init initialize def initialize theo_fog_init @fogs = DataFogs.new @clear_fog = false end end # ============================================================================= # ▼ Game_System # ============================================================================= class Game_System attr_reader :used_fog alias theo_fog_init initialize def initialize theo_fog_init @used_fog = [] end end # ============================================================================= # ▼ Game_Interpreter # ============================================================================= class Game_Interpreter def clear_fogs $game_system.used_fog.clear $game_temp.clear_fog = true Fiber.yield end def get_fog(key) plane = planefogs return nil unless plane plane.get_fog(key) end def planefogs scene = SceneManager.scene spriteset = scene.instance_variable_get("@spriteset") return spriteset.instance_variable_get("@fogs") end def delete_fog(key,speed = 255) fog = get_fog(key) return unless fog $game_system.used_fog.delete(key) fog.fadeout(speed) fog.fade_delete = true end def add_fog(key,speed = 255) return if $game_system.used_fog.include?(key) $game_system.used_fog.push(key) fog = planefogs[key] fog.fadein(speed) end end # ============================================================================= # ▼ Game_Map # ============================================================================= class Game_Map attr_accessor :used_fogs alias theo_fog_init initialize def initialize theo_fog_init @used_fogs = [] end alias theo_fog_setup setup def setup(map_id) theo_fog_setup(map_id) setup_fogs end def setup_fogs @used_fogs = [] @map.note.split(/[\r\n]+/).each do |line| case line when /<(?:ADD_FOG|add fog): (.*)>/i key = $1.to_s next if @used_fogs.include?(key) @used_fogs.push(key) end end end end # ============================================================================= # ▼ PlaneFog # ============================================================================= class PlaneFog < Plane attr_accessor :fade_delete attr_accessor :key def initialize(key, viewport) super(viewport) @real_ox = self.ox.to_f + rand(Graphics.width) @real_oy = self.oy.to_f + rand(Graphics.height) load_data(key) update_oxoy @fade = 0 @fade_delete = false end def load_data(key) @data = THEO::Fog.fog_data[key] self.bitmap = Cache.picture(@data.name) @data.instance_variables.each do |varsymb| ivar_name = varsymb.to_s.gsub(/@/){""} eval(" if self.respond_to?(\"#{ivar_name}\") self.#{ivar_name} = @data.#{ivar_name} end ") end end def fadeout(speed) @fade = -speed end def fadein(speed) @fade = speed self.opacity = 0 end def spd_x @data.speed_x end def spd_y @data.speed_y end def update update_real_oxoy update_oxoy update_visible update_fade end def update_real_oxoy @real_ox += spd_x @real_oy += spd_y end def update_oxoy self.ox = fog_display_x + @real_ox self.oy = fog_display_y + @real_oy end def update_fade self.opacity = [[opacity + @fade,0].max,max_opacity].min end def max_opacity @data.opacity end def fog_display_x $game_map.display_x * (32.0 * @data.scroll_scale_x) end def fog_display_y $game_map.display_y * (32.0 * @data.scroll_scale_y) end def update_visible self.visible = @data.visible end end # ============================================================================= # ▼ PlaneFogs # ============================================================================= class PlaneFogs def initialize(viewport) @data = {} @viewport = viewport init_used_fog end def init_used_fog $game_system.used_fog.each do |fogname| self[fogname] end end def get_fog(key) @data[key] end def delete(key) fog = @data[key] return unless fog fog.dispose @data.delete(key) end def [](key) @data[key] ||= PlaneFog.new(key, @viewport) end def update update_basic @data.values.each {|fog| fog.update unless fog.disposed?} end def update_basic update_delete update_clear end def update_delete @data.values.each do |fog| next unless fog.fade_delete && fog.opacity == 0 delete(fog.key) $game_system.used_fog.delete(fog.key) end end def update_clear if $game_temp.clear_fog @data.keys.each do |key| delete(key) end $game_temp.clear_fog = false end end def dispose @data.values.each {|fog| fog.dispose} end end # ============================================================================= # ▼ MapFogs # ============================================================================= class Mapfogs < PlaneFogs def init_used_fogs @used_fogs = $game_map.used_fogs.dup @used_fogs.each do |fogname| self[fogname] end end def update_basic update_used_fog end def update_used_fog if @used_fogs != $game_map.used_fogs delete_all init_used_fogs end end def delete_all @data.values.each do |fog| delete(fog.key) end end end # ============================================================================= # ▼ Spriteset_Map # ============================================================================= class Spriteset_Map alias theo_fog_viewports create_viewports def create_viewports theo_fog_viewports create_mapfogs create_global_fogs end def create_mapfogs @mapfogs = Mapfogs.new(@viewport1) end def create_global_fogs @fogs = PlaneFogs.new(@viewport1) end alias theo_fog_update update def update theo_fog_update update_global_fogs update_mapfogs end def update_global_fogs @fogs.update end def update_mapfogs @mapfogs.update end alias theo_fog_dispose dispose def dispose theo_fog_dispose dispose_global_fogs dispose_mapfogs end def dispose_global_fogs @fogs.dispose end def dispose_mapfogs @mapfogs.dispose end end # ============================================================================= # ▼ Spriteset_Battle # ============================================================================= class Spriteset_Battle def use_fog? THEO::Fog::BattleFog end alias theo_fog_viewports create_viewports def create_viewports theo_fog_viewports return unless use_fog? create_mapfogs create_global_fogs end def create_mapfogs @mapfogs = Mapfogs.new(@viewport1) end def create_global_fogs @fogs = PlaneFogs.new(@viewport1) end alias theo_fog_update update def update theo_fog_update return unless use_fog? update_global_fogs update_mapfogs end def update_global_fogs @fogs.update end def update_mapfogs @mapfogs.update end alias theo_fog_dispose dispose def dispose theo_fog_dispose return unless use_fog? dispose_global_fogs dispose_mapfogs end def dispose_global_fogs @fogs.dispose end def dispose_mapfogs @mapfogs.dispose end end