Class: Carpet
Constant Summary collapse
- CARPET_SPEED =
5
Instance Attribute Summary collapse
-
#carpet_image ⇒ Object
(also: #image)
readonly
Returns the value of attribute carpet_image.
Attributes included from Positionable
Instance Method Summary collapse
- #collides_with?(object) ⇒ Boolean
- #draw(counter, score) ⇒ Object
-
#initialize(window, carpet_image_file = 'carpet.png', carpet_image_flipped_file = 'carpet_flipped.png') ⇒ Carpet
constructor
A new instance of Carpet.
- #move_left ⇒ Object
- #move_right ⇒ Object
Methods included from Positionable
Constructor Details
#initialize(window, carpet_image_file = 'carpet.png', carpet_image_flipped_file = 'carpet_flipped.png') ⇒ Carpet
Returns a new instance of Carpet.
10 11 12 13 14 15 16 17 |
# File 'lib/carpet.rb', line 10 def initialize(window, carpet_image_file = 'carpet.png', carpet_image_flipped_file = 'carpet_flipped.png') @carpet_image = @carpet_image_right = Gosu::Image.new(window, path_to_media(carpet_image_file)) @carpet_image_left = Gosu::Image.new(window, path_to_media(carpet_image_flipped_file)) @window = window @x = window.width/2.0 - @carpet_image.width/2.0 @x += 1 if window.width.odd? && @carpet_image.width.odd? @y = window.height/(18/13.0) - @carpet_image.height/2.0 end |
Instance Attribute Details
#carpet_image ⇒ Object (readonly) Also known as: image
Returns the value of attribute carpet_image.
6 7 8 |
# File 'lib/carpet.rb', line 6 def carpet_image @carpet_image end |
Instance Method Details
#collides_with?(object) ⇒ Boolean
38 39 40 41 42 43 |
# File 'lib/carpet.rb', line 38 def collides_with?(object) object.bottom * object.scale > top && object.top < bottom && object.right * object.scale > left && object.left < right end |
#draw(counter, score) ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/carpet.rb', line 19 def draw(counter, score) if score > 3 @carpet_image.draw(@x, @y, 4) elsif score > 0 @z = counter % 20 == 1 ? 1 : 4 @carpet_image.draw(@x, @y, @z) end end |
#move_left ⇒ Object
28 29 30 31 |
# File 'lib/carpet.rb', line 28 def move_left @x = [@x - CARPET_SPEED, 0 - @carpet_image.height / 4].max @carpet_image = @carpet_image_left end |
#move_right ⇒ Object
33 34 35 36 |
# File 'lib/carpet.rb', line 33 def move_right @x = [@x + CARPET_SPEED, @window.width - @carpet_image.height / 2].min @carpet_image = @carpet_image_right end |