赞 | 0 |
VIP | 9 |
好人卡 | 0 |
积分 | 1 |
经验 | 3133 |
最后登录 | 2020-7-1 |
在线时间 | 56 小时 |
Lv1.梦旅人
- 梦石
- 0
- 星屑
- 85
- 在线时间
- 56 小时
- 注册时间
- 2011-4-6
- 帖子
- 18
|
加入我们,或者,欢迎回来。
您需要 登录 才可以下载或查看,没有帐号?注册会员
x
本帖最后由 iusan 于 2013-7-18 23:36 编辑
没有办法读取存档,一读取就提示第97行里defined method ‘bitmap' for nil:NilClass
脚本是从这边下载的,存档是在脚本导入后重新开始新游戏才存的
求高人指教!- #==============================================================================
- # ■ Game_Map
- #------------------------------------------------------------------------------
- # 处理地图的类。包含卷动以及可以通行的判断功能。
- # 本类的实例请参考 $game_map 。
- #==============================================================================
- class Game_Map
- MAZE_SWITCH = 1
- MAZE_SPRITE_OPACITY = 180
- #--------------------------------------------------------------------------
- # ● 定义实例变量
- #--------------------------------------------------------------------------
- attr_reader :screen # 地图画面状态
- attr_reader :interpreter # 地图事件用解释器
- attr_reader :display_x # 显示 X 坐标 * 256
- attr_reader :display_y # 显示 Y 坐标 * 256
- attr_reader :parallax_name # 远景 文件名
- attr_reader :passages # 通行表
- attr_reader :events # 事件
- attr_reader :vehicles # 交通工具
- attr_accessor :need_refresh # 刷新要求标志
- attr_accessor :map # 刷新要求标志
- #--------------------------------------------------------------------------
- # ● 初始化对象
- #--------------------------------------------------------------------------
- def initialize
- @screen = Game_Screen.new
- @interpreter = Game_Interpreter.new(0, true)
- @map_id = 0
- @display_x = 0
- @display_y = 0
- create_vehicles
- end
- #--------------------------------------------------------------------------
- # ● 设置
- # map_id : 地图 ID
- #--------------------------------------------------------------------------
- def setup(map_id)
- @map_id = map_id
- @map = load_data(sprintf("Data/Map%03d.rvdata", @map_id))
- setup_maze
- # 临时写在这里
- @display_x = 0
- @display_y = 0
- @passages = $data_system.passages
- referesh_vehicles
- setup_events
- setup_scroll
- setup_parallax
- @need_refresh = false
- end
-
- def setup_maze
- $game_maze6R_search[@map_id] = Table.new(width, height) if $game_maze6R_search[@map_id] == nil
- $maze_sprite = nil if $map_sprite != nil
- $maze_sprite = Sprite.new
- $maze_sprite.bitmap = Bitmap.new(Graphics.width, Graphics.height)
- $maze_sprite.bitmap.fill_rect(0, 0, Graphics.width, Graphics.height, Color.new(0, 0, 0))
- $maze_sprite.z = 2000
- $maze_sprite.zoom_x = 0.4
- $maze_sprite.zoom_y = 0.4
- $maze_sprite.opacity = MAZE_SPRITE_OPACITY
- $maze_sprite.visible = $game_switches[MAZE_SWITCH]
- $maze_sprite.update
- @maze_rect_width = Graphics.width / width
- @maze_rect_height = Graphics.height / height
- $maze_player_sprite = nil if $maze_player_sprite != nil
- $maze_player_sprite = Sprite.new
- $maze_player_sprite.bitmap = Cache.system("Maze_Char_main")
- $maze_player_sprite.z = 2002
- $maze_player_sprite.ox = $maze_player_sprite.bitmap.width / 2
- $maze_player_sprite.oy = $maze_player_sprite.bitmap.height
- $maze_player_sprite.visible = $maze_sprite.visible
- @refresh_maze_count == 0
- end
- #-----------------------------------------------------
- # ☆ 刷新迷宫game数据,主要用于添加当前一屏幕内容
- #-----------------------------------------------------
- def refresh_maze_game
- for x in 0..$game_map.width
- for y in 0..$game_map.height
- next if not in_range?(x, y)
- $game_maze6R_search[@map_id][x, y] = 1 #unless $game_maze6R_search[@map_id][x, y]
- end
- end
- end
-
- #-----------------------------------------------------
- # ☆ 刷新迷宫图片
- #-----------------------------------------------------
- def refresh_maze_sprite
- for x in 0..$game_map.width
- for y in 0..$game_map.height
- if $game_maze6R_search[@map_id][x, y] == 1
- bmpt = get_xy_bitmap(x, y)
- $maze_sprite.bitmap.stretch_blt(Rect.new(@maze_rect_width * x, @maze_rect_height * y, @maze_rect_width, @maze_rect_height), bmpt, bmpt.rect)
- end
- end
- $maze_sprite.visible = $game_switches[MAZE_SWITCH]
- $maze_player_sprite.x = ($game_player.x * @maze_rect_width) * $maze_sprite.zoom_x + $maze_sprite.x
- $maze_player_sprite.y = ($game_player.y * @maze_rect_height) * $maze_sprite.zoom_y + $maze_sprite.y
- $maze_player_sprite.zoom_x = $maze_sprite.zoom_x
- $maze_player_sprite.zoom_y = $maze_sprite.zoom_y
- $maze_player_sprite.visible = $maze_sprite.visible
- $maze_sprite.update
- $maze_player_sprite.update
- end
-
- #-----------------------------------------------------
- # ☆ 刷新迷宫地图的可视情况
- #-----------------------------------------------------
- def change_maze_visible(maze_visible = nil)
- maze_visible = $game_switches[MAZE_SWITCH] if maze_visible == nil
- $maze_sprite.visible = maze_visible
- $maze_player_sprite.visible = maze_visible
- end
-
- #-----------------------------------------------------
- # ☆ 刷新迷宫game数据和图片,小幅度刷新
- #-----------------------------------------------------
- def refresh_maze_small
- screne_x = $game_map.display_x
- screne_x -= 256
- screne_y = $game_map.display_y
- screne_y -= 256
- screne_width = $game_map.display_x
- screne_width += 8 * Graphics.width + 256
- screne_height = $game_map.display_y
- screne_height += 8 * Graphics.height + 256
- xb = screne_x / 256
- yb = screne_y / 256
- xe = screne_width / 256
- ye = screne_height / 256
- if $maze_sprite == nil or $maze_sprite.disposed?
- refresh_maze_sprite
- end
- for x in xb..xe # 0..$game_map.width
- for y in yb..ye # 0..$game_map.height
- next if not in_range?(x, y)
- next if $game_maze6R_search[@map_id][x, y] == 1
- $game_maze6R_search[@map_id][x, y] = 1
- bmpt = get_xy_bitmap(x, y)
- $maze_sprite.bitmap.stretch_blt(Rect.new(@maze_rect_width * x, @maze_rect_height * y, @maze_rect_width, @maze_rect_height), bmpt, bmpt.rect)
- end
- end
- $maze_sprite.visible = $game_switches[MAZE_SWITCH]
- $maze_player_sprite.x = ($game_player.x * @maze_rect_width) * $maze_sprite.zoom_x + $maze_sprite.x
- $maze_player_sprite.y = ($game_player.y * @maze_rect_height) * $maze_sprite.zoom_y + $maze_sprite.y
- $maze_player_sprite.visible = $maze_sprite.visible
- $maze_sprite.update
- $maze_player_sprite.update
- end
-
- #-----------------------------------------------------
- # ☆ 看某XY是否在屏幕显示范围内
- #-----------------------------------------------------
- def in_range?(inx, iny)
- screne_x = $game_map.display_x
- screne_x -= 256
- screne_y = $game_map.display_y
- screne_y -= 256
- screne_width = $game_map.display_x
- screne_width += 4608 # 8 * Graphics.width + 256
- screne_height = $game_map.display_y
- screne_height += 3584 # 8 * Graphics.height + 256
- return false if inx * 256 <= screne_x
- return false if inx * 256 >= screne_width
- return false if iny * 256 <= screne_y
- return false if iny * 256 >= screne_height
- return true
- end
-
- #-----------------------------------------------------
- # ☆ 获得X,Y理论点的图像
- #-----------------------------------------------------
- def get_xy_bitmap(x, y)
- bitmap = Bitmap.new(32, 32)
- for i in [0] #, 1, 2]
- id = @map.data[x, y, i]
- tb = bmprect_id(id)
- bitmap.blt(0, 0, tb[0], Rect.new(tb[1] * 32, tb[2] * 32, 32, 32)) if tb[0] != nil
- end
- return bitmap
- end
-
- #-----------------------------------------------------
- # ☆ 根据ID获得Bitmap的rect
- #-----------------------------------------------------
- def bmprect_id(id)
- case id
- when 0..255
- bitmap_rectxyb = get_where(id)
- return [$map6r_bitmaps[5], bitmap_rectxyb[0], bitmap_rectxyb[1]]
- when 256..511
- bitmap_rectxyb = get_where(id - 256)
- return [$map6r_bitmaps[6], bitmap_rectxyb[0], bitmap_rectxyb[1]]
- when 512..767
- bitmap_rectxyb = get_where(id - 512)
- return [$map6r_bitmaps[7], bitmap_rectxyb[0], bitmap_rectxyb[1]]
- when 768..1023
- bitmap_rectxyb = get_where(id - 768)
- return [$map6r_bitmaps[8], bitmap_rectxyb[0], bitmap_rectxyb[1]]
- when 1536..1791
- bitmap_rectxyb = get_where(id - 1536)
- return [$map6r_bitmaps[4], bitmap_rectxyb[0], bitmap_rectxyb[1]]
- when 2048..8191 # 2048..2048 + 48 * 128 - 1
- bitmap_rectxyb = get_where(id)
- return [bitmap_rectxyb[0], bitmap_rectxyb[1], bitmap_rectxyb[2]]
- end
- return [nil, 0, 0]
- end
-
- #-----------------------------------------------------
- # ☆ 根据ID返回Bitmap的rect
- #-----------------------------------------------------
- def get_where(id)
- case id
- when 0..255
- x = id % 8
- y = id / 8
- return [x, y]
- when 2048..2767 # 2048..2048 + 48 * 15 - 1
- tempid = (id - 2048) % 48 # 这个表示是48系列图中的第几个系列种
- series_id = (id - 2048) / 48 # 这个表示是在图上素材分类的第几个
- case series_id
- when 0
- return get_ofxoftdiyilei(tempid, 0, 0)
- when 1
- return get_ofxoftdiyilei(tempid, 0, 3)
- when 2
- return get_ofxoftdiyilei(tempid, 6, 0)
- when 3
- return get_ofxoftdiyilei(tempid, 6, 3)
- when 4
- return get_ofxoftdiyilei(tempid, 8, 0)
- when 5
- return get_ofxoftdiyilei(tempid, 8, 3)
- when 6
- return get_ofxoftdiyilei(tempid, 14, 0)
- when 7
- return get_ofxoftdiyilei(tempid, 14, 3)
- when 8
- return get_ofxoftdiyilei(tempid, 0, 6)
- when 9
- return get_ofxoftdiyilei(tempid, 0, 9)
- when 10
- return get_ofxoftdiyilei(tempid, 6, 6)
- when 11
- return get_ofxoftdiyilei(tempid, 6, 9)
- when 12
- return get_ofxoftdiyilei(tempid, 8, 6)
- when 13
- return get_ofxoftdiyilei(tempid, 8, 9)
- when 14
- return get_ofxoftdiyilei(tempid, 14, 6)
- when 15
- return get_ofxoftdiyilei(tempid, 14, 9)
- end
-
- #-----------------------------------------------------------------
- # 这个是A2素材的定义方式
- #-----------------------------------------------------------------
- when 2768..4351 #2048 + 48 * 15..2048 + 48 * 48 - 1
- tempid = (id - 2048 - 48 * 16) % 48 # 这个表示是48系列图中的第几个系列种
- series_id = (id - 2048 - 48 * 16) / 48 # 这个表示是在图上素材分类的第几个
- ofx = (series_id % 8) * 2
- ofy = (series_id / 8) * 3
- return get_ofxoftdiyilei(tempid, ofx, ofy, 1)
-
- #-----------------------------------------------------------------
- # 这个是A3素材的房顶方式,前半部分
- #-----------------------------------------------------------------
- when 4352..4735 #2048 + 48 * 48..2048 + 48 * 56 - 1
- tempid = (id - 2048 - 48 * 48) % 48 # 这个表示是48系列图中的第几个系列种
- series_id = (id - 2048 - 48 * 48) / 48 # 这个表示是在图上素材分类的第几个
- ofx = (series_id % 8) * 2
- ofy = 0
- return get_ofxoftdierlei(tempid, ofx, ofy, 2)
- #-----------------------------------------------------------------
- # 这个是A3素材的房顶方式,后半部分
- #-----------------------------------------------------------------
- when 5120..5503 #2048 + 48 * 64..2048 + 48 * 72 - 1
- tempid = (id - 2048 - 48 * 64) % 48 # 这个表示是48系列图中的第几个系列种
- series_id = (id - 2048 - 48 * 64) / 48 # 这个表示是在图上素材分类的第几个
- ofx = (series_id % 8) * 2
- ofy = 4
- return get_ofxoftdierlei(tempid, ofx, ofy, 2)
- #-----------------------------------------------------------------
- # 这个是A3素材的房屋体方式,前半部分
- #-----------------------------------------------------------------
- when 4736..5119 #2048 + 48 * 56..2048 + 48 * 64 - 1
- tempid = (id - 2048 - 48 * 48) % 48 # 这个表示是48系列图中的第几个系列种
- series_id = (id - 2048 - 48 * 48) / 48 # 这个表示是在图上素材分类的第几个
- ofx = (series_id % 8) * 2
- ofy = 0
- return get_ofxoftdierlei(tempid, ofx, ofy, 2, 1)
- #-----------------------------------------------------------------
- # 这个是A3素材的房屋体方式,后半部分
- #-----------------------------------------------------------------
- when 5504..5887#2048 + 48 * 72..2048 + 48 * 80 - 1
- tempid = (id - 2048 - 48 * 64) % 48 # 这个表示是48系列图中的第几个系列种
- series_id = (id - 2048 - 48 * 64) / 48 # 这个表示是在图上素材分类的第几个
- ofx = (series_id % 8) * 2
- ofy = 4
- return get_ofxoftdierlei(tempid, ofx, ofy, 2, 1)
-
-
-
-
- #-----------------------------------------------------------------
- # 这个是A4素材的房顶方式 1
- #-----------------------------------------------------------------
- when 5888..6271 #2048 + 48 * 80..2048 + 48 * 88 - 1
- tempid = (id - 2048 - 48 * 80) % 48
- series_id = (id - 2048 - 48 * 80) / 48
- ofx = (series_id % 8) * 2
- ofy = 0
- return get_ofxoftdiyilei(tempid, ofx, ofy, 3)
- #-----------------------------------------------------------------
- # 这个是A4素材的房顶方式 2
- #-----------------------------------------------------------------
- when 6656..7039 #2048 + 48 * 96..2048 + 48 * 104 - 1
- tempid = (id - 2048 - 48 * 80) % 48
- series_id = (id - 2048 - 48 * 80) / 48
- ofx = (series_id % 8) * 2
- ofy = 5
- return get_ofxoftdiyilei(tempid, ofx, ofy, 3)
- #-----------------------------------------------------------------
- # 这个是A4素材的房顶方式 3
- #-----------------------------------------------------------------
- when 7424..7807 #2048 + 48 * 112..2048 + 48 * 120 - 1
- tempid = (id - 2048 - 48 * 80) % 48
- series_id = (id - 2048 - 48 * 80) / 48
- ofx = (series_id % 8) * 2
- ofy = 10
- return get_ofxoftdiyilei(tempid, ofx, ofy, 3)
-
-
-
- #-----------------------------------------------------------------
- # 这个是A4素材的墙壁方式 1
- #-----------------------------------------------------------------
- when 6272..6655 #2048 + 48 * 88..2048 + 48 * 96 - 1
- tempid = (id - 2048 - 48 * 80) % 48
- series_id = (id - 2048 - 48 * 80) / 48
- ofx = (series_id % 8) * 2
- ofy = 0
- return get_ofxoftdierlei(tempid, ofx, ofy, 3, 2)
- #-----------------------------------------------------------------
- # 这个是A4素材的墙壁方式 2
- #-----------------------------------------------------------------
- when 7040..7423 #2048 + 48 * 104..2048 + 48 * 112 - 1
- tempid = (id - 2048 - 48 * 80) % 48
- series_id = (id - 2048 - 48 * 80) / 48
- ofx = (series_id % 8) * 2
- ofy = 5
- return get_ofxoftdierlei(tempid, ofx, ofy, 3, 2)
- #-----------------------------------------------------------------
- # 这个是A4素材的墙壁方式 3
- #-----------------------------------------------------------------
- when 7808..8191 #2048 + 48 * 120..2048 + 48 * 128 - 1
- tempid = (id - 2048 - 48 * 80) % 48
- series_id = (id - 2048 - 48 * 80) / 48
- ofx = (series_id % 8) * 2
- ofy = 10
- return get_ofxoftdierlei(tempid, ofx, ofy, 3, 2)
- end
- end
-
- #--------------------------------------------------------------------------
- # ☆ 中间函数,用来返回某张图上的一个rect,特别针对A1
- #--------------------------------------------------------------------------
- def get_ofxoftdiyilei(tempid = 0, ofx = 0, ofy = 0, bmps = 0)
- bmp = Bitmap.new(32, 32)
- ta = diyitao(tempid)
- ofx *= 32
- ofy *= 32
- bmp.blt(0,0,$map6r_bitmaps[bmps], Rect.new(ta[0][1]*16 + ofx, ta[0][0]*16 + ofy, 16, 16))
- bmp.blt(16,0,$map6r_bitmaps[bmps], Rect.new(ta[1][1]*16 + ofx, ta[1][0]*16 + ofy, 16, 16))
- bmp.blt(0,16,$map6r_bitmaps[bmps], Rect.new(ta[2][1]*16 + ofx, ta[2][0]*16 + ofy, 16, 16))
- bmp.blt(16,16,$map6r_bitmaps[bmps], Rect.new(ta[3][1]*16 + ofx, ta[3][0]*16 + ofy, 16, 16))
- return [bmp, 0, 0]
- end
-
- #--------------------------------------------------------------------------
- # ☆ 中间函数,用来返回某张图上的一个rect,针对A3
- #--------------------------------------------------------------------------
- def get_ofxoftdierlei(tempid = 0, ofx = 0, ofy = 0, bmps = 0, hx = 0)
- bmp = Bitmap.new(32, 32)
- ta = diertao(tempid) if hx == 0
- ta = disantao(tempid) if hx == 1
- ta = disitao(tempid) if hx == 2
- ofx *= 32
- ofy *= 32
- bmp.blt(0,0,$map6r_bitmaps[bmps], Rect.new(ta[0][1]*16 + ofx, ta[0][0]*16 + ofy, 16, 16))
- bmp.blt(16,0,$map6r_bitmaps[bmps], Rect.new(ta[1][1]*16 + ofx, ta[1][0]*16 + ofy, 16, 16))
- bmp.blt(0,16,$map6r_bitmaps[bmps], Rect.new(ta[2][1]*16 + ofx, ta[2][0]*16 + ofy, 16, 16))
- bmp.blt(16,16,$map6r_bitmaps[bmps], Rect.new(ta[3][1]*16 + ofx, ta[3][0]*16 + ofy, 16, 16))
- return [bmp, 0, 0]
- end
-
- #--------------------------------------------------------------------------
- # ☆ 第二套结构代码,定义了素材A3的房顶部分
- #--------------------------------------------------------------------------
- def diertao(whattype = 0)
- array = [
- [[2,2],[2,1],[1,2],[1,1]],
- [[2,0],[2,1],[1,0],[1,1]],
- [[0,2],[0,1],[1,2],[1,1]],
- [[0,0],[0,1],[1,0],[1,1]],
- [[2,2],[2,3],[1,2],[1,3]],
- [[2,0],[2,3],[1,0],[1,3]],
- [[0,2],[0,3],[1,2],[1,3]],
- [[0,0],[0,3],[1,0],[1,3]],
- [[2,2],[2,1],[3,2],[3,1]],
- [[2,0],[2,1],[3,0],[3,1]],
- [[0,2],[0,1],[3,2],[3,1]],
- [[0,0],[0,1],[3,0],[3,1]],
- [[2,2],[2,3],[3,2],[3,3]],
- [[2,0],[2,3],[3,0],[3,3]],
- [[0,2],[0,3],[3,2],[3,3]],
- [[0,0],[0,3],[3,0],[3,3]],
- [[0,0],[0,0],[0,0],[0,0]],
- ]
- return array[whattype] if array[whattype] != nil
- return [[0,0],[0,0],[0,0],[0,0]]
- end
-
- #--------------------------------------------------------------------------
- # ☆ 第二套结构代码,定义了素材A4的墙壁部分
- #--------------------------------------------------------------------------
- def disitao(whattype = 0)
- array = [
- [[8,2],[8,1],[7,2],[7,1]],
- [[8,0],[8,1],[7,0],[7,1]],
- [[6,2],[6,1],[7,2],[7,1]],
- [[6,0],[6,1],[7,2],[7,1]],
- [[8,2],[8,3],[7,2],[7,3]],
- [[8,0],[8,3],[7,0],[7,3]],
- [[6,2],[6,3],[7,2],[7,3]],
- [[6,2],[6,3],[7,0],[7,3]],
- [[8,2],[8,1],[9,2],[9,1]],
- [[8,0],[8,1],[9,0],[9,1]],
- [[6,2],[6,1],[9,2],[9,1]],
- [[6,0],[6,1],[9,0],[9,1]],
- [[8,2],[8,3],[9,2],[9,3]],
- [[8,0],[8,3],[9,0],[9,3]],
- [[6,2],[6,3],[9,2],[9,3]],
- [[6,0],[6,3],[9,0],[9,3]],
- [[6,0],[6,0],[6,0],[6,0]], # 填满48个
- ]
- return array[whattype] if array[whattype] != nil
- return [[6,0],[6,0],[6,0],[6,0]]
- end
-
- #--------------------------------------------------------------------------
- # ☆ 第三套结构代码,定义了素材A3的房屋部分
- #--------------------------------------------------------------------------
- def disantao(whattype = 0)
- array = [
- [[6,2],[6,1],[5,2],[5,1]],
- [[6,0],[6,1],[5,0],[5,1]],
- [[4,2],[4,1],[5,2],[5,1]],
- [[4,0],[4,1],[5,2],[5,1]],
- [[6,2],[6,3],[5,2],[5,3]],
- [[6,0],[6,3],[5,0],[5,3]],
- [[4,2],[4,3],[5,2],[5,3]],
- [[4,2],[4,3],[5,0],[5,3]],
- [[6,2],[6,1],[7,2],[7,1]],
- [[6,0],[6,1],[7,0],[7,1]],
- [[4,2],[4,1],[7,2],[7,1]],
- [[4,0],[4,1],[7,0],[7,1]],
- [[6,2],[6,3],[7,2],[7,3]],
- [[6,0],[6,3],[7,0],[7,3]],
- [[4,2],[4,3],[7,2],[7,3]],
- [[4,0],[4,3],[7,0],[7,3]],
- [[4,0],[4,0],[4,0],[4,0]], # 填满48个
- ]
- return array[whattype] if array[whattype] != nil
- return [[4,0],[4,0],[4,0],[4,0]]
- end# 房屋部分
-
-
- #--------------------------------------------------------------------
- # ★ 第一套结构数组,这个用于定义A1里面的自动元件构成。写得晕死了
- #--------------------------------------------------------------------
- def diyitao(whattype = 0)
- array = [
- [[4,2],[4,1],[3,2],[3,1]],
- [[0,2],[4,1],[3,2],[3,1]],
- [[4,2],[0,3],[3,2],[3,1]],
- [[0,2],[0,3],[3,2],[3,1]],
- [[4,2],[4,1],[3,2],[1,3]],
- [[0,2],[4,1],[3,2],[1,3]],
- [[4,2],[0,3],[3,2],[1,3]],
- [[0,2],[0,3],[3,2],[1,3]],
- [[4,2],[4,1],[1,2],[3,1]],
- [[0,2],[4,1],[1,2],[3,1]],
- [[4,2],[0,3],[1,2],[3,1]],
- [[0,2],[0,3],[1,2],[3,1]],
- [[4,2],[4,1],[1,2],[1,3]],
- [[0,2],[4,1],[1,2],[1,3]],
- [[4,2],[0,3],[1,2],[1,3]],
- [[0,2],[0,3],[1,2],[1,3]],
- [[4,0],[4,1],[3,0],[3,1]],
- [[4,0],[0,3],[3,0],[3,1]],
- [[4,0],[4,1],[3,0],[1,3]],
- [[4,0],[0,3],[3,0],[1,3]],
- [[2,2],[2,1],[3,2],[3,1]],
- [[2,2],[2,1],[3,2],[1,3]],
- [[2,2],[2,1],[1,2],[3,1]],
- [[2,2],[2,1],[1,2],[1,3]],
- [[4,2],[4,3],[3,2],[3,3]],
- [[4,2],[4,3],[1,2],[3,3]],
- [[0,2],[4,3],[3,2],[3,3]],
- [[0,2],[4,3],[1,2],[3,3]],
- [[4,2],[4,1],[5,2],[5,1]],
- [[0,2],[4,1],[5,2],[5,1]],
- [[4,2],[0,3],[5,2],[5,1]],
- [[0,2],[0,3],[5,2],[5,1]],
- [[4,0],[4,3],[3,0],[3,3]],
- [[2,2],[2,1],[5,2],[5,1]],
- [[2,0],[2,1],[3,0],[3,1]], #34
- [[2,0],[2,1],[3,0],[1,3]],
- [[2,2],[2,3],[3,2],[3,3]],
- [[2,2],[2,3],[1,2],[3,3]],
- [[4,2],[4,3],[5,2],[5,3]],
- [[0,2],[4,3],[5,2],[5,3]],
- [[4,0],[4,1],[5,0],[5,1]],
- [[4,0],[0,3],[5,0],[5,1]],
- [[2,0],[2,3],[3,0],[3,3]],
- [[2,0],[2,1],[5,0],[5,1]],
- [[4,0],[4,3],[5,0],[5,3]],
- [[2,2],[2,3],[5,2],[5,3]],
- [[2,0],[2,3],[5,0],[5,3]],
- [[0,0],[0,1],[1,0],[1,1]]
- ]
- return array[whattype]
- end
-
-
-
-
- #--------------------------------------------------------------------------
- # ● 生成交通工具
- #--------------------------------------------------------------------------
- def create_vehicles
- @vehicles = []
- @vehicles[0] = Game_Vehicle.new(0) # 小型船
- @vehicles[1] = Game_Vehicle.new(1) # 大型船
- @vehicles[2] = Game_Vehicle.new(2) # 飛行船
- end
- #--------------------------------------------------------------------------
- # ● 刷新交通工具
- #--------------------------------------------------------------------------
- def referesh_vehicles
- for vehicle in @vehicles
- vehicle.refresh
- end
- end
- #--------------------------------------------------------------------------
- # ● 获取小型船
- #--------------------------------------------------------------------------
- def boat
- return @vehicles[0]
- end
- #--------------------------------------------------------------------------
- # ● 获取大型船
- #--------------------------------------------------------------------------
- def ship
- return @vehicles[1]
- end
- #--------------------------------------------------------------------------
- # ● 获取飞行船
- #--------------------------------------------------------------------------
- def airship
- return @vehicles[2]
- end
- #--------------------------------------------------------------------------
- # ● 设置事件
- #--------------------------------------------------------------------------
- def setup_events
- @events = {} # 地图事件
- for i in @map.events.keys
- @events[i] = Game_Event.new(@map_id, @map.events[i])
- end
- @common_events = {} # 公共事件
- for i in 1...$data_common_events.size
- @common_events[i] = Game_CommonEvent.new(i)
- end
- end
- #--------------------------------------------------------------------------
- # ● 设置滚动
- #--------------------------------------------------------------------------
- def setup_scroll
- @scroll_direction = 2
- @scroll_rest = 0
- @scroll_speed = 4
- @margin_x = (width - 17) * 256 / 2 # 画面不显示的地方宽 / 2
- @margin_y = (height - 13) * 256 / 2 # 画面不显示的地方高 / 2
- end
- #--------------------------------------------------------------------------
- # ● 设置远景
- #--------------------------------------------------------------------------
- def setup_parallax
- @parallax_name = @map.parallax_name
- @parallax_loop_x = @map.parallax_loop_x
- @parallax_loop_y = @map.parallax_loop_y
- @parallax_sx = @map.parallax_sx
- @parallax_sy = @map.parallax_sy
- @parallax_x = 0
- @parallax_y = 0
- end
- #--------------------------------------------------------------------------
- # ● 设置显示位置
- # x : 新显示 X 坐标 (*256)
- # y : 新显示 Y 坐标 (*256)
- #--------------------------------------------------------------------------
- def set_display_pos(x, y)
- @display_x = (x + @map.width * 256) % (@map.width * 256)
- @display_y = (y + @map.height * 256) % (@map.height * 256)
- @parallax_x = x
- @parallax_y = y
- refresh_maze_game
- refresh_maze_sprite
- end
- #--------------------------------------------------------------------------
- # ● 计算远景显示 X 坐标
- # bitmap : 远景位图
- #--------------------------------------------------------------------------
- def calc_parallax_x(bitmap)
- if bitmap == nil
- return 0
- elsif @parallax_loop_x
- return @parallax_x / 16
- elsif loop_horizontal?
- return 0
- else
- w1 = bitmap.width - 544
- w2 = @map.width * 32 - 544
- if w1 <= 0 or w2 <= 0
- return 0
- else
- return @parallax_x * w1 / w2 / 8
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 计算远景显示 Y 坐标
- # bitmap : 远景位图
- #--------------------------------------------------------------------------
- def calc_parallax_y(bitmap)
- if bitmap == nil
- return 0
- elsif @parallax_loop_y
- return @parallax_y / 16
- elsif loop_vertical?
- return 0
- else
- h1 = bitmap.height - 416
- h2 = @map.height * 32 - 416
- if h1 <= 0 or h2 <= 0
- return 0
- else
- return @parallax_y * h1 / h2 / 8
- end
- end
- end
- #--------------------------------------------------------------------------
- # ● 获取地图 ID
- #--------------------------------------------------------------------------
- def map_id
- return @map_id
- end
- #--------------------------------------------------------------------------
- # ● 获取宽度
- #--------------------------------------------------------------------------
- def width
- return @map.width
- end
- #--------------------------------------------------------------------------
- # ● 获取高度
- #--------------------------------------------------------------------------
- def height
- return @map.height
- end
- #--------------------------------------------------------------------------
- # ● 横方向循环吗?
- #--------------------------------------------------------------------------
- def loop_horizontal?
- return (@map.scroll_type == 2 or @map.scroll_type == 3)
- end
- #--------------------------------------------------------------------------
- # ● 纵方向循环吗?
- #--------------------------------------------------------------------------
- def loop_vertical?
- return (@map.scroll_type == 1 or @map.scroll_type == 3)
- end
- #--------------------------------------------------------------------------
- # ● 获取跑动与否?
- #--------------------------------------------------------------------------
- def disable_dash?
- return @map.disable_dashing
- end
- #--------------------------------------------------------------------------
- # ● 获取遇敌列表
- #--------------------------------------------------------------------------
- def encounter_list
- return @map.encounter_list
- end
- #--------------------------------------------------------------------------
- # ● 获取遇敌步数
- #--------------------------------------------------------------------------
- def encounter_step
- return @map.encounter_step
- end
- #--------------------------------------------------------------------------
- # ● 获取地图数据
- #--------------------------------------------------------------------------
- def data
- return @map.data
- end
- #--------------------------------------------------------------------------
- # ● 计算扣除显示坐标的 X 坐标
- # x : X 坐标
- #--------------------------------------------------------------------------
- def adjust_x(x)
- if loop_horizontal? and x < @display_x - @margin_x
- return x - @display_x + @map.width * 256
- else
- return x - @display_x
- end
- end
- #--------------------------------------------------------------------------
- # ● 计算扣除显示坐标的 Y 坐标
- # y : Y 坐标
- #--------------------------------------------------------------------------
- def adjust_y(y)
- if loop_vertical? and y < @display_y - @margin_y
- return y - @display_y + @map.height * 256
- else
- return y - @display_y
- end
- end
- #--------------------------------------------------------------------------
- # ● 计算循环修正后的 X 坐标
- # x : X 坐标
- #--------------------------------------------------------------------------
- def round_x(x)
- if loop_horizontal?
- return (x + width) % width
- else
- return x
- end
- end
- #--------------------------------------------------------------------------
- # ● 计算循环修正后的 Y坐标
- # y : Y 坐标
- #--------------------------------------------------------------------------
- def round_y(y)
- if loop_vertical?
- return (y + height) % height
- else
- return y
- end
- end
- #--------------------------------------------------------------------------
- # ● 计算特定方向移动 1 マス X 坐标
- # x : X 坐标
- # direction : 方向 (2,4,6,8)
- #--------------------------------------------------------------------------
- def x_with_direction(x, direction)
- return round_x(x + (direction == 6 ? 1 : direction == 4 ? -1 : 0))
- end
- #--------------------------------------------------------------------------
- # ● 计算特定方向移动 1 マス Y 坐标
- # y : Y 坐标
- # direction : 方向 (2,4,6,8)
- #--------------------------------------------------------------------------
- def y_with_direction(y, direction)
- return round_y(y + (direction == 2 ? 1 : direction == 8 ? -1 : 0))
- end
- #--------------------------------------------------------------------------
- # ● 获取指定坐标存在的事件排列
- # x : X 坐标
- # y : Y 坐标
- #--------------------------------------------------------------------------
- def events_xy(x, y)
- result = []
- for event in $game_map.events.values
- result.push(event) if event.pos?(x, y)
- end
- return result
- end
- #--------------------------------------------------------------------------
- # ● BGM / BGS 自动切换
- #--------------------------------------------------------------------------
- def autoplay
- @map.bgm.play if @map.autoplay_bgm
- @map.bgs.play if @map.autoplay_bgs
- end
- #--------------------------------------------------------------------------
- # ● 刷新
- #--------------------------------------------------------------------------
- def refresh
- if @map_id > 0
- for event in @events.values
- event.refresh
- end
- for common_event in @common_events.values
- common_event.refresh
- end
- end
- refresh_mg_tansuo
- @need_refresh = false
- end
- #--------------------------------------------------------------------------
- # ● 迷宫探索系统
- #--------------------------------------------------------------------------
- def refresh_mg_tansuo
-
- end
- #--------------------------------------------------------------------------
- # ● 向下滚动
- # distance : 滚动距离
- #--------------------------------------------------------------------------
- def scroll_down(distance)
- if loop_vertical?
- @display_y += distance
- @display_y %= @map.height * 256
- @parallax_y += distance
- else
- last_y = @display_y
- @display_y = [@display_y + distance, (height - 13) * 256].min
- @parallax_y += @display_y - last_y
- end
- end
- #--------------------------------------------------------------------------
- # ● 向左滚动
- # distance : 滚动距离
- #--------------------------------------------------------------------------
- def scroll_left(distance)
- if loop_horizontal?
- @display_x += @map.width * 256 - distance
- @display_x %= @map.width * 256
- @parallax_x -= distance
- else
- last_x = @display_x
- @display_x = [@display_x - distance, 0].max
- @parallax_x += @display_x - last_x
- end
- end
- #--------------------------------------------------------------------------
- # ● 向右滚动
- # distance : 滚动距离
- #--------------------------------------------------------------------------
- def scroll_right(distance)
- if loop_horizontal?
- @display_x += distance
- @display_x %= @map.width * 256
- @parallax_x += distance
- else
- last_x = @display_x
- @display_x = [@display_x + distance, (width - 17) * 256].min
- @parallax_x += @display_x - last_x
- end
- end
- #--------------------------------------------------------------------------
- # ● 向上滚动
- # distance : 滚动距离
- #--------------------------------------------------------------------------
- def scroll_up(distance)
- if loop_vertical?
- @display_y += @map.height * 256 - distance
- @display_y %= @map.height * 256
- @parallax_y -= distance
- else
- last_y = @display_y
- @display_y = [@display_y - distance, 0].max
- @parallax_y += @display_y - last_y
- end
- end
- #--------------------------------------------------------------------------
- # ● 有效坐标判定
- # x : X 坐标
- # y : Y 坐标
- #--------------------------------------------------------------------------
- def valid?(x, y)
- return (x >= 0 and x < width and y >= 0 and y < height)
- end
- #--------------------------------------------------------------------------
- # ● 可以通行判定
- # x : X 坐标
- # y : Y 坐标
- # flag : 检查通行禁止数据 (通常 0x01、交通工具的情况下变更)
- #--------------------------------------------------------------------------
- def passable?(x, y, flag = 0x01)
- for event in events_xy(x, y) # 检查坐标相同的事件
- next if event.tile_id == 0 # 地图没有图块的情况下
- next if event.priority_type > 0 # 不是[通常形式下]
- next if event.through # 穿透状态
- pass = @passages[event.tile_id] # 获取通行属性
- next if pass & 0x10 == 0x10 # [☆] : 不影响通行
- return true if pass & flag == 0x00 # [○] : 可通行
- return false if pass & flag == flag # [×] : 不可通行
- end
- for i in [2, 1, 0] # 从层按从上到下的顺序调查循环
- tile_id = @map.data[x, y, i] # 获取元件 ID
- return false if tile_id == nil # 取得元件 ID 失败 : 不能通行
- pass = @passages[tile_id] # 获取通行属性
- next if pass & 0x10 == 0x10 # [☆] : 不影响通行
- return true if pass & flag == 0x00 # [○] : 可通行
- return false if pass & flag == flag # [×] : 不可通行
- end
- return false # 通行不可
- end
- #--------------------------------------------------------------------------
- # ● 小型船通行判定
- # x : X 坐标
- # y : Y 坐标
- #--------------------------------------------------------------------------
- def boat_passable?(x, y)
- return passable?(x, y, 0x02)
- end
- #--------------------------------------------------------------------------
- # ● 大型船通行判定
- # x : X 坐标
- # y : Y 坐标
- #--------------------------------------------------------------------------
- def ship_passable?(x, y)
- return passable?(x, y, 0x04)
- end
- #--------------------------------------------------------------------------
- # ● 飞行船着陆可能判定
- # x : X 坐标
- # y : Y 坐标
- #--------------------------------------------------------------------------
- def airship_land_ok?(x, y)
- return passable?(x, y, 0x08)
- end
- #--------------------------------------------------------------------------
- # ● 茂密判定
- # x : X 坐标
- # y : Y 坐标
- #--------------------------------------------------------------------------
- def bush?(x, y)
- return false unless valid?(x, y)
- return @passages[@map.data[x, y, 1]] & 0x40 == 0x40
- end
- #--------------------------------------------------------------------------
- # ● 反击判定
- # x : X 坐标
- # y : Y 坐标
- #--------------------------------------------------------------------------
- def counter?(x, y)
- return false unless valid?(x, y)
- return @passages[@map.data[x, y, 0]] & 0x80 == 0x80
- end
- #--------------------------------------------------------------------------
- # ● 滚动开始
- # direction : 滚动方向
- # distance : 滚动距离
- # speed : 滚动速度
- #--------------------------------------------------------------------------
- def start_scroll(direction, distance, speed)
- @scroll_direction = direction
- @scroll_rest = distance * 256
- @scroll_speed = speed
- end
- #--------------------------------------------------------------------------
- # ● 滚动中中判定
- #--------------------------------------------------------------------------
- def scrolling?
- return @scroll_rest > 0
- end
- #--------------------------------------------------------------------------
- # ● 画面刷新
- #--------------------------------------------------------------------------
- def update
- refresh if $game_map.need_refresh
- update_scroll
- update_events
- update_vehicles
- update_parallax
- update_maze
- @screen.update
- end
- #--------------------------------------------------------------------------
- # ● 刷新迷宫,每20帧刷一次
- #--------------------------------------------------------------------------
- def update_maze
- @refresh_maze_count = 0 if @refresh_maze_count == nil
- if @refresh_maze_count == 0
- refresh_maze_small
- @refresh_maze_count = 20
- else
- @refresh_maze_count -= 1
- end
- end
- #--------------------------------------------------------------------------
- # ● 滚动刷新
- #--------------------------------------------------------------------------
- def update_scroll
- if @scroll_rest > 0 # 滚动中的情况下
- distance = 2 ** @scroll_speed # 滚动速度变化为地图坐标系的距离
- case @scroll_direction
- when 2 # 下
- scroll_down(distance)
- when 4 # 左
- scroll_left(distance)
- when 6 # 右
- scroll_right(distance)
- when 8 # 上
- scroll_up(distance)
- end
- @scroll_rest -= distance # 滚动距离的减法运算
- end
- end
- #--------------------------------------------------------------------------
- # ● 刷新事件
- #--------------------------------------------------------------------------
- def update_events
- for event in @events.values
- event.update
- end
- for common_event in @common_events.values
- common_event.update
- end
- end
- #--------------------------------------------------------------------------
- # ● 刷新交通工具
- #--------------------------------------------------------------------------
- def update_vehicles
- for vehicle in @vehicles
- vehicle.update
- end
- end
- #--------------------------------------------------------------------------
- # ● 刷新远景
- #--------------------------------------------------------------------------
- def update_parallax
- @parallax_x += @parallax_sx * 4 if @parallax_loop_x
- @parallax_y += @parallax_sy * 4 if @parallax_loop_y
- end
- end
复制代码 |
|