package { import flash.display.Sprite; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.events.Event; [SWF( width = "550", height = "400", frameRate = "30", backgroundColor = "0x000000" )] public class 粒子喷射 extends Sprite { private var count:int=3000; private var wind:Number=0.0; private var gravity:Number=0.3; private var balls:Array; //public function Fountain() { public function 粒子喷射() { init(); } private function init():void { stage.scaleMode=StageScaleMode.NO_SCALE; stage.align=StageAlign.TOP_LEFT; balls = new Array(); for (var i:int = 0; i < count; i++) { var ball:Ball=new Ball(1,0xffffff); ball.x=stage.stageWidth/2; ball.y=stage.stageHeight; ball.vx = (Math.random()*2-1) * 1.5 + wind; ball.vy=-5+Math.random()*-10; addChild(ball); balls.push(ball); } addEventListener(Event.ENTER_FRAME, onEnterFrame); } private function onEnterFrame(event:Event):void { wind = -1*(mouseX - stage.stageWidth/2)/200; for (var i:Number = 0; i < balls.length; i++) { var ball:Ball=Ball(balls[i]); ball.vy+=gravity; ball.x+=ball.vx; ball.y+=ball.vy; if (ball.x > stage.stageWidth + ball.radius || ball.x < -ball.radius || ball.y >stage.stageHeight + ball.radius || ball.y<-ball.radius) { ball.x=stage.stageWidth/2; ball.y=stage.stageHeight; ball.vx = (Math.random()*2-1) * 1.5 + wind; ball.vy=-5+Math.random()*-10; } } } } }