本帖最后由 ML4455739 于 2012-4-11 21:02 编辑
class Game_Event < Game_Character $事件ID的变量号 = 10 def event_toward_player $game_variables[$事件ID的变量号] > 0 ? judge = true : judge = false $game_map.events[$game_variables[$事件ID的变量号]] != nil ? judge = true : judge = false sx, sy = 0, 0 sx = $game_map.events[$game_variables[$事件ID的变量号]].x - $game_player.x if judge sy = $game_map.events[$game_variables[$事件ID的变量号]].y - $game_player.y if judge if sx == 0 and sy == 0 return end abs_sx2 = sx.abs abs_sy2 = sy.abs if abs_sx2 == abs_sy2 rand(2) == 0 ? abs_sx2 += 1 : abs_sy2 += 1 end if abs_sx2 > abs_sy2 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 # if end # def end # class
class Game_Event < Game_Character
$事件ID的变量号 = 10
def event_toward_player
$game_variables[$事件ID的变量号] > 0 ? judge = true : judge = false
$game_map.events[$game_variables[$事件ID的变量号]] != nil ? judge = true : judge = false
sx, sy = 0, 0
sx = $game_map.events[$game_variables[$事件ID的变量号]].x - $game_player.x if judge
sy = $game_map.events[$game_variables[$事件ID的变量号]].y - $game_player.y if judge
if sx == 0 and sy == 0
return
end
abs_sx2 = sx.abs
abs_sy2 = sy.abs
if abs_sx2 == abs_sy2
rand(2) == 0 ? abs_sx2 += 1 : abs_sy2 += 1
end
if abs_sx2 > abs_sy2
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 # if
end # def
end # class
$事件ID的变量号 = 10
即10号变量的值等于跟随主角的事件的事件ID。
自行新建一个出现条件带开关的事件,其移动规则为自定义-脚本:event_toward_player
需要关闭跟随时,先将10号变量归零,再关闭事件条件的开关即可。
虽然我语文不好但是如果无法理解便不必再纠结这个跟随问题了= =||。 |