赞 | 12 |
VIP | 107 |
好人卡 | 6 |
积分 | 4 |
经验 | 31122 |
最后登录 | 2024-6-29 |
在线时间 | 1606 小时 |
Lv2.观梦者 傻♂逼
- 梦石
- 0
- 星屑
- 374
- 在线时间
- 1606 小时
- 注册时间
- 2007-3-13
- 帖子
- 6562
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
就是可以把一张地图变成一张远景。从Map***.rxdata到***.png的变化。。。
代码:
- #==============================================================================
- # PNG文件输出
- # 用法:bitmap.save2png(filename)
- # BY:轮回者
- #==============================================================================
- class Bitmap
-
- # 是否自动颠倒上下?
- # false时输出图像上下会颠倒,但并不能节省很多时间
- SWITCH_UP2DOWN = true
-
- # 存入PNG文件
- def save2png(filename)
- file = File.open(filename,"wb")
- file.write(make_png_header)
- file.write(make_png_ihdr)
- file.write(make_png_idat)
- file.write(make_png_iend)
- file.close
- end
-
- # PNG文件头数据块
- def make_png_header
- return [0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a].pack("C*")
- end
- # PNG文件情报头数据块(IHDR)
- def make_png_ihdr
- ih_size = [13].pack("N")
- ih_sign = "IHDR"
- ih_width = [width].pack("N")
- ih_height = [height].pack("N")
- ih_bit_depth = [8].pack("C")
- ih_color_type = [6].pack("C")
- ih_compression_method = [0].pack("C")
- ih_filter_method = [0].pack("C")
- ih_interlace_method = [0].pack("C")
- string = ih_sign + ih_width + ih_height + ih_bit_depth + ih_color_type +
- ih_compression_method + ih_filter_method + ih_interlace_method
- ih_crc = [Zlib.crc32(string)].pack("N")
- return ih_size + string + ih_crc
- end
-
- # PNG图像数据(IDAT)
- def make_png_idat
- header = "\x49\x44\x41\x54"
- data = SWITCH_UP2DOWN ? make_png_data : make_png_data2
- data = Zlib::Deflate.deflate(data, 8)
- crc = [Zlib.crc32(header + data)].pack("N")
- size = [data.length].pack("N")
- return size + header + data + crc
- end
-
- # PNG图像数据(点阵);自动颠倒上下
- def make_png_data
- data = get_data.unpack('x2aX2aX2ax2a'*height*width).to_s
- len = width * 4
- for y in 0...height
- break if 2*y >= height - 1
- nth1 = y * len
- nth2 = (height - 1 - y) * len
- tStr = data[nth1,len]
- data[nth1, len] = data[nth2, len]
- data[nth2, len] = tStr
- end
-
- for y in 0...height
- nth = (height - 1 - y) * width * 4
- data.insert(nth,"\000")
- end
- return data
- end
-
- # PNG图像数据(点阵);不自动颠倒上下
- def make_png_data2
- data = get_data.unpack('x2aX2aX2ax2a'*height*width).to_s
- for y in 0...height
- nth = (height - 1 - y) * width * 4
- data.insert(nth,"\000")
- end
- return data
- end
-
- # PNG文件尾数据块(IEND)
- def make_png_iend
- ie_size = [0].pack("N")
- ie_sign = "IEND"
- ie_crc = [Zlib.crc32(ie_sign)].pack("N")
- return ie_size + ie_sign + ie_crc
- end
-
- # 获取数据
- def get_data
- data = "rgba" * width * height
- RtlMoveMemory_pi.call(data, address, data.length)
- return data
- end
- end
- #==============================================================================
- # Bitmap类修改尝试
- #==============================================================================
- class Bitmap
- # 取得点(x,y)的颜色(Color)
- def get_pixel_plus(x, y)
- data = "rgba"
- nth = ((height - 1 - y) * width + x) * data.length
- RtlMoveMemory_pi.call(data, address + nth, data.length)
- clr_ary = data.unpack('c*')
- return Color.new(clr_ary[2],clr_ary[1],clr_ary[0],clr_ary[3])
- end
-
- # 设定点(x,y)的颜色为 color(Color)
- def set_pixel_plus(x, y, color)
- data = [color.blue,color.green,color.red,color.alpha].pack('c*')
- nth = ((height - 1 - y) * width + x) * data.length
- RtlMoveMemory_ip.call(address + nth, data, data.length)
- return self
- end
- end
- #==============================================================================
- # 快速存储Bitmap的Marshal(修改版)By 柳之一
- #==============================================================================
- class Font
- def marshal_dump;end
- def marshal_load(obj);end
- end
- class Bitmap
- attr_accessor :address
- # 初始化传送到内存的API函数
- RtlMoveMemory_pi = Win32API.new('kernel32', 'RtlMoveMemory', 'pii', 'i')
- RtlMoveMemory_ip = Win32API.new('kernel32', 'RtlMoveMemory', 'ipi', 'i')
-
- # 保存
- def _dump(limit)
- data = "rgba" * width * height
- RtlMoveMemory_pi.call(data, address, data.length)
- [width, height, Zlib::Deflate.deflate(data)].pack("LLa*") # 压缩
- end
-
- # 读取
- def self._load(str)
- w, h, zdata = str.unpack("LLa*"); b = new(w, h)
- RtlMoveMemory_ip.call(b.address, Zlib::Inflate.inflate(zdata), w * h * 4); b
- end
-
- # [[[bitmap.object_id * 2 + 16] + 8] + 16] == 数据的开头
- #
- def address
- @address = ini_address if @address.nil?
- return @address
- end
-
- def ini_address
- buffer, ad = "xxxx", object_id * 2 + 16
- RtlMoveMemory_pi.call(buffer, ad, 4); ad = buffer.unpack("L")[0] + 8
- RtlMoveMemory_pi.call(buffer, ad, 4); ad = buffer.unpack("L")[0] + 16
- RtlMoveMemory_pi.call(buffer, ad, 4); ad = buffer.unpack("L")[0]
- return ad
- end
- end
- #==============================================================================
- # 回收站~
- #==============================================================================
- =begin
- class Color_Plus
- # 初始化实例变量
- attr_accessor :red
- attr_accessor :green
- attr_accessor :blue
- attr_accessor :alpha
- # 初始化
- def initialize(red, green, blue, alpha=255)
- @red = red
- @green = green
- @blue = blue
- @alpha = alpha
- end
-
- # 设定所有属性
- def set(red, green, blue, alpha=255)
- @red = red
- @green = green
- @blue = blue
- @alpha = alpha
- end
- end
- =end
复制代码- #==============================================================================
- # ** Game_Map
- #==============================================================================
- class Game_Map
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_reader :map
- attr_accessor :tilemap_tone
- attr_accessor :tilemap_plane
- attr_accessor :tilemap_zoom_x
- attr_accessor :tilemap_zoom_y
- attr_accessor :tilemap_tile_width
- attr_accessor :tilemap_tile_height
- #--------------------------------------------------------------------------
- # * Alias Listings
- #--------------------------------------------------------------------------
- alias seph_tilemap_gmap_init initialize
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize
- # Original Initialization
- seph_tilemap_gmap_init
- # Sets Special Tilemap Properties
- @tilemap_tone = nil
- @tilemap_plane = false
- @tilemap_zoom_x = 1.0
- @tilemap_zoom_y = 1.0
- @tilemap_tile_width = 32
- @tilemap_tile_height = 32
- end
- end
- #==============================================================================
- # ** Tilemap
- #==============================================================================
- class Tilemap
- #--------------------------------------------------------------------------
- # * Animated Autotiles Frames Reset
- #--------------------------------------------------------------------------
- Animated_Autotiles_Frames = 9999
- #--------------------------------------------------------------------------
- # * Auto-Tiles
- #
- # Auto-Tile 48 : First Auto-Tile, Constructed of tiles 27, 28, 33, 34
- #--------------------------------------------------------------------------
- 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] ]
- ]
- #--------------------------------------------------------------------------
- # * Public Instance Variables
- #--------------------------------------------------------------------------
- attr_reader :layers
- 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
- #--------------------------------------------------------------------------
- # * Object Initialization
- #--------------------------------------------------------------------------
- def initialize(viewport, map = $game_map.map)
- # Creates layers
- @layers = []
- @cont = 0
- for l in 0...3
- layer = ($game_map.tilemap_plane ?
- Plane.new(viewport) : Sprite.new(viewport))
- layer.bitmap = Bitmap.new(map.width * 32, map.height * 32)
- layer.z = l * 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
- @layers << layer
- end
- # Sets Tileset Data
- @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
- # Sets Specials Tile Properties
- @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
- #--------------------------------------------------------------------------
- # * Dispose
- #--------------------------------------------------------------------------
- def dispose
- # Dispose Layers (Sprites)
- for layer in @layers
- layer.dispose
- end
- end
- #--------------------------------------------------------------------------
- # * Frame Update
- #--------------------------------------------------------------------------
- def update
- # If Data Changes
- unless @data == @map_data &&
- @tile_width == $game_map.tilemap_tile_width &&
- @tile_height == $game_map.tilemap_tile_height
- refresh
- end
- # Tone Change
- unless @tone == $game_map.tilemap_tone
- @tone = $game_map.tilemap_tone
- @tone = Tone.new(0, 0, 0, 0) if @tone.nil?
- for layer in @layers
- layer.tone = @tone
- layer.tone = @tone
- end
- end
- # Zoom Change
- unless @zoom_x == $game_map.tilemap_zoom_x
- @zoom_x = $game_map.tilemap_zoom_x
- for layer in @layers
- 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 @layers
- layer.zoom_y = @zoom_y
- layer.zoom_y = @zoom_y
- end
- end
- # Update layer Position offsets
- for layer in @layers
- layer.ox = @ox
- layer.oy = @oy
- end
- # Animated Autotiles
- if Graphics.frame_count % Animated_Autotiles_Frames == 0
- # Refresh Autotile
- refresh_autotiles
- end
- get_bitmap.save2png($iiii.to_s + ".png") if $start_out
- end
- #--------------------------------------------------------------------------
- # * Refresh
- #--------------------------------------------------------------------------
- def refresh
- # Saves Map Data
- @data = @map_data
- # Passes Through All Priorities
- for p in 0..5
- # Passes Through Layers
- for z in 0...@map_data.zsize
- # Passes Through X Coordinates
- for x in 0...@map_data.xsize
- # Passes Through Z Coordinates
- for y in 0...@map_data.ysize
- # Collects Tile ID
- id = @map_data[x, y, z]
- # Skip if 0 tile
- next if id == 0
- # Skip If Priority Doesn't Match
- next unless p == @priorities[id]
- # Cap Priority to Layer 3
- p = 2 if p > 2
- # Draw Tile
- id < 384 ? draw_autotile(x, y, p, id) : draw_tile(x, y, p, id)
- end
- end
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Refresh Auto-Tiles
- #--------------------------------------------------------------------------
- def refresh_autotiles
- # Auto-Tile Locations
- autotile_locations = Table.new(@map_data.xsize, @map_data.ysize,
- @map_data.zsize)
- # Passes Through All Priorities
- for p in 0..5
- # Passes Through Layers
- for z in 0...@map_data.zsize
- # Passes Through X Coordinates
- for x in 0...@map_data.xsize
- # Passes Through Z Coordinates
- for y in 0...@map_data.ysize
- # Collects Tile ID
- id = @map_data[x, y, z]
- # Skip if 0 tile
- next if id == 0
- # Skip If Priority Doesn't Match
- next unless p == @priorities[id]
- # Skip If Non-Animated Tile
- # next unless autotile = @autotiles[id / 48 - 1].width / 96 > 1
- # Cap Priority to Layer 3
- p = 2 if p > 2
- # If Autotile
- if id < 384
- # Draw Auto-Tile
- draw_autotile(x, y, p, id)
- # Save Autotile Location
- autotile_locations[x, y, z] = 1
- # If Normal Tile
- else
- # If Autotile Drawn
- if autotile_locations[x, y, z] == 1
- # Redraw Normal Tile
- draw_tile(x, y, p, id)
- end
- end
- end
- end
- end
- end
- end
- #--------------------------------------------------------------------------
- # * Draw Tile
- #--------------------------------------------------------------------------
- def draw_tile(x, y, z, id)
- # Figures Tile Rect
- rect = Rect.new((id - 384) % 8 * 32, (id - 384) / 8 * 32, 32, 32)
- # Calculates Tile Coordinates
- x *= @tile_width
- y *= @tile_height
- # If Normal Tile
- if @tile_width == 32 && @tile_height == 32
- @layers[z].bitmap.blt(x, y, @tileset, rect)
- # If Altered Dimensions
- else
- dest_rect = Rect.new(x, y, @tile_width, @tile_height)
- @layers[z].bitmap.stretch_blt(dest_rect, @tileset, rect)
- end
- end
- #--------------------------------------------------------------------------
- # * Draw Auto-Tile
- #--------------------------------------------------------------------------
- def draw_autotile(x, y, z, tile_id)
- # Gets Auto-Tile
- autotile = @autotiles[tile_id / 48 - 1]
- # 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]
- # Animated Tiles
- frames = autotile.width / 96
- # Configures Animation Offset
- anim = (Graphics.frame_count / Animated_Autotiles_Frames) % frames * 96
- # Draws Auto-Tile Rects
- 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
- # Calculates Tile Coordinates
- x *= @tile_width
- y *= @tile_height
- # If Normal Tile
- if @tile_width == 32 && @tile_height == 32
- @layers[z].bitmap.blt(x, y, bitmap, Rect.new(0, 0, 32, 32))
- # If Altered Dimensions
- else
- dest_rect = Rect.new(x, y, @tile_width, @tile_height)
- @layers[z].bitmap.stretch_blt(dest_rect, bitmap, Rect.new(0, 0, 32, 32))
- end
- end
- #--------------------------------------------------------------------------
- # * Collect Bitmap
- #--------------------------------------------------------------------------
- def get_bitmap
- # Creates New Blank Bitmap
- bitmap = Bitmap.new(@layers[0].bitmap.width, @layers[0].bitmap.height)
- # Passes Through All Layers
- for layer in @layers
- bitmap.blt(0, 0, layer.bitmap,
- Rect.new(0, 0, bitmap.width, bitmap.height))
- end
- # Return Bitmap
- return bitmap
- end
- end
复制代码- def make_map2png
- 地图数量 = 1
- for $iiii in 1..地图数量
- $start_out = true
- @map = load_data(sprintf("Data/Map%03d.rxdata", $iiii))
- tmp = Tilemap.new(Viewport.new(0,0,6400,4800),@map)
- tileset = $data_tilesets[@map.tileset_id]
- tmp.tileset = RPG::Cache.tileset(tileset.tileset_name)
- for i in 0..6
- autotile_name = tileset.autotile_names[i]
- tmp.autotiles[i] = RPG::Cache.autotile(autotile_name)
- end
- tmp.map_data = @map.data
- tmp.priorities = tileset.priorities
- tmp.update
- Graphics.update
- tmp.dispose
- $start_out = false
- Graphics.update
- end
- exit
- end
复制代码
直接在事件执行make_map2png |
|