class ExplosionParticle
Class used for holding behaviour of particles during explosions of various entitites.
Public Class Methods
new(gamespace, options = {})
click to toggle source
Generates an explosion particle with a set fade_rate (chingu). X and Y velocity is picked randomly between (-7..7).
Calls superclass method
# File lib/prkwars/explosionparticle.rb, line 18 def initialize(gamespace, options = {}) super(options) @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
Public Instance Methods
update()
click to toggle source
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.
# 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
Private Instance Methods
hitting_side()
click to toggle source
Method determining whether a particle is hitting a wall - used to correct the velocity values.
# File lib/prkwars/explosionparticle.rb, line 56 def hitting_side if bounding_box.left < @gamespace.bounding_box.left || bounding_box.right > @gamespace.bounding_box.right true else false end end
velocity_correct!()
click to toggle source
Method correcting the velocity if hitting a wall.
# File lib/prkwars/explosionparticle.rb, line 45 def velocity_correct! if hitting_side @velocity_x = -@velocity_x else @velocity_y = -@velocity_y end end