Game Development Reference
In-Depth Information
@@respawn
||=
StereoSample
.
new(
11
$window
,
Utils
.
media_path(
'respawn.wav'
))
12
13
end
14
end
15
end
Displaying Explosion Damage Trails
When something blows up, you expect it to leave a trail, right? In our case explosions
disappear as if nothing has ever happened, and we just can't leave it like this. Let's
introduce
Damage
game object that will be responsible for displaying explosion residue
on sand and grass:
09-polishing/entities/damage.rb
1
class
Damage
<
GameObject
2
MAX_INSTANCES
= 100
attr_accessor
:x
,
:y
3
@@instances
= []
4
5
6
def
initialize
(object_pool, x, y)
7
super
(object_pool)
8
DamageGraphics
.
new(
self
)
9
@x
,
@y
=
x, y
10
track(
self
)
11
end
12
13
def
effect?
14
true
15
end
16
17
private
18
19
def
track
(instance)
20
if
@@instances
.
size
<
MAX_INSTANCES
21
@@instances
<<
instance
22
else
23
out
=
@@instances
.
shift
24
out
.
mark_for_removal
25
@@instances
<<
instance
26
end
27
end
28
end