+- Save-Point (https://www.save-point.org)
+-- Forum: Material Development (https://www.save-point.org/forum-8.html)
+--- Forum: Scripts Database (https://www.save-point.org/forum-39.html)
+---- Forum: RPGMaker XP (RGSS) Engine (https://www.save-point.org/forum-116.html)
+---- Thread: Fog of War (/thread-2782.html)
Fog of War - Wachunga - 03-02-2008
Fog of War
Ver 2.01
by Wachunga Not DerVVulfman
Text within the post was written by Wachunga, Dec. 6, 2005.
Summary
A map specified as having "fog of war" has tiles that are (fully or partially) obscured until the player gets within visual range. The amount of fog of war to disappear as the player moves depends on the visual range specified. Gamers with experience playing Real Time Strategy games like Warcraft, Age of Empires, etc. should be quite familiar with the concept.
This script supports two kinds of fog of war: static and dynamic.
Static fog of war is the kind that typically hides terrain in RTS games. It covers the entire map until the player explores the area, discovering the underlying terrain. Once static fog of war disappears from an area of the map, it stays gone indefinitely (even if loading a saved game, leaving the map and returning later, going to the menu, etc).
Dynamic fog of war is identical to the static kind except that it doesn't stay gone forever: as soon as the player leaves visual range of an explored tile, dynamic fog of war covers it again. This kind is typically used to hide enemy units in RTS games.
Features
both types of fog of war supported
customizable view range
customizable fog autotile (plug in your own if you wish)
Resources
You'll need this custom fog of war autotile, unless you choose to make your own.
Demo
Featuring a cantankerous old man:
FOG OF WAR DEMO.zip (Size: 955 KB / Downloads: 6)
-- Instructions are within the script --
Compatibility
For compatbility with Cogwheel's Pixel Movement script, place Cog's script ABOVE the Fog of War script. Then replace Cog's Game_Player/update method with the following version (or just copy and paste the section preceded by a "FoW" comment):
Compatability Patch
Code:
alias :update_original :update
def update
unless moving? or $game_system.map_interpreter.running? or
@move_route_forcing or $game_temp.message_window_showing
if @walk != @dash
if Input.press?(Input::C)
if @move_speed != @dash
@move_speed = @dash
end
else
if @move_speed != @walk
@move_speed = @walk
end
end
end
end
if @revise_x == nil and @revise_y == nil
@revise_x = 0
@revise_y = 0
end
unless @dot_m
update_original
return
end
if @move_route_forcing
last_moving = moving?
last_real_x = @real_x
last_real_y = @real_y
if (@revise_x != 0 or @revise_y != 0) and not jumping? and @move == true
if @revise_x != @real_x - @x * 128 or @revise_y != @real_y - @y * 128
@revise_x = @real_x - @x * 128
@revise_y = @real_y - @y * 128
end
distance1 = 2 ** @move_speed
distance2 = Math.sqrt(@revise_x ** 2 + @revise_y ** 2)
if distance1 > distance2
@real_x = @real_x - @revise_x
@real_y = @real_y - @revise_y
@revise_x = 0
@revise_y = 0
anime_update
else
@real_x -= (distance1 * @revise_x / distance2).round
@real_y -= (distance1 * @revise_y / distance2).round
@revise_x = @real_x - @x * 128
@revise_y = @real_y - @y * 128
anime_update
end
else
super
end
else
@move = false
unless moving? or $game_system.map_interpreter.running? or
@move_route_forcing or $game_temp.message_window_showing
@event_run = false
case Input.dir8
when 1
move_lower_left_p
when 2
move_down_p
when 3
move_lower_right_p
when 4
move_left_p
when 6
move_right_p
when 7
move_upper_left_p
when 8
move_up_p
when 9
move_upper_right_p
end
end
last_real_x = @real_x
last_real_y = @real_y
@real_x = @x * 128 + @revise_x
@real_y = @y * 128 + @revise_y
last_moving = moving?
move_on
if (last_real_x != @real_x or last_real_y != @real_y)
@move_distance = 0 if @move_distance == nil
@move_distance += Math.sqrt((last_real_x - @real_x) ** 2 +
(last_real_y - @real_y) ** 2)
if @move_distance >= 128
@move_distance %= 128
increase_steps
end
anime_update
elsif @walk_anime
@pattern = @original_pattern
end
end
# FoW
if $game_map.fow and (@x != @last_x or @y != @last_y)
unless jumping?
$game_map.update_fow_grid
$scene.spriteset.update_event_transparency if $game_map.fow_dynamic
$scene.spriteset.update_fow_tilemap
end
end
@last_x = @x
@last_y = @y
if @real_y > last_real_y and @real_y - $game_map.display_y > CENTER_Y
$game_map.scroll_down(@real_y - last_real_y)
end
if @real_x < last_real_x and @real_x - $game_map.display_x < CENTER_X
$game_map.scroll_left(last_real_x - @real_x)
end
if @real_x > last_real_x and @real_x - $game_map.display_x > CENTER_X
$game_map.scroll_right(@real_x - last_real_x)
end
if @real_y < last_real_y and @real_y - $game_map.display_y < CENTER_Y
$game_map.scroll_up(last_real_y - @real_y)
end
if last_moving
result = check_event_trigger_here([1,2])
if result == true
if (last_real_x / 128.0).round != @x and
(last_real_y / 128.0).round != @y
if @direction == 2 or @direction == 8
if (last_real_x / 128.0).round > @x
turn_left
else
turn_right
end
else
if (last_real_y / 128.0).round > @y
turn_up
else
turn_down
end
end
elsif (last_real_x / 128.0).round > @x
turn_left
elsif (last_real_x / 128.0).round < @x
turn_right
elsif (last_real_y / 128.0).round > @y
turn_up
elsif (last_real_y / 128.0).round < @y
turn_down
end
end
if result == false
unless $DEBUG and Input.press?(Input::CTRL)
# ?????? ???????
if @encounter_count > 0
@encounter_count -= 1
end
end
end
end
if Input.trigger?(Input::C)
check_event_trigger_here([0])
check_event_trigger_there([0,1,2])
end
end
Note: this is a repost. There were many pages of discussion in the original thread at RMXP.net that you would have liked to look through. Site no longer available.