查看: 1264|回复: 0

[地图场景相关] 【管理地图类】——区域功能扩展

[复制链接]

无限の剣制

梦石
0
星屑
10450
在线时间
5019 小时
注册时间
2013-2-28
回帖
4942

开拓者贵宾

发表于 2014-7-2 21:33:30 | 显示全部楼层 |阅读模式

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

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

×
使用方法没什么好说的,地图的备注栏各种备注
区域扩展区域扩展
  1. #==============================================================================
  2. # ■ Game_Map
  3. #------------------------------------------------------------------------------
  4. #  管理地图的类。拥有卷动地图以及判断通行度的功能。
  5. #   本类的实例请参考 $game_map 。
  6. #    添加内容:添加读取地图备注内容并更改一部分通行判定。alias:2个,新定义:2个
  7. #==============================================================================

  8. class Game_Map
  9.   #--------------------------------------------------------------------------
  10.   # ● セットアップ
  11.   #     map_id : マップ ID
  12.   #     enable : 所属レイヤーの変更
  13.   #--------------------------------------------------------------------------
  14.   alias region_effect_setup setup
  15.   def setup(map_id)
  16.     @encountwalk_region = {}
  17.     @passagechange_region = {}
  18.     @canjump_region = {}
  19.     @region_switch = {}
  20.     @forcemove_region = {}
  21.     @move_diag_region = {}
  22.     region_effect_setup(map_id)
  23.     @map.note.each_line{|line|
  24.     case line
  25.     when /\<(?:遇敌步数更改|ENCOUNTWALK_REGION)[ ]**(\d+)(?:\,(\d+))*\>/
  26.       @encountwalk_region[$1.to_i] = $2 == nil ? 0 : $2.to_i
  27.     when /\<(?:更改通行区域|PASSAGECHANGE_REGION)[ ]*(\d+)(?:\,(\d+))*\>/
  28.       push_passage_region($1.to_i,$2)
  29.     when /\<(?:可跳跃区域|JUMP_REGION)[ ]*(\d+)(?:\,([2468]+))*\>/
  30.       push_jump_region($1.to_i,$2)
  31.     when /\<(?:区域开关|REGION_SWITCH)[ ]*(\d+)(?:\,(\d+))*\>/
  32.       @region_switch[$1.to_i] = $2.to_i
  33.     when /\<(?:强制移动区域|FORCEMOVE_REGION)[ ]*(\d+)(?:\,([2468]+))*\>/
  34.       @forcemove_region[$1.to_i] = $2.to_i
  35.     when /\<(?:斜向移动|MOVE_DIAG)[ ]*(\d+)(?:\,([28]+))\>/
  36.       @move_diag_region[$1.to_i] = $2.to_i
  37.     end
  38.     }
  39.   end
  40.   #--------------------------------------------------------------------------
  41.   # ● 添加通行区域
  42.   #--------------------------------------------------------------------------
  43.   def push_passage_region(region_id,direction)
  44.     directions = []
  45.     if direction
  46.       direction.scan(/./){|d|
  47.       case d
  48.       when /2/
  49.         directions.push(0x0001)
  50.       when /4/
  51.         directions.push(0x0002)
  52.       when /6/
  53.         directions.push(0x0004)
  54.       when /8/
  55.         directions.push(0x0008)
  56.       end
  57.       }
  58.     end
  59.     @passagechange_region[region_id] = directions
  60.   end
  61.   #--------------------------------------------------------------------------
  62.   # ● 添加跳跃区域
  63.   #--------------------------------------------------------------------------
  64.   def push_jump_region(region_id,direction)
  65.     directions = []
  66.     if direction
  67.       direction.scan(/./){|d|
  68.       case d
  69.       when /2/
  70.         directions.push(2)
  71.       when /4/
  72.         directions.push(4)
  73.       when /6/
  74.         directions.push(6)
  75.       when /8/
  76.         directions.push(8)
  77.       end
  78.       }
  79.     else
  80.       directions = [2,4,6,8]
  81.     end
  82.     @canjump_region[region_id] = directions
  83.   end
  84.   alias region_change_check_passage check_passage
  85.   #--------------------------------------------------------------------------
  86.   # ● 通行检查
  87.   #     alias:添加区域通行判定
  88.   #--------------------------------------------------------------------------
  89.   def check_passage(x, y, bit)
  90.     change = @passagechange_region[region_id(x,y)]
  91.     return change.include?(bit) if change
  92.     return region_change_check_passage(x,y,bit)
  93.   end
  94.   attr_reader :encountwalk_region
  95.   attr_reader :canjump_region
  96.   attr_reader :region_switch
  97.   attr_reader :forcemove_region
  98.   attr_reader :move_diag_region
  99. end
  100. #==============================================================================
  101. # ■ Game_Player
  102. #------------------------------------------------------------------------------
  103. #  处理玩家人物的类。拥有事件启动的判定、地图的卷动等功能。
  104. #   本类的实例请参考 $game_player 。
  105. #    添加内容:添加有关移动的处理内容。 alias:3个 新定义:3个
  106. #==============================================================================

  107. class Game_Player < Game_Character
  108.   alias _Kine_no_encount_region_encounter_progress_value encounter_progress_value
  109.   #--------------------------------------------------------------------------
  110.   # ● 获取遇敌进行值
  111.   #     alias:在结果添加区域遇敌值
  112.   #--------------------------------------------------------------------------
  113.   def encounter_progress_value
  114.     value = _Kine_no_encount_region_encounter_progress_value
  115.     v2 = $game_map.encountwalk_region[region_id]
  116.     value = v2 if v2
  117.     value
  118.   end
  119.   alias jump_move_by_input move_by_input
  120.   #--------------------------------------------------------------------------
  121.   # ● 由方向键移动
  122.   #     alias:添加强制移动区域与跳跃处理
  123.   #--------------------------------------------------------------------------
  124.   def move_by_input
  125.     @input_jump = false
  126.     return if force_move_by_region
  127.     jump_move_by_input
  128.     unless @move_succeed
  129.       jump_by_input(Input.dir4)
  130.     end
  131.   end
  132.   #--------------------------------------------------------------------------
  133.   # ● 由方向键跳跃
  134.   #--------------------------------------------------------------------------
  135.   def jump_by_input(d)
  136.     return if d == 0
  137.     x1 = $game_map.x_with_direction(@x,d)
  138.     y1 = $game_map.y_with_direction(@y,d)
  139.     x2 = $game_map.x_with_direction(x1,d)
  140.     y2 = $game_map.y_with_direction(y1,d)
  141.     if can_jump?(x1,x2,y1,y2,d)
  142.       jump(x2 - @x,y2 - @y)
  143.       @input_jump = true
  144.       @move_succeed = true
  145.     end
  146.   end
  147.   #--------------------------------------------------------------------------
  148.   # ● 可以跳跃?
  149.   #--------------------------------------------------------------------------
  150.   def can_jump?(x1,x2,y1,y2,d)
  151.     return false unless movable?
  152.     return false unless [2,4,6,8].any?{|di| map_passable?(x2,y2,di)}
  153.     return false if $game_map.canjump_region[$game_map.region_id(x1,y1)] == nil
  154.     return false unless $game_map.canjump_region[$game_map.region_id(x1,y1)].include?(d)
  155.     return true
  156.   end
  157.   #--------------------------------------------------------------------------
  158.   # ● 由区域强制移动
  159.   #--------------------------------------------------------------------------
  160.   def force_move_by_region
  161.     return false if !movable? || $game_map.interpreter.running?
  162.     if $game_map.forcemove_region.include?(region_id)
  163.       move_straight($game_map.forcemove_region[region_id])
  164.       return true
  165.     end
  166.     return false
  167.   end
  168.   alias region_switch_update update
  169.   #--------------------------------------------------------------------------
  170.   # ● 更新画面
  171.   #     alias:添加区域开关控制内容
  172.   #--------------------------------------------------------------------------
  173.   def update
  174.     last_region_id = region_id
  175.     region_switch_update
  176.     if last_region_id != region_id
  177.       $game_map.region_switch.each{|k,v|
  178.         $game_switches[v] = region_id == k
  179.       }
  180.     end
  181.   end
  182. end
  183. #==============================================================================
  184. # ■ Game_CharacterBase
  185. #------------------------------------------------------------------------------
  186. #  管理地图人物的基本类。是所有地图人物类的共通父类。拥有坐标、图片等基本信息。
  187. #==============================================================================

  188. class Game_CharacterBase
  189.   #--------------------------------------------------------------------------
  190.   # ● 径向移动
  191.   #     d       : 方向(2,4,6,8)
  192.   #     turn_ok : 是否可以改变方向
  193.   #--------------------------------------------------------------------------
  194.   alias move_diag_region_move_straight move_straight
  195.   def move_straight(d, turn_ok = true)
  196.     if $game_map.move_diag_region.keys.include?(region_id)
  197.       if [4,6].include?(d)
  198.         x2 = $game_map.round_x_with_direction(@x,d)
  199.         d2 = $game_map.move_diag_region[region_id]
  200.         [d2,10-d2].collect{|yd| $game_map.round_y_with_direction(@y,yd)}.each do |y2|
  201.           if $game_map.region_id(x2,y2) == region_id
  202.             vert = d
  203.             horz = y2 - @y > 0 ? 2 : 8
  204.             @through = true
  205.             return move_diagonal(vert,horz).tap{|x| @through = false}.tap{|x| set_direction(d)}
  206.           end
  207.         end
  208.       end
  209.     end
  210.     move_diag_region_move_straight(d,turn_ok)
  211.   end
  212. end
复制代码

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

在本发帖返回顶部