设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 3707|回复: 7
打印 上一主题 下一主题

[RMVA发布] 迷你地图KMS_MiniMap省事版

[复制链接]

Lv1.梦旅人

梦石
0
星屑
50
在线时间
23 小时
注册时间
2010-12-6
帖子
6
跳转到指定楼层
1
发表于 2014-6-17 20:29:54 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
本帖最后由 真奥丁炮 于 2014-6-17 20:36 编辑

由于程序员的秉性,我把这个脚本修改了一下,现在不需要在事件的头部添加注释标注事件类型了。
此外修改了一下F5为地图切换按键,同时稍微调整了一下地图的位置和大小。
RUBY 代码复制
  1. #_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
  2. #_/    ◆ 迷你地图 - KMS_MiniMap ◆ VX Ace ◆
  3. #_/    ◇ Last update : 2012/02/12  (TOMY@Kamesoft) ◇
  4. #_/----------------------------------------------------------------------------
  5. #_/  追加迷你地图表示机能。
  6. #_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
  7.  
  8. #==============================================================================
  9. # ★ 设定项目 - BEGIN Setting ★
  10. #==============================================================================
  11.  
  12. module KMS_MiniMap
  13.   # ◆ 迷你地图表示切换按键
  14.   #  空白则按钮转换无效。
  15.   SWITCH_BUTTON = :F5
  16.  
  17.   # ◆ 迷你地图表示位置和大小 (X, Y, 寛, 高)
  18.   MAP_RECT = Rect.new(Graphics.width / 8,
  19.                       Graphics.height / 8,
  20.                       Graphics.width / 4 * 3,
  21.                       Graphics.height / 4 * 3)
  22.   # ◆ 迷你地图 Z 座标
  23.   #  注意:太大可能影响其他东西。
  24.   MAP_Z = 0
  25.   # ◆ 1格大小
  26.   # 推荐 3 以上。
  27.   GRID_SIZE = 8
  28.  
  29.   # ◆ 迷你地图顔色
  30.   FOREGROUND_COLOR = Color.new(192, 192, 224, 160)  # 前景色 (通行可)
  31.   BACKGROUND_COLOR = Color.new(  0,   0, 160, 160)  # 背景色 (通行不可)
  32.   POSITION_COLOR   = Color.new(255,   0,   0, 192)  # 现在位置
  33.   MOVE_EVENT_COLOR = Color.new(255, 160,   0, 192)  # 地图移动事件
  34.   VEHICLE_COLOR    = Color.new( 96, 128,   0, 192)  # 载物
  35.  
  36.   # ◆ 物件顔色
  37.   #  按顺序OBJ1, OBJ2,... 对应。
  38.   OBJECT_COLOR = [
  39.     Color.new(  0, 128,   0, 192),  # OBJ 1
  40.     Color.new(  0, 160, 160, 192),  # OBJ 2
  41.     Color.new(160,   0, 160, 192),  # OBJ 3
  42.     Color.new(218, 112, 214, 192),
  43.   ]  # ← 这个]不能消去!
  44.  
  45.   # ◆ 图标的闪烁强度
  46.   # 推荐 5 ~ 8 之间。
  47.   BLINK_LEVEL = 7
  48.  
  49.   # ◆ 地图缓存的数量
  50.   #  超越这个数的话,会删除长期间没参照东西。
  51.   CACHE_NUM = 10
  52. end
  53.  
  54. #==============================================================================
  55. # ☆ 设定完成 - END Setting ☆
  56. #==============================================================================
  57.  
  58. $kms_imported = {} if $kms_imported == nil
  59. $kms_imported["MiniMap"] = true
  60.  
  61. module KMS_MiniMap
  62.   # 迷你地图非表示
  63.   REGEX_NO_MINIMAP_NOTE = /<(?:ミニマップ|MINIMAP)\s*(?:非表示|HIDE)>/i
  64.   REGEX_NO_MINIMAP_NAME = /\[NOMAP\]/i
  65.  
  66.   # 障害物
  67.   REGEX_WALL_EVENT = /<(?:ミニマップ|MINIMAP)\s*(?:壁|障害物|WALL)>/i
  68.  
  69.   # 移动事件
  70.   REGEX_MOVE_EVENT = /<(?:ミニマップ|MINIMAP)\s*(?:移动|MOVE)>/i
  71.  
  72.   # 物件
  73.   REGEX_OBJECT = /<(?:ミニマップ|MINIMAP)\s+OBJ(?:ECT)?\s*(\d+)>/i
  74. end
  75.  
  76. # *****************************************************************************
  77.  
  78. #==============================================================================
  79. # □ KMS_Commands
  80. #==============================================================================
  81.  
  82. module KMS_Commands
  83.   module_function
  84.   #--------------------------------------------------------------------------
  85.   # ○ 表示迷你地图
  86.   #--------------------------------------------------------------------------
  87.   def show_minimap
  88.     $game_temp.minimap_manual_visible = true
  89.     $game_system.minimap_show         = true
  90.   end
  91.   #--------------------------------------------------------------------------
  92.   # ○ 不表示迷你地图
  93.   #--------------------------------------------------------------------------
  94.   def hide_minimap
  95.     $game_system.minimap_show = false
  96.   end
  97.   #--------------------------------------------------------------------------
  98.   # ○ 迷你地图表示状态取得
  99.   #--------------------------------------------------------------------------
  100.   def minimap_showing?
  101.     return $game_system.minimap_show
  102.   end
  103.   #--------------------------------------------------------------------------
  104.   # ○ 刷新迷你地图
  105.   #--------------------------------------------------------------------------
  106.   def refresh_minimap
  107.     return unless SceneManager.scene_is?(Scene_Map)
  108.  
  109.     $game_map.refresh if $game_map.need_refresh
  110.     SceneManager.scene.refresh_minimap
  111.   end
  112.   #--------------------------------------------------------------------------
  113.   # ○ 更新迷你地图对象
  114.   #--------------------------------------------------------------------------
  115.   def update_minimap_object
  116.     return unless SceneManager.scene_is?(Scene_Map)
  117.  
  118.     $game_map.refresh if $game_map.need_refresh
  119.     SceneManager.scene.update_minimap_object
  120.   end
  121. end
  122.  
  123. #==============================================================================
  124. # ■ Game_Interpreter
  125. #==============================================================================
  126.  
  127. class Game_Interpreter
  128.   # 事件指令:直接處理指令
  129.   include KMS_Commands
  130. end
  131.  
  132. #==============================================================================
  133. # ■ RPG::Map
  134. #==============================================================================
  135.  
  136. class RPG::Map
  137.   #--------------------------------------------------------------------------
  138.   # ○ 生成迷你地图缓存
  139.   #--------------------------------------------------------------------------
  140.   def create_minimap_cache
  141.     @__minimap_show = true
  142.  
  143.     note.each_line { |line|
  144.       if line =~ KMS_MiniMap::REGEX_NO_MINIMAP_NOTE  # マップ非表示
  145.         @__minimap_show = false
  146.       end
  147.     }
  148.   end
  149.   #--------------------------------------------------------------------------
  150.   # ○ 表示迷你地图
  151.   #--------------------------------------------------------------------------
  152.   def minimap_show?
  153.     create_minimap_cache if @__minimap_show.nil?
  154.     return @__minimap_show
  155.   end
  156. end
  157.  
  158. #==============================================================================
  159. # ■ RPG::MapInfo
  160. #==============================================================================
  161.  
  162. class RPG::MapInfo
  163.   #--------------------------------------------------------------------------
  164.   # ● 地图名取得
  165.   #--------------------------------------------------------------------------
  166.   def name
  167.     return @name.gsub(/\[.*\]/) { "" }
  168.   end
  169.   #--------------------------------------------------------------------------
  170.   # ○ 取得原始地图名
  171.   #--------------------------------------------------------------------------
  172.   def original_name
  173.     return @name
  174.   end
  175.   #--------------------------------------------------------------------------
  176.   # ○ 生成迷你地图缓存
  177.   #--------------------------------------------------------------------------
  178.   def create_minimap_cache
  179.     @__minimap_show = !(@name =~ KMS_MiniMap::REGEX_NO_MINIMAP_NAME)
  180.   end
  181.   #--------------------------------------------------------------------------
  182.   # ○ 表示迷你地图
  183.   #--------------------------------------------------------------------------
  184.   def minimap_show?
  185.     create_minimap_cache if @__minimap_show == nil
  186.     return @__minimap_show
  187.   end
  188. end
  189.  
  190. #==============================================================================
  191. # ■ Game_Temp
  192. #==============================================================================
  193.  
  194. class Game_Temp
  195.   #--------------------------------------------------------------------------
  196.   # ○ 公共实例变量
  197.   #--------------------------------------------------------------------------
  198.   attr_accessor :minimap_manual_visible  # 手动切换小地图显示标志
  199.   #--------------------------------------------------------------------------
  200.   # ○ 对象初始化
  201.   #--------------------------------------------------------------------------
  202.   alias initialize_KMS_MiniMap initialize
  203.   def initialize
  204.     initialize_KMS_MiniMap
  205.  
  206.     @minimap_manual_visible = true
  207.   end
  208. end
  209.  
  210. #==============================================================================
  211. # ■ Game_System
  212. #==============================================================================
  213.  
  214. class Game_System
  215.   #--------------------------------------------------------------------------
  216.   # ○ 公开インスタンス変数
  217.   #--------------------------------------------------------------------------
  218.   attr_accessor :minimap_show  # 迷你地图显示标志
  219.   #--------------------------------------------------------------------------
  220.   # ○ 对象初始化
  221.   #--------------------------------------------------------------------------
  222.   alias initialize_KMS_MiniMap initialize
  223.   def initialize
  224.     initialize_KMS_MiniMap
  225.  
  226.     @minimap_show = true
  227.   end
  228. end
  229.  
  230. #==============================================================================
  231. # ■ Game_Map
  232. #==============================================================================
  233.  
  234. class Game_Map
  235.   #--------------------------------------------------------------------------
  236.   # ○ 定数
  237.   #--------------------------------------------------------------------------
  238.   MINIMAP_FADE_NONE = 0  # ミニマップ フェードなし
  239.   MINIMAP_FADE_IN   = 1  # ミニマップ フェードイン
  240.   MINIMAP_FADE_OUT  = 2  # ミニマップ フェードアウト
  241.   #--------------------------------------------------------------------------
  242.   # ○ 公开インスタンス変数
  243.   #--------------------------------------------------------------------------
  244.   attr_accessor :minimap_fade
  245.   #--------------------------------------------------------------------------
  246.   # ○ ミニマップを表示するか
  247.   #--------------------------------------------------------------------------
  248.   def minimap_show?
  249.     return $data_mapinfos[map_id].minimap_show? && @map.minimap_show?
  250.   end
  251.   #--------------------------------------------------------------------------
  252.   # ○ ミニマップをフェードイン
  253.   #--------------------------------------------------------------------------
  254.   def fadein_minimap
  255.     @minimap_fade = MINIMAP_FADE_IN
  256.   end
  257.   #--------------------------------------------------------------------------
  258.   # ○ ミニマップをフェードアウト
  259.   #--------------------------------------------------------------------------
  260.   def fadeout_minimap
  261.     @minimap_fade = MINIMAP_FADE_OUT
  262.   end
  263.   #--------------------------------------------------------------------------
  264.   # ● リフレッシュ
  265.   #--------------------------------------------------------------------------
  266.   alias refresh_KMS_MiniMap refresh
  267.   def refresh
  268.     refresh_KMS_MiniMap
  269.  
  270.     SceneManager.scene.refresh_minimap if SceneManager.scene_is?(Scene_Map)
  271.   end
  272. end
  273.  
  274. #==============================================================================
  275. # ■ Game_Event
  276. #==============================================================================
  277.  
  278. class Game_Event < Game_Character
  279.   #--------------------------------------------------------------------------
  280.   # ○ ミニマップ用のキャッシュを作成
  281.   #--------------------------------------------------------------------------
  282.   def __create_minimap_cache
  283.     @__last_page = @page
  284.     @__minimap_wall_event  = false
  285.     @__minimap_move_event  = false
  286.     @__minimap_object_type = -1
  287.     return if @page.nil?
  288.     return if move_event_judge
  289.     return if object_type_judge
  290.   end
  291.   #--------------------------------------------------------------------------
  292.   # ○ 移动事件判定(存在201号解释器事件)
  293.   #--------------------------------------------------------------------------  
  294.   def move_event_judge
  295.     @__minimap_move_event = @page.graphic.character_name == "" &&
  296.                               @page.list.any? { |eve| eve.code == 201 }
  297.   end
  298.   #--------------------------------------------------------------------------
  299.   # ○ 其他类型事件判定
  300.   #--------------------------------------------------------------------------  
  301.   def object_type_judge
  302.     return true if is_actor_event == 1
  303.     return true if is_door_event == 3 || is_switch_event == 3
  304.     return true if is_close_chest_event == 2
  305.     return false
  306.   end
  307.   #--------------------------------------------------------------------------
  308.   # ○ 角色类事件判定(自定义图块仅支持纯数字文件 例如 1.png)
  309.   #--------------------------------------------------------------------------  
  310.   def is_actor_event
  311.     pattren = /(Actor|Animal|Behavior|Damage|
  312.           Evil|Insane|Monster|People|Riding|Spiritual)|(^\d+$)/
  313.  
  314.     @__minimap_object_type = (@page.graphic.character_name =~ pattren ? 1 : -1)
  315.   end
  316.   #--------------------------------------------------------------------------
  317.   # ○ 门类事件判定(这个仅适用范围很小)
  318.   #--------------------------------------------------------------------------
  319.   def is_door_event
  320.     gra = @page.graphic
  321.     @__minimap_object_type = (gra.character_name =~ /Other3/ &&
  322.                                 gra.character_index == 6 ? 3 : -1)   
  323.   end
  324.   #--------------------------------------------------------------------------
  325.   # ○ 开关类事件判定(和上面那个共用一种颜色)
  326.   #--------------------------------------------------------------------------  
  327.   def is_switch_event
  328.     gra = @page.graphic
  329.     @__minimap_object_type = (gra.character_name =~ /Switch/ ? 3 : -1)
  330.   end
  331.   #--------------------------------------------------------------------------
  332.   # ○ 未发现的宝箱事件判定(开启后就消失了)
  333.   #--------------------------------------------------------------------------  
  334.   def is_close_chest_event
  335.     gra = @page.graphic
  336.     @__minimap_object_type = (gra.character_name =~ /Chest/ && gra.direction == 2 ? 2 : -1)
  337.   end
  338.  
  339.   private :__create_minimap_cache
  340.   #--------------------------------------------------------------------------
  341.   # ○ グラフィックがあるか
  342.   #--------------------------------------------------------------------------
  343.   def graphic_exist?
  344.     return (character_name != "" || tile_id > 0)
  345.   end
  346.   #--------------------------------------------------------------------------
  347.   # ○ 障害物か
  348.   #--------------------------------------------------------------------------
  349.   def is_minimap_wall_event?
  350.     if @__minimap_wall_event.nil? || @__last_page != @page
  351.       __create_minimap_cache
  352.     end
  353.  
  354.     return @__minimap_wall_event
  355.   end
  356.   #--------------------------------------------------------------------------
  357.   # ○ 移动イベントか
  358.   #--------------------------------------------------------------------------
  359.   def is_minimap_move_event?
  360.     if @__minimap_move_event.nil? || @__last_page != @page
  361.       __create_minimap_cache
  362.     end
  363.  
  364.     return @__minimap_move_event
  365.   end
  366.   #--------------------------------------------------------------------------
  367.   # ○ ミニマップオブジェクトか
  368.   #--------------------------------------------------------------------------
  369.   def is_minimap_object?
  370.     if @__minimap_object_type.nil? || @__last_page != @page
  371.       __create_minimap_cache
  372.     end
  373.  
  374.     return @__minimap_object_type > 0
  375.   end
  376.   #--------------------------------------------------------------------------
  377.   # ○ ミニマップオブジェクトタイプ
  378.   #--------------------------------------------------------------------------
  379.   def minimap_object_type
  380.     if @__minimap_object_type.nil? || @__last_page != @page
  381.       __create_minimap_cache
  382.     end
  383.  
  384.     return @__minimap_object_type
  385.   end
  386. end
  387.  
  388. #==============================================================================
  389. # □ Game_MiniMap
  390. #------------------------------------------------------------------------------
  391. #   ミニマップを扱うクラスです。
  392. #==============================================================================
  393.  
  394. class Game_MiniMap
  395.   #--------------------------------------------------------------------------
  396.   # ○ 构造体
  397.   #--------------------------------------------------------------------------
  398.   Point = Struct.new(:x, :y)
  399.   Size  = Struct.new(:width, :height)
  400.   PassageCache = Struct.new(:map_id, :table, :scan_table)
  401.   #--------------------------------------------------------------------------
  402.   # ○ クラス変数
  403.   #--------------------------------------------------------------------------
  404.   @@passage_cache = []  # 通行フラグテーブルキャッシュ
  405.   #--------------------------------------------------------------------------
  406.   # ● オブジェクト初期化
  407.   #--------------------------------------------------------------------------
  408.   def initialize(tilemap)
  409.     @map_rect  = KMS_MiniMap::MAP_RECT
  410.     @grid_size = [KMS_MiniMap::GRID_SIZE, 1].max
  411.  
  412.     @x = 0
  413.     @y = 0
  414.     @grid_num = Point.new(
  415.       (@map_rect.width  + @grid_size - 1) / @grid_size,
  416.       (@map_rect.height + @grid_size - 1) / @grid_size
  417.     )
  418.     @draw_grid_num    = Point.new(@grid_num.x + 2, @grid_num.y + 2)
  419.     @draw_range_begin = Point.new(0, 0)
  420.     @draw_range_end   = Point.new(0, 0)
  421.     @tilemap = tilemap
  422.  
  423.     @last_x = $game_player.x
  424.     @last_y = $game_player.y
  425.  
  426.     @showing = false
  427.     @hiding  = false
  428.  
  429.     create_sprites
  430.     refresh
  431.  
  432.     unless $game_temp.minimap_manual_visible
  433.       self.opacity = 0
  434.     end
  435.   end
  436.   #--------------------------------------------------------------------------
  437.   # ○ スプライト作成
  438.   #--------------------------------------------------------------------------
  439.   def create_sprites
  440.     @viewport   = Viewport.new(@map_rect)
  441.     @viewport.z = KMS_MiniMap::MAP_Z
  442.  
  443.     # ビットマップサイズ计算
  444.     @bmp_size = Size.new(
  445.       (@grid_num.x + 2) * @grid_size,
  446.       (@grid_num.y + 2) * @grid_size
  447.     )
  448.     @buf_bitmap = Bitmap.new(@bmp_size.width, @bmp_size.height)
  449.  
  450.     # マップ用スプライト作成
  451.     @map_sprite   = Sprite.new(@viewport)
  452.     @map_sprite.x = -@grid_size
  453.     @map_sprite.y = -@grid_size
  454.     @map_sprite.z = 0
  455.     @map_sprite.bitmap = Bitmap.new(@bmp_size.width, @bmp_size.height)
  456.  
  457.     # オブジェクト用スプライト作成
  458.     @object_sprite   = Sprite_MiniMapIcon.new(@viewport)
  459.     @object_sprite.x = -@grid_size
  460.     @object_sprite.y = -@grid_size
  461.     @object_sprite.z = 1
  462.     @object_sprite.bitmap = Bitmap.new(@bmp_size.width, @bmp_size.height)
  463.  
  464.     # 现在位置スプライト作成
  465.     @position_sprite   = Sprite_MiniMapIcon.new
  466.     @position_sprite.x = @map_rect.x + @grid_num.x / 2 * @grid_size
  467.     @position_sprite.y = @map_rect.y + @grid_num.y / 2 * @grid_size
  468.     @position_sprite.z = @viewport.z + 2
  469.     bitmap = Bitmap.new(@grid_size, @grid_size)
  470.     bitmap.fill_rect(bitmap.rect, KMS_MiniMap::POSITION_COLOR)
  471.     @position_sprite.bitmap = bitmap
  472.   end
  473.   #--------------------------------------------------------------------------
  474.   # ● 解放
  475.   #--------------------------------------------------------------------------
  476.   def dispose
  477.     @buf_bitmap.dispose
  478.     @map_sprite.bitmap.dispose
  479.     @map_sprite.dispose
  480.     @object_sprite.bitmap.dispose
  481.     @object_sprite.dispose
  482.     @position_sprite.bitmap.dispose
  483.     @position_sprite.dispose
  484.     @viewport.dispose
  485.   end
  486.   #--------------------------------------------------------------------------
  487.   # ○ 可视状态取得
  488.   #--------------------------------------------------------------------------
  489.   def visible
  490.     return @map_sprite.visible
  491.   end
  492.   #--------------------------------------------------------------------------
  493.   # ○ 可视状态设定
  494.   #--------------------------------------------------------------------------
  495.   def visible=(value)
  496.     @viewport.visible        = value
  497.     @map_sprite.visible      = value
  498.     @object_sprite.visible   = value
  499.     @position_sprite.visible = value
  500.   end
  501.   #--------------------------------------------------------------------------
  502.   # ○ 不透明度取得
  503.   #--------------------------------------------------------------------------
  504.   def opacity
  505.     return @map_sprite.opacity
  506.   end
  507.   #--------------------------------------------------------------------------
  508.   # ○ 不透明度设定
  509.   #--------------------------------------------------------------------------
  510.   def opacity=(value)
  511.     @map_sprite.opacity      = value
  512.     @object_sprite.opacity   = value
  513.     @position_sprite.opacity = value
  514.   end
  515.   #--------------------------------------------------------------------------
  516.   # ○ リフレッシュ
  517.   #--------------------------------------------------------------------------
  518.   def refresh
  519.     update_draw_range
  520.     update_passage_table
  521.     update_object_list
  522.     update_position
  523.     draw_map
  524.     draw_object
  525.     Graphics.frame_reset
  526.   end
  527.   #--------------------------------------------------------------------------
  528.   # ○ フェードイン
  529.   #--------------------------------------------------------------------------
  530.   def fadein
  531.     @showing = true
  532.     @hiding  = false
  533.   end
  534.   #--------------------------------------------------------------------------
  535.   # ○ フェードアウト
  536.   #--------------------------------------------------------------------------
  537.   def fadeout
  538.     @showing = false
  539.     @hiding  = true
  540.   end
  541.   #--------------------------------------------------------------------------
  542.   # ○ キー入力更新
  543.   #--------------------------------------------------------------------------
  544.   def update_input
  545.     return if KMS_MiniMap::SWITCH_BUTTON.nil?
  546.  
  547.     if Input.trigger?(KMS_MiniMap::SWITCH_BUTTON)
  548.       if opacity < 255 && !@showing
  549.         $game_temp.minimap_manual_visible = true
  550.         fadein
  551.       elsif opacity > 0 && !@hiding
  552.         $game_temp.minimap_manual_visible = false
  553.         fadeout
  554.       end
  555.     end
  556.   end
  557.   #--------------------------------------------------------------------------
  558.   # ○ 描画范囲更新
  559.   #--------------------------------------------------------------------------
  560.   def update_draw_range
  561.     range = []
  562.     (2).times { |i| range[i] = @draw_grid_num[i] / 2 }
  563.  
  564.     @draw_range_begin.x = $game_player.x - range[0]
  565.     @draw_range_begin.y = $game_player.y - range[1]
  566.     @draw_range_end.x   = $game_player.x + range[0]
  567.     @draw_range_end.y   = $game_player.y + range[1]
  568.   end
  569.   #--------------------------------------------------------------------------
  570.   # ○ 通行可否テーブル更新
  571.   #--------------------------------------------------------------------------
  572.   def update_passage_table
  573.     cache = get_passage_table_cache
  574.     @passage_table      = cache.table
  575.     @passage_scan_table = cache.scan_table
  576.  
  577.     update_around_passage_table
  578.   end
  579.   #--------------------------------------------------------------------------
  580.   # ○ 通行可否テーブルのキャッシュを取得
  581.   #--------------------------------------------------------------------------
  582.   def get_passage_table_cache
  583.     map_id = $game_map.map_id
  584.     cache  = @@passage_cache.find { |c| c.map_id == map_id }
  585.  
  586.     # キャッシュミスしたら新规作成
  587.     if cache == nil
  588.       cache = PassageCache.new(map_id)
  589.       cache.table      = Table.new($game_map.width, $game_map.height)
  590.       cache.scan_table = Table.new(
  591.         ($game_map.width  + @draw_grid_num.x - 1) / @draw_grid_num.x,
  592.         ($game_map.height + @draw_grid_num.y - 1) / @draw_grid_num.y
  593.       )
  594.     end
  595.  
  596.     # 直近のキャッシュは先头に移动し、古いキャッシュは削除
  597.     @@passage_cache.unshift(cache)
  598.     @@passage_cache.delete_at(KMS_MiniMap::CACHE_NUM)
  599.  
  600.     return cache
  601.   end
  602.   #--------------------------------------------------------------------------
  603.   # ○ 通行可否テーブルのキャッシュをクリア
  604.   #--------------------------------------------------------------------------
  605.   def clear_passage_table_cache
  606.     return if @passage_scan_table == nil
  607.  
  608.     table = @passage_scan_table
  609.     @passage_scan_table = Table.new(table.xsize, table.ysize)
  610.   end
  611.   #--------------------------------------------------------------------------
  612.   # ○ 通行可否テーブルの探索
  613.   #     x, y : 探索位置
  614.   #--------------------------------------------------------------------------
  615.   def scan_passage(x, y)
  616.     dx = x / @draw_grid_num.x
  617.     dy = y / @draw_grid_num.y
  618.  
  619.     # 探索済み
  620.     return if @passage_scan_table[dx, dy] == 1
  621.  
  622.     # マップ范囲外
  623.     return unless dx.between?(0, @passage_scan_table.xsize - 1)
  624.     return unless dy.between?(0, @passage_scan_table.ysize - 1)
  625.  
  626.     rx = (dx * @draw_grid_num.x)...((dx + 1) * @draw_grid_num.x)
  627.     ry = (dy * @draw_grid_num.y)...((dy + 1) * @draw_grid_num.y)
  628.     mw = $game_map.width  - 1
  629.     mh = $game_map.height - 1
  630.  
  631.     # 探索范囲内の通行テーブルを生成
  632.     rx.each { |x|
  633.       next unless x.between?(0, mw)
  634.       ry.each { |y|
  635.         next unless y.between?(0, mh)
  636.  
  637.         # 通行方向フラグ作成
  638.         # (↓、←、→、↑ の顺に 1, 2, 4, 8 が対応)
  639.         flag = 0
  640.         [2, 4, 6, 8].each{ |d|
  641.           flag |= 1 << (d / 2 - 1) if $game_map.passable?(x, y, d)
  642.         }
  643.         @passage_table[x, y] = flag
  644.       }
  645.     }
  646.     @passage_scan_table[dx, dy] = 1
  647.   end
  648.   #--------------------------------------------------------------------------
  649.   # ○ 周辺の通行可否テーブル更新
  650.   #--------------------------------------------------------------------------
  651.   def update_around_passage_table
  652.     gx = @draw_grid_num.x
  653.     gy = @draw_grid_num.y
  654.     dx = $game_player.x - gx / 2
  655.     dy = $game_player.y - gy / 2
  656.     scan_passage(dx,      dy)
  657.     scan_passage(dx + gx, dy)
  658.     scan_passage(dx,      dy + gy)
  659.     scan_passage(dx + gx, dy + gy)
  660.   end
  661.   #--------------------------------------------------------------------------
  662.   # ○ オブジェクト一覧更新
  663.   #--------------------------------------------------------------------------
  664.   def update_object_list
  665.     events = $game_map.events.values
  666.  
  667.     # WALL
  668.     @wall_events = events.find_all { |e| e.is_minimap_wall_event? }
  669.  
  670.     # MOVE
  671.     @move_events = events.find_all { |e| e.is_minimap_move_event? }
  672.  
  673.     # OBJ
  674.     @object_list = events.find_all { |e| e.is_minimap_object? }
  675.   end
  676.   #--------------------------------------------------------------------------
  677.   # ○ 位置更新
  678.   #--------------------------------------------------------------------------
  679.   def update_position
  680.     # 移动量算出
  681.     pt = Point.new($game_player.x, $game_player.y)
  682.     ox = ($game_player.real_x - pt.x) * @grid_size
  683.     oy = ($game_player.real_y - pt.y) * @grid_size
  684.  
  685.     @viewport.ox = ox
  686.     @viewport.oy = oy
  687.  
  688.     # 移动していたらマップ再描画
  689.     if pt.x != @last_x || pt.y != @last_y
  690.       draw_map
  691.       @last_x = pt.x
  692.       @last_y = pt.y
  693.     end
  694.   end
  695.   #--------------------------------------------------------------------------
  696.   # ○ 描画范囲内判定
  697.   #--------------------------------------------------------------------------
  698.   def in_draw_range?(x, y)
  699.     rb = @draw_range_begin
  700.     re = @draw_range_end
  701.     return (x.between?(rb.x, re.x) && y.between?(rb.y, re.y))
  702.   end
  703.   #--------------------------------------------------------------------------
  704.   # ○ マップ范囲内判定
  705.   #--------------------------------------------------------------------------
  706.   def in_map_range?(x, y)
  707.     mw = $game_map.width
  708.     mh = $game_map.height
  709.     return (x.between?(0, mw - 1) && y.between?(0, mh - 1))
  710.   end
  711.   #--------------------------------------------------------------------------
  712.   # ○ マップ描画
  713.   #--------------------------------------------------------------------------
  714.   def draw_map
  715.     update_around_passage_table
  716.  
  717.     bitmap  = @map_sprite.bitmap
  718.     bitmap.fill_rect(bitmap.rect, KMS_MiniMap::BACKGROUND_COLOR)
  719.  
  720.     draw_map_foreground(bitmap)
  721.     draw_map_move_event(bitmap)
  722.   end
  723.   #--------------------------------------------------------------------------
  724.   # ○ 通行可能领域の描画
  725.   #--------------------------------------------------------------------------
  726.   def draw_map_foreground(bitmap)
  727.     range_x = (@draw_range_begin.x)..(@draw_range_end.x)
  728.     range_y = (@draw_range_begin.y)..(@draw_range_end.y)
  729.     map_w   = $game_map.width  - 1
  730.     map_h   = $game_map.height - 1
  731.     rect    = Rect.new(0, 0, @grid_size, @grid_size)
  732.  
  733.     range_x.each { |x|
  734.       next unless x.between?(0, map_w)
  735.       range_y.each { |y|
  736.         next unless y.between?(0, map_h)
  737.         next if @passage_table[x, y] == 0
  738.         next if @wall_events.find { |e| e.x == x && e.y == y }  # 壁
  739.  
  740.         # グリッド描画サイズ算出
  741.         rect.set(0, 0, @grid_size, @grid_size)
  742.         rect.x = (x - @draw_range_begin.x) * @grid_size
  743.         rect.y = (y - @draw_range_begin.y) * @grid_size
  744.         flag = @passage_table[x, y]
  745.         if flag & 0x01 == 0  # 下通行不能
  746.           rect.height -= 1
  747.         end
  748.         if flag & 0x02 == 0  # 左通行不能
  749.           rect.x     += 1
  750.           rect.width -= 1
  751.         end
  752.         if flag & 0x04 == 0  # 右通行不能
  753.           rect.width -= 1
  754.         end
  755.         if flag & 0x08 == 0  # 上通行不能
  756.           rect.y      += 1
  757.           rect.height -= 1
  758.         end
  759.         bitmap.fill_rect(rect, KMS_MiniMap::FOREGROUND_COLOR)
  760.       }
  761.     }
  762.   end
  763.   #--------------------------------------------------------------------------
  764.   # ○ 移动イベントの描画
  765.   #--------------------------------------------------------------------------
  766.   def draw_map_move_event(bitmap)
  767.     rect = Rect.new(0, 0, @grid_size, @grid_size)
  768.     @move_events.each { |e|
  769.       rect.x = (e.x - @draw_range_begin.x) * @grid_size
  770.       rect.y = (e.y - @draw_range_begin.y) * @grid_size
  771.       bitmap.fill_rect(rect, KMS_MiniMap::MOVE_EVENT_COLOR)
  772.     }
  773.   end
  774.   #--------------------------------------------------------------------------
  775.   # ○ アニメーション更新
  776.   #--------------------------------------------------------------------------
  777.   def update_animation
  778.     if @showing
  779.       # フェードイン
  780.       self.opacity += 16
  781.       if opacity == 255
  782.         @showing = false
  783.       end
  784.     elsif @hiding
  785.       # フェードアウト
  786.       self.opacity -= 16
  787.       if opacity == 0
  788.         @hiding = false
  789.       end
  790.     end
  791.   end
  792.   #--------------------------------------------------------------------------
  793.   # ○ オブジェクト描画
  794.   #--------------------------------------------------------------------------
  795.   def draw_object
  796.     # 下准备
  797.     bitmap = @object_sprite.bitmap
  798.     bitmap.clear
  799.     rect = Rect.new(0, 0, @grid_size, @grid_size)
  800.  
  801.     # オブジェクト描画
  802.     @object_list.each { |obj|
  803.       next unless in_draw_range?(obj.x, obj.y)
  804.  
  805.       color = KMS_MiniMap::OBJECT_COLOR[obj.minimap_object_type - 1]
  806.       next if color.nil?
  807.  
  808.       rect.x = (obj.real_x - @draw_range_begin.x) * @grid_size
  809.       rect.y = (obj.real_y - @draw_range_begin.y) * @grid_size
  810.       bitmap.fill_rect(rect, color)
  811.     }
  812.  
  813.     # 乗り物描画
  814.     $game_map.vehicles.each { |vehicle|
  815.       next if vehicle.transparent
  816.  
  817.       rect.x = (vehicle.real_x - @draw_range_begin.x) * @grid_size
  818.       rect.y = (vehicle.real_y - @draw_range_begin.y) * @grid_size
  819.       bitmap.fill_rect(rect, KMS_MiniMap::VEHICLE_COLOR)
  820.     }
  821.   end
  822.   #--------------------------------------------------------------------------
  823.   # ○ 更新
  824.   #--------------------------------------------------------------------------
  825.   def update
  826.     update_input
  827.  
  828.     return unless need_update?
  829.  
  830.     update_draw_range
  831.     update_position
  832.     update_animation
  833.     draw_object
  834.  
  835.     @map_sprite.update
  836.     @object_sprite.update
  837.     @position_sprite.update
  838.   end
  839.   #--------------------------------------------------------------------------
  840.   # ○ 更新判定
  841.   #--------------------------------------------------------------------------
  842.   def need_update?
  843.     return (visible && opacity > 0) || @showing || @hiding
  844.   end
  845. end
  846.  
  847. #==============================================================================
  848. # □ Sprite_MiniMapIcon
  849. #------------------------------------------------------------------------------
  850. #   ミニマップ用アイコンのクラスです。
  851. #==============================================================================
  852.  
  853. class Sprite_MiniMapIcon < Sprite
  854.   DURATION_MAX = 60
  855.   #--------------------------------------------------------------------------
  856.   # ● オブジェクト初期化
  857.   #     viewport : ビューポート
  858.   #--------------------------------------------------------------------------
  859.   def initialize(viewport = nil)
  860.     super(viewport)
  861.     @duration = DURATION_MAX / 2
  862.   end
  863.   #--------------------------------------------------------------------------
  864.   # ● フレーム更新
  865.   #--------------------------------------------------------------------------
  866.   def update
  867.     super
  868.     @duration += 1
  869.     if @duration == DURATION_MAX
  870.       @duration = 0
  871.     end
  872.     update_effect
  873.   end
  874.   #--------------------------------------------------------------------------
  875.   # ○ エフェクトの更新
  876.   #--------------------------------------------------------------------------
  877.   def update_effect
  878.     self.color.set(255, 255, 255,
  879.       (@duration - DURATION_MAX / 2).abs * KMS_MiniMap::BLINK_LEVEL
  880.     )
  881.   end
  882. end
  883.  
  884. #==============================================================================
  885. # ■ Spriteset_Map
  886. #==============================================================================
  887.  
  888. class Spriteset_Map
  889.   attr_reader :minimap
  890.   #--------------------------------------------------------------------------
  891.   # ● オブジェクト初期化
  892.   #--------------------------------------------------------------------------
  893.   alias initialize_KMS_MiniMap initialize
  894.   def initialize
  895.     initialize_KMS_MiniMap
  896.  
  897.     create_minimap
  898.   end
  899.   #--------------------------------------------------------------------------
  900.   # ○ ミニマップの作成
  901.   #--------------------------------------------------------------------------
  902.   def create_minimap
  903.     @minimap = Game_MiniMap.new(@tilemap)
  904.     @minimap.visible = $game_system.minimap_show && $game_map.minimap_show?
  905.   end
  906.   #--------------------------------------------------------------------------
  907.   # ● 解放
  908.   #--------------------------------------------------------------------------
  909.   alias dispose_KMS_MiniMap dispose
  910.   def dispose
  911.     dispose_KMS_MiniMap
  912.  
  913.     dispose_minimap
  914.   end
  915.   #--------------------------------------------------------------------------
  916.   # ○ ミニマップの解放
  917.   #--------------------------------------------------------------------------
  918.   def dispose_minimap
  919.     @minimap.dispose
  920.     @minimap = nil
  921.   end
  922.   #--------------------------------------------------------------------------
  923.   # ● フレーム更新
  924.   #--------------------------------------------------------------------------
  925.   alias update_KMS_MiniMap update
  926.   def update
  927.     update_KMS_MiniMap
  928.  
  929.     update_minimap
  930.   end
  931.   #--------------------------------------------------------------------------
  932.   # ○ ミニマップ更新
  933.   #--------------------------------------------------------------------------
  934.   def minimap_show?
  935.     return $game_map.minimap_show? && $game_system.minimap_show
  936.   end
  937.   #--------------------------------------------------------------------------
  938.   # ○ ミニマップ更新
  939.   #--------------------------------------------------------------------------
  940.   def update_minimap
  941.     return if @minimap.nil?
  942.  
  943.     # 表示切替
  944.     if minimap_show?
  945.       @minimap.visible = true
  946.     else
  947.       @minimap.visible = false
  948.       return
  949.     end
  950.  
  951.     # フェード判定
  952.     case $game_map.minimap_fade
  953.     when Game_Map::MINIMAP_FADE_IN
  954.       @minimap.fadein
  955.       $game_map.minimap_fade = Game_Map::MINIMAP_FADE_NONE
  956.     when Game_Map::MINIMAP_FADE_OUT
  957.       @minimap.fadeout
  958.       $game_map.minimap_fade = Game_Map::MINIMAP_FADE_NONE
  959.     end
  960.  
  961.     @minimap.update
  962.   end
  963.   #--------------------------------------------------------------------------
  964.   # ○ ミニマップ全体をリフレッシュ
  965.   #--------------------------------------------------------------------------
  966.   def refresh_minimap
  967.     return if @minimap.nil?
  968.  
  969.     @minimap.clear_passage_table_cache
  970.     @minimap.refresh
  971.   end
  972.   #--------------------------------------------------------------------------
  973.   # ○ ミニマップのオブジェクトを更新
  974.   #--------------------------------------------------------------------------
  975.   def update_minimap_object
  976.     @minimap.update_object_list unless @minimap.nil?
  977.   end
  978. end
  979.  
  980. #==============================================================================
  981. # ■ Scene_Map
  982. #==============================================================================
  983.  
  984. class Scene_Map
  985.   #--------------------------------------------------------------------------
  986.   # ● 场所移动後の処理
  987.   #--------------------------------------------------------------------------
  988.   alias post_transfer_KMS_MiniMap post_transfer
  989.   def post_transfer
  990.     refresh_minimap
  991.  
  992.     post_transfer_KMS_MiniMap
  993.   end
  994.   #--------------------------------------------------------------------------
  995.   # ○ ミニマップ全体をリフレッシュ
  996.   #--------------------------------------------------------------------------
  997.   def refresh_minimap
  998.     @spriteset.refresh_minimap unless @spriteset.nil?
  999.   end
  1000.   #--------------------------------------------------------------------------
  1001.   # ○ ミニマップのオブジェクトを更新
  1002.   #--------------------------------------------------------------------------
  1003.   def update_minimap_object
  1004.     @spriteset.update_minimap_object unless @spriteset.nil?
  1005.   end
  1006. end


匹配规则可以参考这里
RUBY 代码复制
  1. class Game_Event < Game_Character
  2.   #--------------------------------------------------------------------------
  3.   # ○ ミニマップ用のキャッシュを作成
  4.   #--------------------------------------------------------------------------
  5.   def __create_minimap_cache
  6.     @__last_page = @page
  7.     @__minimap_wall_event  = false
  8.     @__minimap_move_event  = false
  9.     @__minimap_object_type = -1
  10.     return if @page.nil?
  11.     return if move_event_judge
  12.     return if object_type_judge
  13.   end
  14.   #--------------------------------------------------------------------------
  15.   # ○ 移动事件判定(存在201号解释器事件)
  16.   #--------------------------------------------------------------------------  
  17.   def move_event_judge
  18.     @__minimap_move_event = @page.graphic.character_name == "" &&
  19.                               @page.list.any? { |eve| eve.code == 201 }
  20.   end
  21.   #--------------------------------------------------------------------------
  22.   # ○ 其他类型事件判定
  23.   #--------------------------------------------------------------------------  
  24.   def object_type_judge
  25.     return true if is_actor_event == 1
  26.     return true if is_door_event == 3 || is_switch_event == 3
  27.     return true if is_close_chest_event == 2
  28.     return false
  29.   end
  30.   #--------------------------------------------------------------------------
  31.   # ○ 角色类事件判定(自定义图块仅支持纯数字文件 例如 1.png)
  32.   #--------------------------------------------------------------------------  
  33.   def is_actor_event
  34.     pattren = /(Actor|Animal|Behavior|Damage|
  35.           Evil|Insane|Monster|People|Riding|Spiritual)|(^\d+$)/
  36.  
  37.     @__minimap_object_type = (@page.graphic.character_name =~ pattren ? 1 : -1)
  38.   end
  39.   #--------------------------------------------------------------------------
  40.   # ○ 门类事件判定(这个仅适用范围很小)
  41.   #--------------------------------------------------------------------------
  42.   def is_door_event
  43.     gra = @page.graphic
  44.     @__minimap_object_type = (gra.character_name =~ /Other3/ &&
  45.                                 gra.character_index == 6 ? 3 : -1)   
  46.   end
  47.   #--------------------------------------------------------------------------
  48.   # ○ 开关类事件判定(和上面那个共用一种颜色)
  49.   #--------------------------------------------------------------------------  
  50.   def is_switch_event
  51.     gra = @page.graphic
  52.     @__minimap_object_type = (gra.character_name =~ /Switch/ ? 3 : -1)
  53.   end
  54.   #--------------------------------------------------------------------------
  55.   # ○ 未发现的宝箱事件判定(开启后就消失了)
  56.   #--------------------------------------------------------------------------  
  57.   def is_close_chest_event
  58.     gra = @page.graphic
  59.     @__minimap_object_type = (gra.character_name =~ /Chest/ && gra.direction == 2 ? 2 : -1)
  60.   end
  61.  
  62.   private :__create_minimap_cache


移动事件基于201号命令判断,其他时间基于事件的行走图判断,使用正则去搞它们的文件名来判断。

这样就不用使用加注释的方法标记小地图了,不过需要小心使用图块...

原始地图
小地图效果

评分

参与人数 5星屑 +145 收起 理由
火烧兔子 + 10 塞糖
菜鸟飞呀飞 + 45
喵kano + 15 精品文章
子弹君 + 60 加油w
喜阳阳 + 15 精品文章

查看全部评分

Lv2.观梦者 (暗夜天使)

卑微的梦

梦石
0
星屑
511
在线时间
820 小时
注册时间
2013-2-23
帖子
1185

短篇九勇士组季军

2
发表于 2014-6-17 21:47:43 | 只看该作者
嘛,挺不错的,加油↖(^ω^)↗
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1881
在线时间
414 小时
注册时间
2012-7-30
帖子
82
3
发表于 2014-6-18 19:55:42 | 只看该作者
能不能默认不显示小地图?现在一进新游戏就打开地图了
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1322
在线时间
831 小时
注册时间
2007-12-25
帖子
1558
4
发表于 2014-6-18 23:00:11 | 只看该作者
高手!人性化机器。
不过有一点就是应该添加反规则方式。即在制作过程中,难免遇到特殊情况这些情况与你默认的规则不和。
作者应预留一种方式来应对!

点评

moy
咦,你还活着啊,好久不见/w\  发表于 2014-6-18 23:23
精卫赤龙腾   
总是存在一种强大,去完成似乎不可能的事情.
无畏战乾程   
或是需要一种勇气,去挑战几乎不存在的胜利.
一味玄真魂     
这是拥有一种恒心,去化解根本没有解的困难.
烈卫开天径    
只是带着一种决心,去争取残存的最后的希望。
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
23 小时
注册时间
2010-12-6
帖子
6
5
 楼主| 发表于 2014-6-19 12:46:10 | 只看该作者
duoduo1009215 发表于 2014-6-18 19:55
能不能默认不显示小地图?现在一进新游戏就打开地图了

206行附近@minimap_manual_visible = true  改成false就可以了
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
23 小时
注册时间
2010-12-6
帖子
6
6
 楼主| 发表于 2014-6-19 13:16:25 | 只看该作者
九夜神尊 发表于 2014-6-18 23:00
高手!人性化机器。
不过有一点就是应该添加反规则方式。即在制作过程中,难免遇到特殊情况这些情况与你默 ...

修改了一下,反规则是在事件的第一行处添加注释<hide>或者<事件隐藏>,这样该事件就不会再小地图中显示了。



RUBY 代码复制
  1. #_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
  2. #_/    ◆ 迷你地图 - KMS_MiniMap ◆ VX Ace ◆
  3. #_/    ◇ Last update : 2012/02/12  (TOMY@Kamesoft) ◇
  4. #_/----------------------------------------------------------------------------
  5. #_/  追加迷你地图表示机能。
  6. #_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
  7.  
  8. #==============================================================================
  9. # ★ 设定项目 - BEGIN Setting ★
  10. #==============================================================================
  11.  
  12. module KMS_MiniMap
  13.   # ◆ 迷你地图表示切换按键
  14.   #  空白则按钮转换无效。
  15.   SWITCH_BUTTON = :F5
  16.  
  17.   # ◆ 迷你地图表示位置和大小 (X, Y, 寛, 高)
  18.   MAP_RECT = Rect.new(Graphics.width / 8,
  19.                       Graphics.height / 8,
  20.                       Graphics.width / 4 * 3,
  21.                       Graphics.height / 4 * 3)
  22.   # ◆ 迷你地图 Z 座标
  23.   #  注意:太大可能影响其他东西。
  24.   MAP_Z = 0
  25.   # ◆ 1格大小
  26.   # 推荐 3 以上。
  27.   GRID_SIZE = 8
  28.  
  29.   # ◆ 迷你地图顔色
  30.   FOREGROUND_COLOR = Color.new(192, 192, 224, 160)  # 前景色 (通行可)
  31.   BACKGROUND_COLOR = Color.new(  0,   0, 160, 160)  # 背景色 (通行不可)
  32.   POSITION_COLOR   = Color.new(255,   0,   0, 192)  # 现在位置
  33.   MOVE_EVENT_COLOR = Color.new(255, 160,   0, 192)  # 地图移动事件
  34.   VEHICLE_COLOR    = Color.new( 96, 128,   0, 192)  # 载物
  35.  
  36.   # ◆ 物件顔色
  37.   #  按顺序OBJ1, OBJ2,... 对应。
  38.   OBJECT_COLOR = [
  39.     Color.new(  0, 128,   0, 192),  # OBJ 1
  40.     Color.new(  0, 160, 160, 192),  # OBJ 2
  41.     Color.new(160,   0, 160, 192),  # OBJ 3
  42.     Color.new(218, 112, 214, 192),
  43.   ]  # ← 这个]不能消去!
  44.  
  45.   # ◆ 图标的闪烁强度
  46.   # 推荐 5 ~ 8 之间。
  47.   BLINK_LEVEL = 7
  48.  
  49.   # ◆ 地图缓存的数量
  50.   #  超越这个数的话,会删除长期间没参照东西。
  51.   CACHE_NUM = 10
  52. end
  53.  
  54. #==============================================================================
  55. # ☆ 设定完成 - END Setting ☆
  56. #==============================================================================
  57.  
  58. $kms_imported = {} if $kms_imported == nil
  59. $kms_imported["MiniMap"] = true
  60.  
  61. module KMS_MiniMap
  62.   # 迷你地图非表示
  63.   REGEX_NO_MINIMAP_NOTE = /<(?:ミニマップ|MINIMAP)\s*(?:非表示|HIDE)>/i
  64.   REGEX_NO_MINIMAP_NAME = /\[NOMAP\]/i
  65.  
  66.   # 障害物
  67.   REGEX_WALL_EVENT = /<(?:ミニマップ|MINIMAP)\s*(?:壁|障害物|WALL)>/i
  68.  
  69.   # 移动事件
  70.   REGEX_MOVE_EVENT = /<(?:ミニマップ|MINIMAP)\s*(?:移动|MOVE)>/i
  71.  
  72.   # 物件
  73.   REGEX_OBJECT = /<(?:ミニマップ|MINIMAP)\s+OBJ(?:ECT)?\s*(\d+)>/i
  74. end
  75.  
  76. # *****************************************************************************
  77.  
  78. #==============================================================================
  79. # □ KMS_Commands
  80. #==============================================================================
  81.  
  82. module KMS_Commands
  83.   module_function
  84.   #--------------------------------------------------------------------------
  85.   # ○ 表示迷你地图
  86.   #--------------------------------------------------------------------------
  87.   def show_minimap
  88.     $game_temp.minimap_manual_visible = true
  89.     $game_system.minimap_show         = true
  90.   end
  91.   #--------------------------------------------------------------------------
  92.   # ○ 不表示迷你地图
  93.   #--------------------------------------------------------------------------
  94.   def hide_minimap
  95.     $game_system.minimap_show = false
  96.   end
  97.   #--------------------------------------------------------------------------
  98.   # ○ 迷你地图表示状态取得
  99.   #--------------------------------------------------------------------------
  100.   def minimap_showing?
  101.     return $game_system.minimap_show
  102.   end
  103.   #--------------------------------------------------------------------------
  104.   # ○ 刷新迷你地图
  105.   #--------------------------------------------------------------------------
  106.   def refresh_minimap
  107.     return unless SceneManager.scene_is?(Scene_Map)
  108.  
  109.     $game_map.refresh if $game_map.need_refresh
  110.     SceneManager.scene.refresh_minimap
  111.   end
  112.   #--------------------------------------------------------------------------
  113.   # ○ 更新迷你地图对象
  114.   #--------------------------------------------------------------------------
  115.   def update_minimap_object
  116.     return unless SceneManager.scene_is?(Scene_Map)
  117.  
  118.     $game_map.refresh if $game_map.need_refresh
  119.     SceneManager.scene.update_minimap_object
  120.   end
  121. end
  122.  
  123. #==============================================================================
  124. # ■ Game_Interpreter
  125. #==============================================================================
  126.  
  127. class Game_Interpreter
  128.   # 事件指令:直接處理指令
  129.   include KMS_Commands
  130. end
  131.  
  132. #==============================================================================
  133. # ■ RPG::Map
  134. #==============================================================================
  135.  
  136. class RPG::Map
  137.   #--------------------------------------------------------------------------
  138.   # ○ 生成迷你地图缓存
  139.   #--------------------------------------------------------------------------
  140.   def create_minimap_cache
  141.     @__minimap_show = true
  142.  
  143.     note.each_line { |line|
  144.       if line =~ KMS_MiniMap::REGEX_NO_MINIMAP_NOTE  # マップ非表示
  145.         @__minimap_show = false
  146.       end
  147.     }
  148.   end
  149.   #--------------------------------------------------------------------------
  150.   # ○ 表示迷你地图
  151.   #--------------------------------------------------------------------------
  152.   def minimap_show?
  153.     create_minimap_cache if @__minimap_show.nil?
  154.     return @__minimap_show
  155.   end
  156. end
  157.  
  158. #==============================================================================
  159. # ■ RPG::MapInfo
  160. #==============================================================================
  161.  
  162. class RPG::MapInfo
  163.   #--------------------------------------------------------------------------
  164.   # ● 地图名取得
  165.   #--------------------------------------------------------------------------
  166.   def name
  167.     return @name.gsub(/\[.*\]/) { "" }
  168.   end
  169.   #--------------------------------------------------------------------------
  170.   # ○ 取得原始地图名
  171.   #--------------------------------------------------------------------------
  172.   def original_name
  173.     return @name
  174.   end
  175.   #--------------------------------------------------------------------------
  176.   # ○ 生成迷你地图缓存
  177.   #--------------------------------------------------------------------------
  178.   def create_minimap_cache
  179.     @__minimap_show = !(@name =~ KMS_MiniMap::REGEX_NO_MINIMAP_NAME)
  180.   end
  181.   #--------------------------------------------------------------------------
  182.   # ○ 表示迷你地图
  183.   #--------------------------------------------------------------------------
  184.   def minimap_show?
  185.     create_minimap_cache if @__minimap_show == nil
  186.     return @__minimap_show
  187.   end
  188. end
  189.  
  190. #==============================================================================
  191. # ■ Game_Temp
  192. #==============================================================================
  193.  
  194. class Game_Temp
  195.   #--------------------------------------------------------------------------
  196.   # ○ 公共实例变量
  197.   #--------------------------------------------------------------------------
  198.   attr_accessor :minimap_manual_visible  # 手动切换小地图显示标志
  199.   #--------------------------------------------------------------------------
  200.   # ○ 对象初始化
  201.   #--------------------------------------------------------------------------
  202.   alias initialize_KMS_MiniMap initialize
  203.   def initialize
  204.     initialize_KMS_MiniMap
  205.  
  206.     @minimap_manual_visible = false
  207.   end
  208. end
  209.  
  210. #==============================================================================
  211. # ■ Game_System
  212. #==============================================================================
  213.  
  214. class Game_System
  215.   #--------------------------------------------------------------------------
  216.   # ○ 公开インスタンス変数
  217.   #--------------------------------------------------------------------------
  218.   attr_accessor :minimap_show  # 迷你地图显示标志
  219.   #--------------------------------------------------------------------------
  220.   # ○ 对象初始化
  221.   #--------------------------------------------------------------------------
  222.   alias initialize_KMS_MiniMap initialize
  223.   def initialize
  224.     initialize_KMS_MiniMap
  225.  
  226.     @minimap_show = true
  227.   end
  228. end
  229.  
  230. #==============================================================================
  231. # ■ Game_Map
  232. #==============================================================================
  233.  
  234. class Game_Map
  235.   #--------------------------------------------------------------------------
  236.   # ○ 定数
  237.   #--------------------------------------------------------------------------
  238.   MINIMAP_FADE_NONE = 0  # ミニマップ フェードなし
  239.   MINIMAP_FADE_IN   = 1  # ミニマップ フェードイン
  240.   MINIMAP_FADE_OUT  = 2  # ミニマップ フェードアウト
  241.   #--------------------------------------------------------------------------
  242.   # ○ 公开インスタンス変数
  243.   #--------------------------------------------------------------------------
  244.   attr_accessor :minimap_fade
  245.   #--------------------------------------------------------------------------
  246.   # ○ ミニマップを表示するか
  247.   #--------------------------------------------------------------------------
  248.   def minimap_show?
  249.     return $data_mapinfos[map_id].minimap_show? && @map.minimap_show?
  250.   end
  251.   #--------------------------------------------------------------------------
  252.   # ○ ミニマップをフェードイン
  253.   #--------------------------------------------------------------------------
  254.   def fadein_minimap
  255.     @minimap_fade = MINIMAP_FADE_IN
  256.   end
  257.   #--------------------------------------------------------------------------
  258.   # ○ ミニマップをフェードアウト
  259.   #--------------------------------------------------------------------------
  260.   def fadeout_minimap
  261.     @minimap_fade = MINIMAP_FADE_OUT
  262.   end
  263.   #--------------------------------------------------------------------------
  264.   # ● リフレッシュ
  265.   #--------------------------------------------------------------------------
  266.   alias refresh_KMS_MiniMap refresh
  267.   def refresh
  268.     refresh_KMS_MiniMap
  269.  
  270.     SceneManager.scene.refresh_minimap if SceneManager.scene_is?(Scene_Map)
  271.   end
  272. end
  273.  
  274. #==============================================================================
  275. # ■ Game_Event
  276. #==============================================================================
  277.  
  278. class Game_Event < Game_Character
  279.   #--------------------------------------------------------------------------
  280.   # ○ ミニマップ用のキャッシュを作成
  281.   #--------------------------------------------------------------------------
  282.   def __create_minimap_cache
  283.     @__last_page = @page
  284.     @__minimap_wall_event  = false
  285.     @__minimap_move_event  = false
  286.     @__minimap_object_type = -1
  287.     return if @page.nil?
  288.     return if special_judge
  289.     return if move_event_judge
  290.     return if object_type_judge
  291.   end
  292.   #--------------------------------------------------------------------------
  293.   # ○ 反规则,取消事件着色处理
  294.   #--------------------------------------------------------------------------  
  295.   def special_judge
  296.     @page.list[0] &&
  297.       @page.list[0].code == 108 &&
  298.       @page.list[0].parameters[0] =~ /(<hide>|<事件隐藏>)/ ? true : false
  299.   end
  300.   #--------------------------------------------------------------------------
  301.   # ○ 移动事件判定(存在201号解释器事件)
  302.   #--------------------------------------------------------------------------  
  303.   def move_event_judge
  304.     @__minimap_move_event = @page.graphic.character_name == "" &&
  305.                               @page.list.any? { |eve| eve.code == 201 }
  306.   end
  307.   #--------------------------------------------------------------------------
  308.   # ○ 其他类型事件判定
  309.   #--------------------------------------------------------------------------  
  310.   def object_type_judge
  311.     return true if is_actor_event == 1
  312.     return true if is_door_event == 3 || is_switch_event == 3
  313.     return true if is_close_chest_event == 2
  314.     return false
  315.   end
  316.   #--------------------------------------------------------------------------
  317.   # ○ 角色类事件判定(自定义图块仅支持纯数字文件 例如 1.png)
  318.   #--------------------------------------------------------------------------  
  319.   def is_actor_event
  320.     pattren = /(Actor|Animal|Behavior|Damage|
  321.           Evil|Insane|Monster|People|Riding|Spiritual)|(^\d+$)/
  322.  
  323.     @__minimap_object_type = (@page.graphic.character_name =~ pattren ? 1 : -1)
  324.   end
  325.   #--------------------------------------------------------------------------
  326.   # ○ 门类事件判定(这个仅适用范围很小)
  327.   #--------------------------------------------------------------------------
  328.   def is_door_event
  329.     gra = @page.graphic
  330.     @__minimap_object_type = (gra.character_name =~ /Other3/ &&
  331.                                 gra.character_index == 6 ? 3 : -1)   
  332.   end
  333.   #--------------------------------------------------------------------------
  334.   # ○ 开关类事件判定(和上面那个共用一种颜色)
  335.   #--------------------------------------------------------------------------  
  336.   def is_switch_event
  337.     gra = @page.graphic
  338.     @__minimap_object_type = (gra.character_name =~ /Switch/ ? 3 : -1)
  339.   end
  340.   #--------------------------------------------------------------------------
  341.   # ○ 未发现的宝箱事件判定(开启后就消失了)
  342.   #--------------------------------------------------------------------------  
  343.   def is_close_chest_event
  344.     gra = @page.graphic
  345.     @__minimap_object_type = (gra.character_name =~ /Chest/ && gra.direction == 2 ? 2 : -1)
  346.   end
  347.  
  348.   private :__create_minimap_cache
  349.   #--------------------------------------------------------------------------
  350.   # ○ グラフィックがあるか
  351.   #--------------------------------------------------------------------------
  352.   def graphic_exist?
  353.     return (character_name != "" || tile_id > 0)
  354.   end
  355.   #--------------------------------------------------------------------------
  356.   # ○ 障害物か
  357.   #--------------------------------------------------------------------------
  358.   def is_minimap_wall_event?
  359.     if @__minimap_wall_event.nil? || @__last_page != @page
  360.       __create_minimap_cache
  361.     end
  362.  
  363.     return @__minimap_wall_event
  364.   end
  365.   #--------------------------------------------------------------------------
  366.   # ○ 移动イベントか
  367.   #--------------------------------------------------------------------------
  368.   def is_minimap_move_event?
  369.     if @__minimap_move_event.nil? || @__last_page != @page
  370.       __create_minimap_cache
  371.     end
  372.  
  373.     return @__minimap_move_event
  374.   end
  375.   #--------------------------------------------------------------------------
  376.   # ○ ミニマップオブジェクトか
  377.   #--------------------------------------------------------------------------
  378.   def is_minimap_object?
  379.     if @__minimap_object_type.nil? || @__last_page != @page
  380.       __create_minimap_cache
  381.     end
  382.  
  383.     return @__minimap_object_type > 0
  384.   end
  385.   #--------------------------------------------------------------------------
  386.   # ○ ミニマップオブジェクトタイプ
  387.   #--------------------------------------------------------------------------
  388.   def minimap_object_type
  389.     if @__minimap_object_type.nil? || @__last_page != @page
  390.       __create_minimap_cache
  391.     end
  392.  
  393.     return @__minimap_object_type
  394.   end
  395. end
  396.  
  397. #==============================================================================
  398. # □ Game_MiniMap
  399. #------------------------------------------------------------------------------
  400. #   ミニマップを扱うクラスです。
  401. #==============================================================================
  402.  
  403. class Game_MiniMap
  404.   #--------------------------------------------------------------------------
  405.   # ○ 构造体
  406.   #--------------------------------------------------------------------------
  407.   Point = Struct.new(:x, :y)
  408.   Size  = Struct.new(:width, :height)
  409.   PassageCache = Struct.new(:map_id, :table, :scan_table)
  410.   #--------------------------------------------------------------------------
  411.   # ○ クラス変数
  412.   #--------------------------------------------------------------------------
  413.   @@passage_cache = []  # 通行フラグテーブルキャッシュ
  414.   #--------------------------------------------------------------------------
  415.   # ● オブジェクト初期化
  416.   #--------------------------------------------------------------------------
  417.   def initialize(tilemap)
  418.     @map_rect  = KMS_MiniMap::MAP_RECT
  419.     @grid_size = [KMS_MiniMap::GRID_SIZE, 1].max
  420.  
  421.     @x = 0
  422.     @y = 0
  423.     @grid_num = Point.new(
  424.       (@map_rect.width  + @grid_size - 1) / @grid_size,
  425.       (@map_rect.height + @grid_size - 1) / @grid_size
  426.     )
  427.     @draw_grid_num    = Point.new(@grid_num.x + 2, @grid_num.y + 2)
  428.     @draw_range_begin = Point.new(0, 0)
  429.     @draw_range_end   = Point.new(0, 0)
  430.     @tilemap = tilemap
  431.  
  432.     @last_x = $game_player.x
  433.     @last_y = $game_player.y
  434.  
  435.     @showing = false
  436.     @hiding  = false
  437.  
  438.     create_sprites
  439.     refresh
  440.  
  441.     unless $game_temp.minimap_manual_visible
  442.       self.opacity = 0
  443.     end
  444.   end
  445.   #--------------------------------------------------------------------------
  446.   # ○ スプライト作成
  447.   #--------------------------------------------------------------------------
  448.   def create_sprites
  449.     @viewport   = Viewport.new(@map_rect)
  450.     @viewport.z = KMS_MiniMap::MAP_Z
  451.  
  452.     # ビットマップサイズ计算
  453.     @bmp_size = Size.new(
  454.       (@grid_num.x + 2) * @grid_size,
  455.       (@grid_num.y + 2) * @grid_size
  456.     )
  457.     @buf_bitmap = Bitmap.new(@bmp_size.width, @bmp_size.height)
  458.  
  459.     # マップ用スプライト作成
  460.     @map_sprite   = Sprite.new(@viewport)
  461.     @map_sprite.x = -@grid_size
  462.     @map_sprite.y = -@grid_size
  463.     @map_sprite.z = 0
  464.     @map_sprite.bitmap = Bitmap.new(@bmp_size.width, @bmp_size.height)
  465.  
  466.     # オブジェクト用スプライト作成
  467.     @object_sprite   = Sprite_MiniMapIcon.new(@viewport)
  468.     @object_sprite.x = -@grid_size
  469.     @object_sprite.y = -@grid_size
  470.     @object_sprite.z = 1
  471.     @object_sprite.bitmap = Bitmap.new(@bmp_size.width, @bmp_size.height)
  472.  
  473.     # 现在位置スプライト作成
  474.     @position_sprite   = Sprite_MiniMapIcon.new
  475.     @position_sprite.x = @map_rect.x + @grid_num.x / 2 * @grid_size
  476.     @position_sprite.y = @map_rect.y + @grid_num.y / 2 * @grid_size
  477.     @position_sprite.z = @viewport.z + 2
  478.     bitmap = Bitmap.new(@grid_size, @grid_size)
  479.     bitmap.fill_rect(bitmap.rect, KMS_MiniMap::POSITION_COLOR)
  480.     @position_sprite.bitmap = bitmap
  481.   end
  482.   #--------------------------------------------------------------------------
  483.   # ● 解放
  484.   #--------------------------------------------------------------------------
  485.   def dispose
  486.     @buf_bitmap.dispose
  487.     @map_sprite.bitmap.dispose
  488.     @map_sprite.dispose
  489.     @object_sprite.bitmap.dispose
  490.     @object_sprite.dispose
  491.     @position_sprite.bitmap.dispose
  492.     @position_sprite.dispose
  493.     @viewport.dispose
  494.   end
  495.   #--------------------------------------------------------------------------
  496.   # ○ 可视状态取得
  497.   #--------------------------------------------------------------------------
  498.   def visible
  499.     return @map_sprite.visible
  500.   end
  501.   #--------------------------------------------------------------------------
  502.   # ○ 可视状态设定
  503.   #--------------------------------------------------------------------------
  504.   def visible=(value)
  505.     @viewport.visible        = value
  506.     @map_sprite.visible      = value
  507.     @object_sprite.visible   = value
  508.     @position_sprite.visible = value
  509.   end
  510.   #--------------------------------------------------------------------------
  511.   # ○ 不透明度取得
  512.   #--------------------------------------------------------------------------
  513.   def opacity
  514.     return @map_sprite.opacity
  515.   end
  516.   #--------------------------------------------------------------------------
  517.   # ○ 不透明度设定
  518.   #--------------------------------------------------------------------------
  519.   def opacity=(value)
  520.     @map_sprite.opacity      = value
  521.     @object_sprite.opacity   = value
  522.     @position_sprite.opacity = value
  523.   end
  524.   #--------------------------------------------------------------------------
  525.   # ○ リフレッシュ
  526.   #--------------------------------------------------------------------------
  527.   def refresh
  528.     update_draw_range
  529.     update_passage_table
  530.     update_object_list
  531.     update_position
  532.     draw_map
  533.     draw_object
  534.     Graphics.frame_reset
  535.   end
  536.   #--------------------------------------------------------------------------
  537.   # ○ フェードイン
  538.   #--------------------------------------------------------------------------
  539.   def fadein
  540.     @showing = true
  541.     @hiding  = false
  542.   end
  543.   #--------------------------------------------------------------------------
  544.   # ○ フェードアウト
  545.   #--------------------------------------------------------------------------
  546.   def fadeout
  547.     @showing = false
  548.     @hiding  = true
  549.   end
  550.   #--------------------------------------------------------------------------
  551.   # ○ キー入力更新
  552.   #--------------------------------------------------------------------------
  553.   def update_input
  554.     return if KMS_MiniMap::SWITCH_BUTTON.nil?
  555.  
  556.     if Input.trigger?(KMS_MiniMap::SWITCH_BUTTON)
  557.       if opacity < 255 && !@showing
  558.         $game_temp.minimap_manual_visible = true
  559.         fadein
  560.       elsif opacity > 0 && !@hiding
  561.         $game_temp.minimap_manual_visible = false
  562.         fadeout
  563.       end
  564.     end
  565.   end
  566.   #--------------------------------------------------------------------------
  567.   # ○ 描画范囲更新
  568.   #--------------------------------------------------------------------------
  569.   def update_draw_range
  570.     range = []
  571.     (2).times { |i| range[i] = @draw_grid_num[i] / 2 }
  572.  
  573.     @draw_range_begin.x = $game_player.x - range[0]
  574.     @draw_range_begin.y = $game_player.y - range[1]
  575.     @draw_range_end.x   = $game_player.x + range[0]
  576.     @draw_range_end.y   = $game_player.y + range[1]
  577.   end
  578.   #--------------------------------------------------------------------------
  579.   # ○ 通行可否テーブル更新
  580.   #--------------------------------------------------------------------------
  581.   def update_passage_table
  582.     cache = get_passage_table_cache
  583.     @passage_table      = cache.table
  584.     @passage_scan_table = cache.scan_table
  585.  
  586.     update_around_passage_table
  587.   end
  588.   #--------------------------------------------------------------------------
  589.   # ○ 通行可否テーブルのキャッシュを取得
  590.   #--------------------------------------------------------------------------
  591.   def get_passage_table_cache
  592.     map_id = $game_map.map_id
  593.     cache  = @@passage_cache.find { |c| c.map_id == map_id }
  594.  
  595.     # キャッシュミスしたら新规作成
  596.     if cache == nil
  597.       cache = PassageCache.new(map_id)
  598.       cache.table      = Table.new($game_map.width, $game_map.height)
  599.       cache.scan_table = Table.new(
  600.         ($game_map.width  + @draw_grid_num.x - 1) / @draw_grid_num.x,
  601.         ($game_map.height + @draw_grid_num.y - 1) / @draw_grid_num.y
  602.       )
  603.     end
  604.  
  605.     # 直近のキャッシュは先头に移动し、古いキャッシュは削除
  606.     @@passage_cache.unshift(cache)
  607.     @@passage_cache.delete_at(KMS_MiniMap::CACHE_NUM)
  608.  
  609.     return cache
  610.   end
  611.   #--------------------------------------------------------------------------
  612.   # ○ 通行可否テーブルのキャッシュをクリア
  613.   #--------------------------------------------------------------------------
  614.   def clear_passage_table_cache
  615.     return if @passage_scan_table == nil
  616.  
  617.     table = @passage_scan_table
  618.     @passage_scan_table = Table.new(table.xsize, table.ysize)
  619.   end
  620.   #--------------------------------------------------------------------------
  621.   # ○ 通行可否テーブルの探索
  622.   #     x, y : 探索位置
  623.   #--------------------------------------------------------------------------
  624.   def scan_passage(x, y)
  625.     dx = x / @draw_grid_num.x
  626.     dy = y / @draw_grid_num.y
  627.  
  628.     # 探索済み
  629.     return if @passage_scan_table[dx, dy] == 1
  630.  
  631.     # マップ范囲外
  632.     return unless dx.between?(0, @passage_scan_table.xsize - 1)
  633.     return unless dy.between?(0, @passage_scan_table.ysize - 1)
  634.  
  635.     rx = (dx * @draw_grid_num.x)...((dx + 1) * @draw_grid_num.x)
  636.     ry = (dy * @draw_grid_num.y)...((dy + 1) * @draw_grid_num.y)
  637.     mw = $game_map.width  - 1
  638.     mh = $game_map.height - 1
  639.  
  640.     # 探索范囲内の通行テーブルを生成
  641.     rx.each { |x|
  642.       next unless x.between?(0, mw)
  643.       ry.each { |y|
  644.         next unless y.between?(0, mh)
  645.  
  646.         # 通行方向フラグ作成
  647.         # (↓、←、→、↑ の顺に 1, 2, 4, 8 が対応)
  648.         flag = 0
  649.         [2, 4, 6, 8].each{ |d|
  650.           flag |= 1 << (d / 2 - 1) if $game_map.passable?(x, y, d)
  651.         }
  652.         @passage_table[x, y] = flag
  653.       }
  654.     }
  655.     @passage_scan_table[dx, dy] = 1
  656.   end
  657.   #--------------------------------------------------------------------------
  658.   # ○ 周辺の通行可否テーブル更新
  659.   #--------------------------------------------------------------------------
  660.   def update_around_passage_table
  661.     gx = @draw_grid_num.x
  662.     gy = @draw_grid_num.y
  663.     dx = $game_player.x - gx / 2
  664.     dy = $game_player.y - gy / 2
  665.     scan_passage(dx,      dy)
  666.     scan_passage(dx + gx, dy)
  667.     scan_passage(dx,      dy + gy)
  668.     scan_passage(dx + gx, dy + gy)
  669.   end
  670.   #--------------------------------------------------------------------------
  671.   # ○ オブジェクト一覧更新
  672.   #--------------------------------------------------------------------------
  673.   def update_object_list
  674.     events = $game_map.events.values
  675.  
  676.     # WALL
  677.     @wall_events = events.find_all { |e| e.is_minimap_wall_event? }
  678.  
  679.     # MOVE
  680.     @move_events = events.find_all { |e| e.is_minimap_move_event? }
  681.  
  682.     # OBJ
  683.     @object_list = events.find_all { |e| e.is_minimap_object? }
  684.   end
  685.   #--------------------------------------------------------------------------
  686.   # ○ 位置更新
  687.   #--------------------------------------------------------------------------
  688.   def update_position
  689.     # 移动量算出
  690.     pt = Point.new($game_player.x, $game_player.y)
  691.     ox = ($game_player.real_x - pt.x) * @grid_size
  692.     oy = ($game_player.real_y - pt.y) * @grid_size
  693.  
  694.     @viewport.ox = ox
  695.     @viewport.oy = oy
  696.  
  697.     # 移动していたらマップ再描画
  698.     if pt.x != @last_x || pt.y != @last_y
  699.       draw_map
  700.       @last_x = pt.x
  701.       @last_y = pt.y
  702.     end
  703.   end
  704.   #--------------------------------------------------------------------------
  705.   # ○ 描画范囲内判定
  706.   #--------------------------------------------------------------------------
  707.   def in_draw_range?(x, y)
  708.     rb = @draw_range_begin
  709.     re = @draw_range_end
  710.     return (x.between?(rb.x, re.x) && y.between?(rb.y, re.y))
  711.   end
  712.   #--------------------------------------------------------------------------
  713.   # ○ マップ范囲内判定
  714.   #--------------------------------------------------------------------------
  715.   def in_map_range?(x, y)
  716.     mw = $game_map.width
  717.     mh = $game_map.height
  718.     return (x.between?(0, mw - 1) && y.between?(0, mh - 1))
  719.   end
  720.   #--------------------------------------------------------------------------
  721.   # ○ マップ描画
  722.   #--------------------------------------------------------------------------
  723.   def draw_map
  724.     update_around_passage_table
  725.  
  726.     bitmap  = @map_sprite.bitmap
  727.     bitmap.fill_rect(bitmap.rect, KMS_MiniMap::BACKGROUND_COLOR)
  728.  
  729.     draw_map_foreground(bitmap)
  730.     draw_map_move_event(bitmap)
  731.   end
  732.   #--------------------------------------------------------------------------
  733.   # ○ 通行可能领域の描画
  734.   #--------------------------------------------------------------------------
  735.   def draw_map_foreground(bitmap)
  736.     range_x = (@draw_range_begin.x)..(@draw_range_end.x)
  737.     range_y = (@draw_range_begin.y)..(@draw_range_end.y)
  738.     map_w   = $game_map.width  - 1
  739.     map_h   = $game_map.height - 1
  740.     rect    = Rect.new(0, 0, @grid_size, @grid_size)
  741.  
  742.     range_x.each { |x|
  743.       next unless x.between?(0, map_w)
  744.       range_y.each { |y|
  745.         next unless y.between?(0, map_h)
  746.         next if @passage_table[x, y] == 0
  747.         next if @wall_events.find { |e| e.x == x && e.y == y }  # 壁
  748.  
  749.         # グリッド描画サイズ算出
  750.         rect.set(0, 0, @grid_size, @grid_size)
  751.         rect.x = (x - @draw_range_begin.x) * @grid_size
  752.         rect.y = (y - @draw_range_begin.y) * @grid_size
  753.         flag = @passage_table[x, y]
  754.         if flag & 0x01 == 0  # 下通行不能
  755.           rect.height -= 1
  756.         end
  757.         if flag & 0x02 == 0  # 左通行不能
  758.           rect.x     += 1
  759.           rect.width -= 1
  760.         end
  761.         if flag & 0x04 == 0  # 右通行不能
  762.           rect.width -= 1
  763.         end
  764.         if flag & 0x08 == 0  # 上通行不能
  765.           rect.y      += 1
  766.           rect.height -= 1
  767.         end
  768.         bitmap.fill_rect(rect, KMS_MiniMap::FOREGROUND_COLOR)
  769.       }
  770.     }
  771.   end
  772.   #--------------------------------------------------------------------------
  773.   # ○ 移动イベントの描画
  774.   #--------------------------------------------------------------------------
  775.   def draw_map_move_event(bitmap)
  776.     rect = Rect.new(0, 0, @grid_size, @grid_size)
  777.     @move_events.each { |e|
  778.       rect.x = (e.x - @draw_range_begin.x) * @grid_size
  779.       rect.y = (e.y - @draw_range_begin.y) * @grid_size
  780.       bitmap.fill_rect(rect, KMS_MiniMap::MOVE_EVENT_COLOR)
  781.     }
  782.   end
  783.   #--------------------------------------------------------------------------
  784.   # ○ アニメーション更新
  785.   #--------------------------------------------------------------------------
  786.   def update_animation
  787.     if @showing
  788.       # フェードイン
  789.       self.opacity += 16
  790.       if opacity == 255
  791.         @showing = false
  792.       end
  793.     elsif @hiding
  794.       # フェードアウト
  795.       self.opacity -= 16
  796.       if opacity == 0
  797.         @hiding = false
  798.       end
  799.     end
  800.   end
  801.   #--------------------------------------------------------------------------
  802.   # ○ オブジェクト描画
  803.   #--------------------------------------------------------------------------
  804.   def draw_object
  805.     # 下准备
  806.     bitmap = @object_sprite.bitmap
  807.     bitmap.clear
  808.     rect = Rect.new(0, 0, @grid_size, @grid_size)
  809.  
  810.     # オブジェクト描画
  811.     @object_list.each { |obj|
  812.       next unless in_draw_range?(obj.x, obj.y)
  813.  
  814.       color = KMS_MiniMap::OBJECT_COLOR[obj.minimap_object_type - 1]
  815.       next if color.nil?
  816.  
  817.       rect.x = (obj.real_x - @draw_range_begin.x) * @grid_size
  818.       rect.y = (obj.real_y - @draw_range_begin.y) * @grid_size
  819.       bitmap.fill_rect(rect, color)
  820.     }
  821.  
  822.     # 乗り物描画
  823.     $game_map.vehicles.each { |vehicle|
  824.       next if vehicle.transparent
  825.  
  826.       rect.x = (vehicle.real_x - @draw_range_begin.x) * @grid_size
  827.       rect.y = (vehicle.real_y - @draw_range_begin.y) * @grid_size
  828.       bitmap.fill_rect(rect, KMS_MiniMap::VEHICLE_COLOR)
  829.     }
  830.   end
  831.   #--------------------------------------------------------------------------
  832.   # ○ 更新
  833.   #--------------------------------------------------------------------------
  834.   def update
  835.     update_input
  836.  
  837.     return unless need_update?
  838.  
  839.     update_draw_range
  840.     update_position
  841.     update_animation
  842.     draw_object
  843.  
  844.     @map_sprite.update
  845.     @object_sprite.update
  846.     @position_sprite.update
  847.   end
  848.   #--------------------------------------------------------------------------
  849.   # ○ 更新判定
  850.   #--------------------------------------------------------------------------
  851.   def need_update?
  852.     return (visible && opacity > 0) || @showing || @hiding
  853.   end
  854. end
  855.  
  856. #==============================================================================
  857. # □ Sprite_MiniMapIcon
  858. #------------------------------------------------------------------------------
  859. #   ミニマップ用アイコンのクラスです。
  860. #==============================================================================
  861.  
  862. class Sprite_MiniMapIcon < Sprite
  863.   DURATION_MAX = 60
  864.   #--------------------------------------------------------------------------
  865.   # ● オブジェクト初期化
  866.   #     viewport : ビューポート
  867.   #--------------------------------------------------------------------------
  868.   def initialize(viewport = nil)
  869.     super(viewport)
  870.     @duration = DURATION_MAX / 2
  871.   end
  872.   #--------------------------------------------------------------------------
  873.   # ● フレーム更新
  874.   #--------------------------------------------------------------------------
  875.   def update
  876.     super
  877.     @duration += 1
  878.     if @duration == DURATION_MAX
  879.       @duration = 0
  880.     end
  881.     update_effect
  882.   end
  883.   #--------------------------------------------------------------------------
  884.   # ○ エフェクトの更新
  885.   #--------------------------------------------------------------------------
  886.   def update_effect
  887.     self.color.set(255, 255, 255,
  888.       (@duration - DURATION_MAX / 2).abs * KMS_MiniMap::BLINK_LEVEL
  889.     )
  890.   end
  891. end
  892.  
  893. #==============================================================================
  894. # ■ Spriteset_Map
  895. #==============================================================================
  896.  
  897. class Spriteset_Map
  898.   attr_reader :minimap
  899.   #--------------------------------------------------------------------------
  900.   # ● オブジェクト初期化
  901.   #--------------------------------------------------------------------------
  902.   alias initialize_KMS_MiniMap initialize
  903.   def initialize
  904.     initialize_KMS_MiniMap
  905.  
  906.     create_minimap
  907.   end
  908.   #--------------------------------------------------------------------------
  909.   # ○ ミニマップの作成
  910.   #--------------------------------------------------------------------------
  911.   def create_minimap
  912.     @minimap = Game_MiniMap.new(@tilemap)
  913.     @minimap.visible = $game_system.minimap_show && $game_map.minimap_show?
  914.   end
  915.   #--------------------------------------------------------------------------
  916.   # ● 解放
  917.   #--------------------------------------------------------------------------
  918.   alias dispose_KMS_MiniMap dispose
  919.   def dispose
  920.     dispose_KMS_MiniMap
  921.  
  922.     dispose_minimap
  923.   end
  924.   #--------------------------------------------------------------------------
  925.   # ○ ミニマップの解放
  926.   #--------------------------------------------------------------------------
  927.   def dispose_minimap
  928.     @minimap.dispose
  929.     @minimap = nil
  930.   end
  931.   #--------------------------------------------------------------------------
  932.   # ● フレーム更新
  933.   #--------------------------------------------------------------------------
  934.   alias update_KMS_MiniMap update
  935.   def update
  936.     update_KMS_MiniMap
  937.  
  938.     update_minimap
  939.   end
  940.   #--------------------------------------------------------------------------
  941.   # ○ ミニマップ更新
  942.   #--------------------------------------------------------------------------
  943.   def minimap_show?
  944.     return $game_map.minimap_show? && $game_system.minimap_show
  945.   end
  946.   #--------------------------------------------------------------------------
  947.   # ○ ミニマップ更新
  948.   #--------------------------------------------------------------------------
  949.   def update_minimap
  950.     return if @minimap.nil?
  951.  
  952.     # 表示切替
  953.     if minimap_show?
  954.       @minimap.visible = true
  955.     else
  956.       @minimap.visible = false
  957.       return
  958.     end
  959.  
  960.     # フェード判定
  961.     case $game_map.minimap_fade
  962.     when Game_Map::MINIMAP_FADE_IN
  963.       @minimap.fadein
  964.       $game_map.minimap_fade = Game_Map::MINIMAP_FADE_NONE
  965.     when Game_Map::MINIMAP_FADE_OUT
  966.       @minimap.fadeout
  967.       $game_map.minimap_fade = Game_Map::MINIMAP_FADE_NONE
  968.     end
  969.  
  970.     @minimap.update
  971.   end
  972.   #--------------------------------------------------------------------------
  973.   # ○ ミニマップ全体をリフレッシュ
  974.   #--------------------------------------------------------------------------
  975.   def refresh_minimap
  976.     return if @minimap.nil?
  977.  
  978.     @minimap.clear_passage_table_cache
  979.     @minimap.refresh
  980.   end
  981.   #--------------------------------------------------------------------------
  982.   # ○ ミニマップのオブジェクトを更新
  983.   #--------------------------------------------------------------------------
  984.   def update_minimap_object
  985.     @minimap.update_object_list unless @minimap.nil?
  986.   end
  987. end
  988.  
  989. #==============================================================================
  990. # ■ Scene_Map
  991. #==============================================================================
  992.  
  993. class Scene_Map
  994.   #--------------------------------------------------------------------------
  995.   # ● 场所移动後の処理
  996.   #--------------------------------------------------------------------------
  997.   alias post_transfer_KMS_MiniMap post_transfer
  998.   def post_transfer
  999.     refresh_minimap
  1000.  
  1001.     post_transfer_KMS_MiniMap
  1002.   end
  1003.   #--------------------------------------------------------------------------
  1004.   # ○ ミニマップ全体をリフレッシュ
  1005.   #--------------------------------------------------------------------------
  1006.   def refresh_minimap
  1007.     @spriteset.refresh_minimap unless @spriteset.nil?
  1008.   end
  1009.   #--------------------------------------------------------------------------
  1010.   # ○ ミニマップのオブジェクトを更新
  1011.   #--------------------------------------------------------------------------
  1012.   def update_minimap_object
  1013.     @spriteset.update_minimap_object unless @spriteset.nil?
  1014.   end
  1015. end


添加范例
效果图,那个龙怪物不显示了
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
1322
在线时间
831 小时
注册时间
2007-12-25
帖子
1558
7
发表于 2014-6-19 20:11:56 | 只看该作者
真奥丁炮 发表于 2014-6-19 13:16
修改了一下,反规则是在事件的第一行处添加注释或者,这样该事件就不会再小地图中显示了。

接着说:
第一行注释的方法虽然也可以,但是使用第一行注释的脚本也不在少数,如果都用上了,是把你的改成第二行呢,还是把他的改成第二行呢?是找你呢,还是怎么办呢?
有一个村子,这里的人都受到诅咒,变成动物一般形状。
然后很无耻的放一个自己的脚本。
https://rpg.blue/thread-158742-1-2.html
精卫赤龙腾   
总是存在一种强大,去完成似乎不可能的事情.
无畏战乾程   
或是需要一种勇气,去挑战几乎不存在的胜利.
一味玄真魂     
这是拥有一种恒心,去化解根本没有解的困难.
烈卫开天径    
只是带着一种决心,去争取残存的最后的希望。
回复 支持 反对

使用道具 举报

Lv1.梦旅人

萌萌的小笼包

梦石
0
星屑
50
在线时间
193 小时
注册时间
2012-4-30
帖子
652
8
发表于 2014-7-21 15:51:28 | 只看该作者
弱弱的问下,打开小地图后,能否背景变成黑屏
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-6-13 18:21

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表