Class: ExplosionParticle
- Inherits:
-
Chingu::GameObject
- Object
- Chingu::GameObject
- ExplosionParticle
- Includes:
- GamespacePersistence
- Defined in:
- lib/prkwars/explosionparticle.rb
Overview
Class used for holding behaviour of particles during explosions of various entitites.
Instance Method Summary collapse
-
#initialize(gamespace, options = {}) ⇒ ExplosionParticle
constructor
Generates an explosion particle with a set fade_rate (chingu).
-
#update ⇒ Object
In case a particle collides with the gamespace boundaries, velocity gets corrected (impact angle to the other side).
Methods included from GamespacePersistence
Constructor Details
#initialize(gamespace, options = {}) ⇒ ExplosionParticle
Generates an explosion particle with a set fade_rate (chingu). X and Y velocity is picked randomly between (-7..7).
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/prkwars/explosionparticle.rb', line 18 def initialize(gamespace, = {}) super() @gamespace = gamespace @fade_rate = -3 @mode = :default @image = Image['media/myparticle.png'] @velocity_x = rand(-7..7) @velocity_y = rand(-7..7) @angle = Math.atan2(@velocity_x, @velocity_y) / Math::PI * 180 + 90 end |
Instance Method Details
#update ⇒ Object
In case a particle collides with the gamespace boundaries, velocity gets corrected (impact angle to the other side). A particle gets destroyed once it completely fades out.
35 36 37 38 |
# File 'lib/prkwars/explosionparticle.rb', line 35 def update velocity_correct! unless bounding_box.collide_rect?(@gamespace.bounding_box) destroy! if color.alpha.zero? end |