Class: Tile

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y, size, details) ⇒ Tile

Returns a new instance of Tile.



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/gridmap.rb', line 171

def initialize(x, y, size, details)
	@x, @y, @size, @details = x, y, size, details
	@pixel_x 	= @x * size
	@pixel_y 	= @y * size
	
	@offset_x 	= details[:offset_x] if details[:offset_x]
	@offset_y 	= details[:offset_y] if details[:offset_y]
	@z 			= details[:z] 		 if details[:z]
	@angle 		= details[:angle] 	 if details[:angle]

	@offset_x ||= 0
	@offset_y ||= 0
	@z ||= 0
	@angle ||= 0

	@centre_point = [@x * @size + @size / 2, @y * @size + @size / 2]
end

Instance Attribute Details

#angleObject

Returns the value of attribute angle.



170
171
172
# File 'lib/gridmap.rb', line 170

def angle
  @angle
end

#centre_pointObject (readonly)

Returns the value of attribute centre_point.



169
170
171
# File 'lib/gridmap.rb', line 169

def centre_point
  @centre_point
end

#connectionsObject

Returns the value of attribute connections.



170
171
172
# File 'lib/gridmap.rb', line 170

def connections
  @connections
end

#detailsObject

Returns the value of attribute details.



170
171
172
# File 'lib/gridmap.rb', line 170

def details
  @details
end

#imageObject

Returns the value of attribute image.



170
171
172
# File 'lib/gridmap.rb', line 170

def image
  @image
end

#pixel_xObject (readonly)

Returns the value of attribute pixel_x.



169
170
171
# File 'lib/gridmap.rb', line 169

def pixel_x
  @pixel_x
end

#pixel_yObject (readonly)

Returns the value of attribute pixel_y.



169
170
171
# File 'lib/gridmap.rb', line 169

def pixel_y
  @pixel_y
end

#xObject (readonly)

Returns the value of attribute x.



169
170
171
# File 'lib/gridmap.rb', line 169

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



169
170
171
# File 'lib/gridmap.rb', line 169

def y
  @y
end

#zObject

Returns the value of attribute z.



170
171
172
# File 'lib/gridmap.rb', line 170

def z
  @z
end

Instance Method Details

#drawObject



189
190
191
192
193
194
195
# File 'lib/gridmap.rb', line 189

def draw
	if @details[:connected] || @details[:orientated]
		draw_rot
	else
		@image.draw @x * @size + @offset_x, @y * @size + @offset_y, @z
	end
end

#draw_rotObject



197
198
199
# File 'lib/gridmap.rb', line 197

def draw_rot
	@image.draw_rot @centre_point[0], @centre_point[1], @z, @angle
end