-
Notifications
You must be signed in to change notification settings - Fork 0
/
highscoresstate.rb
49 lines (40 loc) · 1.07 KB
/
highscoresstate.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require_relative 'score.rb'
class HighScoresState
SCORE_Y = 270
SCORE_Y_INC = 50 #height between one score and the next
DISPLAYED = 5 #number of high-score entries displayed
def initialize (window)
@window = window
@background = Shared::background
@splash = Shared::title
@hs_title = Gosu::Image.new(window, "images/titles/highscores.png", false)
@cursor = Shared::cursor
@highscores = get_scores.sort do |s1, s2|
s2.score <=> s1.score
end[0..DISPLAYED - 1]
curr_score_y = SCORE_Y
@highscores.each do |s|
s.set_y curr_score_y += SCORE_Y_INC
end
end
def get_scores
HighScoresFile::scores
end
def update
@background.update
end
def draw
@background.draw
@splash.draw(0, 0, ZOrdinals::TITLE)
@hs_title.draw(@window.width / 2 - @hs_title.width / 2, 200, ZOrdinals::MENU_CURSOR - 1)
@cursor.draw(@window.mouse_x, @window.mouse_y, ZOrdinals::MENU_CURSOR)
@highscores.each do |h|
h.draw
end
end
def button_down (id)
if (id == Gosu::KbEscape or id == Gosu::KbReturn) then
StateMachine.set_state(:mainmenu, :resume)
end
end
end