赞 | 13 |
VIP | 320 |
好人卡 | 64 |
积分 | 3 |
经验 | 112963 |
最后登录 | 2022-8-25 |
在线时间 | 2355 小时 |
Lv2.观梦者 (暗夜天使)
- 梦石
- 0
- 星屑
- 266
- 在线时间
- 2355 小时
- 注册时间
- 2009-3-13
- 帖子
- 2309
|
本帖最后由 Sion 于 2013-2-2 17:38 编辑
视野脚本,mog写的,我把说明汉化了一下。- #==============================================================================
- # +++ MOG - Event Sensor Range (v1.0) +++
- #==============================================================================
- # By Moghunter
- # http://www.atelier-rgss.com
- #==============================================================================
- # Permite que o evento tenha dois comportamentos, de curta distância e de
- # longa distância.
- #===============================================================================
- #
- #在事件名里添加<SensorX>(X = 视野范围)
- #例子: EV001<Sensor2>
- #
- #===============================================================================
- module MOG_EVENT_SENSOR
- #进入视野以后开启的独立开关
- SENSOR_SELF_SWITCH = "D"
- end
- #===============================================================================
- # ■ GAME EVENT
- #===============================================================================
- class Game_Event < Game_Character
-
- attr_reader :sensor_range
-
- #--------------------------------------------------------------------------
- # ● Initialize
- #--------------------------------------------------------------------------
- alias mog_event_sensor_initialize initialize
- def initialize(map_id, event)
- mog_event_sensor_initialize(map_id, event)
- setup_event_sensor
- end
-
- #--------------------------------------------------------------------------
- # ● Setup Event Sensor
- #--------------------------------------------------------------------------
- def setup_event_sensor
- @sensor_range = @event.name =~ /<Sensor(\d+)>/ ? $1.to_i : 0
- end
-
- #--------------------------------------------------------------------------
- # ● Update
- #--------------------------------------------------------------------------
- alias mog_event_sensor_update update
- def update
- mog_event_sensor_update
- update_event_sensor
- end
-
- #--------------------------------------------------------------------------
- # ● Update Sensor
- #--------------------------------------------------------------------------
- def update_event_sensor
- return if @sensor_range == 0
- distance = ($game_player.x - self.x).abs + ($game_player.y - self.y).abs
- enable = (distance <= @sensor_range)
- key = [$game_map.map_id, self.id, MOG_EVENT_SENSOR::SENSOR_SELF_SWITCH]
- last_enable = $game_self_switches[key]
- execute_sensor_effect(enable,key) if enable != last_enable
- end
- #--------------------------------------------------------------------------
- # ● Execute_Sensor Effect
- #--------------------------------------------------------------------------
- def execute_sensor_effect(enable,key)
- @pattern = 0
- @pattern_count = 0
- $game_self_switches[key] = enable
- self.refresh
- end
-
- end
复制代码 怪物寻路脚本,就是覆盖了默认的移动路线为接近玩家的那个方法,这个自己写的。如果有bug或者别的需要再告诉我吧- #2013.2.1 修正了地图循环时不追寻的bug
- #2013.2.2 修正地图通行判断错误,修正绘制路径逻辑错误,增加事件为路障的判断
- class Game_Event < Game_Character
- def move_type_toward_player
- move_chase_player unless moving?
- end
- def move_chase_player
- if @player_x != $game_player.x || @player_y != $game_player.y
- @chase_path = draw_chase_path
- @player_x, @player_y = $game_player.x, $game_player.y
- end
- dirc = @chase_path.shift
- move_straight(dirc) if dirc
- @chase_path = draw_chase_path unless move_succeed
- end
- def draw_chase_path
- sheet = Table.new($game_map.width, $game_map.height)
- new_check_point = [x, y]; sheet[x, y] = 1
- catch_player = false; step = 2
- loop do #loop1
- draw_path = false
- check_point = new_check_point
- new_check_point = []
- loop do #loop2
- point_x = check_point.shift
- break if point_x == nil
- point_y = check_point.shift
- if point_x == $game_player.x && point_y == $game_player.y
- catch_player = true; break; end
- left_x = $game_map.round_x(point_x - 1)
- right_x = $game_map.round_x(point_x + 1)
- up_y = $game_map.round_y(point_y - 1)
- down_y = $game_map.round_y(point_y + 1)
- if $game_map.passable?(left_x, point_y, 6) &&
- $game_map.passable?(point_x, point_y, 4) &&
- !collide_with_events?(left_x, point_y) &&
- sheet[left_x, point_y] == 0 #judge_end
- sheet[left_x, point_y] = step
- draw_path = true
- new_check_point.push(left_x, point_y); end
- if $game_map.passable?(right_x, point_y, 4) &&
- $game_map.passable?(point_x, point_y, 6) &&
- !collide_with_events?(right_x, point_y) &&
- sheet[right_x, point_y] == 0 #judge_end
- sheet[right_x, point_y] = step
- draw_path = true
- new_check_point.push(right_x, point_y); end
- if $game_map.passable?(point_x, up_y, 2) &&
- $game_map.passable?(point_x, point_y, 8) &&
- !collide_with_events?(point_x, up_y) &&
- sheet[point_x, up_y] == 0 #judge_end
- sheet[point_x, up_y] = step
- draw_path = true
- new_check_point.push(point_x, up_y); end
- if $game_map.passable?(point_x, down_y, 8) &&
- $game_map.passable?(point_x, point_y, 2) &&
- !collide_with_events?(point_x, down_y) &&
- sheet[point_x, down_y] == 0 #judge_end
- sheet[point_x, down_y] = step
- draw_path = true
- new_check_point.push(point_x, down_y); end
- end #endOfLoop2
- break if !draw_path || catch_player
- step += 1
- end #endOfLoop1
- reversed_chase_path = []; step -=1
- point_x, point_y = $game_player.x, $game_player.y
- for i in 2..step
- step -= 1
- if sheet[point_x, $game_map.round_y(point_y + 1)] == step &&
- $game_map.passable?(point_x, $game_map.round_y(point_y + 1), 8) &&
- $game_map.passable?(point_x, point_y, 2) #judge_end
- reversed_chase_path.push(8)
- point_y = $game_map.round_y(point_y + 1)
- elsif sheet[$game_map.round_x(point_x - 1), point_y] == step &&
- $game_map.passable?($game_map.round_x(point_x - 1), point_y, 6) &&
- $game_map.passable?(point_x, point_y, 4) #judge_end
- reversed_chase_path.push(6)
- point_x = $game_map.round_x(point_x - 1)
- elsif sheet[$game_map.round_x(point_x + 1), point_y] == step &&
- $game_map.passable?($game_map.round_x(point_x + 1), point_y, 4) &&
- $game_map.passable?(point_x, point_y, 6) #judge_end
- reversed_chase_path.push(4)
- point_x = $game_map.round_x(point_x + 1)
- elsif sheet[point_x, $game_map.round_y(point_y - 1)] == step &&
- $game_map.passable?(point_x, $game_map.round_y(point_y - 1), 2) &&
- $game_map.passable?(point_x, point_y, 8)
- reversed_chase_path.push(2)
- point_y = $game_map.round_y(point_y - 1)
- end
- end
- return reversed_chase_path.reverse
- end
- end
- class Game_CharacterBase
- attr_reader :move_succeed
- end
复制代码 |
|