Class: MazeRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/willb-mazegen/mazerenderer.rb

Instance Method Summary collapse

Constructor Details

#initialize(m, cellsize) ⇒ MazeRenderer

Returns a new instance of MazeRenderer.



13
14
15
16
# File 'lib/willb-mazegen/mazerenderer.rb', line 13

def initialize(m, cellsize)
  @maze = m
  @cellsize = cellsize
end

Instance Method Details

#render_linesObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/willb-mazegen/mazerenderer.rb', line 18

def render_lines
  acc = []
  cols,rows = @maze.size
  (0...rows).each do |y|
    (0...cols).each do |x|
      corners = gen_corners(x,y)
      @maze.closed_sides(y*cols+x).each do |wall|
        case wall
          when :top then 
            acc << [corners[:ul], corners[:ur]]
          when :bottom then 
            acc << [corners[:bl], corners[:br]]
          when :left then 
            acc << [corners[:ul], corners[:bl]]
          when :right then
            acc << [corners[:ur], corners[:br]]
        end
      end
    end
  end
  
  acc
end