Game Development Reference
In-Depth Information
18
now
=
Gosu
.
milliseconds
19
delta
=
now
-
(
@last_frame
||=
now)
20
if
delta
>
FRAME_DELAY
21
@last_frame
=
now
22
end
23
@current_frame
+=
(delta
/
FRAME_DELAY
)
.
floor
24
object
.
mark_for_removal
if
done?
25
end
26
27
private
28
29
def
current_frame
30
animation
[
@current_frame
%
animation
.
size
]
31
end
32
33
def
done?
34
@done
||=
@current_frame
>=
animation
.
size
35
end
36
37
def
animation
38
@@animation
||=
Gosu
::
Image
.
load_tiles(
39
$window
,
Utils
.
media_path(
'explosion.png'
),
40
128
,
128
,
false
)
41
42
end
43
end
Everything
that
is
related
to
animating
the
explosion
is
now
clearly
separated.
mark_for_removal
is called on the explosion after it's animation is done.
05-refactor/entities/components/explosion_sounds.rb
1
class
ExplosionSounds
2
class
<<
self
3
def
play
4
sound
.
play
5
end
6
7
private
8
9
def
sound
10
@@sound
||=
Gosu
::
Sample
.
new(
$window
,
Utils
.
media_path(
'explosion.mp3'
))
11
12
end
13
end
14
end