Game Development Reference
In-Depth Information
1 class Powerup < GameObject
2 def initialize (object_pool, x, y)
3 super
4 PowerupGraphics . new( self , graphics)
5 end
6
7 def box
8
[ x - 8 , y - 8 ,
x + 8 , y - 8 ,
9
x + 8 , y + 8 ,
10
x - 8 , y + 8]
11
12 end
13
14 def on_collision (object)
15 if pickup(object)
16 PowerupSounds . play(object, object_pool . camera)
17 remove
18 end
19 end
20
21 def pickup (object)
22 # override and implement application
23 end
24
25 def remove
26 object_pool . powerup_respawn_queue . enqueue(
27 respawn_delay,
28 self . class, x, y)
29 mark_for_removal
30 end
31
32 def respawn_delay
33 30
34 end
35 end
Ignore
Powerup#remove ,
we
will
get
to
it
when
implementing
PowerupRespawnQueue . The rest should be straightforward.
Implementing Powerup Graphics
All
powerups
will
use
the
same
sprite
sheet,
so
there
could
be
a
single
PowerupGraphics class
that
will
be
rendering
given
sprite
type.
We
will
use
gosu-texture-packer gem, since sprite sheet is conveniently packed already.
Search WWH ::




Custom Search