Class: Hoop

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(level) ⇒ Hoop

Returns a new instance of Hoop.



73
74
75
76
77
78
79
80
# File 'lib/rubyhop.rb', line 73

def initialize level
  @level = level
  @window   = @level.window
  @hoop  = Gosu::Image.new @window, get_my_file("hoop.png")
  # center of screen
  @x = @y = 0
  @active = true
end

Instance Attribute Details

#activeObject

Returns the value of attribute active.



72
73
74
# File 'lib/rubyhop.rb', line 72

def active
  @active
end

#xObject

Returns the value of attribute x.



72
73
74
# File 'lib/rubyhop.rb', line 72

def x
  @x
end

#yObject

Returns the value of attribute y.



72
73
74
# File 'lib/rubyhop.rb', line 72

def y
  @y
end

Instance Method Details

#drawObject



92
93
94
# File 'lib/rubyhop.rb', line 92

def draw
  @hoop.draw @x - 66, @y - 98, 1000 - @x
end

#miss(player) ⇒ Object



81
82
83
84
85
86
87
88
# File 'lib/rubyhop.rb', line 81

def miss player
  if (@x - player.x).abs < 12 &&
     (@y - player.y).abs > 72
     # the player missed the hoop
     return true
   end
   false
end

#updateObject



89
90
91
# File 'lib/rubyhop.rb', line 89

def update
  @x -= @level.movement
end