In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

流れ落ちない (3Dパーティクル&AABコリジョン)

// forked from tktr90755's 流れ落ちる

package
{
	
	import flash.display.MovieClip;
	import flash.display.Shape;
	import flash.display.Stage;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
        [SWF(frameRate="60")] 

	public class Dots extends MovieClip
	{            
		//コンテナ
		private var container:MovieClip;
		//噴出位置とリミット位置
		private var xLimit:Number;
		private var yLimit:Number;
		private var zLimit:Number;
		private var xAxis :Number;
		private var yAxis :Number;
		//色
		private var colors:Array = new Array("0xE89A0A", "0xE910DE", "0x0EEB10", "0xE9C010", "0xE2160F", "0xD6EB0B", "0xEB117C", "0xE81167", "0x7E11E8");
		//クリックで切り替え
		private var clickFlug:Boolean = false;
		
		public function Dots()
		{
		   addEventListener(Event.ADDED_TO_STAGE, onAddedStage);
		}
		
		private function onAddedStage(e:Event):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, onAddedStage);
			stage.addEventListener (MouseEvent.MOUSE_DOWN, _onMouseDown);
			stage.addEventListener (MouseEvent.MOUSE_MOVE, _onMouseMove);
			
			container = new MovieClip();
			addChild (container);
			
			xLimit = stage.stageWidth - 10;
			yLimit = stage.stageHeight - 50;
			zLimit = 160;
			xAxis  = stage.mouseX;
			yAxis  = stage.mouseY;
			
			var textField:TextField=new TextField();
			textField.text="ドラッグしてね";
			addChild(textField);
		}
		private function _onMouseDown (e:Event):void
		{
			addEventListener(Event.ENTER_FRAME, _onEnterFrame);
			stage.addEventListener(MouseEvent.MOUSE_UP, _onMouseUp);
			clickFlug = ! clickFlug
		}
		private function _onMouseUp (e:Event):void
		{
			removeEventListener(Event.ENTER_FRAME, _onEnterFrame);
			stage.removeEventListener(MouseEvent.MOUSE_UP, _onMouseUp);
		}
		private function _onMouseMove (e:Event):void
		{
			xAxis = stage.mouseX;
			yAxis = stage.mouseY;
		}
		private function _onEnterFrame(e:Event):void
		{
			createClip (container, xAxis, yAxis);
		}
		
		private function createClip (a:MovieClip, b:Number, c:Number):void
		{
			//ランダムな数値
			var value1:Number = Math.floor(Math.random() * 10);
			var value2:Number = Math.floor(Math.random() * 10);
			var value3:Number = Math.floor(Math.random() * 10);

			//速さ [X軸,Y軸,z軸]
			var xSpeed:Number = 0;
			var ySpeed:Number = 0;
			var zSpeed:Number = 0;
                        var lifeMax:Number = 60 * 2;
                        var life:Number = lifeMax;

			if (clickFlug)
			{
                                //ばらける
				xSpeed = value1 - value2;
				ySpeed = value3 - 10;
				zSpeed = value1*4;
			}
			else
			{
                                //集中
				xSpeed = 1;
				ySpeed = -10;
				zSpeed = 20;
			}
			//減速率 [X軸,Y軸,z軸]
			var xDeceleration:Number = 0.998;
			var yDeceleration:Number = 0.998;
			var zDeceleration:Number = 0.998;

			//重力
			var gravity:Number = 0.35;

			//shape生成と
			var shape:Shape = new Shape();
			a.addChild(shape);
			shape.graphics.beginFill(0xf00000 * Math.random());
			shape.graphics.drawCircle(0, 0, 10);
			shape.graphics.endFill();
			shape.x = b;
			shape.y = c;
                        shape.z = 1;
			shape.alpha = 0;

			//流れ落ちる動き
			shape.addEventListener (Event.ENTER_FRAME,__onEnterFrame);
			function __onEnterFrame (e:Event):void
			{
				shape.alpha = life / lifeMax;
				xSpeed = xSpeed * xDeceleration;
                                ySpeed = ySpeed * yDeceleration + gravity;
				zSpeed = zSpeed * zDeceleration;

				e.target.x += xSpeed;
				e.target.y += ySpeed;
				e.target.z += zSpeed;

				if ((e.target.x > xLimit) || (e.target.x < 10) )
                                {
                                    xSpeed = -xSpeed;
                                    e.target.x += xSpeed;
                                }
				if (e.target.y > yLimit) {
                                    ySpeed = -ySpeed;
                                    e.target.y += ySpeed;
                                }
				if ((e.target.z > zLimit) || (e.target.z < -zLimit) )
                                {
                                    zSpeed = -zSpeed;
                                    e.target.z += zSpeed;
                                }

                                life --;
                                if (life == 0)
				{
					shape.removeEventListener (Event.ENTER_FRAME, __onEnterFrame);
					removeMC ();
				}
			}
			function removeMC ():void
			{
				a.removeChild (shape);
			}
		}
		private function randomInt(max:int,min:int):int
		{
			var value:int = min + Math.floor(Math.random() * (max - min));
			return value;
		}
	}
}