Class: Core::Layer
Instance Attribute Summary collapse
-
#filled ⇒ Object
Returns the value of attribute filled.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#tileset ⇒ Object
readonly
Returns the value of attribute tileset.
Instance Method Summary collapse
- #create_tilemap(w, h, tiles) ⇒ Object
- #fill_tilemap(tileset) ⇒ Object
-
#initialize(w, h, props, tiles, tileset = nil) ⇒ Layer
constructor
A new instance of Layer.
Constructor Details
#initialize(w, h, props, tiles, tileset = nil) ⇒ Layer
Returns a new instance of Layer.
6 7 8 9 10 11 12 13 14 |
# File 'lib/layer.rb', line 6 def initialize(w, h, props, tiles, tileset=nil) @properties = props @z = Core::MAP_Z @z += props[:z].to_i if props[:z] create_tilemap(w, h, tiles) if tileset fill_tilemap(tileset) end end |
Instance Attribute Details
#filled ⇒ Object
Returns the value of attribute filled.
5 6 7 |
# File 'lib/layer.rb', line 5 def filled @filled end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
4 5 6 |
# File 'lib/layer.rb', line 4 def properties @properties end |
#tileset ⇒ Object (readonly)
Returns the value of attribute tileset.
4 5 6 |
# File 'lib/layer.rb', line 4 def tileset @tileset end |
Instance Method Details
#create_tilemap(w, h, tiles) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/layer.rb', line 16 def create_tilemap(w, h, tiles) @tiles = Array.new(h) { [] } @filled = @tiles.dup wi = hi = 0 tiles.each { |int| @tiles[hi].push(int) wi += 1 if wi >= w wi = 0 hi += 1 end } end |
#fill_tilemap(tileset) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/layer.rb', line 29 def fill_tilemap(tileset) @tileset = tileset @filled = Array.new(@tiles.size) { [] } h = w = 0 @tiles.each { |ary| ary.each { |gid| @filled[h][w] = tileset.tile(gid-1, w*32, h*32, @z) w += 1 } w = 0 h += 1 } return @filled end |