Class: Core::CollisionLayer

Inherits:
Object show all
Defined in:
lib/layer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(w, h, tiles) ⇒ CollisionLayer

Returns a new instance of CollisionLayer.



47
48
49
# File 'lib/layer.rb', line 47

def initialize(w, h, tiles)
  create_tilemap(w, h, tiles)
end

Instance Attribute Details

#tilesObject (readonly)

Returns the value of attribute tiles.



46
47
48
# File 'lib/layer.rb', line 46

def tiles
  @tiles
end

Instance Method Details

#create_tilemap(w, h, tiles) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/layer.rb', line 50

def create_tilemap(w, h, tiles)
  @tiles = Array.new(h) { [] }
  wi = hi = 0
  tiles.each { |int|
    @tiles[hi].push(int)
    wi += 1
    if wi >= w
      wi = 0
      hi += 1
    end
  }
end