-
-
Save apeiros/5571a69fc5065e2fec4e0582b611c670 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Map | |
TileSetPath = "../data/graphics/texturepack_dungeon.png" | |
TileSetSize = 32 | |
def initialize(f_map) | |
puts "Loading map from #{f_map}.." | |
@tileset = Gosu::Image.load_tiles(TileSetPath, TileSetSize, TileSetSize) | |
@tile_size = TileSetSize | |
@tiles = File.readlines(f_map, chomp: true).map.with_index { |line, y| | |
line.chars.each_slice(2).map.with_index { |(char, _), x| | |
Tile.new(x * @tile_size, y * @tile_size, @tileset, char) | |
} | |
} | |
@width = @tiles.first.size | |
@height = @tiles.size | |
puts "\n" + 'width: ' + @width.to_s + ', height: ' + @height.to_s | |
puts 'Test data: ' + @tiles[0, 1].get_code | |
end | |
def tile_at(x, y) | |
@tiles.dig(y, x) | |
end | |
# Render whole map | |
def draw | |
@tiles.each do |row| | |
row.each(&:draw) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment