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 2012-1-27

Use Arrow keys to turn, fly up or down
Get Adobe Flash player
by mutantleg 23 Oct 2012
    Embed
/**
 * Copyright mutantleg ( http://wonderfl.net/user/mutantleg )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/8TK8
 */

package {
    import flash.display.AVM1Movie;
    import flash.display.BlendMode;
    import flash.display.BitmapData;
    import flash.events.KeyboardEvent;
    import flash.events.Event;
    //import flash.media.Camera;
    
    //http://alternativaplatform.com/en/docs/7.7.0/index.html
    
    import alternativ7.engine3d.containers.ConflictContainer;
    import alternativ7.engine3d.containers.BSPContainer;
    import alternativ7.engine3d.core.Camera3D;
    import alternativ7.engine3d.primitives.Plane;
    import alternativ7.engine3d.primitives.Box;
    import alternativ7.engine3d.core.View;
     import alternativ7.engine3d.materials.Material;
    import alternativ7.engine3d.materials.FillMaterial;
    import alternativ7.engine3d.materials.TextureMaterial;
  import alternativ7.engine3d.materials.FlatShadingMaterial;
 import alternativ7.engine3d.lights.DirectionalLight;
 import alternativ7.engine3d.objects.SkyBox;
    import alternativ7.types.Texture;
    import alternativ7.engine3d.core.Sorting;
    import flash.display.Sprite;
    
    public class FlashTest extends Sprite {
        
        public var cam:Camera3D;
  //      public var cont:BSPContainer = new BSPContainer();
        public var cont:ConflictContainer = new ConflictContainer();       
        public var gBox:ConflictContainer; //Box;
        public var gShad:Plane;
        public var sbox:SkyBox;
        
        public function FlashTest() {
            // write as3 code here..
               cam = new Camera3D();
                cam.view = new View(500,500); 
                cam.z = -1000;
                
               addChild(cam.view);
                cont.addChild(cam);
                
                var light:DirectionalLight;
               light = new DirectionalLight(0xFFaaFFff);
               light.y = -16384;
               light.x = 16384;
               light.z = 16384;
               light.lookAt(0,0,0);
               cont.addChild(light);
                
                var bm:BitmapData;
                bm = new BitmapData(512,512,false,0);
                bm.noise(123213,0,16,2,false);
                bm.draw( new BitmapData(512,512,true,0x1F00FF00) );
                
                var p:Plane;
                
                //ground
                p = new Plane(16384, 16384, 32, 32);
                p.setMaterialToAllFaces( new TextureMaterial( bm ) );
                //p.setMaterialToAllFaces( new FillMaterial(0xFF00AA00, 1, 1, 0) );
                p.rotationX = 1.57;
                p.sorting = Sorting.DYNAMIC_BSP;
                p.y = 200;
                cont.addChild(p);
                
                bm = new BitmapData(64,64,false,0);
                bm.noise(123123);
                
                //player
                var cbox:ConflictContainer = new ConflictContainer();
                //cbox.sorting = Sorting.DYNAMIC_BSP;
                var bx:Box;
                bx = new Box(20,20,50,1,1,1);
                //bx.sorting = Sorting.DYNAMIC_BSP;
                bx.setMaterialToAllFaces( new FillMaterial(0xFF998899) );
                cbox.addChild(bx);
                
                bx = new Box(15,5, 40,1,1,1);
                bx.setMaterialToAllFaces( new FillMaterial(0xFFBbBbBb) );
                bx.x = -15;
                bx.y = 2.5;
                cbox.addChild(bx);
                
                bx = new Box(15,5, 40,1,1,1);
                bx.setMaterialToAllFaces( new FillMaterial(0xFFBbBbBb) );
                bx.x = 15;
                bx.y = 2.5;
                cbox.addChild(bx);
                
                bx = new Box(5,15, 40,1,1,1);
                bx.setMaterialToAllFaces( new FillMaterial(0xFFBbBbBb) );
                //bx.x = 15;
                bx.y = -5;
                cbox.addChild(bx);
                
                cont.addChild(cbox);
                gBox = cbox;
                
                
                /*
                var box:Box;
                box = new Box(20,20,50,1,1,1);
               // box.setMaterialToAllFaces( new FillMaterial(0) );
                box.setMaterialToAllFaces( new TextureMaterial( bm) );
               
                  cont.addChild(box);
                  gBox = box;
                  */
                  
                  //shadow
               p = new Plane(20, 50);
               p.setMaterialToAllFaces( new FillMaterial(0, 0.65) );
                p.rotationX = 1.57; 
                  p.y= 180;
                  
                  cont.addChild(p);
                  gShad = p;
                  
                 makeDeco();
                 makeSky();
                  
                  stage.addEventListener(Event.ENTER_FRAME, onEnter);  
                  stage.addEventListener(KeyboardEvent.KEY_DOWN, kdown);
                  stage.addEventListener(KeyboardEvent.KEY_UP, kup);    
               
               
        }//ctor
        
        public function makeSky():void
        {
            var bm:BitmapData;
             bm = new BitmapData(32,32,false,0);
             bm.noise(123213,0,255,4);
             bm.draw( new BitmapData(32,32,true,0x1FaaaaFF) );
            
            var tex:TextureMaterial = new TextureMaterial(bm);            
            var sk:SkyBox;
            
            sk = new SkyBox(16385, tex, tex, tex,  tex, tex, tex);
            cont.addChild(sk);
            sbox = sk;
        }//makesky
        
        public function makeDeco():void
        {
            var b:Box;
            var i:int;
            var h:Number;
            
            var bm:BitmapData;
            bm = new BitmapData(8,8,false,0);
            bm.noise(12321);
            var tex:FlatShadingMaterial;
            tex = new FlatShadingMaterial(bm);
            
            for (i = 0; i < 128; i++)
            {
                h = 30 + Math.random() * 400;
                 b = new Box(10+Math.random() *500, h, 10 + Math.random() * 500);
               //   b.setMaterialToAllFaces( new FillMaterial( Math.random() * 0xFFffFFff, 1, 1, 0) );
                   b.setMaterialToAllFaces(tex);
                  b.x = (Math.random()-Math.random()) * (8192 );
                   b.z= (Math.random()-Math.random()) * (8192 );
                   b.y = 200 - 1 - h *0.5 ;
                   cont.addChild(b);  
                
            }//nexti
            
            
        }//deco
        
        
        public var ang:Number = 0;
        
        public function onEnter(e:Event):void
        {
            //ref
         //http://www.dakmm.com/?p=272
          /*
            if (cKeyMan.isKeyDown(39) ) { cam.x -= 20;}
            if (cKeyMan.isKeyDown(37) ) { cam.x += 20;}
            if (cKeyMan.isKeyDown(38) ) { cam.y += 20;}
            if (cKeyMan.isKeyDown(40) ) { cam.y -= 20;}
           */ 
            //gBox.rotationY += 0.1;
            
            if (cKeyMan.isKeyDown(39) ) { ang -= 0.04;}
            if (cKeyMan.isKeyDown(37) ) { ang += 0.04;}
            
            if (cKeyMan.isKeyDown(38) ) { gBox.y -= 5; if (gBox.rotationX < 0.4) {gBox.rotationX += 0.06;} }
            if (cKeyMan.isKeyDown(40) ) { gBox.y += 5; if (gBox.rotationX > -0.4) {gBox.rotationX -= 0.06;} }
            
            if (gBox.y >= 160) { gBox.y = 160; }
            
            if (gBox.x < -8192) {gBox.x = -8192;}
            if (gBox.x > 8192) {gBox.x = 8192;}
            if (gBox.z < -8192) {gBox.z = -8192;}
            if (gBox.z > 8192) {gBox.z = 8192;}
            
            gShad.x = gBox.x;
            gShad.z = gBox.z;
            
            
            var bx:Number;
            var bz:Number;
            var by:Number;
            
            var dist:Number = 300;
            
            bx = gBox.x - Math.cos(ang) * dist;
            bz = gBox.z - Math.sin(ang) * dist;
            
            by = gBox.y - 50;
            
            cam.x +=  (bx - cam.x) * 0.2;
            cam.z += (bz - cam.z) * 0.2;
            cam.y += (by - cam.y) * 0.05;
            
            gBox.rotationY = -ang + (3.1415 *0.5);
            gShad.rotationY = -ang + (3.1415 *0.5);
            cam.rotationY = -ang + (3.1415 *0.5);
            
            gBox.rotationX *= 0.95;
            
            gBox.x += Math.cos(ang) * 25;
            gBox.z += Math.sin(ang) * 25;
            
            sbox.x = cam.x;
            sbox.y = cam.y;
            sbox.z = cam.z;
            
             cam.render();
             
        }//onenter
        
        public function kdown(e:KeyboardEvent):void
        {
         cKeyMan.setKey(e.keyCode, true);   
        }//kdown
        
        public function kup(e:KeyboardEvent):void
        {
          cKeyMan.setKey(e.keyCode, false);  
        }//kup
        
        
    }//flashtest
}//package


internal class cKeyMan
   {
       public function cKeyMan() {}//ctor (unused)
       
       public static var vecKey:Vector.<Boolean> = new Vector.<Boolean>(512,true);
       
       public static function setKey(k:int, b:Boolean):void
       {
           if (k < 0) return;
           if (k >= 512) return;
           vecKey[k] = b;
       }//setkey
       
       public static function isKeyDown(k:int):Boolean
       {
           if  (k < 0) return false;
           if (k >= 512) return false;
           return vecKey[k];
       }//iskey
       
   }//keyman