05-06-2007, 01:00 PM
IMPROVED Fog of War System(FOW) V1.0
by Samo, the Thief
May 6 2007
I'm Sure that many people have ever wanted a Fog of War like Strategy Games.
Here you have it! But this isn't the only thing, you can do tiles that you can't
see through. Just play the Demo nd you will see my words.
CODE:
-----
here it is:
INSTRUCTIONS:
-------------
Enjoy the script and give me the credit.
Samo, the thief.
by Samo, the Thief
May 6 2007
This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given. If you are the owner of the thread, please contact administration.
No support is given. If you are the owner of the thread, please contact administration.
I'm Sure that many people have ever wanted a Fog of War like Strategy Games.
Here you have it! But this isn't the only thing, you can do tiles that you can't
see through. Just play the Demo nd you will see my words.
CODE:
-----
here it is:
CODE
Code:
=begin
Fog of War System(FOW) V1.0 by Samo, the Thief
Instructions:
-------------
1-Put this Script Above Main
2- Add in Scene_Title the lines Between ADDED:
$game_map.update
#-----------ADDED------------------------
$game_fog_of_war = Game_Fog_Of_War.new
#-----------ADDED------------------------
3- The Same in Scene_Map the with this:
@message_window.update
#---------------------------------ADDED-------------
if wait(20)
$game_fog_of_war.update
@spriteset.update_tilemap
end
#---------------------------------ADDED-------------
4- Go to your tilesets and put with counter 1 the tiles you don't want
to be seen through, like walls or trees.
5- Enjoy!
Feautures:
----------
-YOu can't see thorugh some tiles depending on where you are
-The tiles you revealed and you are not seeing are semi-revealed
-It is cool!
=end
class Game_Fog_Of_War
#--------------------------------------------------------------------
attr_accessor :map_grid
SIGHTNESS = 9
#--------------------------------------------------------------------
def initialize
@map_grid = {}
for i in 1..$map_infos.size
data = load_data(sprintf("Data/Map%03d.rxdata", i))
@map_grid[i] = Array.new(data.width, 0)
for j in 0..data.width
@map_grid[i][j] = Array.new(data.height, 0)
end
end
$map_grid_wall = Array.new($game_map.width, 0)
for j in 0..$game_map.width
$map_grid_wall[j] = Array.new($game_map.height, 0)
end
refresh_grid
@last_fow = []
end
#-------------------------------------------------------------------------
def setup_map(map_id)
data = load_data(sprintf("Data/Map%03d.rxdata", map_id))
@map_grid[i] = Array.new(data.width, 0)
for j in 0..data.width
@map_grid[i][j] = Array.new(data.height, 0)
end
end
#--------------------------------------
def refresh_grid
$map_grid_wall = Array.new($game_map.width, 0)
for j in 0..$game_map.width
$map_grid_wall[j] = Array.new($game_map.height, 0)
end
for i in 0..$game_map.width
for j in 0..$game_map.height
if $game_map.terrain_tag(i,j) == 1
$map_grid_wall[i][j] = 1
end
end
end
end
#----------------------------------------------------------------------
def update
in_range_tiles
end
#-----------------------------------------------------
def circle_of_view(x,y,sightness)
coords = []
fow = []
fx1 = x + sightness
fx2 = x - sightness
fy1 = y + sightness
fy2 = y - sightness
coords += line(fx1,y,x,fy1)
coords += line(x-1,fy1-1,fx2,y)
coords += line(fx2+1,y-1,x,fy2)
coords += line(x+1,fy2+1,fx1-1,y-1)
for coord in coords
fow = fow | line_fow(x,y,coord[0],coord[1]) #Weird Method je,je
end
for coord in fow
if coord[0] < 0 or coord[0] > $game_map.width or coord[1] < 0 or coord[1] > $game_map.height
next
end
@map_grid[$game_map.map_id][coord[0]][coord[1]] = 2
end
return fow
end
#------------------------------------------------------------------------
def in_range_tiles
fow = circle_of_view($game_player.x,$game_player.y,SIGHTNESS)
for coord in @last_fow
x = coord[0]
y = coord[1]
if x < 0 or x > $game_map.width or y < 0 or y > $game_map.height
next
end
if @map_grid[$game_map.map_id][x][y] == 2
if fow.include?([x,y]) == false
@map_grid[$game_map.map_id][x][y] = 1
end
end
end
@last_fow = fow.clone
end
#----------------------------------------------------------------------------
end
class Spriteset_Map
alias old_initialize initialize
def initialize
#=================
old_initialize
@viewport4 = Viewport.new(0, 0, 640, 480)
@viewport4.z = 5004
@fow_tilemap = Tilemap.new(@viewport4)
@fow_tilemap.tileset = RPG::Cache.picture("FOW")
@fow_tilemap.autotiles[0] = RPG::Cache.autotile("FOW0")
data = Table.new($game_map.width, $game_map.height, 3)
@fow_tilemap.map_data = data
priorities = Table.new(424)
# set to highest priority to ensure everything is covered
for i in 0...424
priorities[i] = 5
end
@fow_tilemap.priorities = priorities
for x in 0...$game_map.width
for y in 0...$game_map.height
if $game_fog_of_war.map_grid[$game_map.map_id][x][y] == 0
if @fow_tilemap.map_data[x,y,2] != 384
@fow_tilemap.map_data[x,y,2] = 384
end
end
if $game_fog_of_war.map_grid[$game_map.map_id][x][y] == 1
if @fow_tilemap.map_data[x,y,2] != 385
@fow_tilemap.map_data[x,y,2] = 385
end
end
if $game_fog_of_war.map_grid[$game_map.map_id][x][y] == 2
if @fow_tilemap.map_data[x,y,2] != 386
@fow_tilemap.map_data[x,y,2] = 386
end
end
end
end
#=================
update
end
alias old_dispose dispose
def dispose
old_dispose
@fow_tilemap.tileset.dispose
@fow_tilemap.autotiles[0].dispose
@fow_tilemap.dispose
@viewport4.dispose
end
#--------------------------------------------------------------------------
def update_tilemap
for x in 0...$game_map.width
for y in 0...$game_map.height
if $game_fog_of_war.map_grid[$game_map.map_id][x][y] == 0
if @fow_tilemap.map_data[x,y,2] != 384
@fow_tilemap.map_data[x,y,2] = 384
end
end
if $game_fog_of_war.map_grid[$game_map.map_id][x][y] == 1
if @fow_tilemap.map_data[x,y,2] != 385
@fow_tilemap.map_data[x,y,2] = 385
end
end
if $game_fog_of_war.map_grid[$game_map.map_id][x][y] == 2
if @fow_tilemap.map_data[x,y,2] != 386
@fow_tilemap.map_data[x,y,2] = 386
end
end
end
end
end
#---------------------------------------------------
alias old_update update
def update
old_update
@fow_tilemap.ox = $game_map.display_x / 4
@fow_tilemap.oy = $game_map.display_y / 4
@fow_tilemap.update
@viewport4.update
end
end
def wait(frames)
if Graphics.frame_count % (frames) == 0
return true
end
end
def line(a,b,c,d)
coords = []
u = c - a
v = d - b
d1x = sgn(u)
d1y = sgn(v)
d2x = sgn(u)
d2y = 0
m = ABS(u)
n = ABS(v)
if not m > n
d2x = 0
d2y = sgn(v)
m = ABS(v)
n = ABS(u)
end
s = m / 2
for i in 0..m
coords.push([a,b])
s = s + n
if not (s<m)
s = s - m
a = a + d1x
b = b + d1y
else
a = a + d2x
b = b + d2y
end
end
return coords
end
#-------------------------------
def line_fow(a,b,c,d)
coords = []
u = c - a
v = d - b
d1x = sgn(u)
d1y = sgn(v)
d2x = sgn(u)
d2y = 0
m = ABS(u)
n = ABS(v)
if not m > n
d2x = 0
d2y = sgn(v)
m = ABS(v)
n = ABS(u)
end
s = m / 2
for i in 0..m
coords.push([a,b])
if a >= 0 and a <= $game_map.width and b >= 0 and b <= $game_map.height
break if $map_grid_wall[a][b] == 1
end
s = s + n
if not (s<m)
s = s - m
a = a + d1x
coords.push([a,b])
b = b + d1y
else
a = a + d2x
coords.push([a,b])
b = b + d2y
end
end
return coords
end
def sgn(a)
return sgn = +1 if a>0
return sgn = -1 if a<0
return sgn = 0 if a==0
end
def ABS(a)
return a if a > 0
return a * -1 if a < 0
return 0
end
#========================================
#Game_Map
#--------------------------------------------------------------------------
# Setting functions for the Map
#========================================
class Game_Map
def name
$map_infos[@map_id]
end
end
#========================================
#Window_Title
#--------------------------------------------------------------------------
# Setting functions for the Title
#========================================
class Scene_Title
$map_infos = load_data("Data/MapInfos.rxdata")
for key in $map_infos.keys
$map_infos[key] = $map_infos[key].name
end
end
INSTRUCTIONS:
-------------
Enjoy the script and give me the credit.
Samo, the thief.