1 R.Engine.define({
  2     "class": "R.particles.effects.SprayParticle",
  3     "requires": [
  4         "R.particles.AbstractParticle",
  5         "R.math.Math2D"
  6     ]
  7 });
  8 
  9 /**
 10  * @class A spray particle
 11  *
 12  * @param position {Point2D} The starting position of the particle.  A
 13  *            velocity vector will be derived from this position.
 14  * @param angle {Number} The angle, about the point, at which to emit particles.
 15  * @param spread {Number} The spread, or range, about the angle which to emit particles
 16  * @param ttl {Number} The lifetime of the particle in milliseconds
 17  */
 18 R.particles.effects.SprayParticle = function() {
 19     return R.particles.AbstractParticle.extend(/** @scope TrailParticle.prototype */{
 20 
 21         velocityVector: null,
 22 
 23         constructor: function(position, ttl, angle, spread) {
 24             this.base(ttl || 2000);
 25             this.setPosition(position.x, position.y);
 26             var a = angle + Math.floor((180 - (spread / 2)) + (R.lang.Math2.random() * (spread * 2)));
 27 
 28             if (this.velocityVector == null) {
 29                 this.velocityVector = R.math.Vector2D.create(0, 0);
 30             }
 31 
 32             R.math.Math2D.getDirectionVector(R.math.Point2D.ZERO, R.math.Vector2D.UP, a, this.velocityVector);
 33             var vel = 1 + (R.lang.Math2.random() * 2);
 34             this.velocityVector.mul(vel);
 35         },
 36 
 37         release: function() {
 38             this.base();
 39         },
 40 
 41         /**
 42          * Called by the particle engine to draw the particle to the rendering
 43          * context.
 44          *
 45          * @param renderContext {RenderContext} The rendering context
 46          * @param time {Number} The engine time in milliseconds
 47          * @param dt {Number} The delta between the world time and the last time the world was updated
 48          *          in milliseconds.
 49          */
 50         draw: function(renderContext, time, dt) {
 51             this.getPosition().add(this.velocityVector);
 52             this.renderParticle(renderContext, time, dt);
 53         },
 54 
 55         renderParticle: function(renderContext, time, dt) {
 56             renderContext.setFillStyle("#fff");
 57             renderContext.drawPoint(this.getPosition());
 58         }
 59 
 60     }, {
 61         getClassName: function() {
 62             return "R.particles.effects.SprayParticle";
 63         }
 64     });
 65 };
 66 
 67 R.Engine.define({
 68     "class": "R.particles.effects.Spray",
 69     "requires": [
 70         "R.particles.Effect"
 71     ]
 72 });
 73 R.particles.effects.Spray = function() {
 74     return R.particles.Effect.extend({
 75 
 76         spread: 10,
 77         spreadVariance: 0,
 78         angle: 0,
 79         angleVariance: 0,
 80 
 81         width: function(spread, spreadVariance) {
 82             this.spread = spread;
 83             this.spreadVariance = spreadVariance || 0;
 84             return this;
 85         },
 86 
 87         rotation: function(angle, angleVariance) {
 88             this.angle = angle;
 89             this.angleVariance = angleVariance;
 90             return this;
 91         },
 92 
 93         generateParticles: function(particles, particleCount, particleLife) {
 94             var sprayWidth = this.spread + R.lang.Math2.randomRange(0, this.spreadVariance, true);
 95             var halfAngle = Math.floor(this.angleVariance / 2);
 96             var angle = this.angle + R.lang.Math2.randomRange(-halfAngle, halfAngle, true);
 97             for (var x = 0; x < particleCount; x++) {
 98                 particles.add(this.particleClass.create(this.position, particleLife, angle, sprayWidth));
 99             }
100         }
101 
102     }, {
103         getClassName: function() {
104             return "R.particles.effects.Spray";
105         }
106     });
107 
108 };
109