topical media & game development

talk show tell print

student-papervision-samples-CF02.ax

student-papervision-samples-CF02.ax [swf] flex


  package  {
          import student_papervision_samples_PaperBase;
          
          import org.papervision3d.lights.PointLight3D;
          import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
          import org.papervision3d.materials.utils.MaterialsList;
          import org.papervision3d.materials.WireframeMaterial;
          import org.papervision3d.objects.primitives.Cube;
          import org.papervision3d.objects.primitives.Plane;
          import org.papervision3d.cameras.Camera3D;
          import org.papervision3d.materials.BitmapFileMaterial;
          
          import caurina.transitions.Tweener;
          
          import flash.events.KeyboardEvent;
          import flash.text.TextField;
          import flash.text.TextFormat;
  
          public class @ax-student-papervision-samples-CF02 extends student_papervision_samples_PaperBase {
                  public var updown:Boolean = false;
                  public var leftdown:Boolean = false;
                  public var downdown:Boolean = false;
                  public var rightdown:Boolean = false;
                  public var speed:Number = 150; //here you can set the speed of the object. 
                  public var text:TextField = new TextField();
                  
                  private var fontstyle:TextFormat = new TextFormat("Arial",44,0x000000);
                  private var cube:Cube;
                  private var cube2:Cube;
                  private var mat:FlatShadeMaterial = new FlatShadeMaterial(new PointLight3D(), 0xFFFFFF, 0xFF0000);
                  private var mat2:WireframeMaterial = new WireframeMaterial(0x00FF00);
                  private var plane:Plane = new Plane(null, 2000, 2000, 10, 10);
                  
             
                  public function @ax-student-papervision-samples-CF02() {
                          init(600, 300);
                          
                          stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
                          stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
                  }
                  
                  override protected function init3d():void{
                          cube = new Cube(new MaterialsList( { all: mat } ), 100, 100, 100);
                          cube.y = 0;
                          cube2 = new Cube(new MaterialsList( { all: mat2 } ), 100, 100, 100);
                          cube2.y = 0;
                          cube2.x = 1000;
                          cube2.z = 1000;
                          plane.material.lineColor = 0x777777;
                          plane.material.doubleSided = true;
                          plane.pitch(90);
                          plane.y = -50;
                          default_scene.addChild(plane);
                          default_scene.addChild(cube);
                          default_scene.addChild(cube2);
                          Tweener.addTween(cube, { x:1000, z:1000, time:2, onComplete: randomize } );
                          default_camera.x = 0;
                          default_camera.z = 1000;
                          default_camera.y = 1000;
                  }
                  
                  override protected function init2d():void {
                          addChild(text);        
                          text.selectable = false;
                          text.setTextFormat(fontstyle);
                          text.width = 800;
                          text.text = "Multimedia Authoring - ~vr0815";
                  }
                  
                  public function randomize():void {
                          cube2.x = cube.x;
                          cube2.z = cube.z;
                  }
                  
                  public function onKeyDown( event:KeyboardEvent ):void {
                          switch(event.keyCode) {
                                  case 38:
                                          updown = true;
                                  break;
                                  case 37:
                                          leftdown = true;
                                  break;
                                  case 40:
                                          downdown = true;
                                  break;
                                  case 39:
                                          rightdown = true;
                                  break;
                          }
                  }
                  
                  public function onKeyUp( event:KeyboardEvent ):void {
                          switch(event.keyCode) {
                                  case 38:
                                          updown = false;
                                  break;
                                  case 37:
                                          leftdown = false;
                                  break;
                                  case 40:
                                          downdown = false;
                                  break;
                                  case 39:
                                          rightdown = false;
                                  break;
                          }
                  }
                  
                  override protected function processFrame():void {
                          var xp:Number = 0;
                          var yp:Number = 0;
                                                  
                          if (updown && leftdown) {
                                  xp = cube.x + speed;
                                  yp = cube.z + speed;
                                  Tweener.addTween(cube, { x:xp, z:yp, time:2, onComplete: randomize } );
                          } else if (updown && rightdown) {
                                  xp = cube.x + speed;
                                  yp = cube.z - speed;
                                  Tweener.addTween(cube, { x:xp, z:yp, time:2, onComplete: randomize } );
                          } else if (downdown && leftdown) {
                                  xp = cube.x - speed;
                                  yp = cube.z + speed;
                                  Tweener.addTween(cube, { x:xp, z:yp, time:2, onComplete: randomize } );
                          } else if (downdown && rightdown) {
                                  xp = cube.x - speed;
                                  yp = cube.z - speed;
                                  Tweener.addTween(cube, { x:xp, z:yp, time:2, onComplete: randomize } );
                          } else if (updown) {
                                  xp = cube.x + speed;
                                  yp = cube.z;
                                  Tweener.addTween(cube, { x:xp, z:yp, time:2, onComplete: randomize } );
                          } else if (downdown) {
                                  xp = cube.x - speed;
                                  yp = cube.z;
                                  Tweener.addTween(cube, { x:xp, z:yp, time:2, onComplete: randomize } );
                          } else if (leftdown) {
                                  xp = cube.x;
                                  yp = cube.z + speed;
                                  Tweener.addTween(cube, { x:xp, z:yp, time:2, onComplete: randomize } );
                          } else if (rightdown) {
                                  xp = cube.x;
                                  yp = cube.z - speed;
                                  Tweener.addTween(cube, { x:xp, z:yp, time:2, onComplete: randomize } );
                          }
                          default_camera.lookAt(cube);
                  }
          }
  }
  


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.