MJTheOne

Away3D-Minecraft

Nov 20th, 2012
4,768
0
Never
2
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package {
  2.     import away3d.animators.*;
  3.     import away3d.animators.data.*;
  4.     import away3d.animators.transitions.*;
  5.     import away3d.cameras.*;
  6.     import away3d.containers.*;
  7.     import away3d.controllers.*;
  8.     import away3d.debug.*;
  9.     import away3d.entities.*;
  10.     import away3d.events.*;
  11.     import away3d.library.*;
  12.     import away3d.lights.*;
  13.     import away3d.loaders.*;
  14.     import away3d.loaders.parsers.*;
  15.     import away3d.materials.*;
  16.     import away3d.materials.lightpickers.*;
  17.     import away3d.materials.methods.*;
  18.     import away3d.primitives.*;
  19.     import away3d.textures.*;
  20.    
  21.     import flash.display.*;
  22.     import flash.events.*;
  23.     import flash.filters.*;
  24.     import flash.geom.*;
  25.     import flash.net.*;
  26.     import flash.text.*;
  27.     import flash.ui.*;
  28.    
  29.     [SWF(width=640, height=480, frameRate=60, backgroundColor="#e0e0e0")]
  30.     public class MinecraftAway extends Sprite {
  31.        
  32.         [Embed(source="bottom.jpg")]
  33.         private var I1:Class;
  34.         [Embed(source="side.jpg")]
  35.         private var I2:Class;
  36.         [Embed(source="top.jpg")]
  37.         private var I3:Class;
  38.        
  39.         private var view:View3D;
  40.         private var cube:Mesh;
  41.         private var hc:HoverController;
  42.        
  43.         private var awayStats:AwayStats;
  44.        
  45.         //DragEase
  46.         private var destination:Point = new Point();
  47.         private var dragging:Boolean = false;
  48.         private var speed:Number = 20;
  49.         private var offset:Point = new Point();
  50.        
  51.         private var cubeY:Number = 0;
  52.         private var cubeX:Number = 0;
  53.        
  54.         public function MinecraftAway() {
  55.             setupScene();
  56.         }
  57.        
  58.         private function setupScene():void {
  59.             view = new View3D();
  60.             view.backgroundColor = 0xe0e0e0;
  61.             view.antiAlias = 4;
  62.            
  63.             addChild(view);
  64.            
  65.             var bct:BitmapCubeTexture = new BitmapCubeTexture(new I2().bitmapData,
  66.                 new I2().bitmapData,
  67.                 new I3().bitmapData,
  68.                 new I1().bitmapData,
  69.                 new I2().bitmapData,
  70.                 new I2().bitmapData)
  71.            
  72.             cube = new Mesh(new CubeGeometry(), new SkyBoxMaterial(bct));
  73.            
  74.             view.scene.addChild(cube);
  75.            
  76.             view.camera.z = -500;
  77.             view.camera.y = 300;
  78.             view.camera.lookAt(new Vector3D());
  79.            
  80.             hc = new HoverController(view.camera, null, 150, 10, 200);
  81.            
  82.             addEventListener(Event.ENTER_FRAME, loop);
  83.             cube.addEventListener(MouseEvent3D.MOUSE_DOWN, startDragCube);
  84.             addEventListener(MouseEvent.MOUSE_UP, stopDragCube);
  85.             addEventListener(MouseEvent.MOUSE_OUT, stopDragCube);
  86.            
  87.             awayStats = new AwayStats(view);
  88.             addChild(awayStats);
  89.            
  90.             cube.mouseEnabled = true;
  91.         }
  92.        
  93.         private function startDragCube(e:MouseEvent3D):void {
  94.             /*offset.x = mouseX - cube.rotationY;
  95.             offset.y = mouseY - cube.rotationX;*/
  96.             offset.x = mouseX;
  97.             cubeY = cube.rotationY;
  98.             offset.y = mouseY;
  99.             cubeX = cube.rotationX;
  100.             dragging = true;
  101.         }
  102.        
  103.         private function stopDragCube(e:MouseEvent):void {
  104.             dragging = false;
  105.         }
  106.        
  107.         protected function loop(e:Event):void {
  108.             if (dragging) {
  109.                 destination.x = mouseX;
  110.                 destination.y = mouseY;
  111.             }
  112.             /*cube.rotationX -= (cube.rotationX - (destination.y - offset.y)) / speed;
  113.             cube.rotationY -= (cube.rotationY - (destination.x - offset.x)) / speed;*/
  114.             cube.rotationX -= (cube.rotationX - (cubeX - (destination.y - offset.y))) / speed;
  115.             cube.rotationY -= (cube.rotationY - (cubeY - (destination.x - offset.x))) / speed;
  116.             view.render();
  117.         }
  118.     }
  119. }
Advertisement