Class: Kawaii::TmxLayer

Inherits:
Object
  • Object
show all
Defined in:
lib/kawaii/tmx_layer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ TmxLayer

Returns a new instance of TmxLayer.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/kawaii/tmx_layer.rb', line 6

def initialize hash
	@data = []
	hash['data'].each{|cell| @data.push cell}
	@name = hash['name']
	@opacity = hash['opacity']
	@width = hash['width']
	@height = hash['height']
	@x = hash['x']
	@y = hash['y']
	@textures = nil
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



4
5
6
# File 'lib/kawaii/tmx_layer.rb', line 4

def data
  @data
end

#heightObject

Returns the value of attribute height.



4
5
6
# File 'lib/kawaii/tmx_layer.rb', line 4

def height
  @height
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/kawaii/tmx_layer.rb', line 4

def name
  @name
end

#opacityObject

Returns the value of attribute opacity.



4
5
6
# File 'lib/kawaii/tmx_layer.rb', line 4

def opacity
  @opacity
end

#texturesObject

Returns the value of attribute textures.



4
5
6
# File 'lib/kawaii/tmx_layer.rb', line 4

def textures
  @textures
end

#widthObject

Returns the value of attribute width.



4
5
6
# File 'lib/kawaii/tmx_layer.rb', line 4

def width
  @width
end

#xObject

Returns the value of attribute x.



4
5
6
# File 'lib/kawaii/tmx_layer.rb', line 4

def x
  @x
end

#yObject

Returns the value of attribute y.



4
5
6
# File 'lib/kawaii/tmx_layer.rb', line 4

def y
  @y
end

Instance Method Details

#drawObject



33
34
35
36
37
38
39
40
41
42
# File 'lib/kawaii/tmx_layer.rb', line 33

def draw
	@width.times do |i|
		@height.times do |j|
			cell = get_cell(i, j)
			if(cell != 0)
				@textures[cell-1].draw(i * 32, j * 32, 0)
			end
		end
	end
end

#get_cell(col, row) ⇒ Object



18
19
20
21
22
# File 'lib/kawaii/tmx_layer.rb', line 18

def get_cell col, row
	#puts "Getting cell w col:#{col} and row: #{row} and it has the value #{@data[col + row * @width]}"
	#puts @data
	@data[col + row * @width]
end

#to_sObject



24
25
26
27
28
29
30
31
# File 'lib/kawaii/tmx_layer.rb', line 24

def to_s
	puts "Name: #{name}"
	puts "Opacity: #{opacity}"
	puts "Width: #{width}"
	puts "Height: #{height}"
	puts "X: #{x}"
	puts "Y: #{y}"
end