Class: Building
Instance Attribute Summary collapse
-
#width ⇒ Object
readonly
Returns the value of attribute width.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
- #height ⇒ Object
-
#initialize(x, y, width, background) ⇒ Building
constructor
A new instance of Building.
- #move_left(distance) ⇒ Object
- #pixel(x, y, rx, ry, ticks) ⇒ Object
Methods included from Renderable
Constructor Details
#initialize(x, y, width, background) ⇒ Building
Returns a new instance of Building.
271 272 273 274 275 276 277 278 279 280 |
# File 'lib/roflbalt.rb', line 271 def initialize x, y, width, background @x, @y = x, y @width = width @background = background @period = rand(4) + 6 @window_width = @period - rand(2) - 1 @color = (235..238).to_a.shuffle.first # Ruby 1.8 @top_color = @color + 4 @left_color = @color + 2 end |
Instance Attribute Details
#width ⇒ Object (readonly)
Returns the value of attribute width.
281 282 283 |
# File 'lib/roflbalt.rb', line 281 def width @width end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
281 282 283 |
# File 'lib/roflbalt.rb', line 281 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
281 282 283 |
# File 'lib/roflbalt.rb', line 281 def y @y end |
Instance Method Details
#height ⇒ Object
285 |
# File 'lib/roflbalt.rb', line 285 def height; SCREEN_HEIGHT - @y end |
#move_left(distance) ⇒ Object
282 283 284 |
# File 'lib/roflbalt.rb', line 282 def move_left distance @x -= distance end |
#pixel(x, y, rx, ry, ticks) ⇒ Object
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
# File 'lib/roflbalt.rb', line 286 def pixel x, y, rx, ry, ticks if ry == 0 if rx == width - 1 Pixel.new " " else Pixel.new "=", 234, @top_color end elsif rx == 0 || rx == 1 Pixel.new ":", @left_color + 1, @left_color elsif rx == 2 Pixel.new ":", 236, 236 elsif rx == width - 1 Pixel.new ":", 236, 236 else if rx % @period >= @period - @window_width && ry % 5 >= 2 Pixel.new(" ", 255, @background.color(rx + x/2, ry)) else Pixel.new(":", 235, @color) end end end |