class Core::Layer
Attributes
filled[RW]
properties[R]
tileset[R]
Public Class Methods
new(w, h, props, tiles, tileset=nil)
click to toggle source
# 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
Public Instance Methods
create_tilemap(w, h, tiles)
click to toggle source
# 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)
click to toggle source
# 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