查看: 1827|回复: 0

显示地图通行度

[复制链接]

…あたしは天

梦石
0
星屑
2311
在线时间
4033 小时
注册时间
2010-10-4
回帖
10548

开拓者贵宾

发表于 2014-6-14 18:37:03 | 显示全部楼层 |阅读模式

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

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

×
本帖最后由 taroxd 于 2015-2-18 12:50 编辑

  1. #--------------------------------------------------------------------------
  2. # ● require Taroxd基础设置,修复bug
  3. #    使用方法:游戏测试中按下F6即可启用,再按一次关闭
  4. #--------------------------------------------------------------------------

  5. class Taroxd::PlanePassage < Plane

  6.   ENABLE = $TEST                       # 是否启用功能
  7.   KEY = :F6                            # 控制显示通行度的按键
  8.   VISIBLE = false                      # 起始时是否可见
  9.   OPACITY = 150                        # 不透明度
  10.   NG = Color.new(255, 0, 0, OPACITY)   # 不可通行的颜色
  11.   OK = Color.new(0, 0, 255, OPACITY)   # 可以通行的颜色
  12.   NG_WIDTH = 4                         # 不可通行方向显示的宽度

  13.   include Taroxd::DisposeBitmap
  14.   include Taroxd::BugFix::PlaneVisible

  15.   def initialize(_)
  16.     super
  17.     self.visible = VISIBLE
  18.     self.z = 200
  19.     refresh
  20.     update
  21.   end

  22.   def update
  23.     self.visible ^= true if Input.trigger?(KEY)
  24.     self.ox = $game_map.display_x * 32
  25.     self.oy = $game_map.display_y * 32
  26.   end

  27.   def refresh
  28.     bitmap.dispose if bitmap
  29.     self.bitmap = Bitmap.new($game_map.width * 32, $game_map.height * 32)
  30.     $game_map.width.times do |x|
  31.       $game_map.height.times do |y|
  32.         draw_point(x, y)
  33.       end
  34.     end
  35.   end

  36.   # 绘制地图上的点 (x, y)
  37.   def draw_point(x, y)
  38.     ng_dirs = [2, 4, 6, 8].reject { |d| $game_map.passable?(x, y, d) }
  39.     if ng_dirs.size == 4
  40.       bitmap.fill_rect(x * 32, y * 32, 32, 32, NG)
  41.       return
  42.     end
  43.     bitmap.fill_rect(x * 32, y * 32, 32, 32, OK)
  44.     ng_dirs.each do |d|
  45.       dx = d == 6 ? 32 - NG_WIDTH : 0
  46.       dy = d == 2 ? 32 - NG_WIDTH : 0
  47.       if d == 2 || d == 8
  48.         width  = 32
  49.         height = NG_WIDTH
  50.       else
  51.         width  = NG_WIDTH
  52.         height = 32
  53.       end
  54.       bitmap.fill_rect(x * 32 + dx, y * 32 + dy, width, height, NG)
  55.     end
  56.   end
  57. end

  58. class Spriteset_Map
  59.   def_before :create_parallax do
  60.     @passage_plane = Taroxd::PlanePassage.new(@viewport3)
  61.   end
  62.   def_before(:update_parallax)    { @passage_plane.update  }
  63.   def_before(:refresh_characters) { @passage_plane.refresh }
  64.   def_before(:dispose_parallax)   { @passage_plane.dispose }
  65. end if Taroxd::PlanePassage::ENABLE
复制代码

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本发帖返回顶部