Class: Bullet
- Inherits:
-
Chingu::GameObject
- Object
- Chingu::GameObject
- Bullet
- 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
-
#initialize(gamespace, options = {}) ⇒ Bullet
constructor
Initializes the gamespace where the bullet is present in.
-
#update ⇒ Object
Updating position is not necessary thanks to the velocity trait.
Methods included from GamespacePersistence
Constructor Details
#initialize(gamespace, options = {}) ⇒ Bullet
Initializes the gamespace where the bullet is present in. Velocity is passed as a paremeter in the options hash
18 19 20 21 22 23 24 |
# File 'lib/prkwars/bullet.rb', line 18 def initialize(gamespace, = {}) super() @image = Image['media/bullet.png'] @gamespace = gamespace cache_bounding_box end |
Instance Method Details
#update ⇒ Object
Updating position is not necessary thanks to the velocity trait. In case the bullet is out of bounds, it gets destroyed and explosion particles are spawned.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/prkwars/bullet.rb', line 31 def update return if in_bounds(self, @gamespace) 2.times do ExplosionParticle.create(@gamespace, x: @x, y: @y, zorder: ZOrder::GAMEOBJECT) destroy! end end |