Animate Circles with Reflection(Failed)

by satrex
円が枠の外に出ないよう、縦横の反射処理を実装。そうしたら、画面の角から戻ってこなくなってしまった。
♥0 | Line 76 | Modified 2011-03-18 11:04:32 | MIT License
play

ActionScript3 source code

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

// forked from satrex's Animate Circles
package {
    import flash.display.*;
    import flash.events.Event;
    [SWF(frameRate="30", width="465", height="465")]
    public class MyFirstAnimation extends Sprite {
        private var _circle:Circle;
        public function MyFirstAnimation() {
            // write as3 code here..
            _circle = new Circle(10);
            _circle.alpha = 0.25;
            _circle.vx = 3;
            _circle.vy = 4;
            
            _circle.x = 465 / 2;
            _circle.y = 465 / 2;
            
            addChild(_circle);
            
            addEventListener(Event.ENTER_FRAME, enterFrameHandler);
        }
        
        private function enterFrameHandler(e:Event):void{
            _circle.move();
        }

    }
}
import flash.display.Sprite;
import flash.display.Stage;
class Circle extends Sprite{
    public var vx:Number;
    public var vy:Number;
    public var radius:Number;
    private var xDirection:int;
    private var yDirection:int;
    private var ASCENDING:int = 0;
    private var DESCENDING:int = 1;
    
    public function Circle(_radius:Number, _fillColor:uint = 0x000000){
        graphics.beginFill(_fillColor);
        graphics.drawCircle(0, 0, _radius);
        graphics.endFill();
        radius = _radius;
    }
    public function move(): void{
        this.AdjustDirection();
        if(this.xDirection == ASCENDING)
        {
            x += vx;
        }
        else
        {
            x -= vx;
        }
        
        if(this.yDirection == ASCENDING)
        {
            y += vy;
        }
        else
        {
            y -= vy;
        }
    }
    
    private function AdjustDirection():void
    {
        if(this.x >= stage.width)
        {
            this.xDirection = DESCENDING;
        }
        else if(this.x <= 0)
        {
            this.xDirection = ASCENDING;
        }
        
        if(this.y >= stage.height)
        {
            this.yDirection = DESCENDING;
        }
        else if(this.y <= 0)
        {
            this.yDirection = ASCENDING;
        }

    }

}