Skip to content

Instantly share code, notes, and snippets.

@ruprict
Created February 3, 2012 01:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruprict/1726907 to your computer and use it in GitHub Desktop.
Save ruprict/1726907 to your computer and use it in GitHub Desktop.
ROFLBALT Building
class Building
include Renderable
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
attr_reader :x, :y, :width
def move_left distance
@x -= distance
end
def height; SCREEN_HEIGHT - @y end
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
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment