Class: Core::Tileset
Constant Summary collapse
- @@tilesets =
{}
Instance Attribute Summary collapse
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#first ⇒ Object
readonly
Returns the value of attribute first.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#props ⇒ Object
readonly
Returns the value of attribute props.
-
#tiles ⇒ Object
readonly
Returns the value of attribute tiles.
Instance Method Summary collapse
- #create_tiles ⇒ Object
-
#initialize(fgid, name, filename, props) ⇒ Tileset
constructor
A new instance of Tileset.
- #tile(gid, x, y, z) ⇒ Object
Constructor Details
#initialize(fgid, name, filename, props) ⇒ Tileset
Returns a new instance of Tileset.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/tileset.rb', line 8 def initialize(fgid, name, filename, props) @first = fgid @name = name if !@@tilesets[filename] @@tilesets[filename] = Gosu::Image.load_tiles(Core.window, "#{Core::LIBRARY_PATH}/#{filename}", 32, 32, true) end @tiles = @@tilesets[filename].dup @props = props @props.default = {} @filename = filename @filled = [] end |
Instance Attribute Details
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
7 8 9 |
# File 'lib/tileset.rb', line 7 def filename @filename end |
#first ⇒ Object (readonly)
Returns the value of attribute first.
7 8 9 |
# File 'lib/tileset.rb', line 7 def first @first end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/tileset.rb', line 7 def name @name end |
#props ⇒ Object (readonly)
Returns the value of attribute props.
7 8 9 |
# File 'lib/tileset.rb', line 7 def props @props end |
#tiles ⇒ Object (readonly)
Returns the value of attribute tiles.
7 8 9 |
# File 'lib/tileset.rb', line 7 def tiles @tiles end |
Instance Method Details
#create_tiles ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/tileset.rb', line 20 def create_tiles @filled = [] i = 0 @tiles.each { |tile| @filled.push(Core::Game::Tile.new(tile, 0, 0, 0, @props[i])) i += 1 } return @filled end |
#tile(gid, x, y, z) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/tileset.rb', line 29 def tile(gid, x, y, z) if gid < 0 return nil end if @filled.empty? create_tiles end tile = @filled[gid].dup tile.x, tile.y = x, y tile.z = z return tile end |