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

Project1

 找回密码
 注册会员
搜索
查看: 2299|回复: 4

[已经解决] 请教下迷你地图脚本的问题

[复制链接]

Lv2.观梦者

梦石
0
星屑
453
在线时间
33 小时
注册时间
2017-10-4
帖子
38
发表于 2020-5-17 19:55:46 | 显示全部楼层 |阅读模式

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

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

x
  1. #_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
  2. #_/    ◆ 迷你地图 - KMS_MiniMap ◆ VX Ace ◆
  3. #_/    ◇ Last update : 2012/02/12  (TOMY@Kamesoft) ◇
  4. #_/----------------------------------------------------------------------------
  5. #_/  追加迷你地图表示机能。
  6. #_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

  7. #==============================================================================
  8. # ★ 设定项目 - BEGIN Setting ★
  9. #==============================================================================

  10. module KMS_MiniMap
  11.   # ◆ 迷你地图表示切换按键
  12.   #  空白则按钮转换无效。
  13.   SWITCH_BUTTON =

  14.   # ◆ 迷你地图表示位置和大小 (X, Y, 寛, 高)
  15.   MAP_RECT = Rect.new(0, 0, 544, 416)
  16.   # ◆ 迷你地图 Z 座标
  17.   #  注意:太大可能影响其他东西。
  18.   MAP_Z = 0
  19.   # ◆ 1格大小
  20.   # 推荐 3 以上。
  21.   GRID_SIZE = 3

  22.   # ◆ 迷你地图顔色
  23.   FOREGROUND_COLOR = Color.new(255, 255, 255, 255)  # 前景色 (通行可)
  24.   BACKGROUND_COLOR = Color.new(  0,   0, 0, 255)  # 背景色 (通行不可)
  25.   POSITION_COLOR   = Color.new(255,   0,   0, 192)  # 现在位置
  26.   MOVE_EVENT_COLOR = Color.new(255, 160,   0, 192)  # 地图移动事件
  27.   VEHICLE_COLOR    = Color.new( 0, 255,   0, 192)  # 载物

  28.   # ◆ 物件顔色
  29.   #  按顺序OBJ1, OBJ2,... 对应。
  30.   OBJECT_COLOR = [
  31.     Color.new(  0, 128,   0, 192),  # OBJ 1
  32.     Color.new(  0, 160, 160, 192),  # OBJ 2
  33.     Color.new(160,   0, 160, 192),  # OBJ 3
  34.   ]  # ← 这个]不能消去!

  35.   # ◆ 图标的闪烁强度
  36.   # 推荐 5 ~ 8 之间。
  37.   BLINK_LEVEL = 7

  38.   # ◆ 地图缓存的数量
  39.   #  超越这个数的话,会删除长期间没参照东西。
  40.   CACHE_NUM = 10
  41. end

  42. #==============================================================================
  43. # ☆ 设定完成 - END Setting ☆
  44. #==============================================================================

  45. $kms_imported = {} if $kms_imported == nil
  46. $kms_imported["MiniMap"] = true

  47. module KMS_MiniMap
  48.   # 迷你地图非表示
  49.   REGEX_NO_MINIMAP_NOTE = /<(?:ミニマップ|MINIMAP)\s*(?:非表示|HIDE)>/i
  50.   REGEX_NO_MINIMAP_NAME = /\[NOMAP\]/i

  51.   # 障害物
  52.   REGEX_WALL_EVENT = /<(?:ミニマップ|MINIMAP)\s*(?:壁|障害物|WALL)>/i

  53.   # 移动事件
  54.   REGEX_MOVE_EVENT = /<(?:ミニマップ|MINIMAP)\s*(?:移动|MOVE)>/i

  55.   # 物件
  56.   REGEX_OBJECT = /<(?:ミニマップ|MINIMAP)\s+OBJ(?:ECT)?\s*(\d+)>/i
  57. end

  58. # *****************************************************************************

  59. #==============================================================================
  60. # □ KMS_Commands
  61. #==============================================================================

  62. module KMS_Commands
  63.   module_function
  64.   #--------------------------------------------------------------------------
  65.   # ○ 表示迷你地图
  66.   #--------------------------------------------------------------------------
  67.   def show_minimap
  68.     $game_temp.minimap_manual_visible = true
  69.     $game_system.minimap_show         = true
  70.   end
  71.   #--------------------------------------------------------------------------
  72.   # ○ 不表示迷你地图
  73.   #--------------------------------------------------------------------------
  74.   def hide_minimap
  75.     $game_system.minimap_show = false
  76.   end
  77.   #--------------------------------------------------------------------------
  78.   # ○ 迷你地图表示状态取得
  79.   #--------------------------------------------------------------------------
  80.   def minimap_showing?
  81.     return $game_system.minimap_show
  82.   end
  83.   #--------------------------------------------------------------------------
  84.   # ○ 刷新迷你地图
  85.   #--------------------------------------------------------------------------
  86.   def refresh_minimap
  87.     return unless SceneManager.scene_is?(Scene_Map)

  88.     $game_map.refresh if $game_map.need_refresh
  89.     SceneManager.scene.refresh_minimap
  90.   end
  91.   #--------------------------------------------------------------------------
  92.   # ○ 更新迷你地图对象
  93.   #--------------------------------------------------------------------------
  94.   def update_minimap_object
  95.     return unless SceneManager.scene_is?(Scene_Map)

  96.     $game_map.refresh if $game_map.need_refresh
  97.     SceneManager.scene.update_minimap_object
  98.   end
  99. end

  100. #==============================================================================
  101. # ■ Game_Interpreter
  102. #==============================================================================

  103. class Game_Interpreter
  104.   # 事件指令:直接處理指令
  105.   include KMS_Commands
  106. end

  107. #==============================================================================
  108. # ■ RPG::Map
  109. #==============================================================================

  110. class RPG::Map
  111.   #--------------------------------------------------------------------------
  112.   # ○ 生成迷你地图缓存
  113.   #--------------------------------------------------------------------------
  114.   def create_minimap_cache
  115.     @__minimap_show = true

  116.     note.each_line { |line|
  117.       if line =~ KMS_MiniMap::REGEX_NO_MINIMAP_NOTE  # マップ非表示
  118.         @__minimap_show = false
  119.       end
  120.     }
  121.   end
  122.   #--------------------------------------------------------------------------
  123.   # ○ 表示迷你地图
  124.   #--------------------------------------------------------------------------
  125.   def minimap_show?
  126.     create_minimap_cache if @__minimap_show.nil?
  127.     return @__minimap_show
  128.   end
  129. end

  130. #==============================================================================
  131. # ■ RPG::MapInfo
  132. #==============================================================================

  133. class RPG::MapInfo
  134.   #--------------------------------------------------------------------------
  135.   # ● 地图名取得
  136.   #--------------------------------------------------------------------------
  137.   def name
  138.     return @name.gsub(/\[.*\]/) { "" }
  139.   end
  140.   #--------------------------------------------------------------------------
  141.   # ○ 取得原始地图名
  142.   #--------------------------------------------------------------------------
  143.   def original_name
  144.     return @name
  145.   end
  146.   #--------------------------------------------------------------------------
  147.   # ○ 生成迷你地图缓存
  148.   #--------------------------------------------------------------------------
  149.   def create_minimap_cache
  150.     @__minimap_show = !(@name =~ KMS_MiniMap::REGEX_NO_MINIMAP_NAME)
  151.   end
  152.   #--------------------------------------------------------------------------
  153.   # ○ 表示迷你地图
  154.   #--------------------------------------------------------------------------
  155.   def minimap_show?
  156.     create_minimap_cache if @__minimap_show == nil
  157.     return @__minimap_show
  158.   end
  159. end

  160. #==============================================================================
  161. # ■ Game_Temp
  162. #==============================================================================

  163. class Game_Temp
  164.   #--------------------------------------------------------------------------
  165.   # ○ 公共实例变量
  166.   #--------------------------------------------------------------------------
  167.   attr_accessor :minimap_manual_visible  # 手动切换小地图显示标志
  168.   #--------------------------------------------------------------------------
  169.   # ○ 对象初始化
  170.   #--------------------------------------------------------------------------
  171.   alias initialize_KMS_MiniMap initialize
  172.   def initialize
  173.     initialize_KMS_MiniMap

  174.     @minimap_manual_visible = false
  175.   end
  176. end

  177. #==============================================================================
  178. # ■ Game_System
  179. #==============================================================================

  180. class Game_System
  181.   #--------------------------------------------------------------------------
  182.   # ○ 公开インスタンス変数
  183.   #--------------------------------------------------------------------------
  184.   attr_accessor :minimap_show  # 迷你地图显示标志
  185.   #--------------------------------------------------------------------------
  186.   # ○ 对象初始化
  187.   #--------------------------------------------------------------------------
  188.   alias initialize_KMS_MiniMap initialize
  189.   def initialize
  190.     initialize_KMS_MiniMap

  191.     @minimap_show = true
  192.   end
  193. end

  194. #==============================================================================
  195. # ■ Game_Map
  196. #==============================================================================

  197. class Game_Map
  198.   #--------------------------------------------------------------------------
  199.   # ○ 定数
  200.   #--------------------------------------------------------------------------
  201.   MINIMAP_FADE_NONE = 0  # ミニマップ フェードなし
  202.   MINIMAP_FADE_IN   = 1  # ミニマップ フェードイン
  203.   MINIMAP_FADE_OUT  = 2  # ミニマップ フェードアウト
  204.   #--------------------------------------------------------------------------
  205.   # ○ 公开インスタンス変数
  206.   #--------------------------------------------------------------------------
  207.   attr_accessor :minimap_fade
  208.   #--------------------------------------------------------------------------
  209.   # ○ ミニマップを表示するか
  210.   #--------------------------------------------------------------------------
  211.   def minimap_show?
  212.     return $data_mapinfos[map_id].minimap_show? && @map.minimap_show?
  213.   end
  214.   #--------------------------------------------------------------------------
  215.   # ○ ミニマップをフェードイン
  216.   #--------------------------------------------------------------------------
  217.   def fadein_minimap
  218.     @minimap_fade = MINIMAP_FADE_IN
  219.   end
  220.   #--------------------------------------------------------------------------
  221.   # ○ ミニマップをフェードアウト
  222.   #--------------------------------------------------------------------------
  223.   def fadeout_minimap
  224.     @minimap_fade = MINIMAP_FADE_OUT
  225.   end
  226.   #--------------------------------------------------------------------------
  227.   # ● リフレッシュ
  228.   #--------------------------------------------------------------------------
  229.   alias refresh_KMS_MiniMap refresh
  230.   def refresh
  231.     refresh_KMS_MiniMap

  232.     SceneManager.scene.refresh_minimap if SceneManager.scene_is?(Scene_Map)
  233.   end
  234. end

  235. #==============================================================================
  236. # ■ Game_Event
  237. #==============================================================================

  238. class Game_Event < Game_Character
  239.   #--------------------------------------------------------------------------
  240.   # ○ ミニマップ用のキャッシュを作成
  241.   #--------------------------------------------------------------------------
  242.   def __create_minimap_cache
  243.     @__last_page = @page
  244.     @__minimap_wall_event  = false
  245.     @__minimap_move_event  = false
  246.     @__minimap_object_type = -1

  247.     return if @page.nil?

  248.     @page.list.each { |cmd|
  249.       # 注釈以外に到达したら离脱
  250.       break unless [108, 408].include?(cmd.code)

  251.       # 正规表现判定
  252.       case cmd.parameters[0]
  253.       when KMS_MiniMap::REGEX_WALL_EVENT
  254.         @__minimap_wall_event = true
  255.       when KMS_MiniMap::REGEX_MOVE_EVENT
  256.         @__minimap_move_event = true
  257.       when KMS_MiniMap::REGEX_OBJECT
  258.         @__minimap_object_type = $1.to_i
  259.       end
  260.     }
  261.   end
  262.   private :__create_minimap_cache
  263.   #--------------------------------------------------------------------------
  264.   # ○ グラフィックがあるか
  265.   #--------------------------------------------------------------------------
  266.   def graphic_exist?
  267.     return (character_name != "" || tile_id > 0)
  268.   end
  269.   #--------------------------------------------------------------------------
  270.   # ○ 障害物か
  271.   #--------------------------------------------------------------------------
  272.   def is_minimap_wall_event?
  273.     if @__minimap_wall_event.nil? || @__last_page != @page
  274.       __create_minimap_cache
  275.     end

  276.     return @__minimap_wall_event
  277.   end
  278.   #--------------------------------------------------------------------------
  279.   # ○ 移动イベントか
  280.   #--------------------------------------------------------------------------
  281.   def is_minimap_move_event?
  282.     if @__minimap_move_event.nil? || @__last_page != @page
  283.       __create_minimap_cache
  284.     end

  285.     return @__minimap_move_event
  286.   end
  287.   #--------------------------------------------------------------------------
  288.   # ○ ミニマップオブジェクトか
  289.   #--------------------------------------------------------------------------
  290.   def is_minimap_object?
  291.     if @__minimap_object_type.nil? || @__last_page != @page
  292.       __create_minimap_cache
  293.     end

  294.     return @__minimap_object_type > 0
  295.   end
  296.   #--------------------------------------------------------------------------
  297.   # ○ ミニマップオブジェクトタイプ
  298.   #--------------------------------------------------------------------------
  299.   def minimap_object_type
  300.     if @__minimap_object_type.nil? || @__last_page != @page
  301.       __create_minimap_cache
  302.     end

  303.     return @__minimap_object_type
  304.   end
  305. end

  306. #==============================================================================
  307. # □ Game_MiniMap
  308. #------------------------------------------------------------------------------
  309. #   ミニマップを扱うクラスです。
  310. #==============================================================================

  311. class Game_MiniMap
  312.   #--------------------------------------------------------------------------
  313.   # ○ 构造体
  314.   #--------------------------------------------------------------------------
  315.   Point = Struct.new(:x, :y)
  316.   Size  = Struct.new(:width, :height)
  317.   PassageCache = Struct.new(:map_id, :table, :scan_table)
  318.   #--------------------------------------------------------------------------
  319.   # ○ クラス変数
  320.   #--------------------------------------------------------------------------
  321.   @@passage_cache = []  # 通行フラグテーブルキャッシュ
  322.   #--------------------------------------------------------------------------
  323.   # ● オブジェクト初期化
  324.   #--------------------------------------------------------------------------
  325.   def initialize(tilemap)
  326.     @map_rect  = KMS_MiniMap::MAP_RECT
  327.     @grid_size = [KMS_MiniMap::GRID_SIZE, 1].max

  328.     @x = 0
  329.     @y = 0
  330.     @grid_num = Point.new(
  331.       (@map_rect.width  + @grid_size - 1) / @grid_size,
  332.       (@map_rect.height + @grid_size - 1) / @grid_size
  333.     )
  334.     @draw_grid_num    = Point.new(@grid_num.x + 2, @grid_num.y + 2)
  335.     @draw_range_begin = Point.new(0, 0)
  336.     @draw_range_end   = Point.new(0, 0)
  337.     @tilemap = tilemap

  338.     @last_x = $game_player.x
  339.     @last_y = $game_player.y

  340.     @showing = false
  341.     @hiding  = false

  342.     create_sprites
  343.     refresh

  344.     unless $game_temp.minimap_manual_visible
  345.       self.opacity = 0
  346.     end
  347.   end
  348.   #--------------------------------------------------------------------------
  349.   # ○ スプライト作成
  350.   #--------------------------------------------------------------------------
  351.   def create_sprites
  352.     @viewport   = Viewport.new(@map_rect)
  353.     @viewport.z = KMS_MiniMap::MAP_Z

  354.     # ビットマップサイズ计算
  355.     @bmp_size = Size.new(
  356.       (@grid_num.x + 2) * @grid_size,
  357.       (@grid_num.y + 2) * @grid_size
  358.     )
  359.     @buf_bitmap = Bitmap.new(@bmp_size.width, @bmp_size.height)

  360.     # マップ用スプライト作成
  361.     @map_sprite   = Sprite.new(@viewport)
  362.     @map_sprite.x = -@grid_size
  363.     @map_sprite.y = -@grid_size
  364.     @map_sprite.z = 0
  365.     @map_sprite.bitmap = Bitmap.new(@bmp_size.width, @bmp_size.height)

  366.     # オブジェクト用スプライト作成
  367.     @object_sprite   = Sprite_MiniMapIcon.new(@viewport)
  368.     @object_sprite.x = -@grid_size
  369.     @object_sprite.y = -@grid_size
  370.     @object_sprite.z = 1
  371.     @object_sprite.bitmap = Bitmap.new(@bmp_size.width, @bmp_size.height)

  372.     # 现在位置スプライト作成
  373.     @position_sprite   = Sprite_MiniMapIcon.new
  374.     @position_sprite.x = @map_rect.x + @grid_num.x / 2 * @grid_size
  375.     @position_sprite.y = @map_rect.y + @grid_num.y / 2 * @grid_size
  376.     @position_sprite.z = @viewport.z + 2
  377.     bitmap = Bitmap.new(@grid_size, @grid_size)
  378.     bitmap.fill_rect(bitmap.rect, KMS_MiniMap::POSITION_COLOR)
  379.     @position_sprite.bitmap = bitmap
  380.   end
  381.   #--------------------------------------------------------------------------
  382.   # ● 解放
  383.   #--------------------------------------------------------------------------
  384.   def dispose
  385.     @buf_bitmap.dispose
  386.     @map_sprite.bitmap.dispose
  387.     @map_sprite.dispose
  388.     @object_sprite.bitmap.dispose
  389.     @object_sprite.dispose
  390.     @position_sprite.bitmap.dispose
  391.     @position_sprite.dispose
  392.     @viewport.dispose
  393.   end
  394.   #--------------------------------------------------------------------------
  395.   # ○ 可视状态取得
  396.   #--------------------------------------------------------------------------
  397.   def visible
  398.     return @map_sprite.visible
  399.   end
  400.   #--------------------------------------------------------------------------
  401.   # ○ 可视状态设定
  402.   #--------------------------------------------------------------------------
  403.   def visible=(value)
  404.     @viewport.visible        = value
  405.     @map_sprite.visible      = value
  406.     @object_sprite.visible   = value
  407.     @position_sprite.visible = value
  408.   end
  409.   #--------------------------------------------------------------------------
  410.   # ○ 不透明度取得
  411.   #--------------------------------------------------------------------------
  412.   def opacity
  413.     return @map_sprite.opacity
  414.   end
  415.   #--------------------------------------------------------------------------
  416.   # ○ 不透明度设定
  417.   #--------------------------------------------------------------------------
  418.   def opacity=(value)
  419.     @map_sprite.opacity      = value
  420.     @object_sprite.opacity   = value
  421.     @position_sprite.opacity = value
  422.   end
  423.   #--------------------------------------------------------------------------
  424.   # ○ リフレッシュ
  425.   #--------------------------------------------------------------------------
  426.   def refresh
  427.     update_draw_range
  428.     update_passage_table
  429.     update_object_list
  430.     update_position
  431.     draw_map
  432.     draw_object
  433.     Graphics.frame_reset
  434.   end
  435.   #--------------------------------------------------------------------------
  436.   # ○ フェードイン
  437.   #--------------------------------------------------------------------------
  438.   def fadein
  439.     @showing = true
  440.     @hiding  = false
  441.   end
  442.   #--------------------------------------------------------------------------
  443.   # ○ フェードアウト
  444.   #--------------------------------------------------------------------------
  445.   def fadeout
  446.     @showing = false
  447.     @hiding  = true
  448.   end
  449.   #--------------------------------------------------------------------------
  450.   # ○ キー入力更新
  451.   #--------------------------------------------------------------------------
  452.   def update_input
  453.     return if KMS_MiniMap::SWITCH_BUTTON.nil?

  454.     if Input.trigger?(KMS_MiniMap::SWITCH_BUTTON)
  455.       if opacity < 255 && !@showing
  456.         $game_temp.minimap_manual_visible = true
  457.         fadein
  458.       elsif opacity > 0 && !@hiding
  459.         $game_temp.minimap_manual_visible = false
  460.         fadeout
  461.       end
  462.     end
  463.   end
  464.   #--------------------------------------------------------------------------
  465.   # ○ 描画范囲更新
  466.   #--------------------------------------------------------------------------
  467.   def update_draw_range
  468.     range = []
  469.     (2).times { |i| range[i] = @draw_grid_num[i] / 2 }

  470.     @draw_range_begin.x = $game_player.x - range[0]
  471.     @draw_range_begin.y = $game_player.y - range[1]
  472.     @draw_range_end.x   = $game_player.x + range[0]
  473.     @draw_range_end.y   = $game_player.y + range[1]
  474.   end
  475.   #--------------------------------------------------------------------------
  476.   # ○ 通行可否テーブル更新
  477.   #--------------------------------------------------------------------------
  478.   def update_passage_table
  479.     cache = get_passage_table_cache
  480.     @passage_table      = cache.table
  481.     @passage_scan_table = cache.scan_table

  482.     update_around_passage_table
  483.   end
  484.   #--------------------------------------------------------------------------
  485.   # ○ 通行可否テーブルのキャッシュを取得
  486.   #--------------------------------------------------------------------------
  487.   def get_passage_table_cache
  488.     map_id = $game_map.map_id
  489.     cache  = @@passage_cache.find { |c| c.map_id == map_id }

  490.     # キャッシュミスしたら新规作成
  491.     if cache == nil
  492.       cache = PassageCache.new(map_id)
  493.       cache.table      = Table.new($game_map.width, $game_map.height)
  494.       cache.scan_table = Table.new(
  495.         ($game_map.width  + @draw_grid_num.x - 1) / @draw_grid_num.x,
  496.         ($game_map.height + @draw_grid_num.y - 1) / @draw_grid_num.y
  497.       )
  498.     end

  499.     # 直近のキャッシュは先头に移动し、古いキャッシュは削除
  500.     @@passage_cache.unshift(cache)
  501.     @@passage_cache.delete_at(KMS_MiniMap::CACHE_NUM)

  502.     return cache
  503.   end
  504.   #--------------------------------------------------------------------------
  505.   # ○ 通行可否テーブルのキャッシュをクリア
  506.   #--------------------------------------------------------------------------
  507.   def clear_passage_table_cache
  508.     return if @passage_scan_table == nil

  509.     table = @passage_scan_table
  510.     @passage_scan_table = Table.new(table.xsize, table.ysize)
  511.   end
  512.   #--------------------------------------------------------------------------
  513.   # ○ 通行可否テーブルの探索
  514.   #     x, y : 探索位置
  515.   #--------------------------------------------------------------------------
  516.   def scan_passage(x, y)
  517.     dx = x / @draw_grid_num.x
  518.     dy = y / @draw_grid_num.y

  519.     # 探索済み
  520.     return if @passage_scan_table[dx, dy] == 1

  521.     # マップ范囲外
  522.     return unless dx.between?(0, @passage_scan_table.xsize - 1)
  523.     return unless dy.between?(0, @passage_scan_table.ysize - 1)

  524.     rx = (dx * @draw_grid_num.x)...((dx + 1) * @draw_grid_num.x)
  525.     ry = (dy * @draw_grid_num.y)...((dy + 1) * @draw_grid_num.y)
  526.     mw = $game_map.width  - 1
  527.     mh = $game_map.height - 1

  528.     # 探索范囲内の通行テーブルを生成
  529.     rx.each { |x|
  530.       next unless x.between?(0, mw)
  531.       ry.each { |y|
  532.         next unless y.between?(0, mh)

  533.         # 通行方向フラグ作成
  534.         # (↓、←、→、↑ の顺に 1, 2, 4, 8 が対応)
  535.         flag = 0
  536.         [2, 4, 6, 8].each{ |d|
  537.           flag |= 1 << (d / 2 - 1) if $game_map.passable?(x, y, d)
  538.         }
  539.         @passage_table[x, y] = flag
  540.       }
  541.     }
  542.     @passage_scan_table[dx, dy] = 1
  543.   end
  544.   #--------------------------------------------------------------------------
  545.   # ○ 周辺の通行可否テーブル更新
  546.   #--------------------------------------------------------------------------
  547.   def update_around_passage_table
  548.     gx = @draw_grid_num.x
  549.     gy = @draw_grid_num.y
  550.     dx = $game_player.x - gx / 2
  551.     dy = $game_player.y - gy / 2
  552.     scan_passage(dx,      dy)
  553.     scan_passage(dx + gx, dy)
  554.     scan_passage(dx,      dy + gy)
  555.     scan_passage(dx + gx, dy + gy)
  556.   end
  557.   #--------------------------------------------------------------------------
  558.   # ○ オブジェクト一覧更新
  559.   #--------------------------------------------------------------------------
  560.   def update_object_list
  561.     events = $game_map.events.values

  562.     # WALL
  563.     @wall_events = events.find_all { |e| e.is_minimap_wall_event? }

  564.     # MOVE
  565.     @move_events = events.find_all { |e| e.is_minimap_move_event? }

  566.     # OBJ
  567.     @object_list = events.find_all { |e| e.is_minimap_object? }
  568.   end
  569.   #--------------------------------------------------------------------------
  570.   # ○ 位置更新
  571.   #--------------------------------------------------------------------------
  572.   def update_position
  573.     # 移动量算出
  574.     pt = Point.new($game_player.x, $game_player.y)
  575.     ox = ($game_player.real_x - pt.x) * @grid_size
  576.     oy = ($game_player.real_y - pt.y) * @grid_size

  577.     @viewport.ox = ox
  578.     @viewport.oy = oy

  579.     # 移动していたらマップ再描画
  580.     if pt.x != @last_x || pt.y != @last_y
  581.       draw_map
  582.       @last_x = pt.x
  583.       @last_y = pt.y
  584.     end
  585.   end
  586.   #--------------------------------------------------------------------------
  587.   # ○ 描画范囲内判定
  588.   #--------------------------------------------------------------------------
  589.   def in_draw_range?(x, y)
  590.     rb = @draw_range_begin
  591.     re = @draw_range_end
  592.     return (x.between?(rb.x, re.x) && y.between?(rb.y, re.y))
  593.   end
  594.   #--------------------------------------------------------------------------
  595.   # ○ マップ范囲内判定
  596.   #--------------------------------------------------------------------------
  597.   def in_map_range?(x, y)
  598.     mw = $game_map.width
  599.     mh = $game_map.height
  600.     return (x.between?(0, mw - 1) && y.between?(0, mh - 1))
  601.   end
  602.   #--------------------------------------------------------------------------
  603.   # ○ マップ描画
  604.   #--------------------------------------------------------------------------
  605.   def draw_map
  606.     update_around_passage_table

  607.     bitmap  = @map_sprite.bitmap
  608.     bitmap.fill_rect(bitmap.rect, KMS_MiniMap::BACKGROUND_COLOR)

  609.     draw_map_foreground(bitmap)
  610.     draw_map_move_event(bitmap)
  611.   end
  612.   #--------------------------------------------------------------------------
  613.   # ○ 通行可能领域の描画
  614.   #--------------------------------------------------------------------------
  615.   def draw_map_foreground(bitmap)
  616.     range_x = (@draw_range_begin.x)..(@draw_range_end.x)
  617.     range_y = (@draw_range_begin.y)..(@draw_range_end.y)
  618.     map_w   = $game_map.width  - 1
  619.     map_h   = $game_map.height - 1
  620.     rect    = Rect.new(0, 0, @grid_size, @grid_size)

  621.     range_x.each { |x|
  622.       next unless x.between?(0, map_w)
  623.       range_y.each { |y|
  624.         next unless y.between?(0, map_h)
  625.         next if @passage_table[x, y] == 0
  626.         next if @wall_events.find { |e| e.x == x && e.y == y }  # 壁

  627.         # グリッド描画サイズ算出
  628.         rect.set(0, 0, @grid_size, @grid_size)
  629.         rect.x = (x - @draw_range_begin.x) * @grid_size
  630.         rect.y = (y - @draw_range_begin.y) * @grid_size
  631.         flag = @passage_table[x, y]
  632.         if flag & 0x01 == 0  # 下通行不能
  633.           rect.height -= 1
  634.         end
  635.         if flag & 0x02 == 0  # 左通行不能
  636.           rect.x     += 1
  637.           rect.width -= 1
  638.         end
  639.         if flag & 0x04 == 0  # 右通行不能
  640.           rect.width -= 1
  641.         end
  642.         if flag & 0x08 == 0  # 上通行不能
  643.           rect.y      += 1
  644.           rect.height -= 1
  645.         end
  646.         bitmap.fill_rect(rect, KMS_MiniMap::FOREGROUND_COLOR)
  647.       }
  648.     }
  649.   end
  650.   #--------------------------------------------------------------------------
  651.   # ○ 移动イベントの描画
  652.   #--------------------------------------------------------------------------
  653.   def draw_map_move_event(bitmap)
  654.     rect = Rect.new(0, 0, @grid_size, @grid_size)
  655.     @move_events.each { |e|
  656.       rect.x = (e.x - @draw_range_begin.x) * @grid_size
  657.       rect.y = (e.y - @draw_range_begin.y) * @grid_size
  658.       bitmap.fill_rect(rect, KMS_MiniMap::MOVE_EVENT_COLOR)
  659.     }
  660.   end
  661.   #--------------------------------------------------------------------------
  662.   # ○ アニメーション更新
  663.   #--------------------------------------------------------------------------
  664.   def update_animation
  665.     if @showing
  666.       # フェードイン
  667.       self.opacity += 16
  668.       if opacity == 255
  669.         @showing = false
  670.       end
  671.     elsif @hiding
  672.       # フェードアウト
  673.       self.opacity -= 16
  674.       if opacity == 0
  675.         @hiding = false
  676.       end
  677.     end
  678.   end
  679.   #--------------------------------------------------------------------------
  680.   # ○ オブジェクト描画
  681.   #--------------------------------------------------------------------------
  682.   def draw_object
  683.     # 下准备
  684.     bitmap = @object_sprite.bitmap
  685.     bitmap.clear
  686.     rect = Rect.new(0, 0, @grid_size, @grid_size)

  687.     # オブジェクト描画
  688.     @object_list.each { |obj|
  689.       next unless in_draw_range?(obj.x, obj.y)

  690.       color = KMS_MiniMap::OBJECT_COLOR[obj.minimap_object_type - 1]
  691.       next if color.nil?

  692.       rect.x = (obj.real_x - @draw_range_begin.x) * @grid_size
  693.       rect.y = (obj.real_y - @draw_range_begin.y) * @grid_size
  694.       bitmap.fill_rect(rect, color)
  695.     }

  696.     # 乗り物描画
  697.     $game_map.vehicles.each { |vehicle|
  698.       next if vehicle.transparent

  699.       rect.x = (vehicle.real_x - @draw_range_begin.x) * @grid_size
  700.       rect.y = (vehicle.real_y - @draw_range_begin.y) * @grid_size
  701.       bitmap.fill_rect(rect, KMS_MiniMap::VEHICLE_COLOR)
  702.     }
  703.   end
  704.   #--------------------------------------------------------------------------
  705.   # ○ 更新
  706.   #--------------------------------------------------------------------------
  707.   def update
  708.     update_input

  709.     return unless need_update?

  710.     update_draw_range
  711.     update_position
  712.     update_animation
  713.     draw_object

  714.     @map_sprite.update
  715.     @object_sprite.update
  716.     @position_sprite.update
  717.   end
  718.   #--------------------------------------------------------------------------
  719.   # ○ 更新判定
  720.   #--------------------------------------------------------------------------
  721.   def need_update?
  722.     return (visible && opacity > 0) || @showing || @hiding
  723.   end
  724. end

  725. #==============================================================================
  726. # □ Sprite_MiniMapIcon
  727. #------------------------------------------------------------------------------
  728. #   ミニマップ用アイコンのクラスです。
  729. #==============================================================================

  730. class Sprite_MiniMapIcon < Sprite
  731.   DURATION_MAX = 60
  732.   #--------------------------------------------------------------------------
  733.   # ● オブジェクト初期化
  734.   #     viewport : ビューポート
  735.   #--------------------------------------------------------------------------
  736.   def initialize(viewport = nil)
  737.     super(viewport)
  738.     @duration = DURATION_MAX / 2
  739.   end
  740.   #--------------------------------------------------------------------------
  741.   # ● フレーム更新
  742.   #--------------------------------------------------------------------------
  743.   def update
  744.     super
  745.     @duration += 1
  746.     if @duration == DURATION_MAX
  747.       @duration = 0
  748.     end
  749.     update_effect
  750.   end
  751.   #--------------------------------------------------------------------------
  752.   # ○ エフェクトの更新
  753.   #--------------------------------------------------------------------------
  754.   def update_effect
  755.     self.color.set(255, 255, 255,
  756.       (@duration - DURATION_MAX / 2).abs * KMS_MiniMap::BLINK_LEVEL
  757.     )
  758.   end
  759. end

  760. #==============================================================================
  761. # ■ Spriteset_Map
  762. #==============================================================================

  763. class Spriteset_Map
  764.   attr_reader :minimap
  765.   #--------------------------------------------------------------------------
  766.   # ● オブジェクト初期化
  767.   #--------------------------------------------------------------------------
  768.   alias initialize_KMS_MiniMap initialize
  769.   def initialize
  770.     initialize_KMS_MiniMap

  771.     create_minimap
  772.   end
  773.   #--------------------------------------------------------------------------
  774.   # ○ ミニマップの作成
  775.   #--------------------------------------------------------------------------
  776.   def create_minimap
  777.     @minimap = Game_MiniMap.new(@tilemap)
  778.     @minimap.visible = $game_system.minimap_show && $game_map.minimap_show?
  779.   end
  780.   #--------------------------------------------------------------------------
  781.   # ● 解放
  782.   #--------------------------------------------------------------------------
  783.   alias dispose_KMS_MiniMap dispose
  784.   def dispose
  785.     dispose_KMS_MiniMap

  786.     dispose_minimap
  787.   end
  788.   #--------------------------------------------------------------------------
  789.   # ○ ミニマップの解放
  790.   #--------------------------------------------------------------------------
  791.   def dispose_minimap
  792.     @minimap.dispose
  793.     @minimap = nil
  794.   end
  795.   #--------------------------------------------------------------------------
  796.   # ● フレーム更新
  797.   #--------------------------------------------------------------------------
  798.   alias update_KMS_MiniMap update
  799.   def update
  800.     update_KMS_MiniMap

  801.     update_minimap
  802.   end
  803.   #--------------------------------------------------------------------------
  804.   # ○ ミニマップ更新
  805.   #--------------------------------------------------------------------------
  806.   def minimap_show?
  807.     return $game_map.minimap_show? && $game_system.minimap_show
  808.   end
  809.   #--------------------------------------------------------------------------
  810.   # ○ ミニマップ更新
  811.   #--------------------------------------------------------------------------
  812.   def update_minimap
  813.     return if @minimap.nil?

  814.     # 表示切替
  815.     if minimap_show?
  816.       @minimap.visible = true
  817.     else
  818.       @minimap.visible = false
  819.       return
  820.     end

  821.     # フェード判定
  822.     case $game_map.minimap_fade
  823.     when Game_Map::MINIMAP_FADE_IN
  824.       @minimap.fadein
  825.       $game_map.minimap_fade = Game_Map::MINIMAP_FADE_NONE
  826.     when Game_Map::MINIMAP_FADE_OUT
  827.       @minimap.fadeout
  828.       $game_map.minimap_fade = Game_Map::MINIMAP_FADE_NONE
  829.     end

  830.     @minimap.update
  831.   end
  832.   #--------------------------------------------------------------------------
  833.   # ○ ミニマップ全体をリフレッシュ
  834.   #--------------------------------------------------------------------------
  835.   def refresh_minimap
  836.     return if @minimap.nil?

  837.     @minimap.clear_passage_table_cache
  838.     @minimap.refresh
  839.   end
  840.   #--------------------------------------------------------------------------
  841.   # ○ ミニマップのオブジェクトを更新
  842.   #--------------------------------------------------------------------------
  843.   def update_minimap_object
  844.     @minimap.update_object_list unless @minimap.nil?
  845.   end
  846. end

  847. #==============================================================================
  848. # ■ Scene_Map
  849. #==============================================================================

  850. class Scene_Map
  851.   #--------------------------------------------------------------------------
  852.   # ● 场所移动後の処理
  853.   #--------------------------------------------------------------------------
  854.   alias post_transfer_KMS_MiniMap post_transfer
  855.   def post_transfer
  856.     refresh_minimap

  857.     post_transfer_KMS_MiniMap
  858.   end
  859.   #--------------------------------------------------------------------------
  860.   # ○ ミニマップ全体をリフレッシュ
  861.   #--------------------------------------------------------------------------
  862.   def refresh_minimap
  863.     @spriteset.refresh_minimap unless @spriteset.nil?
  864.   end
  865.   #--------------------------------------------------------------------------
  866.   # ○ ミニマップのオブジェクトを更新
  867.   #--------------------------------------------------------------------------
  868.   def update_minimap_object
  869.     @spriteset.update_minimap_object unless @spriteset.nil?
  870.   end
  871. end
复制代码


想请教下,脚本中的物件颜色对应的OBJ1,OBJ2,这种是怎么设置的呢?需要单独对事件注释什么的吗?

Lv4.逐梦者

梦石
0
星屑
9617
在线时间
566 小时
注册时间
2017-9-28
帖子
208
发表于 2020-5-18 10:42:15 | 显示全部楼层
本帖最后由 hyrious 于 2020-5-18 14:17 编辑

事件注释里写 <MINIMAP OBJ 1> 就会在小地图上使用 OBJECT_COLOR 里的第一个颜色画一个方块

评分

参与人数 1星屑 +100 收起 理由
VIPArcher + 100 认可答案

查看全部评分

喵喵喵
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
453
在线时间
33 小时
注册时间
2017-10-4
帖子
38
 楼主| 发表于 2020-5-18 13:44:20 | 显示全部楼层
hyrious 发表于 2020-5-18 10:42
事件注释里写  就会在小地图上使用 OBJECT_COLOR 里的第一个颜色画一个方块

大佬,好像不行啊
QQ截图20200518134405.png
QQ截图20200518134421.png
QQ截图20200518134436.png

点评

看错了,是 <MINIMAP OBJ 1>  发表于 2020-5-18 14:16
回复 支持 反对

使用道具 举报

Lv2.观梦者

梦石
0
星屑
453
在线时间
33 小时
注册时间
2017-10-4
帖子
38
 楼主| 发表于 2020-5-18 14:20:39 | 显示全部楼层
hyrious 发表于 2020-5-18 10:42
事件注释里写  就会在小地图上使用 OBJECT_COLOR 里的第一个颜色画一个方块

谢谢大佬!!
回复 支持 反对

使用道具 举报

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

本版积分规则

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

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

GMT+8, 2024-4-19 07:52

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

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