In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

forked from: flash on 2015-9-9

Get Adobe Flash player
by hemingway 09 Sep 2015
    Embed
/**
 * Copyright hemingway ( http://wonderfl.net/user/hemingway )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/ygpS
 */

// forked from mutantleg's flash on 2015-9-9
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 var vecKey:Vector.<Boolean> = new Vector.<Boolean>(512,false);
        public function isKeyDown(k:int):Boolean { return vecKey[k]; }
        public function onKdown(e:KeyboardEvent):void { vecKey[e.keyCode] = true; }
        public function onKup(e:KeyboardEvent):void { vecKey[e.keyCode] = false;  }
        
        public var rx:Number = 64;        public var ry:Number = 64;
        public var rw:Number = 256;       public var rh:Number = 256;
        
        public function isWall(ax:Number, ay:Number):Boolean
        { if (ax < rx) { return true; } if (ay <ry) { return true; }
          if (ax > rx+rw) { return true; } if (ay > ry+rh) { return true; }
          return false;
        }//iswall 
        
        
        public var cx:Number = 230;
        public var cy:Number = 230;
        public var vx:Number = 0;
        public var vy:Number = 1;
        
        public function onEnter(e:Event):void
        {
            graphics.clear();
            graphics.lineStyle(2, 0);
            
            graphics.drawRect(rx,ry,rw,rh);
            graphics.drawCircle(cx,cy, 8);

            var onGround:Boolean;
            var xr:Number; var yr:Number;
            xr = 8; yr = 8;            
            var ms:Number; ms = 0.4;
            
            onGround = isWall(cx,cy+yr) || isWall(cx,cy+yr+2);
            
            if (isKeyDown(Keyboard.LEFT)) { vx -= ms; }
            if (isKeyDown(Keyboard.RIGHT)) { vx += ms; }
            //if (isKeyDown(Keyboard.UP)) { vy -= ms; }
            if (onGround && isKeyDown(Keyboard.UP)) { vy = -8; }

            //if (onGround == false) { vy += 0.4; }
            
            if (onGround) { vx *= 0.91; }
            //vx *= 0.99; vy *= 0.99;

                        
            if (vx > 0 && isWall(cx+xr, cy)) { vx = 0; }
            if (vx < 0 && isWall(cx-xr, cy)) { vx = 0; }
            if (vy > 0 && isWall(cx, cy+yr)) { vy = 0; }
            if (vy < 0 && isWall(cx, cy-yr)) { vy = 0; }
            
            if (isKeyDown(Keyboard.UP) && vx == 0)
            {
             if (isWall(cx+xr+8, cy)) { vy = -7; vx = -3;  }
             if (isWall(cx-xr-8, cy)) { vy = -7; vx = 3;  }
            }//endif
            
            
            cx += vx; cy += vy;
            
            if (isWall(cx, cy+vy+yr)) { cy += ((ry+rh)-(cy+yr)); vy = ~((vy*0.67)-1); }
            else { vy += 0.4;}
            
            
            
            //if (onGround)
            //if (isWall(cx,cy+yr+1)) { cy -= 1; }         
                    
            //if (isWall(cx+1,cy)) { cx -= 1; }         
            //if (isWall(cx-1,cy)) { cx += 1; }         
            
        }//onenter
        
        
    }//classend
}