class Sprite_FogCover < Sprite
attr_accessor :tileset_name
attr_accessor :autotiles
attr_accessor :autotiles_name
attr_accessor :terrain_tags
attr_accessor :priorities
attr_reader :map_data
def initialize(viewport = nil)
super(viewport)
@refresh_data = nil
@autotiles_name = []
end
def map_data=(map_data)
@map_data = map_data
if self.bitmap != nil
self.bitmap.dispose
end
self.bitmap = Bitmap.new(@map_data.xsize * 32, @map_data.ysize * 32)
refresh
end
def refresh
@refresh_data = @map_data
for z in 0...@map_data.zsize
for x in 0...@map_data.xsize
for y in 0...@map_data.ysize
id = @map_data[x, y, z]
next if id == 0
next if terrain_tag(x, y) != 7
id < 384 ? draw_autotile(x, y, id) : draw_tile(x, y, id)
end
end
end
end
def draw_tile(x, y, id)
bit = RPG::Cache.tile(@tileset_name, id, 0)
self.bitmap.blt(x * 32, y * 32, bit, Rect.new(0, 0, 32, 32))
end
def draw_autotile(x, y, tile_id)
filename = @autotiles_name[tile_id / 48 - 1]
bit = RPG::Cache.autotile_tile(filename, tile_id % 48)
self.bitmap.blt(x * 32, y * 32, bit, Rect.new(0, 0, 32, 32))
end
def update
if @refresh_data != @map_data || Graphics.frame_count % 16 == 0
refresh
end
end
def terrain_tag(x, y)
for i in [2, 1, 0]
tile_id = @map_data[x, y, i]
if tile_id == nil
return 0
elsif @terrain_tags[tile_id] > 0
return @terrain_tags[tile_id]
end
end
end
end
class Spriteset_Map
alias_method :seph_tilefogcover_scnmap_init, :initialize
alias_method :seph_tilefogcover_scnmap_updt, :update
def initialize
seph_tilefogcover_scnmap_init
@fog_cover_sprite = Sprite_FogCover.new(@viewport1)
@fog_cover_sprite.tileset_name = $game_map.tileset_name
@fog_cover_sprite.autotiles = @tilemap.autotiles
for i in 0..6
@fog_cover_sprite.autotiles_name[i] = $game_map.autotile_names[i]
end
@fog_cover_sprite.terrain_tags = $game_map.terrain_tags
@fog_cover_sprite.priorities = $game_map.priorities
@fog_cover_sprite.map_data = $game_map.data
@fog_cover_sprite.z = 3001
end
def update
seph_tilefogcover_scnmap_updt
unless @fog_cover_sprite.nil?
@fog_cover_sprite.update
@fog_cover_sprite.ox = @tilemap.ox
@fog_cover_sprite.oy = @tilemap.oy
end
end
end
module RPG::Cache
#--------------------------------------------------------------------------
# * Auto-Tiles
#--------------------------------------------------------------------------
Autotiles = [
[[27, 28, 33, 34], [ 5, 28, 33, 34], [27, 6, 33, 34], [ 5, 6, 33, 34],
[27, 28, 33, 12], [ 5, 28, 33, 12], [27, 6, 33, 12], [ 5, 6, 33, 12]],
[[27, 28, 11, 34], [ 5, 28, 11, 34], [27, 6, 11, 34], [ 5, 6, 11, 34],
[27, 28, 11, 12], [ 5, 28, 11, 12], [27, 6, 11, 12], [ 5, 6, 11, 12]],
[[25, 26, 31, 32], [25, 6, 31, 32], [25, 26, 31, 12], [25, 6, 31, 12],
[15, 16, 21, 22], [15, 16, 21, 12], [15, 16, 11, 22], [15, 16, 11, 12]],
[[29, 30, 35, 36], [29, 30, 11, 36], [ 5, 30, 35, 36], [ 5, 30, 11, 36],
[39, 40, 45, 46], [ 5, 40, 45, 46], [39, 6, 45, 46], [ 5, 6, 45, 46]],
[[25, 30, 31, 36], [15, 16, 45, 46], [13, 14, 19, 20], [13, 14, 19, 12],
[17, 18, 23, 24], [17, 18, 11, 24], [41, 42, 47, 48], [ 5, 42, 47, 48]],
[[37, 38, 43, 44], [37, 6, 43, 44], [13, 18, 19, 24], [13, 14, 43, 44],
[37, 42, 43, 48], [17, 18, 47, 48], [13, 18, 43, 48], [ 1, 2, 7, 8]]
]
#--------------------------------------------------------------------------
# * Autotile Cache
#
# @autotile_cache = {
# filename => { [autotile_id, frame_id, hue] => bitmap, ... },
# ...
# }
#--------------------------------------------------------------------------
@autotile_cache = {}
#--------------------------------------------------------------------------
# * Autotile Tile
#--------------------------------------------------------------------------
def self.autotile_tile(filename, tile_id, hue = 0, frame_id = nil)
# Gets Autotile Bitmap
autotile = self.autotile(filename)
# Configures Frame ID if not specified
if frame_id.nil?
# Animated Tiles
frames = autotile.width / 96
# Configures Animation Offset
fc = Graphics.frame_count / 16
frame_id = (fc) % frames * 96
end
# Creates list if already not created
@autotile_cache[filename] = {} unless @autotile_cache.has_key?(filename)
# Gets Key
key = [tile_id, frame_id, hue]
# If Key Not Found
unless @autotile_cache[filename].has_key?(key)
# Reconfigure Tile ID
tile_id %= 48
# Creates Bitmap
bitmap = Bitmap.new(32, 32)
# Collects Auto-Tile Tile Layout
tiles = Autotiles[tile_id / 8][tile_id % 8]
# Draws Auto-Tile Rects
for i in 0...4
tile_position = tiles[i] - 1
src_rect = Rect.new(tile_position % 6 * 16 + frame_id,
tile_position / 6 * 16, 16, 16)
bitmap.blt(i % 2 * 16, i / 2 * 16, autotile, src_rect)
end
# Saves Autotile to Cache
@autotile_cache[filename][key] = bitmap
# Change Hue
@autotile_cache[filename][key].hue_change(hue)
end
# Return Autotile
return @autotile_cache[filename][key]
end
end