Game Development Reference
In-Depth Information
PlayerSounds
.
respawn(object,
@object_pool
.
camera)
end
end
end
We need some changes in
TankHealth
class too:
class
TankHealth
<
Health
RESPAWN_DELAY
= 5000
# ...
def
should_respawn?
Gosu
.
milliseconds
-
@death_time
>
RESPAWN_DELAY
end
# ...
def
after_death
@death_time
=
Gosu
.
milliseconds
# ...
end
end
class
Health
<
Component
# ...
def
restore
@health
=
@initial_health
@health_updated
=
true
end
# ...
end
It shouldn't be hard to put everything together and enjoy the never ending gameplay.
You may have noticed that we also added a sound that will be played when player
respawns. A nice “whoosh”.
09-polishing/entities/components/player_sounds.rb
1
class
PlayerSounds
2
class
<<
self
3
def
respawn
(object, camera)
4
volume, pan
=
Utils
.
volume_and_pan(object, camera)
5
respawn_sound
.
play(object
.
object_id, pan, volume
* 0.5
)
6
end
7
8
private
9
10
def
respawn_sound