package org.flixel { public class FlxEmitter extends FlxGroup { public var x:Number; public var y:Number; public var width:Number; public var height:Number; public var minParticleSpeed:FlxPoint; public var maxParticleSpeed:FlxPoint; public var particleDrag:FlxPoint; public var minRotation:Number; public var maxRotation:Number; public var gravity:Number; public var on:Boolean; public var frequency:Number; public var lifespan:Number; public var bounce:Number; public var particleClass:Class; protected var _quantity:uint; protected var _explode:Boolean; protected var _timer:Number; protected var _counter:uint; protected var _point:FlxPoint; public function FlxEmitter(param1:Number = 0, param2:Number = 0, param3:Number = 0) { super(param3); this.x = param1; this.y = param2; this.width = 0; this.height = 0; this.minParticleSpeed = new FlxPoint(-100,-100); this.maxParticleSpeed = new FlxPoint(100,100); this.minRotation = -360; this.maxRotation = 360; this.gravity = 0; this.particleClass = null; this.particleDrag = new FlxPoint(); this.frequency = 0.1; this.lifespan = 3; this.bounce = 0; this._quantity = 0; this._counter = 0; this._explode = true; this.on = false; this._point = new FlxPoint(); } override public function destroy() : void { this.minParticleSpeed = null; this.maxParticleSpeed = null; this.particleDrag = null; this.particleClass = null; this._point = null; super.destroy(); } public function makeParticles(param1:Class, param2:uint = 50, param3:uint = 16, param4:Boolean = false, param5:Number = 0.8) : FlxEmitter { var _loc7_:uint = 0; var _loc8_:FlxParticle = null; var _loc10_:FlxSprite = null; maxSize = param2; var _loc6_:uint = 1; if(param4) { _loc10_ = new FlxSprite(); _loc10_.loadGraphic(param1,true); _loc6_ = _loc10_.frames; _loc10_.destroy(); } var _loc9_:uint = 0; while(_loc9_ < param2) { if(this.particleClass == null) { _loc8_ = new FlxParticle(); } else { _loc8_ = new this.particleClass(); } if(param4) { _loc7_ = FlxG.random() * _loc6_; if(param3 > 0) { _loc8_.loadRotatedGraphic(param1,param3,_loc7_); } else { _loc8_.loadGraphic(param1,true); _loc8_.frame = _loc7_; } } else if(param3 > 0) { _loc8_.loadRotatedGraphic(param1,param3); } else { _loc8_.loadGraphic(param1); } if(param5 > 0) { _loc8_.width *= param5; _loc8_.height *= param5; _loc8_.centerOffsets(); } else { _loc8_.allowCollisions = FlxObject.NONE; } _loc8_.exists = false; add(_loc8_); _loc9_++; } return this; } override public function update() : void { var _loc1_:uint = 0; var _loc2_:uint = 0; if(this.on) { if(this._explode) { this.on = false; _loc1_ = 0; _loc2_ = this._quantity; if(_loc2_ <= 0 || _loc2_ > members.length) { _loc2_ = members.length; } while(_loc1_ < _loc2_) { this.emitParticle(); _loc1_++; } this._quantity = 0; } else { this._timer += FlxG.elapsed; while(this.frequency > 0 && this._timer > this.frequency && this.on) { this._timer -= this.frequency; this.emitParticle(); if(this._quantity > 0 && ++this._counter >= this._quantity) { this.on = false; this._quantity = 0; } } } } super.update(); } override public function kill() : void { this.on = false; super.kill(); } public function start(param1:Boolean = true, param2:Number = 0, param3:Number = 0.1, param4:uint = 0) : void { revive(); visible = true; this.on = true; this._explode = param1; this.lifespan = param2; this.frequency = param3; this._quantity += param4; this._counter = 0; this._timer = 0; } public function emitParticle() : void { var _loc1_:FlxParticle = recycle(FlxParticle) as FlxParticle; _loc1_.lifespan = this.lifespan + Math.random() / 2; _loc1_.elasticity = this.bounce; _loc1_.reset(this.x - (_loc1_.width >> 1) + FlxG.random() * this.width,this.y - (_loc1_.height >> 1) + FlxG.random() * this.height); _loc1_.visible = true; if(this.minParticleSpeed.x != this.maxParticleSpeed.x) { _loc1_.velocity.x = this.minParticleSpeed.x + FlxG.random() * (this.maxParticleSpeed.x - this.minParticleSpeed.x); } else { _loc1_.velocity.x = this.minParticleSpeed.x; } if(this.minParticleSpeed.y != this.maxParticleSpeed.y) { _loc1_.velocity.y = this.minParticleSpeed.y + FlxG.random() * (this.maxParticleSpeed.y - this.minParticleSpeed.y); } else { _loc1_.velocity.y = this.minParticleSpeed.y; } _loc1_.acceleration.y = this.gravity; if(this.minRotation != this.maxRotation) { _loc1_.angularVelocity = this.minRotation + FlxG.random() * (this.maxRotation - this.minRotation); } else { _loc1_.angularVelocity = this.minRotation; } if(_loc1_.angularVelocity != 0) { _loc1_.angle = FlxG.random() * 360 - 180; } _loc1_.drag.x = this.particleDrag.x; _loc1_.drag.y = this.particleDrag.y; _loc1_.onEmit(); } public function setSize(param1:uint, param2:uint) : void { this.width = param1; this.height = param2; } public function setXSpeed(param1:Number = 0, param2:Number = 0) : void { this.minParticleSpeed.x = param1; this.maxParticleSpeed.x = param2; } public function setYSpeed(param1:Number = 0, param2:Number = 0) : void { this.minParticleSpeed.y = param1; this.maxParticleSpeed.y = param2; } public function setRotation(param1:Number = 0, param2:Number = 0) : void { this.minRotation = param1; this.maxRotation = param2; } public function at(param1:FlxObject) : void { param1.getMidpoint(this._point); this.x = this._point.x - (this.width >> 1); this.y = this._point.y - (this.height >> 1); } } }