玩家一WSAD移动 Q攻击 玩家二上下左右 0攻击 玩家1是近程 玩家2是远程(距离限制四格) 有那些错误的或者要改的地方帮忙看看,我想弄双人游戏。 ...
张咚咚 发表于 2017-7-26 20:07 插入到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 endend
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
折叠内容标题(非必须)
折叠内容
站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作
GMT+8, 2025-4-22 19:20
Powered by Discuz! X3.1
© 2001-2013 Comsenz Inc.