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

forked from: 魔法使いが炎の魔法を指先から放つようなものを作りたい

/**
 * Copyright knowt ( http://wonderfl.net/user/knowt )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/1Xop
 */

// forked from cpu_t's 魔法使いが炎の魔法を指先から放つようなものを作りたい
package
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.display.Shape;
    public class FlashTest extends Sprite
    {
        public function FlashTest()
        {
            this.graphics.beginFill(0);
            this.graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight);
            
            addEventListener(Event.ENTER_FRAME,loop);
        }
        
        private const range:Number=20;
        
        private var head:Explode;
        private var tail:Explode;
        
        private var lastMousePosX:Number=0;
        private var lastMousePosY:Number=0;
        
        private var firePos:Object={x:0,y:0,vx:0,vy:0};
        private function loop(e:Event):void
        {
        		firePos.vx+=(mouseX-firePos.x)*0.1;
        		firePos.vy+=(mouseY-firePos.y)*0.1;
        		
        		firePos.x+=firePos.vx;
        		firePos.y+=firePos.vy;
        		
        		
            var diff:Number=Math.sqrt((this.mouseX-lastMousePosX)*(this.mouseX-lastMousePosX)+(this.mouseY-lastMousePosY)*(this.mouseY-lastMousePosY));
            
            var size:Number=diff;
            var exX:Number=this.mouseX;
            var exY:Number=this.mouseY;
            {
				var ex:Explode=new Explode(size);
            		addChild(ex);
            		ex.x=exX;
            		ex.y=exY;
            		ex.life=size*10;
            		if(head==null)head=tail=ex;
            		else tail=tail.next=ex;
            }
            
            var prev:Explode=null;
            ex=head;
            while(ex!=null)
            {
            		ex.update();
            		if(ex.isDead)
            		{
            			if(prev==null) head=ex.next;
            			else prev.next=ex.next;
            		}
            		else prev=ex;
            		ex=ex.next;
            }
            
            lastMousePosX=this.mouseX;
            lastMousePosY=this.mouseY;
        }
    }
}

import flash.display.Sprite;
class Explode extends Sprite
{
	public function Explode(size:Number=20)
	{
		this.graphics.beginFill(0x409010);
		this.graphics.drawCircle(0,0,size);
		this.blendMode="add";
		
		vx=(Math.random()-0.5)*3;
		vy=Math.random()*1;
	}
	public var life:Number=0;
	public var next:Explode;
	public var isDead:Boolean=false;
	private var vx:Number;
	private var vy:Number;
	public function update():void
	{
		if(life--<0)
		{
			this.parent.removeChild(this);
			isDead=true;
		}
		else
		{
			this.x+=vx;
			this.y+=vy;
			vx+=(Math.random()-0.5)*0.5;
			this.scaleX=this.scaleY*=0.97;
		}
	}
}