samples/99_genre_rpg_roguelike/02_roguelike_line_of_sight/app/main.rb
# Adds points to the result collection to create the player's line of sight
Adds points to the result collection to create the player's line of sight
Adds points to the result collection to create the player ' s line of sight
def line_of_sight start_x, start_y, rise, run, distance, cell_exists_lambda
    result = [] 
    points = points_on_line start_x, start_y, rise, run, distance 
    points.each do |p| 
      if cell_exists_lambda.call(p.x, p.y) 
        result << p 
      else 
        return result 
      end
    end
    result 
  end
def line_of_sight start_x , start_y , rise , run , distance , cell_exists_lambda result = [ ] points = points_on_line start_x , start_y , rise , run , distance points . each do | p | if cell_exists_lambda . call ( p . x , p . y ) result << p else return result end end result end
Adds points to the result collection to create the player's line of sight
Adds points to the result collection to create the player ' s line of sight
# starts as empty collection # calls points_on_line method # for each point in collection # if the cell exists # add it to result collection # if cell does not exist # return result collection as it is # return result collection
start_x
start_y
rise
run
distance
cell_exists_lambda