Advertisement
neonblack

Smart Followers v0.4

Sep 22nd, 2013
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.74 KB | None | 0 0
  1. class Game_Player < Game_Character
  2.   def move_straight(d, turn_ok = true)
  3.     forefront = passable?(@x, @y, d)
  4.     super
  5.     return unless forefront
  6.     @followers.move(d, nil, self.direction, :str)
  7.   end
  8.  
  9.   def move_diagonal(horz, vert)
  10.     forefront = diagonal_passable?(@x, @y, horz, vert)
  11.     super
  12.     return unless forefront
  13.     @followers.move(horz, vert, self.direction, :dia)
  14.   end
  15.  
  16.   def jump(x_plus, y_plus)
  17.     super
  18.     @followers.move(x_plus, y_plus, self.direction, :jum)
  19.   end
  20. end
  21.  
  22. class Game_Followers
  23.   alias_method "cp_092013_move", "move"
  24.   alias_method "cp_092013_initialize", "initialize"
  25.   alias_method "cp_092213_synchronize", "synchronize"
  26.  
  27.   def initialize(*args)
  28.     cp_092013_initialize(*args)
  29.     @follower_queue = []
  30.   end
  31.  
  32.   def update
  33.     update_movement(gathering?)
  34.     @gathering = false if gathering? && gather?
  35.     each { |follower| follower.update }
  36.   end
  37.  
  38.   def update_movement(force = false)
  39.     @last_follow = nil
  40.     @data.each_with_index do |f,i|
  41.       @last_follow = f if f.moving?
  42.       unless force
  43.         @last_follow = f if @last_follow.nil? && @follower_queue[f.movement_index+1].nil?
  44.         @last_follow = f if @last_follow && f.movement_index+1 >= @last_follow.movement_index
  45.       end
  46.       comm = @follower_queue[f.movement_index]
  47.       @last_follow = f unless comm
  48.       next if @last_follow == f
  49.       f.direction = comm[2]
  50.       case comm[3]
  51.       when :str
  52.         f.move_straight(comm[0])
  53.       when :dia
  54.         f.move_diagonal(*comm[0..1])
  55.       when :jum
  56.         f.jump(*comm[0..1])
  57.       end
  58.       f.movement_index += 1
  59.       @last_follow = f
  60.     end
  61.     if @data[-1].movement_index > 0
  62.       each { |follower| follower.movement_index -= 1 }
  63.       @follower_queue.shift
  64.     end
  65.   end
  66.  
  67.   def move(*args)
  68.     if args.empty?
  69.       cp_092013_move()
  70.     else
  71.       @follower_queue.push(args)
  72.     end
  73.   end
  74.  
  75.   def synchronize(*args)
  76.     cp_092213_synchronize(*args)
  77.     clear_queue
  78.   end
  79.  
  80.   def clear_queue
  81.     each do |follower|
  82.       follower.movement_index = 0
  83.       follower.jump_count = 0
  84.     end
  85.     @follower_queue = []
  86.   end
  87. end
  88.  
  89. class Game_Follower < Game_Character
  90.   attr_accessor :direction, :movement_index
  91.   attr_writer :jump_count
  92.   alias_method "cp_092213_initialize", "initialize"
  93.  
  94.   def initialize(*args)
  95.     cp_092213_initialize(*args)
  96.     @movement_index = 0
  97.   end
  98.  
  99.   def update
  100.     @direction_fix  = true
  101.     @move_speed     = $game_player.real_move_speed
  102.     @transparent    = $game_player.transparent
  103.     @walk_anime     = $game_player.walk_anime
  104.     @step_anime     = $game_player.step_anime
  105.     @opacity        = $game_player.opacity
  106.     @blend_type     = $game_player.blend_type
  107.     super
  108.   end
  109. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement