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

水砂分離ゲーム!

水と砂がごちゃまぜで降ってくるのを分離する程度のゲーム

・・・を作る予定。
侵食付けたら難易度かなりあがったwwww
/**
 * Copyright FOXEye ( http://wonderfl.net/user/FOXEye )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/5xij
 */

// forked from kuma360's 砂ゲー
package 
{
    import com.bit101.components.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    import flash.net.navigateToURL;
    import flash.net.URLRequest;
    import flash.net.URLVariables;
    
    [SWF ( width = 465, height = 465, frameRate = 60 )];
    public class Main extends Sprite 
    {
        
        private var _CANVAS:BitmapData = new BitmapData ( stage.stageWidth , stage.stageHeight , false , 0 ) ;
        
        //宣伝用//////////////////////
        private var _S0:PushButton ; 
        /////////////////////////////
        
        private var _B0:PushButton ; 
        private var _B1:PushButton ; 
        private var _B2:PushButton ; 
        private var _B3:PushButton ; 
        
        private var _CLICK:Boolean = false ;
        private var _COLOR:uint = 0x836034;
        private var _BX:int = 0 ;
        private var _BY:int = 0 ;
        
        private var _FrameCnt:int = 1;
        
        public function Main():void {
            
            addChild ( new Bitmap ( _CANVAS ) ) ;
            
            //宣伝用////////////////////////////////////////////////////
            _S0 = new PushButton ( this, 465-100 , 0, "Ad:kuma-flashgame" ) ;
            _S0.addEventListener ( MouseEvent.CLICK , function ():void { var url:URLRequest = new URLRequest ( "http://kuma-flashgame.blogspot.com/" ) ; navigateToURL( url ); } ) ;
            //////////////////////////////////////////////////////////
            
            _B0 = new PushButton ( this,  10 , 25, "ERASE" ) ;
            _B1 = new PushButton ( this, 120 , 25, "WALL" ) ;
            _B2 = new PushButton ( this, 230 , 25, "SLOW" ) ;
            _B3 = new PushButton ( this, 340 , 25, "FAST" ) ;
            _B1.enabled = false ;
            _B2.enabled = false ;
            
            _B0.addEventListener ( MouseEvent.CLICK , function ():void { _COLOR = 0x000000 ; _B0.enabled = false ; _B1.enabled = true  ; } ) ;
            _B1.addEventListener ( MouseEvent.CLICK , function ():void { _COLOR = 0x836034 ; _B0.enabled = true  ; _B1.enabled = false ; } ) ;
            _B2.addEventListener ( MouseEvent.CLICK , function ():void { _FrameCnt = 1 ; _B2.enabled = false ; _B3.enabled = true  ; } ) ;
            _B3.addEventListener ( MouseEvent.CLICK , function ():void { _FrameCnt = 5 ; _B2.enabled = true  ; _B3.enabled = false ; } ) ;
            
            
            //////////////////////////////////////////////////////////
            //*初期動作:タンク生成
            
            //左右
            for(var I:int = 60;I<100;++I){
                _CANVAS.setPixel(185,I,0x836034);
                _CANVAS.setPixel(186,I,0x836034);
                _CANVAS.setPixel(187,I,0x836034);
                _CANVAS.setPixel(188,I,0x836034);
                _CANVAS.setPixel(189,I,0x836034);
                _CANVAS.setPixel(190,I,0x836034);
                _CANVAS.setPixel(191,I,0x836034);
                _CANVAS.setPixel(192,I,0x836034);
                _CANVAS.setPixel(193,I,0x836034);
                _CANVAS.setPixel(194,I,0x836034);
                
                _CANVAS.setPixel(260,I,0x836034);
                _CANVAS.setPixel(261,I,0x836034);
                _CANVAS.setPixel(262,I,0x836034);
                _CANVAS.setPixel(263,I,0x836034);
                _CANVAS.setPixel(264,I,0x836034);
                _CANVAS.setPixel(265,I,0x836034);
                _CANVAS.setPixel(266,I,0x836034);
                _CANVAS.setPixel(267,I,0x836034);
                _CANVAS.setPixel(268,I,0x836034);
                _CANVAS.setPixel(269,I,0x836034);
            }
            
            for(I=185;I<270;++I){
                _CANVAS.setPixel(I,105,0x836034);
                _CANVAS.setPixel(I,104,0x836034);
                _CANVAS.setPixel(I,103,0x836034);
                _CANVAS.setPixel(I,102,0x836034);
                _CANVAS.setPixel(I,101,0x836034); 
                _CANVAS.setPixel(I,100,0x836034);
                _CANVAS.setPixel(I,99,0x836034);
                _CANVAS.setPixel(I,98,0x836034);
                _CANVAS.setPixel(I,97,0x836034);
                _CANVAS.setPixel(I,96,0x836034);           
                
            }


            //*/

            //////////////////////////////////////////////////////////
            
           
            stage.addEventListener ( MouseEvent.MOUSE_DOWN , function ():void { _CLICK = true ; } ) ;
            stage.addEventListener ( MouseEvent.MOUSE_UP   , function ():void { _CLICK = false; } ) ;
            addEventListener ( Event.ENTER_FRAME , RUN ) ;

            
        }
        
        
        
        
        public function RUN ( e:Event ):void {
            
            _CANVAS.lock() ;
            
            ////////////////////////////////////
            //上壁
            for(var I:int = 0;I<_CANVAS.width;++ I){
                _CANVAS.setPixel(I,59,0x836034);
                _CANVAS.setPixel(I,60,0x836034);
            }
            
            //左右壁 ちょっと厚め
            for(I=60;I<_CANVAS.height;++I){
                _CANVAS.setPixel(0,I,0x836034);
                _CANVAS.setPixel(1,I,0x836034);
                _CANVAS.setPixel(2,I,0x836034);
                _CANVAS.setPixel(3,I,0x836034);
                _CANVAS.setPixel(4,I,0x836034);
                
                _CANVAS.setPixel(_CANVAS.width-1,I,0x836034);
                _CANVAS.setPixel(_CANVAS.width-2,I,0x836034);
                _CANVAS.setPixel(_CANVAS.width-3,I,0x836034);
                _CANVAS.setPixel(_CANVAS.width-4,I,0x836034);
                _CANVAS.setPixel(_CANVAS.width-5,I,0x836034);
                
                
            }

            
            ////////////////////////////////////
            //マウスクリック
            if ( _CLICK && 60 < mouseY && 60 < _BY ) {
                
                for ( var J:int = 0 ; J < 20 ; ++ J ) {
                    var R:Number = J / 20 ;
                    _CANVAS.fillRect ( new Rectangle ( _BX * R + mouseX * ( 1 - R ) , _BY * R + mouseY * ( 1 - R ) , 5 , 5 ) , _COLOR ) ;
                }
                
            }
            _BX = mouseX ;
            _BY = mouseY ;



            
            //FrameCnt数だけループ
            for(var N:int = 0;N < _FrameCnt; ++N){
                ////////////////////////////////////
                //New Sand & Watar Make 
                for ( I= 200 ; I < 250 ; ++ I ) {
                    
                    if ( Math.random() < .1 ) {
                        if(_CANVAS.getPixel(I-2 , 61)==0x000000)_CANVAS.setPixel ( I-2 , 61 , 0xF7E779 ) ;
                        if(_CANVAS.getPixel(I-1 , 61)==0x000000)_CANVAS.setPixel ( I-1 , 61 , 0x80A2F0 ) ;
                        if(_CANVAS.getPixel(I   , 61)==0x000000)_CANVAS.setPixel ( I   , 61 , 0xF7E779 ) ;
                        if(_CANVAS.getPixel(I+1 , 61)==0x000000)_CANVAS.setPixel ( I+1 , 61 , 0x80A2F0 ) ;
                        if(_CANVAS.getPixel(I+2 , 61)==0x000000)_CANVAS.setPixel ( I+2 , 61 , 0xF7E779 ) ;
                    }
                    
                }
                //////////////////////////////////// 
                //Move
                for ( var X:int = 0 ; X < _CANVAS.width ; ++ X ) {
                    
                    for ( var Y:int = _CANVAS.height - 1 ; Y >= 0 ; -- Y ) {
                        
                        var C:uint = _CANVAS.getPixel ( X , Y ) ;
                        if ( C == 0 ) {
                            continue ;
                        }
                        if ( C == 0xF7E779 ) {
                            //Sand
                            
                            var T:uint ;
                            var TX:int ;
                            
                            
                            {//落下
                                T = _CANVAS.getPixel ( X , Y + 1 ) ;
                                if ( T == 0 ) {
                                    _CANVAS.setPixel ( X , Y     , T ) ;
                                    _CANVAS.setPixel ( X , Y + 1 , C ) ;
                                    continue ;
                                }
                                
                                //水より砂の方が重い,適当な確率で場所の置換を許す。
                                if ( T == 0x80A2F0 && Math.random() < .5 ) {
                                    _CANVAS.setPixel ( X , Y     , T ) ;
                                    _CANVAS.setPixel ( X , Y + 1 , C ) ;
                                    continue ;
                                }
                                
                                //侵食された壁なら低確率で破損。
                                if ( T == 0x41301A && Math.random() < .005 ){
                                    _CANVAS.setPixel ( X , Y     , 0x000000 ) ;
                                    _CANVAS.setPixel ( X , Y + 1 , C ) ;
                                    continue ;
                                }
                                
                                //壁なら低確率で侵食。
                                if ( T == 0x836034 && Math.random() < .003 ){
                                    _CANVAS.setPixel ( X , Y + 1 , 0x41301A ) ;
                                }
                                
 
                            }
                            
                            {//左右移動
                                TX = X + Math.floor ( Math.random() * 7 ) - 3 ;
                                T = _CANVAS.getPixel ( TX , Y ) ;
                                if ( T == 0 ) {
                                    _CANVAS.setPixel (  X , Y , T ) ;
                                    _CANVAS.setPixel ( TX , Y , C ) ;
                                    continue ;
                                }
                                
                                //水より砂の方が重い,適当な確率で場所の置換を許す。
                                if ( T == 0x80A2F0 && Math.random() < .8 ) {
                                    _CANVAS.setPixel (  X , Y , T ) ;
                                    _CANVAS.setPixel ( TX , Y , C ) ;
                                    continue ;
                                }
                                
                                //侵食された壁なら低確率で破損。
                                if ( T == 0x41301A && Math.random() < .002 ){
                                    _CANVAS.setPixel (  X , Y , 0x000000 ) ;
                                    _CANVAS.setPixel ( TX , Y , C ) ;
                                    continue ;
                                }
                                
                                //壁なら低確率で侵食。
                                if ( T == 0x836034 && Math.random() < .0007 ){
                                    _CANVAS.setPixel ( TX , Y , 0x41301A ) ;

                                }
                                
                            }
                            
                        }
                        
                        if ( C == 0x80A2F0 ) {
                            //Watar
                            
                            {//落下
                                T = _CANVAS.getPixel ( X , Y + 1 ) ;
                                if ( T == 0 ) {
                                    _CANVAS.setPixel ( X , Y     , T ) ;
                                    _CANVAS.setPixel ( X , Y + 1 , C ) ;
                                    continue ;
                                }
                            }
                            
                            {//左右移動
                                TX = X + Math.floor ( Math.random() * 11 ) - 5 ;
                                T = _CANVAS.getPixel ( TX , Y ) ;
                                if ( T == 0 ) {
                                    _CANVAS.setPixel (  X , Y , T ) ;
                                    _CANVAS.setPixel ( TX , Y , C ) ;
                                    continue ;
                                }
                            }
    
                        }
                        
                    }
                    
                }
            }
            
            _CANVAS.unlock() ;
            
        }
        
    }
    
}