EmitPanda
/**
* Copyright ProjectNya ( http://wonderfl.net/user/ProjectNya )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/huQX
*/
////////////////////////////////////////////////////////////////////////////////
// EmitPanda
////////////////////////////////////////////////////////////////////////////////
package {
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.display.Loader;
import flash.net.URLRequest;
import flash.system.Security;
import flash.system.LoaderContext;
[SWF(backgroundColor="#FFFFFF", width="465", height="465", frameRate="30")]
public class Main extends Sprite {
private var loader:Loader;
private static var pandaPath:String = "http://www.project-nya.jp/images/flash/panda2d.swf";
private var Panda:Class;
private var panda:MovieClip;
private var emit:EmitParticle;
public function Main() {
//Wonderfl.capture_delay(1);
init();
}
private function init():void {
Security.allowDomain("www.project-nya.jp");
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, complete, false, 0, true);
loader.load(new URLRequest(pandaPath), new LoaderContext(true));
}
private function complete(evt:Event):void {
loader.removeEventListener(Event.COMPLETE, complete);
var content:MovieClip = MovieClip(evt.target.content);
//Pandaクラス
Panda = MovieClip(content.panda).constructor;
emit = new EmitParticle(Panda);
addChild(emit);
loader = null;
}
}
}
//////////////////////////////////////////////////
// EmitParticleクラス
//////////////////////////////////////////////////
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
class EmitParticle extends Sprite {
private static var max:uint = 4;
private var id:uint = 0;
private var particles:Array;
private var Panda:Class;
private static var friction:Number = 0.96;
private static var gravity:Number = 0.5;
public function EmitParticle(panda:Class) {
Panda = panda;
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init, false, 0, true);
}
private function init(evt:Event = null):void {
removeEventListener(Event.ADDED_TO_STAGE, init);
particles = new Array();
stage.addEventListener(MouseEvent.MOUSE_MOVE, create, false, 0, true);
addEventListener(Event.ENTER_FRAME, update, false, 0, true);
}
private function create(evt:MouseEvent):void {
var particle:Particle = new Particle();
particle.id = id;
addChild(particle);
particle.addChild(new Panda());
particle.vx = Math.random()*10 - 5;
particle.vy = -8;
particle.x = mouseX + Math.random()*20 - 10;
particle.y = mouseY + Math.random()*20 - 10;
particles.push(particle);
id ++;
}
private function update(evt:Event):void {
for (var n:uint = 0; n < particles.length; n++) {
var particle:Particle = particles[n];
particle.x += particle.vx;
particle.y += particle.vy;
particle.vx *= friction;
particle.vy *= friction;
particle.vy += gravity;
if (particle.y > stage.stageHeight + 20) {
removeChild(particle);
particles.splice(n, 1);
particle = null;
}
}
}
}
//////////////////////////////////////////////////
// Particleクラス
//////////////////////////////////////////////////
import flash.display.Sprite;
class Particle extends Sprite {
public var id:uint;
public var vx:Number = 0;
public var vy:Number = 0;
public function Particle() {
}
}