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

wolrd 3d

package
{
    import alternativ5.engine3d.controllers.*;
    import alternativ5.engine3d.core.*;
    import alternativ5.engine3d.display.*;
    import alternativ5.engine3d.materials.*;
    import alternativ5.engine3d.primitives.*;
    import alternativ5.types.*;
    import alternativ5.utils.*;

    import flash.net.*;
    import flash.display.*;
    import flash.events.*;
    import flash.geom.*;
    [SWF(frameRate="60")]

    public class Main extends Sprite
    {
        private const WIDTH_NUM:int = 10;
        private const HEIGHT_NUM:int = 10;
        private const LINE_SIZE:int = 500;
        
        private const MAZE_ARR:Array = 
        [
            [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
            [1, 0, 0, 0, 0, 0, 0, 0, 0, 1],
            [1, 0, 1, 1, 1, 1, 1, 1, 0, 1],
            [1, 0, 0, 0, 0, 0, 0, 0, 0, 1],
            [1, 0, 1, 1, 1, 1, 1, 1, 0, 1],
            [1, 0, 0, 0, 0, 0, 0, 0, 0, 1],
            [1, 0, 1, 1, 1, 1, 1, 1, 0, 1],
            [1, 0, 0, 0, 0, 0, 0, 0, 0, 1],
            [1, 0, 1, 1, 0, 0, 1, 1, 0, 1],
            [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
        ]
        
        private var scene:Scene3D;
        private var view:View;
        private var camera:Camera3D;
        
        // The camera controller
        private var controller:WalkController;
        

        public function Main()
        {
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
            
            // Creating scene
            scene = new Scene3D();
            scene.root = new Object3D();
            
            // create box
            for (var i:int = 0; i < MAZE_ARR.length; i++ )
            {
                for (var j:int = 0; j < MAZE_ARR[i].length; j++ )
                {
                    if (MAZE_ARR[i][j] == 0) continue;
                                       
                    var box:Box = Box(scene.root.addChild(new Box(LINE_SIZE, LINE_SIZE, LINE_SIZE)));
                    box.cloneMaterialToAllSurfaces(new FillMaterial (0xFFFFCC, 1, BlendMode.NORMAL, 2, 0));
                    box.x = LINE_SIZE * (i - WIDTH_NUM / 2);
                    box.y = LINE_SIZE * (j - HEIGHT_NUM / 2);
           
               }
            }
            var plane:Plane = Plane(scene.root.addChild(new Plane(LINE_SIZE * MAZE_ARR.length, LINE_SIZE * MAZE_ARR.length)));
            plane.cloneMaterialToAllSurfaces(new FillMaterial(0xFFCCFF));
            
            plane.z = -LINE_SIZE / 2;
            plane.rotationX = 0 * Math.PI / 180;
            
            // Adding camera and view
            camera = new Camera3D();
            camera.rotationX = MathUtils.toRadian(-90)
            camera.rotationZ = MathUtils.toRadian(120)
            scene.root.addChild(camera);
            view = new View();
            addChild(view);
            view.camera = camera;
            

            controller = new WalkController(stage);
            

            controller.setDefaultBindings();

            controller.bindKey(KeyboardUtils.UP, ObjectController.ACTION_FORWARD);
            controller.bindKey(KeyboardUtils.DOWN, ObjectController.ACTION_BACK);
            controller.bindKey(KeyboardUtils.LEFT, ObjectController.ACTION_LEFT);
            controller.bindKey(KeyboardUtils.RIGHT, ObjectController.ACTION_RIGHT);
            

            controller.object = camera;

            controller.checkCollisions = true;

            controller.speed = 1500;

            controller.jumpSpeed = 350;

            controller.gravity = 600;

            controller.objectZPosition = 1;
            
            // FPS display launch
            // FPS.init(stage);
            
            stage.addEventListener(Event.RESIZE, onResize);
            stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
            onResize(null);
        }
        
 
        
        private function onEnterFrame(e:Event):void
        {
            // interface
            controller.processInput();
            
            // Scene calculating
            scene.calculate();
        }
        


        private function onResize(e:Event):void
        {
            view.width = stage.stageWidth;
            view.height = stage.stageHeight;
            
            // BackGround Color
            var bgMatrix:Matrix = new Matrix();
            bgMatrix.rotate(90 * Math.PI / 180);
            graphics.clear()
            graphics.beginGradientFill("linear", [0xFFFFFF, 0x009933], [100, 100], [0, 255], bgMatrix);
            graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
     
           

}
   }
}