|
本帖最后由 百里_飞柳 于 2023-2-4 09:57 编辑
最后一段,在实际应用a星时,加个冷却时间咯
- class Game_Character
- alias old_move_toward_character move_toward_character
- def move_toward_character(character)
- @astar_wait ||= 0
- if @astar_wait <= 0
- astr = AStar.new($game_map)
- astr.set_origin(@x, @y)
- astr.set_target(character.x, character.y)
- astr.set_character(self)
- path = astr.do_search
- pass = [2, 4, 6, 8].any? {|d| self.passable?(character.x, character.y, d) }
- if path.empty? || !pass
- @astar_wait = 10
- old_move_toward_character(character)
- else
- move_straight(path.shift)
- end
- else
- @astar_wait -= 1
- old_move_toward_character(character)
- end
- end
- end
复制代码 |
|