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

キャラクターの視界用テスト

SRPGでよく使いそうなのでメモ用に保存

ついでに変化も見れるようにしておきました。
もう少し手を加えたいと思います。
Get Adobe Flash player
by tororo_zz 16 Jan 2011
    Embed
/**
 * Copyright tororo_zz ( http://wonderfl.net/user/tororo_zz )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/sy3r
 */

package
{
    import flash.net.IDynamicPropertyOutput;
    import flash.display.Sprite;
    import flash.events.*;
    import flash.utils.*;
    
    import com.bit101.components.HUISlider;
    import com.bit101.components.PushButton;
    
    [SWF(width="465", height="465")]
    public class FlashTest extends Sprite
    {
        public var addAry:Array
        public var chTimer:Timer
        public var searchSlider:HUISlider;
        public var search:int = 5
        
        public function FlashTest():void
        {
            init();
   
        }//FlashTest0
        
        public function init():void
        {          
            var colr:int
            var mk:int = 1
            addAry = new Array()
            /* ---------------------------------------------------------------------------
             * 四方のチップマップを確認する時に使う
             * --------------------------------------------------------------------------- */
            for ( var i:int = 1; i <= search; i++ )
            {
                var xt:int = 0, yt:int = i, inj:Object = { 0: i, 1: i * 2, 2: i * 3, 3: i * 4 };
                
                rn:for( var v:int= 0; v < inj[3]; v++) //左下から
                {
                    ( v <  inj[0] || v >= inj[2]) ? xt++ : xt-- ;
                    ( v >= inj[1] ) ? yt++ : yt-- ;
                    
                    switch( mk )
                    {
                        case 1: if ( yt < 0 ) continue rn; break; //4 右上を向いてる 1を見れないように
                        case 2: if ( xt < 0 ) continue rn; break; //3 左上を向いてる 2を見れないように
                        case 3: if ( yt > 0 ) continue rn; break; //2 右下を向いてる 3を見れないように
                        case 4: if ( xt > 0 ) continue rn; break; //1 左下を向いてる 4を見れないように
                    }
                    //適当にXとYから色を決めるたために16進法に変換
                    colr = (( xt * 40 & 0xff ) << 16 | ( yt * 30 & 0xff ) << 8 | ( ( yt + xt - 1 ) * 30  & 0xff ) << 0 )
                    addAry.push( { x:xt * 10, y:yt * 10, c:colr } )
                }
            }
            /* ---------------------------------------------------------------------------
             * --------------------------------------------------------------------------- */
            
            circle1( 0 , 0 , 0x000000); //中心  
            
            var btn:PushButton = new PushButton( this, 200, 10, 'ReStart', redrow );
            
            searchSlider = new HUISlider( this, 10, 10, 'search' );
            searchSlider.maximum = 20;
            searchSlider.value = search;
            
            chTimer = new Timer( 200 / search , addAry.length )
            chTimer.addEventListener( TimerEvent.TIMER, testCh )
            chTimer.start()
        }//init
        
        public function testCh( e:TimerEvent ):void
        {
            var obj:Object = addAry.shift();
            circle1( obj.x , obj.y , obj.c);
        }//testCh

        public function redrow( e:Event ):void
        {
            
            while ( this.numChildren ) { removeChildAt(0); }
            search = Math.round(searchSlider.value)
            chTimer.removeEventListener( TimerEvent.TIMER, testCh )
            init();
        }//redrow
               
        public function circle1( _x:int, _y:int , _colr:int = 0x339999):void
        { 
            var x:int = 465/2 + _x
            var y:int = 465/2 + _y
            
            var circle1:Sprite = new Sprite();
            circle1.graphics.beginFill(_colr);
            circle1.graphics.drawCircle(x,y,5);
            addChild(circle1);
        }//circle1
    }
}