flash on 2016-10-7

by mutantleg
♥0 | Line 94 | Modified 2016-10-07 05:43:38 | 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/yeCX
 */

package {
    import flash.ui.Keyboard;
    import flash.events.KeyboardEvent;
    import flash.events.Event;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            
            stage.addEventListener(KeyboardEvent.KEY_DOWN, onKdown);
            stage.addEventListener(KeyboardEvent.KEY_UP, onKup);
            stage.addEventListener(Event.ENTER_FRAME, onEnter);
        }//ctor
        
        public function onKdown(e:KeyboardEvent):void { vecKey[e.keyCode] = true; }
        public function onKup(e:KeyboardEvent):void { vecKey[e.keyCode] = false; }
        public function isKey(k:int):Boolean { return vecKey[k]; }
        public var vecKey:Vector.<Boolean> = new Vector.<Boolean>(512, false);
        
        
        public var cx:Number = 230;
        public var cy:Number = 230;
        public var vx:Number = 0;
        public var vy:Number = 0;
        
        public var rx:Number = 280;
        public var ry:Number = 300 - 16;
        public var wx:Number = 0;
        public var wy:Number = 0;
        public var my:Number = 0;
        
        public var dir:int  =0;
        
        public var wmode:int =0;
        
        public var holdKey:int = 0;
        
        public var wait:int = 0;
        
        public function onEnter(e:Event):void
        {
            graphics.clear();
            graphics.lineStyle(2, 0);
            
            graphics.drawCircle(cx,cy, 4);
            graphics.drawRect(cx-8,cy-16,16,32);
            
            graphics.drawCircle(rx,ry, 4);
            graphics.drawRect(rx-16,ry-16,32,32);
            
            graphics.drawRect(0,300,465, 300);
            
     
            var over:Boolean; over= false;
            if (Math.abs(cx-rx)<(16+8))
            {
              if (cy+16 < ry-16+8)
              if ( cy+4 >=  ry-16-16) { over=true; }   
            }
            
            
            wx*=0.95;
            wy+=0.4;
            if(wx==0){wx=1;}
            if (rx<30){wx=1;}
            else if (rx>450){wx=-1; }
            if (wmode>0){ wx=0;wy=0; over=false;}
 
            my=ry;
            if (wy>0 && ry+wy>300-16){ ry=300-16; wy=0;}
            if (Math.random()<0.04 && ry >270){wy=-5;}
            rx+=wx;
            ry+=wy;
            my = ry-my;
            if (over) {  cx+=wx; cy+=my;   if(vy>0){vy=0; cy=ry-16-16; } }
         
            if (isKey(Keyboard.DOWN))  { holdKey +=1; }
            else { holdKey = 0; }
            
            
            vx=0;
            if (wait<=0)
            {
             if (isKey(Keyboard.LEFT)) { vx=-3;dir=1;}
             if (isKey(Keyboard.RIGHT)) { vx=3;dir=0;}
             if (isKey(Keyboard.UP)) { vy = -4; }
            }//endif
            if (isKey(Keyboard.DOWN))
            { if (over && wmode<=0) { wmode=1; holdKey = 2; wait=15; }  }
            if (wait>0){holdKey=2;}
            if (holdKey==1 && wmode == 1)
            { wmode = 0;  wx=dir==0?5:-5; wy=-3; }
            
            
            vy+=0.4;
            
            if (vy>0 && cy+vy>300-16){ cy=300-16; vy=0;}
            
            if (wmode <=0)
            if (Math.abs(cx-rx)<(16+8))
            {
              if (cy+16 < ry-16+8)
              if (vy>0 && cy+vy >  ry-16-16) { vy=0; cy=ry-16-16; }   
            }
            
            cx +=vx;
            cy+=vy;
            
            if (wait>0)
            {
              wait-=1;
              rx+=(cx-rx)*0.1; 
              if (ry>cy-16-16){ry-=4;}
              else if (ry<cy-16-16){ry=cy-16-16;}  
            }

            if (wmode==1&&wait<=0)
            {
              rx=cx; ry=cy-16-16;
            }
            
        }//onenter
        
    }//classend
}