Project1

标题: 偷偷丢Tilemap试写(感谢胃君的地图讲解)10.2更新 [打印本页]

作者: kissye    时间: 2008-9-26 09:44
提示: 作者被禁止或删除 内容自动屏蔽
作者: 约束帝王攻    时间: 2008-9-26 10:40
提示: 作者被禁止或删除 内容自动屏蔽
作者: wy29    时间: 2008-9-26 18:51
提示: 作者被禁止或删除 内容自动屏蔽
作者: kissye    时间: 2008-9-27 01:07
提示: 作者被禁止或删除 内容自动屏蔽
作者: zh99998    时间: 2008-9-27 02:18
看起来我的偷代码方式完全被54了
作者: kissye    时间: 2008-9-27 03:03
提示: 作者被禁止或删除 内容自动屏蔽
作者: drgdrg    时间: 2008-9-28 03:11
那个……

问下这个是怎么用的……

我地图盲{/gg}
作者: kissye    时间: 2008-9-28 03:21
提示: 作者被禁止或删除 内容自动屏蔽
作者: drgdrg    时间: 2008-9-28 06:52
以下引用kissye于2008-9-27 19:21:52的发言:


以下引用drgdrg于2008-9-27 19:11:49的发言:

那个……

问下这个是怎么用的……

我地图盲



这个,替代默认脚本的Tilemap
如果用这个脚本和不用这个脚本效果完全一样,那么就达到脚本目的了....

因为底层RGSS类看不到也不能改,如果能用这个脚本替代掉,就可以在这个脚本的基础上改动了
例如改动阴影计算


原来如此,很厉害呢{/qiang}{/qiang}{/qiang}

作者: hitlerson    时间: 2008-9-29 07:22
很好很強大,果然是要對地圖了如指掌才能寫出來的
作者: 沉影不器    时间: 2008-9-30 03:58
提示: 作者被禁止或删除 内容自动屏蔽
作者: kissye    时间: 2008-9-30 06:54
提示: 作者被禁止或删除 内容自动屏蔽
作者: 沉影不器    时间: 2008-9-30 17:43
提示: 作者被禁止或删除 内容自动屏蔽
作者: IamI    时间: 2008-9-30 18:18
我在望天。占楼慢慢看
没有flash_data没有flash_data没有flash_data没有flash_data没有flash_data没有flash_data没有flash_data没有flash_data
作者: 一路一风尘    时间: 2008-9-30 20:14
提示: 作者被禁止或删除 内容自动屏蔽
作者: kissye    时间: 2008-9-30 22:25
提示: 作者被禁止或删除 内容自动屏蔽
作者: 沉影不器    时间: 2008-10-2 04:53
提示: 作者被禁止或删除 内容自动屏蔽
作者: 一路一风尘    时间: 2008-10-2 04:59
提示: 作者被禁止或删除 内容自动屏蔽
作者: lhbadsl    时间: 2008-10-2 13:26
楼主很牛逼。。。。。。。。。{/fd}
我有个问题就是楼主知不知道是否可以绘制,更大分辨率的tilemap,从而破除rmvx或者rmxp的544*416或者640*480的限制,因为我试过这个和分辨率脚本一起使用,可是发觉还是直接拖大了元件地图的图块尺寸,不知道能不能写个加大图块数量的脚本版出来,让rmvx的分辨率提高成为事实,最好是能够写出rmxp的那个tilemap就更好了,我试过有一个脚本是可以支持更大的图块数量的,结合分辨率脚本后真的能够提高分辨率,不过只是。。。。。。。哎。。。。。卡死人了,如果楼主的这个脚本速度和它的图块数量结合起来的话,那么高分辨率将成为事实。。。。。。。。
作者: lhbadsl    时间: 2008-10-2 13:41
再不好意思的顶下。。。。。。。支持楼主,支持tilemap,支持楼主转行玩xp。。。。{/hx}
  1. #===========================================================
  2. # ** Game_Map
  3. #===========================================================

  4. class Game_Map
  5.   #--------------------------------------------------------------------------
  6.   # * Public Instance Variables
  7.   #--------------------------------------------------------------------------
  8.   attr_reader :map
  9.   attr_accessor :tilemap_tone
  10.   attr_accessor :tilemap_plane
  11.   attr_accessor :tilemap_zoom_x
  12.   attr_accessor :tilemap_zoom_y
  13.   attr_accessor :tilemap_tile_width
  14.   attr_accessor :tilemap_tile_height
  15.   #--------------------------------------------------------------------------
  16.   # * Alias Listings
  17.   #--------------------------------------------------------------------------
  18.   alias seph_tilemap_gmap_init initialize
  19.   #--------------------------------------------------------------------------
  20.   # * Object Initialization
  21.   #--------------------------------------------------------------------------
  22.   def initialize
  23.     # Original Initialization
  24.     seph_tilemap_gmap_init
  25.     # Sets Special Tilemap Properties
  26.     @tilemap_tone        = nil
  27.     @tilemap_plane       = false
  28.     @tilemap_zoom_x      = 1.0
  29.     @tilemap_zoom_y      = 1.0
  30.     @tilemap_tile_width  = 32
  31.     @tilemap_tile_height = 32
  32.   end
  33. end

  34. #=============================================================
  35. # ** Tilemap
  36. #=============================================================

  37. class Tilemap
  38.   #--------------------------------------------------------------------------
  39.   # * Animated Autotiles Frames Reset
  40.   #--------------------------------------------------------------------------
  41.   Animated_Autotiles_Frames = 15
  42.   #--------------------------------------------------------------------------
  43.   # * Auto-Tiles
  44.   #
  45.   #   Auto-Tile 48 : First Auto-Tile, Constructed of tiles 27, 28, 33, 34
  46.   #--------------------------------------------------------------------------
  47.   Autotiles = [
  48.     [ [27, 28, 33, 34], [ 5, 28, 33, 34], [27,  6, 33, 34], [ 5,  6, 33, 34],
  49.       [27, 28, 33, 12], [ 5, 28, 33, 12], [27,  6, 33, 12], [ 5,  6, 33, 12] ],
  50.     [ [27, 28, 11, 34], [ 5, 28, 11, 34], [27,  6, 11, 34], [ 5,  6, 11, 34],
  51.       [27, 28, 11, 12], [ 5, 28, 11, 12], [27,  6, 11, 12], [ 5,  6, 11, 12] ],
  52.     [ [25, 26, 31, 32], [25,  6, 31, 32], [25, 26, 31, 12], [25,  6, 31, 12],
  53.       [15, 16, 21, 22], [15, 16, 21, 12], [15, 16, 11, 22], [15, 16, 11, 12] ],
  54.     [ [29, 30, 35, 36], [29, 30, 11, 36], [ 5, 30, 35, 36], [ 5, 30, 11, 36],
  55.       [39, 40, 45, 46], [ 5, 40, 45, 46], [39,  6, 45, 46], [ 5,  6, 45, 46] ],
  56.     [ [25, 30, 31, 36], [15, 16, 45, 46], [13, 14, 19, 20], [13, 14, 19, 12],
  57.       [17, 18, 23, 24], [17, 18, 11, 24], [41, 42, 47, 48], [ 5, 42, 47, 48] ],
  58.     [ [37, 38, 43, 44], [37,  6, 43, 44], [13, 18, 19, 24], [13, 14, 43, 44],
  59.       [37, 42, 43, 48], [17, 18, 47, 48], [13, 18, 43, 48], [ 1,  2,  7,  8] ]
  60.   ]
  61.   #--------------------------------------------------------------------------
  62.   # * Public Instance Variables
  63.   #--------------------------------------------------------------------------
  64.   attr_reader :layers
  65.   attr_accessor :tileset
  66.   attr_accessor :autotiles
  67.   attr_accessor :map_data
  68.   attr_accessor :flash_data
  69.   attr_accessor :priorities
  70.   attr_accessor :visible
  71.   attr_accessor :ox
  72.   attr_accessor :oy
  73.   #--------------------------------------------------------------------------
  74.   # * Object Initialization
  75.   #--------------------------------------------------------------------------
  76.   def initialize(viewport, map = $game_map.map)
  77.     # Creates layers
  78.     @layers = []
  79.     for l in 0...3
  80.       layer = ($game_map.tilemap_plane ?
  81.                Plane.new(viewport) : Sprite.new(viewport))
  82.       layer.bitmap = Bitmap.new(map.width * 32, map.height * 32)
  83.       layer.z = l * 150
  84.       layer.zoom_x = $game_map.tilemap_zoom_x
  85.       layer.zoom_y = $game_map.tilemap_zoom_y
  86.       if (tone = $game_map.tilemap_tone).is_a?(Tone)
  87.         layer.tone = tone
  88.       end
  89.       @layers << layer
  90.     end
  91.     # Sets Tileset Data
  92.     @tileset    = nil  # Refers to Map Tileset Name
  93.     @autotiles  = []   # Refers to Tileset Auto-Tiles (Actual Auto-Tiles)
  94.     @map_data   = nil  # Refers to 3D Array Of Tile Settings
  95.     @flash_data = nil  # Refers to 3D Array of Tile Flashdata
  96.     @priorities = nil  # Refers to Tileset Priorities
  97.     @visible    = true # Refers to Tilest Visibleness
  98.     @ox         = 0    # Bitmap Offsets         
  99.     @oy         = 0    # bitmap Offsets
  100.     @data       = nil  # Acts As Refresh Flag
  101.     # Sets Specials Tile Properties
  102.     @map         = map
  103.     @tone        = $game_map.tilemap_tone
  104.     @plane       = $game_map.tilemap_plane
  105.     @zoom_x      = $game_map.tilemap_zoom_x
  106.     @zoom_y      = $game_map.tilemap_zoom_y
  107.     @tile_width  = $game_map.tilemap_tile_width
  108.     @tile_height = $game_map.tilemap_tile_height
  109.   end
  110.   #--------------------------------------------------------------------------
  111.   # * Dispose
  112.   #--------------------------------------------------------------------------
  113.   def dispose
  114.     # Dispose Layers (Sprites)
  115.     for layer in @layers
  116.       layer.dispose
  117.     end
  118.   end
  119.   #--------------------------------------------------------------------------
  120.   # * Frame Update
  121.   #--------------------------------------------------------------------------
  122.   def update
  123.     # If Data Changes
  124.     unless @data == @map_data &&
  125.            @tile_width == $game_map.tilemap_tile_width &&
  126.            @tile_height == $game_map.tilemap_tile_height
  127.       refresh
  128.     end
  129.     # Tone Change
  130.     unless @tone == $game_map.tilemap_tone
  131.       @tone = $game_map.tilemap_tone
  132.       @tone = Tone.new(0, 0, 0, 0) if @tone.nil?
  133.       for layer in @layers
  134.         layer.tone = @tone
  135.         layer.tone = @tone
  136.       end
  137.     end
  138.     # Zoom Change
  139.     unless @zoom_x == $game_map.tilemap_zoom_x
  140.       @zoom_x = $game_map.tilemap_zoom_x
  141.       for layer in @layers
  142.         layer.zoom_x = @zoom_x
  143.         layer.zoom_x = @zoom_x
  144.       end
  145.     end
  146.     unless @zoom_y == $game_map.tilemap_zoom_y
  147.       @zoom_y = $game_map.tilemap_zoom_y
  148.       for layer in @layers
  149.         layer.zoom_y = @zoom_y
  150.         layer.zoom_y = @zoom_y
  151.       end
  152.     end
  153.     # Update layer Position offsets
  154.     for layer in @layers
  155.       layer.ox = @ox
  156.       layer.oy = @oy
  157.     end
  158.     # Animated Autotiles
  159.     if Graphics.frame_count % Animated_Autotiles_Frames == 0
  160.       # Refresh Autotiles
  161.       refresh_autotiles
  162.     end
  163.   end
  164.   #--------------------------------------------------------------------------
  165.   # * Refresh
  166.   #--------------------------------------------------------------------------
  167.   def refresh
  168.     # Saves Map Data
  169.     @data = @map_data
  170.     # Passes Through All Priorities
  171.     for p in 0..5
  172.       # Passes Through Layers
  173.       for z in 0...@map_data.zsize
  174.         # Passes Through X Coordinates
  175.         for x in 0...@map_data.xsize
  176.           # Passes Through Z Coordinates
  177.           for y in 0...@map_data.ysize
  178.             # Collects Tile ID
  179.             id = @map_data[x, y, z]
  180.             # Skip if 0 tile
  181.             next if id == 0
  182.             # Skip If Priority Doesn't Match
  183.             next unless p == @priorities[id]
  184.             # Cap Priority to Layer 3
  185.             p = 2 if p > 2
  186.             # Draw Tile
  187.             id < 384 ? draw_autotile(x, y, p, id) : draw_tile(x, y, p, id)
  188.           end
  189.         end
  190.       end
  191.     end
  192.   end
  193.   #--------------------------------------------------------------------------
  194.   # * Refresh Auto-Tiles
  195.   #--------------------------------------------------------------------------
  196.   def refresh_autotiles
  197.     # Auto-Tile Locations
  198.     autotile_locations = Table.new(@map_data.xsize, @map_data.ysize,
  199.       @map_data.zsize)
  200.     # Passes Through All Priorities
  201.     for p in 0..5
  202.       # Passes Through Layers
  203.       for z in 0...@map_data.zsize
  204.         # Passes Through X Coordinates
  205.         for x in 0...@map_data.xsize
  206.           # Passes Through Z Coordinates
  207.           for y in 0...@map_data.ysize
  208.             # Collects Tile ID
  209.             id = @map_data[x, y, z]
  210.             # Skip if 0 tile
  211.             next if id == 0
  212.             # Skip If Priority Doesn't Match
  213.             next unless p == @priorities[id]
  214.             # Skip If Non-Animated Tile
  215. #            next unless autotile = @autotiles[id / 48 - 1].width / 96 > 1
  216.             # Cap Priority to Layer 3
  217.             p = 2 if p > 2
  218.             # If Autotile
  219.             if id < 384
  220.               # Draw Auto-Tile
  221.               draw_autotile(x, y, p, id)
  222.               # Save Autotile Location
  223.               autotile_locations[x, y, z] = 1
  224.             # If Normal Tile
  225.             else
  226.               # If Autotile Drawn
  227.               if autotile_locations[x, y, z] == 1
  228.                 # Redraw Normal Tile
  229.                 draw_tile(x, y, p, id)
  230.               end
  231.             end
  232.           end
  233.         end
  234.       end
  235.     end
  236.   end
  237.   #--------------------------------------------------------------------------
  238.   # * Draw Tile
  239.   #--------------------------------------------------------------------------
  240.   def draw_tile(x, y, z, id)
  241.     # Figures Tile Rect
  242.     rect = Rect.new((id - 384) % 8 * 32, (id - 384) / 8 * 32, 32, 32)
  243.     # Calculates Tile Coordinates
  244.     x *= @tile_width
  245.     y *= @tile_height
  246.     # If Normal Tile
  247.     if @tile_width == 32 && @tile_height == 32
  248.       @layers[z].bitmap.blt(x, y, @tileset, rect)
  249.     # If Altered Dimensions
  250.     else
  251.       dest_rect = Rect.new(x, y, @tile_width, @tile_height)
  252.       @layers[z].bitmap.stretch_blt(dest_rect, @tileset, rect)
  253.     end
  254.   end
  255.   #--------------------------------------------------------------------------
  256.   # * Draw Auto-Tile
  257.   #--------------------------------------------------------------------------
  258.   def draw_autotile(x, y, z, tile_id)
  259.     # Gets Auto-Tile
  260.     autotile = @autotiles[tile_id / 48 - 1]
  261.     # Reconfigure Tile ID
  262.     tile_id %= 48
  263.     # Creates Bitmap
  264.     bitmap = Bitmap.new(32, 32)
  265.     # Collects Auto-Tile Tile Layout
  266.     tiles = Autotiles[tile_id / 8][tile_id % 8]
  267.     # Animated Tiles
  268.     frames = autotile.width / 96
  269.     # Configures Animation Offset
  270.     anim = (Graphics.frame_count / Animated_Autotiles_Frames) % frames * 96
  271.     # Draws Auto-Tile Rects
  272.     for i in 0...4
  273.       tile_position = tiles[i] - 1
  274.       src_rect = Rect.new(tile_position % 6 * 16 + anim, tile_position / 6 * 16, 16, 16)
  275.       bitmap.blt(i % 2 * 16, i / 2 * 16, autotile, src_rect)
  276.     end
  277.     # Calculates Tile Coordinates
  278.     x *= @tile_width
  279.     y *= @tile_height
  280.     # If Normal Tile
  281.     if @tile_width == 32 && @tile_height == 32
  282.       @layers[z].bitmap.blt(x, y, bitmap, Rect.new(0, 0, 32, 32))
  283.     # If Altered Dimensions
  284.     else
  285.       dest_rect = Rect.new(x, y, @tile_width, @tile_height)
  286.       @layers[z].bitmap.stretch_blt(dest_rect, bitmap, Rect.new(0, 0, 32, 32))
  287.     end
  288.   end
  289.   #--------------------------------------------------------------------------
  290.   # * Collect Bitmap
  291.   #--------------------------------------------------------------------------
  292.   def bitmap
  293.     # Creates New Blank Bitmap
  294.     bitmap = Bitmap.new(@layers[0].bitmap.width, @layers[0].bitmap.height)
  295.     # Passes Through All Layers
  296.     for layer in @layers
  297.       bitmap.blt(0, 0, layer.bitmap,
  298.         Rect.new(0, 0, bitmap.width, bitmap.height))
  299.     end
  300.     # Return Bitmap
  301.     return bitmap
  302.   end
  303. end
复制代码

这个是xp那个可以破除分辨率低下的titlmap脚本,楼主参考下,如果可以优化它的速度的话,那么1024*768就会成为事实了。。。。。。
作者: zh99998    时间: 2008-10-2 17:18
640*480是Graphics的限制
Graphics.resize_screen(width, height) (RGSS2)
修改画面的尺寸。

宽度和高度的指定值最大到 640×480 。

作者: kissye    时间: 2008-10-2 17:39
提示: 作者被禁止或删除 内容自动屏蔽
作者: IamI    时间: 2008-10-2 18:12
我是懒人,真的= =
先弱弱的说一句,flash_data是accessor,而且默认值是nil
属于“内置功能”吧……恩,这是以前写的一个脚本,一看效果不是很好就扔了
  1. class Spriteset_Map
  2. def create_tilemap
  3.     @tilemap = Tilemap.new(@viewport1)
  4.     @tilemap.bitmaps[0] = Cache.system("TileA1")
  5.     @tilemap.bitmaps[1] = Cache.system("TileA2")
  6.     @tilemap.bitmaps[2] = Cache.system("TileA3")
  7.     @tilemap.bitmaps[3] = Cache.system("TileA4")
  8.     @tilemap.bitmaps[4] = Cache.system("TileA5")
  9.     @tilemap.bitmaps[5] = Cache.system("TileB")
  10.     @tilemap.bitmaps[6] = Cache.system("TileC")
  11.     @tilemap.bitmaps[7] = Cache.system("TileD")
  12.     @tilemap.bitmaps[8] = Cache.system("TileE")
  13.     @tilemap.map_data = $game_map.data
  14.     @tilemap.passages = $game_map.passages
  15.     @tilemap.flash_data = Table.new(@tilemap.map_data.xsize,@tilemap.map_data.ysize)
  16.   end
  17.   def set_color(x,y,c)
  18.     @tilemap.flash_data[x,y] = c
  19.   end
  20. end
  21. class Scene_Map
  22.   def map
  23.     return @spriteset
  24.   end
  25. end
  26. class Game_Interpreter
  27.   def set_c(x,y,c)
  28.     if $scene.is_a?(Scene_Map)
  29.       $scene.map.set_color(x,y,c)
  30.     end
  31.   end
  32. end
复制代码
在正常的Tilemap下随便找个NPC执行脚本
set_c(2,2,0xf26)

在左上角能看到效果= =
就是这样= =
作者: lhbadsl    时间: 2008-10-2 19:42
没用过xp,而且现在用vx比较熟,暂时没准备转xp...
我这个脚本可以改分辨率的啊,前2行
FBLX = x方向分辨率
FBLY = y方向分辨率
不过其他地方也全部都要注意该掉,尤其是Game_Map和Game_Player里

呵呵,vx的脚本我写出来也没有用。。。楼主和我差不多都是从vx开始的。。。。。不过后面我真的发觉其实原来vx做个游戏出来真的比较费时,因为vx基本就非常少参考脚本,要做好游戏必须重新手写所有的脚本,不像xp那样贴过去再改可以少很多功夫,所以很早就改行了,而我最强的部分在于战斗系统。然后vx虽然公开了Game_Map类,令到titlmap的编写容易多了,可是其他地方一样难写。。而xp是站在很多巨人后面的,可以偷懒。如果楼主可以把我上面的titlmap优化一下xp就牛逼了。。。如果没有时间的话,请给分胃君的“地图讲解”给我参考下,我试试按照你的脚本思路,强行把这个脚本写出来把,因为我现在就有个游戏要提高分辨率的,而柳大那个四个窗口的脚本又有很多问题,所以。。。厚着脸皮求救了,就差titlmap了,其他都容易啊。。。。。。{/gg}
作者: kissye    时间: 2008-10-2 19:58
提示: 作者被禁止或删除 内容自动屏蔽




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1