Game Development Reference
In-Depth Information
$window . draw_quad(x - 2 , y - 2 , COLOR ,
5
x + 2 , y - 2 , COLOR ,
6
x - 2 , y + 2 , COLOR ,
7
x + 2 , y + 2 , COLOR ,
8
1 )
9
10 end
11
12 end
After pulling away Bullet graphics code, it looks very small and elegant. We will
probably never have to edit anything here again.
05-refactor/entities/components/bullet_sounds.rb
1 class BulletSounds
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( 'fire.mp3' ))
11
12 end
13 end
14 end
Just like ExplosionSounds , BulletSounds are stateless and static. We could make
it just like a regular component, but consider it our little optimization.
Refactoring Tank
Time to take a look at freshly decoupled Tank :
05-refactor/entities/tank.rb
1 class Tank < GameObject
2 SHOOT_DELAY = 500
3 attr_accessor :x , :y , :throttle_down , :direction , :gun_angle ,
:sounds , :physics
4
5 def initialize (object_pool, input)
6 super (object_pool)
7
@input = input
Search WWH ::




Custom Search