Game Development Reference
In-Depth Information
8
stat2
.
kills
<=>
stat1
.
kills
9
end
10
create_stats_image(stats)
11
end
12
13
def
create_stats_image
(stats)
14
text
=
stats
.
map
do
|
stat
|
15
"
#{
stat
.
kills
}
:
#{
stat
.
name
}
"
16
end
.
join(
"
\n
"
)
17
@stats_image
=
Gosu
::
Image
.
from_text(
$window
, text,
Utils
.
main_font,
30
)
18
19
end
20
21
def
draw
22
@stats_image
.
draw(
$window
.
width
/ 2 -
@stats_image
.
width
/ 2
,
23
$window
.
height
/ 4 + 30
,
24
1000
)
25
26
end
27
end
We will have to initialize
ScoreDisplay
every time when we want to show the updated
score. Time to create the
PauseState
that would show the score.
12-stats/game_states/pause_state.rb
1
require
'singleton'
2
class
PauseState
<
GameState
3
include
Singleton
attr_accessor
:play_state
4
5
6
def
initialize
7
@message
=
Gosu
::
Image
.
from_text(
$window
,
"Game Paused"
,
8
Utils
.
title_font,
60
)
9
10
end
11
12
def
enter
13
music
.
play(
true
)
14
music
.
volume
= 1
15
@score_display
=
ScoreDisplay
.
new(
@play_state
.
object_pool)
16
@mouse_coords
= [
$window
.
mouse_x,
$window
.
mouse_y
]
17
end
18
19
def
leave
20
music
.
volume
= 0