All pastes #219619 Raw Edit

Mine

public ruby v1 · immutable
#219619 ·published 2006-10-24 19:54 UTC
rendered paste body
class Game_Character  def find_path(x, y)    path = []    path << PathObject.new(nil, @x, @y, x, y, false)    loop do      new_tiles = {}      for x_pos in (path.last.x - 1)..(path.last.x + 1)        for y_pos in (path.last.y - 1)..(path.last.y + 1)          next unless $game_map.passable?(x_pos, y_pos, 0)          next if path.last.x == x_pos and path.last.y == y_pos          new_tiles[[x_pos, y_pos]] = PathObject.new(path.last, x_pos, y_pos, x, y)        end      end      f_hash = {}      for tile in new_tiles        f_hash[tile[1]] = tile[1].f      end      f_hash = f_hash.sort {|a, b| a[1] <=> b[1]}      f_hash.first[0].close      path << new_tiles.values      break if path.last.x == x and path.last.y == y    end    move_route = RPG::MoveRoute.new    move_route.repeat = false    move_route.skippable = true    move_route.list = []    for i in path.size..0      next unless path[i] != nil and path[i-1] != nil      diff_x = path[i].x - path[i-1].x      diff_y = path[i].y - path[i-1].y      print "#{diff_x}, #{diff_y}"      if diff_x == 1 and diff_y == 1        move_route.list << RPG::MoveCommand.new(6)      elsif diff_x == 1 and diff_y == 0        move_route.list << RPG::MoveCommand.new(3)      elsif diff_x == 1 and diff_y == -1        move_route.list << RPG::MoveCommand.new(8)      elsif diff_x == 0 and diff_y == 1        move_route.list << RPG::MoveCommand.new(1)      elsif diff_x == 0 and diff_y == -1        move_route.list << RPG::MoveCommand.new(4)      elsif diff_x == -1 and diff_y == 1        move_route.list << RPG::MoveCommand.new(5)      elsif diff_x == -1 and diff_y == 0        move_route.list << RPG::MoveCommand.new(2)      elsif diff_x == -1 and diff_y == -1        move_route.list << RPG::MoveCommand.new(7)      end    end    force_move_route(move_route)  endendclass PathObject  attr_reader :parent  attr_reader :x  attr_reader :y  attr_reader :g  attr_reader :h  attr_reader :open  def initialize(parent, x, y, dest_x, dest_y, open = true)    @parent = parent    @x, @y = x, y    if @parent      @g, @h = find_g, find_h(dest_x, dest_y)    else      @g, @h = 0, 0    end    @open = open  end  def parent_x    return 0 unless @parent    return @parent.x  end  def parent_y    return 0 unless @parent    return @parent.y  end  def parent_g    return 0 unless @parent    return @parent.g  end  def find_g    if parent_x == @x or parent_y == @y      @g = 10      @g += parent_g    else      @g = 14      @g += parent_g    end  end  def f    return @g + @h unless @g == nil or @h == nil    return nil  end  def find_h(dest_x, dest_y)    @h = (dest_x - @x).abs + (dest_y - @y).abs  end  def close    @open = false  endend