flash on 2015-1-28

by mutantleg
♥0 | Line 73 | Modified 2015-01-28 06:20:33 | 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/oh4I
 */

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 world_width:Number = 465+465+465;
        public var world_height:Number = 320;
        public var scr_width:Number = 465;
        public var scr_height:Number = 465;
        
        public var camx:Number = 0;
        public var camy:Number = 0;

        //world width needs to be at least 3X screen width or it doesnt work right
        public function getScrx(wx:Number):Number
        {
           if (camx > world_width-scr_width)
           if (wx < scr_width) { return (wx-camx)+world_width; }  
           
           if (camx < scr_width)
           if (wx > world_width-scr_width) { return (wx-world_width)-camx; }  
            
           return wx - camx; 
            
          // if ((wx < scr_width) && (camx > (world_width-scr_width)) )
         //  if ((wx < scr_width) && (camx > (world_width*0.5)) )
         //  { return world_width - camx + wx; } 
         //  return wx - camx; 
        }//getscrx
        
        public function getAng(ax:Number, ay:Number, bx:Number, by:Number):Number
        {
           var wh:Number;
           wh = world_width / 2; 
           if (ax-bx > wh) { ax -= world_width; } 
           if (bx-ax > wh) { bx -= world_width; }
            
           return Math.atan2(by-ay, bx-ax);
            
           return 0; 
        }//getang
        
        public var cx:Number = 320;
        public var cy:Number = 240;
        public var vx:Number = 0;
        public var vy:Number = 0;
        
        public function onEnter(e:Event):void
        {
            graphics.clear();
            graphics.lineStyle(2, 0);
            
            var ms:Number;      ms =4;
            graphics.drawRect(0,0, world_width/ms, world_height/ms);
            graphics.drawCircle(cx/ms,cy/ms, 4);
            graphics.drawRect(camx/ms,0,scr_width/ms,scr_height/ms);
      
            cy = stage.mouseY;      
            
            if (stage.mouseX < 150) { vx = -16; }
            else if (stage.mouseX > 465-150) { vx = 16;}
            else { vx*=0.9;} 
            //vx = stage.mouseX < 230 ? -32 : 32;
            
            
            //cx = 1024-43;
            //cx = world_width - 48;
            //vx = 8;
            
            cx += vx;      cy += vy;
            
            if (cx > world_width) { cx -= world_width; camx -= world_width; }
            if (cx < 0) { cx+= world_width; camx += world_width; }
            
            camx = camx +  ((cx-(scr_width*0.5)) - camx) *0.2;
            camy = 0; //cy-scr_height*0.5;
            
            graphics.drawCircle(cx-camx,cy-camy, 16);
            graphics.drawRect(world_width-camx, 0, 8, 465);
            graphics.drawRect(0-camx, 0, 8, 465);
            
            
            var ax:Number; var ay:Number;
            var i:int; var sx:Number;
            var ang:Number;
            ax = 0;
            ay = 50;
            for (i = 0; i < 64; i++)
            {
                ax += 64; if (ax > world_width) { ax -= world_width; ay += 50; }

                sx = getScrx(ax);         
                //sx = ax - camx;       
                graphics.drawCircle(sx, ay-camy, 8);
                graphics.drawCircle(ax/ms, ay/ms, 2);
          
                ang = Math.atan2(cy-ay, cx-ax);
                ang = getAng(ax,ay, cx, cy);
                graphics.moveTo(sx, ay-camy);
                graphics.lineTo(sx+Math.cos(ang)*16, ay-camy+(Math.sin(ang)*16) );      
                
            }//nexti
            
            
            
        }//onenter     
        
        
    }//classend
}