Game Development Reference
In-Depth Information
if
@explodes
Thread
.
new
do
# ...
Explosion
.
new(
@object_pool
, x, y, cause)
# ...
end
# ...
end
end
end
# 12-stats/entities/components/tank_health.rb
class
TankHealth
<
Health
# ...
def
after_death
(cause)
# ...
Thread
.
new
do
# ...
Explosion
.
new(
@object_pool
, x, y, cause)
end
end
end
Now every bit of damage gets accounted for.
Displaying Game Score
Having all the data is useless unless we display it somehow. For this, let's rethink our game
states. Now we have
MenuState
and
PlayState
. Both of them can switch one into
another. What if we introduced a
PauseState
, which would freeze the game and display
the list of all tanks along with their kills. Then
MenuState
would switch to
PlayState
,
and from
PlayState
you would be able to get to
PauseState
.
Let's begin by implementing
ScoreDisplay
, that would print a sorted list of tank kills
along with their names.
12-stats/entities/score_display.rb
1
class
ScoreDisplay
2
def
initialize
(object_pool)
3
tanks
=
object_pool
.
objects
.
select
do
|
o
|
4
o
.
class
==
Tank
5
end
6
stats
=
tanks
.
map(
&
:input
)
.
map(
&
:stats
)
stats
.
sort!
do
|
stat1, stat2
|
7