Project1
标题:
求VA的怪物寻路和怪物视野=A=
[打印本页]
作者:
Luciffer
时间:
2013-1-31 16:27
标题:
求VA的怪物寻路和怪物视野=A=
刚刚回归RM,试着自己做了一些追逐游戏玩,发现怪物默认寻路实在是太蠢了。。。地形一复杂就被墙壁卡住不会绕路了。。。这种智能给玩家玩也太无趣了吧=A=
另外这种躲避动作游戏的定番果然就是视野限制嘛,怪物在一定范围内才会看到你,所以躲避怪物视野前往下一个地点也变成了游戏点。=w=
(嘛。。。由于不是什么认真做的坑,只是做着玩的,所以完全提不起干劲就是了。。。)
怪物寻路脚本要求怪物会绕过障碍物,运行时最好不要太卡。
怪物视野脚本要求可以由玩家自己改变怪物视野大小。
作者:
Sion
时间:
2013-1-31 16:27
本帖最后由 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
复制代码
作者:
j433463
时间:
2013-1-31 18:59
本帖最后由 j433463 于 2013-2-2 09:23 编辑
我看到一个国外的鼠标脚本 Mouse System Buttons 2.0 做得挺不错,下载了范例工程来试,
它似乎在工程中还附了一个应该是自动寻路的脚本,或滑鼠脚本本身有这功能?
滑鼠点击位置后会自动找路过去,试过做一个 24*24 大小地图迷宫,结果很顺的到出口,
或许您可以试试看作参考:
http://falcaorgss.wordpress.com/
:
另外,这一个好像是跟视野有关的,也是国外脚本,我看不懂:
http://www.santuariorpgmaker.com/forum/index.php?topic=14641
怪物寻路?是事件NPC那种明雷方式的吗?这个脚本不知道算不算,它说明内容中有提到可移动任何 Game_Character 的对象:
http://arcthunder.site40.net/en-khas-pathfinder/
而这个,需要在事件中先指定一个目的座标,它会自动找出合适的路线过去:
http://forums.rpgmakerweb.com/in ... r-rpg-maker-vx-ace/
另外,还看到了一个警卫脚本,就是进入视线范围触发的脚本:
http://forums.rpgmakerweb.com/in ... r-rpg-maker-vx-ace/
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1