Class: HopLevel
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Level
#continue!, #fail!, #on_continue, #on_fail, #on_quit, #quit!
Constructor Details
Returns a new instance of HopLevel.
49
50
51
52
53
54
55
56
57
|
# File 'lib/rubyhop/level.rb', line 49
def initialize
super
@music = Rubyhop.song "music.mp3"
@music.play true
@player = Player.new
@hoops = 6.times.map { Hoop.new }
init_hoops!
@movement = 3
end
|
Instance Attribute Details
#movement ⇒ Object
Returns the value of attribute movement.
48
49
50
|
# File 'lib/rubyhop/level.rb', line 48
def movement
@movement
end
|
#score ⇒ Object
Returns the value of attribute score.
48
49
50
|
# File 'lib/rubyhop/level.rb', line 48
def score
@score
end
|
Instance Method Details
87
88
89
90
|
# File 'lib/rubyhop/level.rb', line 87
def button_down id
quit! if id == Gosu::KbEscape
@player.hop if id == Gosu::KbSpace
end
|
#draw ⇒ Object
111
112
113
114
115
|
# File 'lib/rubyhop/level.rb', line 111
def draw
@player.draw
@hoops.each(&:draw)
draw_score
end
|
#draw_score ⇒ Object
117
118
119
|
# File 'lib/rubyhop/level.rb', line 117
def draw_score
Rubyhop.score_font.draw "Score: #{@score}", 700, 10, 1, 1.0, 1.0, Gosu::Color::RED
end
|
#init_hoops! ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/rubyhop/level.rb', line 66
def init_hoops!
@hoops.each do |hoop|
hoop.y = 325
end
hoop_start = 400
@hoops.each do |hoop|
reset_hoop! hoop
hoop_start += 200
hoop.x = hoop_start
end
end
|
#reset_hoop!(hoop) ⇒ Object
78
79
80
81
82
83
84
85
|
# File 'lib/rubyhop/level.rb', line 78
def reset_hoop! hoop
idx = @hoops.index hoop
prev = @hoops[idx - 1]
new_y = ((prev.y-150..prev.y+125).to_a & (150..500).to_a).sample
hoop.x += 1200
hoop.y = new_y
hoop.active = true
end
|
#start! ⇒ Object
59
60
61
62
63
64
|
# File 'lib/rubyhop/level.rb', line 59
def start!
@score = 0
@movement = 3
@player.start!
init_hoops!
end
|
#update ⇒ Object
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/rubyhop/level.rb', line 92
def update
@movement += 0.0025
@player.update
if @player.offscreen?
fail!
end
@hoops.each do |hoop|
hoop.update @movement
reset_hoop!(hoop) if hoop.x < -200
@player.die! if hoop.miss @player
if hoop.active && @player.alive && hoop.x < @player.x
@score += 1
hoop.active = false
end
end
end
|