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

perspective

矢印キーで赤いのが移動。
移動制限を設けてないのでどこまでも行く。
Get Adobe Flash player
by Scmiz 16 Apr 2011
/**
 * Copyright Scmiz ( http://wonderfl.net/user/Scmiz )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/ld7u
 */

package {
    import flash.geom.Point;
    import flash.utils.Proxy;
    import flash.events.Event;
    import flash.events.KeyboardEvent;
    import flash.ui.Keyboard;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        private var _isL:Boolean;
        private var _isR:Boolean;
        private var _isU:Boolean;
        private var _isD:Boolean;
        private var _chr:Sprite;
        
        public function FlashTest() {
            _isL = false;
            _isR = false;
            _isU = false;
            _isD = false;
            
            this.graphics.beginFill(0xf8f8ff);
            this.graphics.drawRect(0, 0, 465, 465);
            this.graphics.endFill();

            var floor:Sprite = new Sprite();
            for (var y:uint = 0; y < 41; ++y) {
                for (var x:uint = 0; x < 21; ++x) {
                    floor.graphics.beginFill(((x + y) % 2 == 0) ? 0xb0ffb0 : 0xb0d0ff);
                    floor.graphics.drawRect(-210 + (x * 20), -210 + (20 * y), 20, 20);
                    floor.graphics.endFill();
                }
            }
            floor.x = 232.5;
            floor.y = 120;
            floor.rotationX = -70;
            this.addChild(floor);
            
            var chr:Sprite = new Sprite();
            chr.graphics.beginFill(0x000000, 0.25);
            chr.graphics.drawEllipse(-8, -3, 16, 6);
            chr.graphics.endFill();
            chr.graphics.beginFill(0xff5050);
            chr.graphics.drawEllipse(-6, -18, 12, 18);
            chr.graphics.endFill();
            floor.addChild(chr);
            chr.rotationX = -floor.rotationX;
            chr.y = 400;
            _chr = chr;
            
            stage.addEventListener(KeyboardEvent.KEY_DOWN, onDown);
            stage.addEventListener(KeyboardEvent.KEY_UP, onUp);
            this.addEventListener(Event.ENTER_FRAME, proc);
        }
        
        private function proc(e:Event):void {
            var speed:Number = 2.0;
            var vel:Point = new Point();
            if (_isL) vel.x -= speed;
            if (_isR) vel.x += speed;
            if (_isU) vel.y -= speed;
            if (_isD) vel.y += speed;
            if (vel.length > 0.0) {
                vel.normalize(speed);
            }
            _chr.x += vel.x;
            _chr.y += vel.y;
        }

        
        private function onDown(e:KeyboardEvent):void {
            updateKey(e.keyCode, true);
        }

        private function onUp(e:KeyboardEvent):void {
            updateKey(e.keyCode, false);
        }
        
        private function updateKey(keyCode:uint, isDown:Boolean):void {
            switch (keyCode) {
                case Keyboard.LEFT: _isL = isDown; break;
                case Keyboard.RIGHT: _isR = isDown; break;
                case Keyboard.UP: _isU = isDown; break;
                case Keyboard.DOWN: _isD = isDown; break;
            }

        }

    }
}