Class: Bullet

Inherits:
Chingu::GameObject
  • Object
show all
Includes:
GamespacePersistence
Defined in:
lib/prkwars/bullet.rb

Overview

Class representing a bullet shot by the player. Destroys itself if is present out of bounds.

Instance Method Summary collapse

Methods included from GamespacePersistence

#correct_coords, #in_bounds

Constructor Details

#initialize(gamespace, options = {}) ⇒ Bullet

Returns a new instance of Bullet.



12
13
14
15
16
17
18
# File 'lib/prkwars/bullet.rb', line 12

def initialize(gamespace, options = {})
  super(options)
  @image = Image['media/bullet.png']
  @gamespace = gamespace

  cache_bounding_box
end

Instance Method Details

#updateObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/prkwars/bullet.rb', line 20

def update
  return if in_bounds(self, @gamespace)

  2.times do
    ExplosionParticle.create(@gamespace,
                             x: @x, y: @y,
                             zorder: ZOrder::GAMEOBJECT)
    destroy!
  end
end