| 赞 | 120 |
| VIP | |
| 好人卡 | |
| 积分 | 194 |
| 经验 | |
| 最后登录 | 2026-7-4 |
| 在线时间 | 3082 小时 |
- 梦石
- 0
- 星屑
- 19426
- 在线时间
- 3082 小时
- 注册时间
- 2013-1-11
- 回帖
- 1207
|
发表于 2017-7-26 20:07:48
|
显示全部楼层
插入到main前面,在事件的移动路线里写上 move_toward_event(要接近的事件ID)
- class Game_Character
- #--------------------------------------------------------------------------
- # ● 接近事件(ID)
- #--------------------------------------------------------------------------
- def move_toward_event(id)
- # 求得与主角的坐标差
- sx = @x - $game_map.events[id].x
- sy = @y - $game_map.events[id].y
- # 坐标相等情况下
- if sx == 0 and sy == 0
- return
- end
- # 求得差的绝对值
- abs_sx = sx.abs
- abs_sy = sy.abs
- # 横距离与纵距离相等的情况下
- if abs_sx == abs_sy
- # 随机将边数增加 1
- rand(2) == 0 ? abs_sx += 1 : abs_sy += 1
- end
- # 横侧距离长的情况下
- if abs_sx > abs_sy
- # 左右方向优先。向主角移动
- sx > 0 ? move_left : move_right
- if not moving? and sy != 0
- sy > 0 ? move_up : move_down
- end
- # 竖侧距离长的情况下
- else
- # 上下方向优先。向主角移动
- sy > 0 ? move_up : move_down
- if not moving? and sx != 0
- sx > 0 ? move_left : move_right
- end
- end
- end
- end
复制代码 |
|