Game Development Reference
In-Depth Information
11-powerups/entities/components/powerup_graphics.rb
1 class PowerupGraphics < Component
2 def initialize (object, type)
3 super (object)
4 @type = type
5 end
6
7 def draw (viewport)
8 image . draw(x - 12 , y - 12 , 1 )
9 Utils . mark_corners(object . box) if $debug
10 end
11
12
private
13
14 def image
15 @image ||= images . frame( " #{ @type } .png" )
16 end
17
18 def images
19
@@images ||= Gosu :: TexturePacker . load_json(
$window , Utils . media_path( 'pickups.json' ))
20
21 end
22 end
Implementing Powerup Sounds
It's even simpler with sounds. All powerups will emit a mellow “bleep” when picked
up,
so PowerupSounds can
be
completely
static,
like ExplosionSounds or
BulletSounds :
11-powerups/entities/components/powerup_sounds.rb
1 class PowerupSounds
2 class << self
3 def play (object, camera)
4 volume, pan = Utils . volume_and_pan(object, camera)
5 sound . play(object . object_id, pan, volume)
6 end
7
8
private
9
10 def sound
11
@@sound ||= StereoSample . new(
$window , Utils . media_path( 'powerup.mp3' ))
12
13 end
Search WWH ::




Custom Search