Class: Brickyard

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBrickyard

Returns a new instance of Brickyard.



6
7
8
9
10
11
# File 'lib/lib/items/brickyard.rb', line 6

def initialize()
  dir_path = File.dirname(__FILE__)
  @image = Gosu::Image.new(dir_path + '/../../media/square.png') # TODO

  reset!
end

Instance Attribute Details

#bricksObject (readonly)

Returns the value of attribute bricks.



4
5
6
# File 'lib/lib/items/brickyard.rb', line 4

def bricks
  @bricks
end

Instance Method Details

#drawObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/lib/items/brickyard.rb', line 30

def draw
  # Draw self
  @image.draw_rot(@x, @y, ZITEMS, 0,
              center_x = 0.5, center_y = 0, # y: top
              scale_x = BRICK_THICKNESS, scale_y = GRASS_THICKNESS / 2,
              color = Gosu::Color::WHITE)

  # Draw all bricks
  @bricks.each {|ii| ii.draw}

  if $debug
    info = Gosu::Image.from_text("[#{@bricks.count} brick(s)]", LINE_HEIGHT)
    info.draw(@x, @y, ZTEXT)
  end
end

#produce!Object



46
47
48
49
50
51
52
53
54
# File 'lib/lib/items/brickyard.rb', line 46

def produce!
  puts "producing" #TODO
  brick_x = @x
  brick_y = @y - BRICK_LENGTH * TILESIZE # just above brickyard
  brick_angle = 90

  new_brick = Brick.new(self, brick_x, brick_y, brick_angle)
  @bricks.append(new_brick)
end

#reset!Object

Load default setup



14
15
16
17
18
# File 'lib/lib/items/brickyard.rb', line 14

def reset!
  @x = 0.8 * MAPX * TILESIZE
  @y = WINDOW_HEIGHT - GRASS_THICKNESS * TILESIZE
  @bricks = [] # all (collidable) bricks
end

#update(button) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/lib/items/brickyard.rb', line 20

def update(button)
  case button
    when Gosu::KB_N then
      produce!
  end

  # Update all bricks
  @bricks.each {|ii| ii.update(button)}
end