Class: Building

Inherits:
Object
  • Object
show all
Includes:
Renderable
Defined in:
lib/roflbalt.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Renderable

#each_pixel, #right_x

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

#widthObject (readonly)

Returns the value of attribute width.



281
282
283
# File 'lib/roflbalt.rb', line 281

def width
  @width
end

#xObject (readonly)

Returns the value of attribute x.



281
282
283
# File 'lib/roflbalt.rb', line 281

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



281
282
283
# File 'lib/roflbalt.rb', line 281

def y
  @y
end

Instance Method Details

#heightObject



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