flash on 2009-6-24

by TheCoolMuseum
♥0 | Line 39 | Modified 2009-06-24 00:48:35 | MIT License
play

ActionScript3 source code

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

package {
    import flash.display.Sprite;
    import flash.events.Event;

    public class Trian extends Sprite {
        private var s:Sprite;
        private var v:Array = [Math.cos(1)*3,-Math.cos(1)*3];

        public function Trian() {
            s = new Sprite();
            s.graphics.beginFill(0x0000ff);
            s.graphics.moveTo(0,-10);
            s.graphics.lineTo(5,10);
            s.graphics.lineTo(-5,10);
            s.graphics.endFill();
            addChild(s);
            s.x = stage.stageWidth/2;
            s.y = stage.stageHeight/2;
            addEventListener(Event.ENTER_FRAME, step);
        }

        public function step(e:Event):void{
            v[0] = Math.cos(0.01)*v[0] + Math.sin(0.01)*v[1];
            v[1] = -Math.sin(0.01)*v[0] + Math.cos(0.01)*v[1];
            s.x+=v[0];
            s.y+=v[1];
            s.rotation = Math.atan2(v[0],-v[1])*180/Math.PI;
            if(s.x<0){
                s.x+=stage.stageWidth;
            }
            if(s.x>stage.stageWidth){
                s.x-=stage.stageWidth;
            }
            if(s.y<0){
                s.y+=stage.stageHeight;
            }
            if(s.y>stage.stageHeight){
                s.y-=stage.stageHeight;
            }
        }
    }
}