设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 5056|回复: 2
打印 上一主题 下一主题

[已经解决] 求VA的怪物寻路和怪物视野=A=

[复制链接]

Lv4.逐梦者 (超级版主)

嗜谎者

梦石
2
星屑
16631
在线时间
3894 小时
注册时间
2010-9-12
帖子
9637

极短24评委极短23评委极短22评委极短21评委开拓者

跳转到指定楼层
1
 楼主| 发表于 2013-1-31 16:27:45 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
5星屑
刚刚回归RM,试着自己做了一些追逐游戏玩,发现怪物默认寻路实在是太蠢了。。。地形一复杂就被墙壁卡住不会绕路了。。。这种智能给玩家玩也太无趣了吧=A=
另外这种躲避动作游戏的定番果然就是视野限制嘛,怪物在一定范围内才会看到你,所以躲避怪物视野前往下一个地点也变成了游戏点。=w=
(嘛。。。由于不是什么认真做的坑,只是做着玩的,所以完全提不起干劲就是了。。。)
怪物寻路脚本要求怪物会绕过障碍物,运行时最好不要太卡。
怪物视野脚本要求可以由玩家自己改变怪物视野大小。

最佳答案

查看完整内容

视野脚本,mog写的,我把说明汉化了一下。怪物寻路脚本,就是覆盖了默认的移动路线为接近玩家的那个方法,这个自己写的。如果有bug或者别的需要再告诉我吧

Lv2.观梦者 (暗夜天使)

梦石
0
星屑
266
在线时间
2355 小时
注册时间
2009-3-13
帖子
2309

贵宾

2
发表于 2013-1-31 16:27:46 | 只看该作者
本帖最后由 Sion 于 2013-2-2 17:38 编辑

视野脚本,mog写的,我把说明汉化了一下。
  1. #==============================================================================
  2. # +++ MOG - Event Sensor Range (v1.0) +++
  3. #==============================================================================
  4. # By Moghunter
  5. # http://www.atelier-rgss.com
  6. #==============================================================================
  7. # Permite que o evento tenha dois comportamentos, de curta distância e de
  8. # longa distância.
  9. #===============================================================================
  10. #
  11. #在事件名里添加<SensorX>(X = 视野范围)
  12. #例子: EV001<Sensor2>
  13. #
  14. #===============================================================================
  15. module MOG_EVENT_SENSOR
  16.   #进入视野以后开启的独立开关
  17.   SENSOR_SELF_SWITCH = "D"
  18. end

  19. #===============================================================================
  20. # ■ GAME EVENT
  21. #===============================================================================
  22. class Game_Event < Game_Character
  23.   
  24.   attr_reader   :sensor_range
  25.   
  26.   #--------------------------------------------------------------------------
  27.   # ● Initialize
  28.   #--------------------------------------------------------------------------            
  29.   alias mog_event_sensor_initialize initialize
  30.   def initialize(map_id, event)
  31.       mog_event_sensor_initialize(map_id, event)
  32.       setup_event_sensor
  33.   end
  34.   
  35.   #--------------------------------------------------------------------------
  36.   # ● Setup Event Sensor
  37.   #--------------------------------------------------------------------------         
  38.   def setup_event_sensor
  39.       @sensor_range =  @event.name =~ /<Sensor(\d+)>/ ? $1.to_i : 0
  40.   end  
  41.   
  42.   #--------------------------------------------------------------------------
  43.   # ● Update
  44.   #--------------------------------------------------------------------------            
  45.   alias mog_event_sensor_update update
  46.   def update
  47.       mog_event_sensor_update
  48.       update_event_sensor
  49.   end  
  50.   
  51.   #--------------------------------------------------------------------------
  52.   # ● Update Sensor
  53.   #--------------------------------------------------------------------------        
  54.   def update_event_sensor
  55.       return if @sensor_range == 0
  56.       distance = ($game_player.x - self.x).abs + ($game_player.y - self.y).abs
  57.       enable   = (distance <= @sensor_range)
  58.       key = [$game_map.map_id, self.id, MOG_EVENT_SENSOR::SENSOR_SELF_SWITCH]
  59.       last_enable = $game_self_switches[key]
  60.       execute_sensor_effect(enable,key) if enable != last_enable
  61.     end

  62.   #--------------------------------------------------------------------------
  63.   # ● Execute_Sensor Effect
  64.   #--------------------------------------------------------------------------            
  65.   def execute_sensor_effect(enable,key)      
  66.       @pattern = 0
  67.       @pattern_count = 0               
  68.       $game_self_switches[key] = enable
  69.       self.refresh
  70.   end
  71.    
  72. end
复制代码
怪物寻路脚本,就是覆盖了默认的移动路线为接近玩家的那个方法,这个自己写的。如果有bug或者别的需要再告诉我吧
  1. #2013.2.1 修正了地图循环时不追寻的bug
  2. #2013.2.2 修正地图通行判断错误,修正绘制路径逻辑错误,增加事件为路障的判断
  3. class Game_Event < Game_Character
  4.   def move_type_toward_player
  5.     move_chase_player unless moving?
  6.   end
  7.   def move_chase_player
  8.     if @player_x != $game_player.x || @player_y != $game_player.y
  9.       @chase_path = draw_chase_path
  10.       @player_x, @player_y = $game_player.x, $game_player.y
  11.     end
  12.     dirc = @chase_path.shift
  13.     move_straight(dirc) if dirc
  14.     @chase_path = draw_chase_path unless move_succeed
  15.   end
  16.   def draw_chase_path
  17.     sheet = Table.new($game_map.width, $game_map.height)
  18.     new_check_point = [x, y]; sheet[x, y] = 1
  19.     catch_player = false;     step = 2
  20.     loop do #loop1
  21.       draw_path = false
  22.       check_point = new_check_point
  23.       new_check_point = []
  24.       loop do #loop2
  25.         point_x = check_point.shift
  26.         break if point_x == nil
  27.         point_y = check_point.shift
  28.         if point_x == $game_player.x && point_y == $game_player.y
  29.           catch_player = true; break; end
  30.         left_x  = $game_map.round_x(point_x - 1)
  31.         right_x = $game_map.round_x(point_x + 1)
  32.         up_y    = $game_map.round_y(point_y - 1)
  33.         down_y  = $game_map.round_y(point_y + 1)
  34.         if $game_map.passable?(left_x, point_y, 6)  &&
  35.            $game_map.passable?(point_x, point_y, 4) &&
  36.            !collide_with_events?(left_x, point_y)   &&
  37.            sheet[left_x, point_y] == 0 #judge_end
  38.           sheet[left_x, point_y] = step
  39.           draw_path = true
  40.           new_check_point.push(left_x, point_y); end
  41.         if $game_map.passable?(right_x, point_y, 4) &&
  42.            $game_map.passable?(point_x, point_y, 6) &&
  43.            !collide_with_events?(right_x, point_y)  &&
  44.            sheet[right_x, point_y] == 0 #judge_end
  45.           sheet[right_x, point_y] = step
  46.           draw_path = true
  47.           new_check_point.push(right_x, point_y); end
  48.         if $game_map.passable?(point_x, up_y, 2)    &&
  49.            $game_map.passable?(point_x, point_y, 8) &&
  50.            !collide_with_events?(point_x, up_y)     &&
  51.            sheet[point_x, up_y] == 0 #judge_end
  52.           sheet[point_x, up_y] = step
  53.           draw_path = true
  54.           new_check_point.push(point_x, up_y); end
  55.         if $game_map.passable?(point_x, down_y, 8)  &&
  56.            $game_map.passable?(point_x, point_y, 2) &&
  57.            !collide_with_events?(point_x, down_y)   &&
  58.            sheet[point_x, down_y] == 0 #judge_end
  59.           sheet[point_x, down_y] = step
  60.           draw_path = true
  61.           new_check_point.push(point_x, down_y); end
  62.       end #endOfLoop2
  63.       break if !draw_path || catch_player
  64.       step += 1
  65.     end #endOfLoop1
  66.     reversed_chase_path = []; step -=1
  67.     point_x, point_y = $game_player.x, $game_player.y
  68.     for i in 2..step
  69.      step -= 1
  70.       if sheet[point_x, $game_map.round_y(point_y + 1)] == step             &&
  71.          $game_map.passable?(point_x, $game_map.round_y(point_y + 1), 8)    &&
  72.          $game_map.passable?(point_x, point_y, 2) #judge_end
  73.         reversed_chase_path.push(8)
  74.         point_y = $game_map.round_y(point_y + 1)
  75.       elsif sheet[$game_map.round_x(point_x - 1), point_y] == step          &&
  76.             $game_map.passable?($game_map.round_x(point_x - 1), point_y, 6) &&
  77.             $game_map.passable?(point_x, point_y, 4) #judge_end
  78.         reversed_chase_path.push(6)
  79.         point_x = $game_map.round_x(point_x - 1)
  80.       elsif sheet[$game_map.round_x(point_x + 1), point_y] == step          &&
  81.             $game_map.passable?($game_map.round_x(point_x + 1), point_y, 4) &&
  82.             $game_map.passable?(point_x, point_y, 6) #judge_end
  83.         reversed_chase_path.push(4)
  84.         point_x = $game_map.round_x(point_x + 1)
  85.       elsif sheet[point_x, $game_map.round_y(point_y - 1)] == step          &&
  86.             $game_map.passable?(point_x, $game_map.round_y(point_y - 1), 2) &&
  87.             $game_map.passable?(point_x, point_y, 8)
  88.         reversed_chase_path.push(2)
  89.         point_y = $game_map.round_y(point_y - 1)
  90.       end
  91.     end
  92.     return reversed_chase_path.reverse
  93.   end
  94. end

  95. class Game_CharacterBase
  96. attr_reader :move_succeed
  97. end
复制代码

点评

骚年,看你等级/w\  发表于 2013-2-1 17:41
忘记说了,那个视野脚本是进入视野以后,事件的独立开关D开启……  发表于 2013-2-1 16:15
先多谢啦,我先拿去测试一下使用  发表于 2013-2-1 16:10
回复

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
50
在线时间
687 小时
注册时间
2012-10-29
帖子
1543
3
发表于 2013-1-31 18:59:14 | 只看该作者
本帖最后由 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/

点评

LBQ
我记得Yami有A*自寻路算法的。。。  发表于 2013-2-2 05:33
寻路是说怪物寻路AI,不是单机鼠标后玩家寻路。。。  发表于 2013-1-31 22:04
修改劇本中,仔細審查原來的劇情大綱,覺得有點不太滿意,嘗試編寫不同主角不同主線的劇情,希望能寫得出來。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-5-13 00:17

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表