Commit 172ca62ee5ea07f1fd96ab265c435d2a18685a07

Authored by Marius Hanne
1 parent b57aae3d9e
Exists in master

track object alive? state and prevent destroy explosion for dead objects

so ships don't explode again when being hit while exploding

Showing 2 changed files with 6 additions and 4 deletions Side-by-side Diff

... ... @@ -31,6 +31,8 @@
31 31  
32 32 game.space.add_body(@body)
33 33 game.space.add_shape(@shape)
  34 +
  35 + @alive = true
34 36 end
35 37  
36 38 def pos; @body.p.to_a; end
... ... @@ -48,11 +48,11 @@
48 48 end
49 49  
50 50 def destroy
  51 + return unless @alive
51 52 @game.enemies.delete(self)
52   - Explosion.new(@game, p: pos.add(size.div(2)), image: "explosion.png",
53   - zoom: options[:zoom] * 1.5, volume: options[:zoom]) do
54   - hide
55   - end.show
  53 + Explosion.new(@game, p: pos, image: "explosion.png",
  54 + zoom: options[:zoom] * 1.25, volume: options[:zoom]) { hide }.show
  55 + @alive = false
56 56 end
57 57  
58 58 def debug