Game Development Reference
In-Depth Information
8
end
9
else
10
if
@driving
&&
@driving
.
playing?
11
@driving
.
pause
12
end
13
end
14
end
15
16
def
collide
17
crash_sound
.
play(
1
,
0.25
,
false
)
18
end
19
20
private
21
22
def
driving_sound
23
@@driving_sound
||=
Gosu
::
Sample
.
new(
$window
,
Utils
.
media_path(
'tank_driving.mp3'
))
24
25
end
26
27
def
crash_sound
28
@@crash_sound
||=
Gosu
::
Sample
.
new(
$window
,
Utils
.
media_path(
'crash.ogg'
))
29
30
end
31
end
Unlike
Explosion
and
Bullet
,
Tank
sounds are stateful. We have to keep track of
should have been.
we have full control over it. Now we are ready to play sounds for more than one tank at
once.
05-refactor/entities/components/player_input.rb
1
class
PlayerInput
<
Component
2
def
initialize
(camera)
3
super
(
nil
)
4
@camera
=
camera
5
end
6
7
def
control
(obj)
8
self
.
object
=
obj
9
end
10