Project1

标题: 关于限制主角在地图上的移动范围 [打印本页]

作者: sumaoxian123456    时间: 2022-2-13 17:05
标题: 关于限制主角在地图上的移动范围
想请教一下,如何实现在一张大地图上,让主角只能在当前画面大小的区域内移动?
做的是个动作游戏,想做一个遇到boss了就锁定在当前区域,不能跑出去,只能强行战斗的系统。
作者: 任小雪    时间: 2022-2-13 17:46
并行,开关
与空气墙这种设定了解一下
作者: alexncf125    时间: 2022-2-13 18:18
插入以下脚本后, 打开3号及4号开关
  1. #==============================================================================
  2. # ★スクロール禁止 ver1.0 by USK
  3. #------------------------------------------------------------------------------
  4. # ・特定のスイッチがオンのときスクロールを禁止します。
  5. #==============================================================================
  6. =begin
  7. ・21行目のFixDisplayFlagVで設定した番号のスイッチがオンのとき
  8.   縦スクロールが禁止されます。
  9. ・22行目のFixDisplayFlagHで設定した番号のスイッチがオンのとき
  10.   横スクロールが禁止されます。
  11. =end

  12. #==============================================================================
  13. # ■ Game_Map
  14. #==============================================================================

  15. class Game_Map
  16.   #--------------------------------------------------------------------------
  17.   # ● 設定
  18.   #--------------------------------------------------------------------------
  19.   FixDisplayFlagV = 3 #禁止Y轴卷动的开关编号
  20.   FixDisplayFlagH = 4 #禁止X轴卷动的开关编号
  21.   #--------------------------------------------------------------------------
  22.   # ●
  23.   #--------------------------------------------------------------------------
  24.   alias :fix_display_scroll_down  :scroll_down
  25.   alias :fix_display_scroll_left  :scroll_left
  26.   alias :fix_display_scroll_right :scroll_right
  27.   alias :fix_display_scroll_up    :scroll_up
  28.   alias :fix_display_refresh      :refresh
  29.   alias :fix_display_valid?       :valid?
  30.   #--------------------------------------------------------------------------
  31.   # ●
  32.   #--------------------------------------------------------------------------
  33.   def fix_display?
  34.     $game_switches[FixDisplayFlagV] || $game_switches[FixDisplayFlagH]
  35.   end
  36.   #--------------------------------------------------------------------------
  37.   # ●
  38.   #--------------------------------------------------------------------------
  39.   def need_centering?
  40.     ret = !fix_display? &&
  41.           SceneManager.scene.is_a?(Scene_Map) &&
  42.           @on_fix_display
  43.     @on_fix_display = fix_display?
  44.     ret
  45.   end
  46.   #--------------------------------------------------------------------------
  47.   # ●
  48.   #--------------------------------------------------------------------------
  49.   def centering
  50.     div = 20
  51.     x = @display_x
  52.     dx = $game_player.x - (Graphics.width / 32 - 1) / 2.0 - x
  53.     dx /= div
  54.     y = @display_y
  55.     dy = $game_player.y - (Graphics.height / 32 - 1) / 2.0 - y
  56.     dy /= div
  57.     div.times do
  58.       set_display_pos(x, y)
  59.       x += dx
  60.       y += dy
  61.       scene = SceneManager.scene
  62.       scene.update_basic
  63.       scene.instance_variable_get(:@spriteset).update
  64.     end
  65.   end
  66.   #--------------------------------------------------------------------------
  67.   # ● リフレッシュ
  68.   #--------------------------------------------------------------------------
  69.   def refresh
  70.     centering if need_centering?
  71.     fix_display_refresh
  72.   end
  73.   #--------------------------------------------------------------------------
  74.   # ● 下にスクロール
  75.   #--------------------------------------------------------------------------
  76.   def scroll_down(distance)
  77.     fix_display_scroll_down(distance) unless $game_switches[FixDisplayFlagV]
  78.   end
  79.   #--------------------------------------------------------------------------
  80.   # ● 左にスクロール
  81.   #--------------------------------------------------------------------------
  82.   def scroll_left(distance)
  83.     fix_display_scroll_left(distance) unless $game_switches[FixDisplayFlagH]
  84.   end
  85.   #--------------------------------------------------------------------------
  86.   # ● 右にスクロール
  87.   #--------------------------------------------------------------------------
  88.   def scroll_right(distance)
  89.     fix_display_scroll_right(distance) unless $game_switches[FixDisplayFlagH]
  90.   end
  91.   #--------------------------------------------------------------------------
  92.   # ● 上にスクロール
  93.   #--------------------------------------------------------------------------
  94.   def scroll_up(distance)
  95.     fix_display_scroll_up(distance) unless $game_switches[FixDisplayFlagV]
  96.   end
  97.   #--------------------------------------------------------------------------
  98.   # ● 有効座標判定
  99.   #--------------------------------------------------------------------------
  100.   def valid?(x, y)
  101.     ret = fix_display_valid?(x, y)
  102.     if $game_switches[FixDisplayFlagV]
  103.       ret &&= y >= @display_y && y < @display_y + (Graphics.height >> 5)
  104.     end
  105.     if $game_switches[FixDisplayFlagH]
  106.       ret &&= x >= @display_x && x < @display_x + (Graphics.width >> 5)
  107.     end
  108.     ret
  109.   end
  110. end
复制代码

作者: sumaoxian123456    时间: 2022-2-13 21:07
任小雪 发表于 2022-2-13 17:46
并行,开关
与空气墙这种设定了解一下

对哦,这个不错,作为事件党来说是个好方案,谢谢。
作者: sumaoxian123456    时间: 2022-2-13 21:08
alexncf125 发表于 2022-2-13 18:18
插入以下脚本后, 打开3号及4号开关

好的,非常感谢!我去试试!




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