Script - Código:
#=============================================================================== # Fog Of War # By Jet10985 (Jet) #=============================================================================== # This script will created a Fog Of War effect, which marks parts of the map # as "visible", "explored", and "unexplored". Details further down. # This script has: 4 customization options. #=============================================================================== # Overwritten Methods: # None #------------------------------------------------------------------------------- # Aliased methods: # Spriteset_Map: update, initialize, dispose # Game_Temp: initialize # Game_System: initialize # Game_Character: transparent #=============================================================================== =begin Fog Of War Explanation:
With the Fog Of War, there are 3 parts of a map, "visible", "explored" and "unexplored". Visible parts you can see everything as one normally would. Explored you see the generall area, like tiles and maybe events. Unexplored is pure lack space, which nothing can be seen.
Areas are marked as "explored" as soon as it becomes "visible" by the player. -------------------------------------------------------------------------------- Depending on the value of EVENT_TRANSPARENCY in the configuration below, this comment will have a specific event do the opposite:
IGNORE FOW
So, if EVENT_TRANSPARENCY is true, then the event WILL NOT become invisible, but if EVENT_TRANSPARENCY is false, then it WILL become invisible. -------------------------------------------------------------------------------- To change the player's range of site, use this in an event "Script..." command:
change_fow_range(new_fow_range)
replace new_fow_range with a number, like 4. =end
module JetFOW # This is how far the player's Fog Of War visible range is by default. PLAYER_DEFAULT_RANGE = 4 # This is the switch id of the switch which when turned off, will turn off # the Fog Of War effect. FOG_OFF_SWITCH = 99 # Should events outside the player's "visible" range become invisible? EVENT_TRANSPARENCY = true # Do you want to pre-cache map's fogs while the player is playing? PRE_CACHE_MAPS = true end
#=============================================================================== # DON'T EDIT FURTHER UNLESS YOU KNOW WHAT TO DO. #=============================================================================== class Game_Temp attr_accessor :map_fog_sprites alias jet6754_initialize initialize unless $@ def initialize(*args, &block) @map_fog_sprites = {} jet6754_initialize(*args, &block) end end
class Game_System attr_accessor :exposed_tiles, :player_fow_range alias jet2834_initialize initialize unless $@ def initialize(*args, &block) @exposed_tiles = {} @player_fow_range = JetFOW::PLAYER_DEFAULT_RANGE jet2834_initialize(*args, &block) end end
class Game_Interpreter def change_fow_range(t) $game_system.player_fow_range = t end end
class Spriteset_Map alias jet1245_initialize initialize unless $@ def initialize(*args, &block) create_fog_of_war Thread.new { @pre_cached ||= false precache_fogs_of_war if JetFOW::PRE_CACHE_MAPS && !@pre_cached } jet1245_initialize(*args, &block) end alias jet8677_update update unless $@ def update(*args, &block) update_fog_of_war jet8677_update(*args, &block) end alias jet8677_dispose dispose unless $@ def dispose(*args, &block) dispose_fog_of_war jet8677_dispose(*args, &block) end def precache_fogs_of_war @pre_cached = true f = load_data("Data/MapInfos.rvdata") (f.keys - $game_temp.map_fog_sprites.keys).each {|a| $game_temp.map_fog_sprites[a] = {} map = load_data(sprintf("Data/Map%03d.rvdata", a)) width, height = map.width, map.height viewport = Viewport.new(0, 0, width * 32, height * 32) width.times {|i| height.times {|i2| bit = Bitmap.new(32, 32) bit.fill_rect(bit.rect, Color.new(0, 0, 0)) sprite = Sprite.new(viewport) sprite.bitmap = bit viewport.z = 9999 sprite.visible = false $game_temp.map_fog_sprites[a][[i, i2]] = sprite } } } GC.start end def create_fog_of_war(*args, &block) if $game_temp.map_fog_sprites[$game_map.map_id].nil? @making_fow = true $game_temp.map_fog_sprites[$game_map.map_id] = {} width, height = $game_map.width, $game_map.height viewport = Viewport.new(0, 0, width * 32, height * 32) width.times {|i| height.times {|i2| bit = Bitmap.new(32, 32) bit.fill_rect(bit.rect, Color.new(0, 0, 0)) sprite = Sprite.new(viewport) sprite.bitmap = bit viewport.z = 9999 $game_temp.map_fog_sprites[$game_map.map_id][[i, i2]] = sprite } } @making_fow = false end if $game_system.exposed_tiles[$game_map.map_id].nil? $game_system.exposed_tiles[$game_map.map_id] = [] end $game_system.exposed_tiles[$game_map.map_id].each {|a| $game_temp.map_fog_sprites[$game_map.map_id][a].opacity = 128 } end def update_fog_of_war(*args, &block) @did_first_move ||= false @did_fow_first ||= false @fow_invis ||= false if $game_switches[JetFOW::FOG_OFF_SWITCH] && !@fow_invis $game_temp.map_fog_sprites[$game_map.map_id].each {|a, b| b.visible = false unless !b.visible @fow_invis = true } return else @fow_invis = false end if (!$game_player.stopping? && !@did_first_move) || !@did_fow_first @did_first_move = true @did_fow_first = true unless @did_fow_first || @making_fow $game_temp.map_fog_sprites[$game_map.map_id].each {|a, b| b.visible = true unless b.visible b.x = a[0] * 32 - ($game_map.display_x + 255) / 256 * 32 b.y = a[1] * 32 - ($game_map.display_y + 255) / 256 * 32 x = ($game_player.x - a[0]).abs y = ($game_player.y - a[1]).abs dist = x + y if dist <= $game_system.player_fow_range b.opacity = 0 unless b.opacity == 0 if !$game_system.exposed_tiles[$game_map.map_id].include?(a) $game_system.exposed_tiles[$game_map.map_id].push(a) end elsif $game_system.exposed_tiles[$game_map.map_id].include?(a) b.opacity = 128 unless b.opacity == 128 else b.opacity = 255 unless b.opacity == 255 end } end if $game_player.stopping? && @did_first_move @did_first_move = false end end def dispose_fog_of_war(*args, &block) $game_temp.map_fog_sprites[$game_map.map_id].each {|a, b| b.visible = false unless !b.visible } end end
class Game_Character alias jet4567_transparent transparent unless $@ def transparent(*args, &block) if !$game_switches[JetFOW::FOG_OFF_SWITCH] && !within_range_fow? if JetFOW::EVENT_TRANSPARENCY return true unless self.is_a?(Game_Event) && ignore_fow_comment? end end return jet4567_transparent(*args, &block) end def within_range_fow?(*args, &block) a, b = $game_player, self return true if b == a if ((b.x - a.x).abs + (b.y - a.y).abs) <= $game_system.player_fow_range return true end return false end end
class Game_Event def ignore_fow_comment?(*args, &block) return false if @list.nil? or @list.size <= 0 for item in @list if item.code == 108 or item.code == 408 if item.parameters[0].match(/IGNORE[ ]*FOW/i) return true end end end return false end end |