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

LifeShooter

自機は想像で補ってください。または補ってください。
Get Adobe Flash player
by tananuka13 24 Dec 2010
/**
 * Copyright tananuka13 ( http://wonderfl.net/user/tananuka13 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/ETAX
 */

// forked from miyaoka's LifeShooter
// forked from psyark's forked from: convolution_life
// forked from hacker_3szp8277's convolution_life
// 自機は想像で補ってください。または補ってください。
package  
{
    import flash.display.*;
    import flash.filters.ConvolutionFilter;
    import flash.events.*;
    import flash.geom.*;
    [SWF(width="465", height="465", backgroundColor= 0x000033, frameRate="60")]
    public class LifeShooter
    extends Sprite
    {
        private var pixelScale:Number = 1 + Math.random()*4;
        private var scrollHeight:int = 4;
        private var scrollFrame:int = 120;
        private var lifeBD:BitmapData = new BitmapData(stage.stageWidth * 0.75 / pixelScale, stage.stageHeight / pixelScale + scrollHeight * pixelScale, false, 0x000000);
        private var lifeBmp:Bitmap = new Bitmap(lifeBD);
        private var field:Sprite = new Sprite();
        private var step:ConvolutionFilter = new ConvolutionFilter(3, 3, [1, 1, 1, 1, 9, 1, 1, 1, 1], 0xFF, 0);
        private var rule:Array = [0, 0, 0, 0xFF0000, 0, 0, 0, 0, 0, 0, 0, 0xFF0000, 0xFF0000];// 0xFF0000];
        private var scrollWaitFrames:uint = 0;
        private var mouseHold:uint = 0;
        public function LifeShooter() 
        {
            field.addChild(lifeBmp);
            field.scaleX = field.scaleY = pixelScale;
            addChild(field);
            field.x = (stage.stageWidth - field.width)/2
            lifeBmp.y = -scrollHeight;
            lifeBD.pixelDissolve(lifeBD, new Rectangle(0,0,lifeBD.width, lifeBD.height * 0.1), lifeBD.rect.topLeft, Math.floor(Math.random() * int.MAX_VALUE), lifeBD.width*lifeBD.height /10, 0xFFFF0000);            
            field.addEventListener(MouseEvent.MOUSE_DOWN, function (mEvt:MouseEvent):void { mouseHold = 2 });
            stage.addEventListener(MouseEvent.MOUSE_UP, function ():void { mouseHold = 0 });
            addEventListener(Event.ENTER_FRAME, enterFrameHandler);
        }
        private function enterFrameHandler(evt:Event):void 
        {
            if (mouseHold)
            {
                if(mouseHold++ % 2 == 0)
                {
                    var bullet:Sprite = new Sprite;
                    bullet.graphics.beginFill(0xFF0000);
                    var bulletSize:Number =  Math.min(10, 2 +mouseHold / 10);
                    bullet.graphics.drawRect(-bulletSize / 2, -1/2, bulletSize, 1);
                    bullet.x = field.mouseX; 
                    bullet.y = field.mouseY;
                    field.addChild(bullet);
                    bullet.addEventListener(Event.ENTER_FRAME, bulletEnterFrameHandler, false, 0, true);
                }
            }
            lifeBD.lock();
            lifeBD.applyFilter(lifeBD, lifeBD.rect, lifeBD.rect.topLeft, step);
            lifeBD.paletteMap(lifeBD, lifeBD.rect, lifeBD.rect.topLeft, rule);
            lifeBmp.y = -scrollHeight + scrollHeight  * scrollWaitFrames / scrollFrame            
            if (++scrollWaitFrames % scrollFrame == 0)
            {
                lifeBmp.y = -scrollHeight;
                scrollWaitFrames = 0;
                lifeBD.scroll(0, scrollHeight);
                lifeBD.fillRect(new Rectangle(0, 0, lifeBD.width, scrollHeight), 0xFF000000);
                lifeBD.pixelDissolve(lifeBD, new Rectangle(0, 0, lifeBD.width, scrollHeight), lifeBD.rect.topLeft, Math.floor(Math.random() * int.MAX_VALUE), lifeBD.width * scrollHeight / 2, 0xFFFF0000);            
            }
            lifeBD.unlock();
        }
        private function bulletEnterFrameHandler(evt:Event):void 
        {
            var bullet:Sprite = evt.target as Sprite;
            bullet.y -= bullet.height * 2;
            if (bullet.height / 2 >= bullet.y)
            {
                bullet.removeEventListener(Event.ENTER_FRAME, bulletEnterFrameHandler);
                field.removeChild(bullet);
                return;
            }
            var bd:BitmapData = new BitmapData(Math.floor(bullet.width + 2), Math.floor(bullet.height + 2));
            bd.copyPixels(lifeBD, new Rectangle(Math.floor(bullet.x - bullet.width /2), Math.floor(bullet.y-bullet.height/2), bd.width, bd.height), bd.rect.topLeft);
            if (bd.compare( new BitmapData(bd.width, bd.height, true, 0xFF000000) ) != 0)
            {
                bullet.removeEventListener(Event.ENTER_FRAME, bulletEnterFrameHandler);
                lifeBD.draw(bullet, new Matrix(1, 0, 0, 1, bullet.x , bullet.y));
                field.removeChild(bullet);
            }
        }
    }
}