class Tilemap #========================================================================= #Script editer par Yourii #Une petite pensée car j'ai du arreter de faire les events pour ça #========================================================================= #-------------------------------------------------------------------------- Animated_Autotiles_Frames = 15 #-------------------------------------------------------------------------- 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] ] ] #-------------------------------------------------------------------------- attr_reader :sprite attr_reader :spa attr_accessor :tileset attr_accessor :autotiles attr_accessor :map_data attr_accessor :flash_data attr_accessor :priorities attr_accessor :visible attr_accessor :ox attr_accessor :oy #-------------------------------------------------------------------------- def initialize(viewport, map = $game_map.map) @sprite = [] for l in 0...9 layer = Sprite.new(viewport) layer.bitmap = Bitmap.new(map.width * 32, map.height * 32) layer.z = l * 150 - 150 layer.zoom_x = $game_map.tilemap_zoom_x layer.zoom_y = $game_map.tilemap_zoom_y if (tone = $game_map.tilemap_tone).is_a?(Tone) layer.tone = tone end @sprite << layer end @spa=[] for l in 0...9 layer = Sprite.new(viewport) layer.bitmap = Bitmap.new(map.width * 32, map.height * 32) layer.z = l * 150 - 150 layer.zoom_x = $game_map.tilemap_zoom_x layer.zoom_y = $game_map.tilemap_zoom_y if (tone = $game_map.tilemap_tone).is_a?(Tone) layer.tone = tone end @spa << layer end @tileset = nil # Refers to Map Tileset Name @autotiles = [] # Refers to Tileset Auto-Tiles (Actual Auto-Tiles) @map_data = nil # Refers to 3D Array Of Tile Settings @flash_data = nil # Refers to 3D Array of Tile Flashdata @priorities = nil # Refers to Tileset Priorities @visible = true # Refers to Tilest Visibleness @ox = 0 # Bitmap Offsets @oy = 0 # bitmap Offsets @data = nil # Acts As Refresh Flag @map = map @tone = $game_map.tilemap_tone @plane = $game_map.tilemap_plane @zoom_x = $game_map.tilemap_zoom_x @zoom_y = $game_map.tilemap_zoom_y @tile_width = $game_map.tilemap_tile_width @tile_height = $game_map.tilemap_tile_height end #-------------------------------------------------------------------------- def dispose for sprite in @sprite sprite.dispose end for sprite in @spa sprite.dispose end end #-------------------------------------------------------------------------- def update unless @data == @map_data && @tile_width == $game_map.tilemap_tile_width && @tile_height == $game_map.tilemap_tile_height refresh end unless @tone == $game_map.tilemap_tone @tone = $game_map.tilemap_tone @tone = Tone.new(0, 0, 0, 0) if @tone.nil? for layer in @sprite layer.tone = @tone layer.tone = @tone end for layer in @spa layer.tone = @tone layer.tone = @tone end end unless @zoom_x == $game_map.tilemap_zoom_x @zoom_x = $game_map.tilemap_zoom_x for layer in @sprite layer.zoom_x = @zoom_x layer.zoom_x = @zoom_x end for layer in @spa layer.zoom_x = @zoom_x layer.zoom_x = @zoom_x end end unless @zoom_y == $game_map.tilemap_zoom_y @zoom_y = $game_map.tilemap_zoom_y for layer in @sprite layer.zoom_y = @zoom_y layer.zoom_y = @zoom_y end for layer in @spa layer.zoom_y = @zoom_y layer.zoom_y = @zoom_y end end for layer in @sprite layer.ox = @ox layer.oy = @oy end for layer in @spa layer.ox = @ox layer.oy = @oy end if Graphics.frame_count % Animated_Autotiles_Frames == 0 refresh_autotiles end end #-------------------------------------------------------------------------- def refresh @data = @map_data for z in 0...@data.zsize for x in 0...@data.xsize for y in 0...@data.ysize id = @data[x,y,z] if id >= 384 and id != 0 draw_tile(x,y,z+@priorities[id],id) end end end end end #-------------------------------------------------------------------------- def refresh_autotiles for i in 0...9 @spa[i].bitmap.clear end for z in 0...@data.zsize for x in 0...@data.xsize for y in 0...@data.ysize id = @data[x,y,z] if id < 384 and id != 0 draw_autotile(x,y,z+@priorities[id],id) end end end end end #-------------------------------------------------------------------------- def draw_tile(x, y, z, id) rect = Rect.new((id - 384) % 8 * 32, (id - 384) / 8 * 32, 32, 32) x *= @tile_width y *= @tile_height if @tile_width == 32 && @tile_height == 32 @sprite[z].bitmap.blt(x, y, @tileset, rect) else dest_rect = Rect.new(x, y, @tile_width, @tile_height) @sprite[z].bitmap.stretch_blt(dest_rect, @tileset, rect) end end #-------------------------------------------------------------------------- def draw_autotile(x, y, z, tile_id) autotile = @autotiles[tile_id / 48 - 1] tile_id %= 48 bitmap = Bitmap.new(32, 32) tiles = Autotiles[tile_id / 8][tile_id % 8] frames = autotile.width / 96 anim = (Graphics.frame_count / Animated_Autotiles_Frames) % frames * 96 for i in 0...4 tile_position = tiles[i] - 1 src_rect = Rect.new(tile_position % 6 * 16 + anim, tile_position / 6 * 16, 16, 16) bitmap.blt(i % 2 * 16, i / 2 * 16, autotile, src_rect) end x *= @tile_width y *= @tile_height if @tile_width == 32 && @tile_height == 32 @spa[z].bitmap.blt(x, y, bitmap, Rect.new(0, 0, 32, 32)) else dest_rect = Rect.new(x, y, @tile_width, @tile_height) @spa[z].bitmap.stretch_blt(dest_rect, bitmap, Rect.new(0, 0, 32, 32)) end end #-------------------------------------------------------------------------- def bitmap bitmap = Bitmap.new(@sprite[0].bitmap.width, @sprite[0].bitmap.height) for layer in @sprite bitmap.blt(0, 0, layer.bitmap, Rect.new(0, 0, bitmap.width, bitmap.height)) end return bitmap end #-------------------------------------------------------------------------- end |