Skip to content

Commit

Permalink
Building doesn't subclass Struct, has #move_left method.
Browse files Browse the repository at this point in the history
  • Loading branch information
pda committed Jan 15, 2012
1 parent eb64ef1 commit 5237919
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions asc.rb
Expand Up @@ -141,12 +141,12 @@ def tick
@distance += speed

buildings.each do |b|
b.x -= speed
b.move_left speed
end

if b = building_under_player
if player.bottom_y > b.y
b.x += speed
b.move_left(-speed)
@speed = 0
@misc << Blood.new(player.x, player.y)
@misc << GameOverBanner.new
Expand Down Expand Up @@ -218,16 +218,21 @@ def each_pixel ticks
def right_x; x + width end
end

class Building < Struct.new(:x, :y, :width)
class Building
include Renderable
def initialize x, y, width
super
@x, @y = x, y
@width = width
@period = rand(4) + 6
@window_width = @period - rand(2) - 1
@color = (235..238).to_a.sample
@top_color = @color + 4
@left_color = @color + 2
end
attr_reader :x, :y, :width
def move_left distance
@x -= distance
end
def height; 20 end
def pixel x, y, rx, ry, ticks
if ry == 0
Expand Down

0 comments on commit 5237919

Please sign in to comment.