flash on 2015-2-21

by mutantleg
♥0 | Line 50 | Modified 2015-02-21 23:00:34 | MIT License
play

ActionScript3 source code

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

package {
    import flash.events.Event;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            
            stage.addEventListener(Event.ENTER_FRAME, onEnter);
        }//ctor
        
        public var cx:Number = 230;
        public var cy:Number = 230;
        public var vx:Number = 2;
        public var vy:Number = 0;
        public var last:int = -1;
        
        public var mw:int = 32;
        public var mh:int = 32;
        public var cw:Number = 32;
        public var ch:Number = 32;
            
        public var gt:int = 0;
        public var wt:int = 0;    
            
        public function onEnter(e:Event):void
        {
             cx += vx;
             cy += vy;

            if (cx>465) { cx = 16; }
            if (cx < 0) {cx = 465-16;}
            if (cy>465) { cy = 16; }
            if (cy < 0) {cy = 465-16;}
             
             var tx:int; var ty:int; var t:int;
             tx = Math.floor(cx/cw);
             ty = Math.floor(cy/ch);
             t = tx+(ty*mw);
             
             

            if (wt < gt)
            if (t != last)
            {
              wt = gt+30;
              last = t;
              var tmp:Number;
              if (Math.random()<0.5)
              {  tmp = vx; vx = -vy; vy = tmp;  }
              else
               {  tmp = vx; vx = vy; vy = -tmp;  }              
            }//endif
            

            gt +=1;

            graphics.clear();
            graphics.lineStyle(2, 0);

            graphics.drawCircle(cx,cy,8);

            graphics.lineStyle(2, 0, 0.2);
            graphics.drawRect(tx*cw,ty*ch, cw,ch);

            
        }//onenter    
        
    }//classend
}