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

flash on 2016-3-27

Get Adobe Flash player
by mutantleg 26 Mar 2016
    Embed
/**
 * Copyright mutantleg ( http://wonderfl.net/user/mutantleg )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/ErdZ
 */

package {
    import flash.geom.Rectangle;
    import flash.ui.Keyboard;
    import flash.geom.Matrix;
    import flash.display.BitmapData;
    import flash.events.KeyboardEvent;
    import flash.events.Event;
    import flash.display.Sprite;
    public class FlashTest extends Sprite {
        public function FlashTest() {
            
          map = new BitmapData(64,64,false, 0);  
          
          fillRect(map, 4,4, 8,1,0xFF);
          
          var i:int;
          for (i=0;i<200;i+=1)
          { fillRect(map, Math.random()*64,Math.random()*64, Math.random()*8, Math.random()*8, 0xFF); }

          fillRect(map, cx-8,cy-8,16,16,0);
        
          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]==true; }
        public function onKdown(e:KeyboardEvent):void { vecKey[e.keyCode] = true; }
        public function onKup(e:KeyboardEvent):void { vecKey[e.keyCode] = false; }
        
        public var tempRect:Rectangle = new Rectangle(0,0,0,0);  
        public function fillRect(to:BitmapData, ax:Number, ay:Number, aw:Number, ah:Number, c:uint):void
        {  tempRect.x = ax|0; tempRect.y = ay|0;        tempRect.width = aw; tempRect.height = ah;
            to.fillRect(tempRect, c);
        }//fillrect
 
        public var gt:int = 0;
        
        public var canMat:Matrix = new Matrix(8,0,0,8);
        public var map:BitmapData;
        public var cw:Number = 8;
        public var ch:Number = 8;

        public var cx:int = 16;
        public var cy:int = 16;
        public var vy:int = 0;
        
        public function isWall(ax:int, ay:int):Boolean
        { if (ax<0||ax>64||ay<0||ay>64) { return true; }  return map.getPixel(ax,ay) != 0; }
        
        public function onEnter(e:Event):void
        {
            if (gt % 2 ==0)
            { 
            
            var onGround:Boolean;
            var kx:int; var ky:int;
            kx = 0; ky=0;
            
            onGround = isWall(cx,cy+1);
            
            if (vy < 1) {vy+=1;}
            if (vy > 0) { ky = 1;}
            else if (vy < -3){ky=-1;}
            //ky=1;
            
            if (isKeyDown(Keyboard.ENTER)) { cx= stage.mouseX/cw;cy=stage.mouseY/ch;vy=0; }
            
             //  if (isKeyDown(Keyboard.UP)) { ky-=1; }
              //  if (isKeyDown(Keyboard.DOWN)) { ky+=1; }
                if (isKeyDown(Keyboard.LEFT)) { kx-=1; }
                if (isKeyDown(Keyboard.RIGHT)) { kx+=1; }
                if ((isKeyDown(Keyboard.SPACE)||isKeyDown(Keyboard.UP)) && onGround) {vy = -8; onGround=false;}
                
           // if (isWall(cx+kx,cy+ky)) { kx=0;}
            
            
                //slope
                if (onGround)
                if (isWall(cx+kx, cy))
                if (isWall(cx+kx, cy-1)==false)
                if (isWall(cx+kx, cy-2)==false)
                { cx+=kx; cy-=1; kx=0; }
                
                
                if (isWall(cx+kx,cy) || isWall(cx+kx,cy-1)) {kx= 0;} cx+=kx; 
                if (isWall(cx,cy+ky)) {ky = 0;}cy+=ky;
            
              //cx+=kx;       cy+=ky;
            }//endif
            
            
            gt += 1;
            
            graphics.clear();
            graphics.lineStyle(2, 0);
            
            graphics.beginBitmapFill(map, canMat,false,false);
              graphics.drawRect(0,0,465,465);
            graphics.endFill();
            
            graphics.beginFill(0xFFffFF);
           //  graphics.drawRect(cx*cw,cy*ch,cw,ch);
             graphics.drawRect(cx*cw,cy*ch-ch,cw,ch+ch);
             
            graphics.endFill();
            
            
        }//onenter
        
        
    }//classend
}