Class: Map
- Inherits:
-
Object
- Object
- Map
- Defined in:
- lib/map.rb
Constant Summary collapse
- SOLID =
[1, 2, 3, 4, 5, 10]
Instance Attribute Summary collapse
-
#solid_tiles ⇒ Object
Returns the value of attribute solid_tiles.
Instance Method Summary collapse
- #draw(screen_x, screen_y) ⇒ Object
-
#initialize(path) ⇒ Map
constructor
A new instance of Map.
- #legend ⇒ Object
- #register_solid_tiles ⇒ Object
- #solid_at?(x, y) ⇒ Boolean
- #tiles ⇒ Object
Constructor Details
Instance Attribute Details
#solid_tiles ⇒ Object
Returns the value of attribute solid_tiles.
2 3 4 |
# File 'lib/map.rb', line 2 def solid_tiles @solid_tiles end |
Instance Method Details
#draw(screen_x, screen_y) ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/map.rb', line 12 def draw(screen_x, screen_y) tiles.each_with_index do |row_array, y| row_array.each_with_index do |col, x| @set[col].draw(x * @t_size, y * @t_size, 0) #z-order is 0 end end end |
#legend ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/map.rb', line 44 def legend { '.' => 0, 'x' => 10, ']' => 2, '-' => 3, '=' => 1, '[' => 5, '/' => 6, '\\' => 7, '<' => 8, '>' => 9 } end |
#register_solid_tiles ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/map.rb', line 31 def register_solid_tiles @solid_tiles = [] tiles.each_with_index do |row, y| row.each_with_index do |col, x| @solid_tiles << SolidTile.new(x*@t_size, y*@t_size) if SOLID.include?(col) end end end |
#solid_at?(x, y) ⇒ Boolean
40 41 42 |
# File 'lib/map.rb', line 40 def solid_at?(x,y) @solid_tiles.detect {|tile| tile.at?(x,y) } || x < 0 || y < 0 end |
#tiles ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/map.rb', line 20 def tiles @tiles ||= File.readlines(@path).inject([]) do |acc, line| tile = [] line.strip.each_char do |char| tile << legend[char] end acc << tile acc end end |