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

Sandy Spaceship Game (With Explosions)

3d Spaceship Model in Sandy
Arrow Keys to move
Spacebar to fire laser
Going to add Mode7 ground soon...
// 3d Spaceship Model in Sandy
// Arrow Keys to move
// Spacebar to fire laser
// Going to add Mode7 ground soon...
package {
	import flash.display.*
	import flash.events.*;
        import flash.text.*;

	[SWF(width="465",height="465",backgroundColor="0x000000",frameRate="45")]
	public class AS3Code extends Sprite {
		public function AS3Code() {
			main=this;
                        stage.addChild(main);
                        
                            debugText = new TextField();
                            debugText.width = 400;
                            debugText.height = 300;
                            debugText.multiline = true;
                            debugText.wordWrap = true;
                            debugText.textColor = 0xFF00FF;
                            debugText.selectable = false;
                            stage.addChild(debugText);
                        
			initialize();

                        stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
			stage.addEventListener(KeyboardEvent.KEY_UP, keyReleased);
			
			addEventListener(Event.ENTER_FRAME, EveryFrame);

		}
	}
}
import flash.display.*;
import flash.events.*;
import flash.ui.*;
import flash.utils.*;
import flash.filters.*
import flash.text.*;
import flash.geom.*
import flash.media.*
import flash.net.*
//
import sandy.core.*;
import sandy.core.data.*;
import sandy.core.scenegraph.*;
import sandy.events.*
import sandy.materials.*;
import sandy.materials.attributes.*;
import sandy.primitive.*;
//
var main:Sprite;
var debugText:TextField = new TextField();
//
var scene:Scene3D;
var camera:Camera3D;
var root:Group;

var lightA:LightAttributes = new LightAttributes (true, 0.5);
var lightB:GouraudAttributes = new GouraudAttributes (true, 0.25);

var arwing:Arwing;
var Ship:ShipVars = new ShipVars();
var stars:Array = [];
var StarAmount:uint = 400;
var CalculatedSpeed:Number = 40;

var objectHolder:Array = [];
var objectexists:Array = [];
var objectnum:Number = 0;

var particleHolder:Array = [];
var particleexists:Array = [];
var particlenum:Number = 0;
var particles:StarField = new StarField ();

var spriteHolder:Array = [];
var spriteexists:Array = [];
var spritenum:Number = 0;

var p:Point = new Point ();
var f:BlurFilter = new BlurFilter (); 
var ct:ColorTransform = new ColorTransform (0.9, 0.7, 0.5);

function initialize():void {
    
    camera = new Camera3D( 465, 465);
    camera.z = -1500;
    camera.y = 0;
    root = new Group();
    
    lightA.diffuse = 0.5;
    lightA.specular = 0.5;
    lightA.gloss = 1;
    lightA.ambient = 0.5;
    
    lightB.diffuse = 2.5;
    lightB.specular = 1.5;
    lightB.gloss = 1;
    lightB.ambient = 0.4;
    
    arwing = new Arwing( "arwing");
    var materialAttr:MaterialAttributes = new MaterialAttributes(lightB);
     
    var colorArray:Array = [];
    for(var i:int=0;i<212;i++){
	    if(i > 0 && i <20){
		colorArray[i] = 0x212E9A;
	    }else{
		colorArray[i] = 0xAAAAAA;
	    }
    }
    var material:Material = new ColorMaterial2( 0xAAAAAA, 1, materialAttr, colorArray);
    material.lightingEnable = true;
    arwing.appearance = new Appearance(material)
    arwing.rotateY = 180;
    arwing.boundingSphere.radius = 400;
    root.addChild(arwing);
    var sf:StarField = new StarField();
    for (i = 0; i<StarAmount; i++) {
	//var stars[i]:Vertex = new Vertex ();
	stars[i] = new Vertex ();
	stars[i].x = 10000*(Math.random()-Math.random());
	stars[i].z = -2000+10000*(Math.random()-Math.random());
	stars[i].y = 5000*(Math.random()-Math.random());
	
	sf.stars.push(stars[i]);
	sf.starColors.push(0xFF000000 + Math.floor(Math.random() * 0xFFFFFF));
	sf.fadeFrom = 4000;
	sf.fadeTo = 15000;
    }
    sf.container.filters = [ new GlowFilter (0x7FFF, 0.5, 3, 3, 3) ];
    root.addChild(sf);
    
    particles = new StarField ();
    root.addChild(particles);
    particles.addEventListener (StarFieldRenderEvent.BEFORE_RENDER, beforeRenderHandler);
    //particles.container.filters = [new BlurFilter (4,4,1)];
    
    //var enemy:BasicEnemy1 = new BasicEnemy1("enemy");
    //enemy.appearance = new Appearance(material)
    //root.addChild(enemy);
    
    
    scene = new Scene3D( "scene", main, camera, root );
    scene.light.color = 0xFFFFFF;
    scene.light.setDirection(0, -100, 0);
    scene.light.setPower(2.5);
}
var count:int = 0;
function EveryFrame(event:Event):void{
    //debugText.text = "Text";
    
    var i:int = 0;
    var z:int = 0;
    
    if(isDown(Keyboard.RIGHT)){
        Ship.xspeed += 3;    
    }
     if(isDown(Keyboard.LEFT)){
        Ship.xspeed -= 3;  
    }
     if(isDown(Keyboard.UP)){
        Ship.yspeed += 3;    
    }
     if(isDown(Keyboard.DOWN)){
        Ship.yspeed -= 3;  
    }
    Ship.x += Ship.xspeed;
    Ship.y += Ship.yspeed;
    Ship.x = Math.min(Ship.x,800);
    Ship.x = Math.max(Ship.x,-800);
    Ship.y = Math.min(Ship.y,700);
    Ship.y = Math.max(Ship.y,-700);
    Ship.xspeed *= 0.9;
    Ship.yspeed *= 0.9;
    
    arwing.x = Ship.x;
    arwing.y = Ship.y;
    
    arwing.rotateY = 0;
    arwing.rotateZ = 0;
    arwing.lookAt(arwing.x,arwing.y,arwing.z-50);
    arwing.rotateY = 0;
    
    arwing.rotateZ += Ship.zrot;
    arwing.rotateX -= Ship.yspeed*0.75;
    arwing.rotateY = -Ship.xspeed*0.75;
    
    camera.x += ((-arwing.x/2)-camera.x)/5;
    camera.y += (((arwing.y+700)/4)-camera.y)/5;
    camera.lookAt(arwing.x/5,arwing.y/5,arwing.z);
    
    count++;
    if(count%30 == 0){
        createBasicEnemy1(Math.random()*2000-1000,Math.random()*1000-500,10000, [Math.random()*0.5-0.25,0,1], "BasicEnemy1EnterFrame",20);
    }
    if(isDown(Keyboard.SPACE)){
          if(count%5 == 0){
               shootlaser();
               //createBasicEnemy1(Math.random()*2000-1000,Math.random()*1000-500,5000, [Math.random()*0.5-0.25,0,1], "BasicEnemy1EnterFrame",20);
          }
     }
    
    var arraycounter:int = 0;
    for (i = 0; i<objectnum+1; i++) {
	if (objectexists[i] == true) {
		arraycounter = i;
		//this[objectHolder[i].functionname](i);
                if(objectHolder[i].functionname == "BasicEnemy1EnterFrame"){
                    BasicEnemy1EnterFrame(i);
                }else if(objectHolder[i].functionname == "LaserEnterFrame"){
                    LaserEnterFrame(i);
                }
                
	}
    }
    objectnum  = arraycounter+1;
    
    arraycounter = 0;
    for (i = 0; i<particlenum+1; i++) {
	if (particleexists[i] == true) {
		arraycounter = i;
		//this[spriteHolder[i].functionname](i);
                ParticleEnterFrame(i);
            
	}
    }
    particlenum  = arraycounter+1;
    
    
      
    
    
    
    for (i = 0; i<StarAmount; i++) {
	stars[i].z -= CalculatedSpeed;
	if(stars[i].z < -3000){
		stars[i].z += 20000;
	}
    }
    scene.render();
}

function shootlaser():void {
    for (var i:int = 0; i<objectnum+1; i++) {
	if (objectexists[i] !== true) {
		objectexists[i] = true;
                if(i > objectnum){
                    objectHolder.push(new ObjectVars());
                }else{
                    objectHolder[i] = new ObjectVars();
                }
                objectHolder[i].exists = true;
	        objectHolder[i].object = new Laser("laser"+i);
	        var lasermaterialAttr:MaterialAttributes=new MaterialAttributes(new LightAttributes(true,0.2));
	        var lasermaterial:Material = new ColorMaterial( 0x00FF00, 0.5, lasermaterialAttr);
	        objectHolder[i].object.appearance = new Appearance(lasermaterial);
	         //
	        objectHolder[i].object.x = arwing.x;
	        objectHolder[i].object.y = arwing.y;
	        objectHolder[i].object.z = arwing.z;
                arwing.moveForward(-100);
	        objectHolder[i].object.lookAt(arwing.x,arwing.y,arwing.z);
                arwing.moveForward(100);
	        objectHolder[i].object.scaleZ = 30;
	        objectHolder[i].object.moveForward(-500);
	        objectHolder[i].functionname = "LaserEnterFrame";
	        objectHolder[i].Name = "laser"
	        objectHolder[i].count = 0;
                objectHolder[i].object.boundingSphere.radius = 100;
                //objectHolder[i].object.filters = [ new BlurFilter (4, 4, 2) ];
			
	        scene.root.addChild(objectHolder[i].object);
		objectnum++;
		break;
            }
        }
}
function LaserEnterFrame(i:int):void {
    var h:int = 0;
    var j:int = 0;
    var removed:Boolean = false;
    for(j=0;j<10;j++){
    	objectHolder[i].object.moveForward(1000/10);
        // insert collision detection
        for(h=0;h<objectnum;h++){
	    if (objectexists[h] == true) {
		if(h!==i){
		    if(objectHolder[h].Name == "BasicEnemy1"){
			if(Math.abs(objectHolder[i].object.x-objectHolder[h].object.x)<200 &&
                           Math.abs(objectHolder[i].object.y-objectHolder[h].object.y)<200 && 
                           Math.abs(objectHolder[i].object.z-objectHolder[h].object.z)<200 &&
                           objectHolder[h].count > 0
                        ){ 
			    // laser collide
			    
			    BasicEnemy1Hit(h);

                            removed = true;
		            //
			    j = 200;
			    h = objectnum+1;
			    break;
			    break;
			    break;
			}
		    }
                }
            }
        }
        
        
           
    }
    if(objectHolder[i].count == 0){
	    objectHolder[i].object.scaleZ = 40;
    }else if(objectHolder[i].count == 1){
	    objectHolder[i].object.scaleZ = 60;
    }else{
	    objectHolder[i].object.scaleZ = 80;
    }
    //objectHolder[i].count++;
    if(objectHolder[i].object.z > 20000){
	    removed = true;
    }
    if(objectexists[i] == true){
        if(removed == true){
           objectexists[i] = false;
           objectHolder[i].object.destroy();
           //objectHolder[i] = null;
        }
    }		
}


function createBasicEnemy1(X:Number,Y:Number, Z:Number, rot:Array, functionname:String, speed:Number):void {
    for (var i:int = 0; i<objectnum+1; i++) {
	if (objectexists[i] !== true) {
		objectexists[i] = true;
                if(i >= objectnum){
                    objectHolder.push(new ObjectVars());
                }else{
                    objectHolder[i] = new ObjectVars();
                }
                objectHolder[i].exists = true;
		objectHolder[i].object = new BasicEnemy1("BasicEnemy1"+i);
		var materialAttr:MaterialAttributes= new MaterialAttributes (lightB);
		var material:Material = new ColorMaterial( 0xAAAAAA, 1, materialAttr);
		material.lightingEnable = true;
		objectHolder[i].object.appearance = new Appearance(material);
		//
		objectHolder[i].object.x = X;
		objectHolder[i].object.y = Y;
		objectHolder[i].object.z = Z;
		//objectHolder[i].object.lookAt(pointer1.x,pointer1.y,pointer1.z);
		objectHolder[i].object.lookAt(X+rot[0],Y+rot[1],Z+rot[2])
		objectHolder[i].functionname = functionname;
		objectHolder[i].Name = "BasicEnemy1";
		objectHolder[i].speed = speed;
		objectHolder[i].HP = 1;
		objectHolder[i].count = 0;
		objectHolder[i].object.boundingSphere.radius = 100;
		objectHolder[i].X2 = 50;
		objectHolder[i].Y2 = 30;
		objectHolder[i].Z2 = 30;
		//
		scene.root.addChild(objectHolder[i].object);
		objectnum++;
		break;
            }
        }
}
function BasicEnemy1EnterFrame(i:int):void {
    var removed:Boolean = false;
    objectHolder[i].count++;
    if(objectHolder[i].HP > 0){
	objectHolder[i].object.z -= CalculatedSpeed;
	objectHolder[i].object.moveForward(-objectHolder[i].speed);
        if(objectHolder[i].object.z < -2000){
            removed = true
        }
    }else{
	removed = true
    }
    if(removed == true){
        objectexists[i] = false;
        objectHolder[i].object.destroy();
        //objectHolder[i] = null;
    }	
}
function BasicEnemy1Hit(who:int):void {
    if(objectHolder[who].HP > 0){
        objectHolder[who].HP = 0;
        // add explosion
        for(var q:int = 0;q<50;q++){
            createParticle(objectHolder[who].object.x,objectHolder[who].object.y,objectHolder[who].object.z,
            Math.random()*50-25,Math.random()*50-25,Math.random()*50-25, "particleEnterFrame", Math.random()*50+20);
        }
    }
}
function createParticle(X:Number,Y:Number, Z:Number, Xspeed:Number, Yspeed:Number, Zspeed:Number,
 functionname:String, lifeTime:Number):void {
     //debugText.appendText("Create Particle ");
    for (var p:int = 0; p<particlenum+1; p++) {
	if (particleexists[p] !== true) {
                   //debugText.appendText(p+"\n");
		particleexists[p] = true;
                if(p >= particlenum){
                    particleHolder.push(new ObjectVars());
                }else{
                    particleHolder[p] = new ObjectVars();
                }
                particleHolder[p].exists = true;
                
                particleHolder[p].vertex = new Vertex ();
		particleHolder[p].vertex.x = X;
		particleHolder[p].vertex.y = Y;
                particleHolder[p].vertex.z = Z;
                
                var gfx:MovieClip = new Circle;
                gfx.blendMode = BlendMode.ADD;
                particles.starSprites[p] = gfx;
                
                particleHolder[p].xspeed = Xspeed;
		particleHolder[p].yspeed = Yspeed;
                particleHolder[p].zspeed = Zspeed;
                particleHolder[p].lifeTime = lifeTime;
                
		//particles.stars.push(particleHolder[p].vertex);
                particles.stars[p] = particleHolder[p].vertex
		//particles.starColors[p] = (0xFF000000 + Math.floor(Math.random() * 0xFFFFFF));
		particles.starColors[p] = 0xFFFF0000;
                particles.fadeFrom = 10000;
		particles.fadeTo = 15000;
                particlenum++;
                break;
        }
    }
}
function ParticleEnterFrame(i:int):void {
    
    var removed:Boolean = false;
    particleHolder[i].count++;
    if(true){
	particleHolder[i].vertex.z -= CalculatedSpeed;
	particleHolder[i].vertex.x += particleHolder[i].xspeed;
        particleHolder[i].vertex.y += particleHolder[i].yspeed;
        particleHolder[i].vertex.z += particleHolder[i].zspeed;
        particleHolder[i].yspeed -= 1;
        if(particleHolder[i].count > particleHolder[i].lifeTime){
            removed = true
        }
    }else{
	removed = true
    }
    if(removed == true){
       particleexists[i] = false;
       particleHolder[i].vertex = null;
       particles.starColors[i] = null;
        //objectHolder[i] = null;
    }	
}
function beforeRenderHandler (event:StarFieldRenderEvent):void {
    //debugText.appendText(String(event));
    // do not clear bitmap data from last frame
    event.clear = false;
    // blur and fade instead
    event.bitmapData.applyFilter (event.bitmapData, event.bitmapData.rect, p, f);
    event.bitmapData.colorTransform (event.bitmapData.rect, ct);      

}
class ShipVars{
    public var xspeed:Number = 0;
    public var yspeed:Number = 0;
    public var x:Number = 0;
    public var y:Number = 0;
    public var zrot:Number = 0;
}
class ObjectVars{
    public var xspeed:Number = 0;
    public var yspeed:Number = 0;
    public var zspeed:Number = 0;
    public var X2:Number = 0;
    public var Y2:Number = 0;
    public var Z2:Number = 0;
    public var HP:Number;
    public var count:Number = 0;
    public var speed:Number = 0;
    public var exists:Boolean = false;
    public var object;
    public var vertex:Vertex;
    public var lifeTime:Number;
    public var functionname:String;
    public var Name:String;
    public var aArray:Array = new Array();
}
class Circle extends MovieClip{
    //var clip:MovieClip = new MovieClip();
    public var sprite:Sprite = new Sprite();
    public function Circle():void{
        var size:Number = 40;
        var matrix:Matrix = new Matrix;
        matrix.createGradientBox(size * 2, size * 2, 0, -size, -size);
        sprite.graphics.beginGradientFill(GradientType.RADIAL,
         [0xFFFFFF,0xFFFFFF], // colors
         [0xFF, 0x00],        // alpha
         [0x00, 0xFF],        // ratio
         matrix,
         SpreadMethod.PAD
         );
        sprite.graphics.drawCircle( 0, 0, size); 
        sprite.graphics.endFill();
        addChild(sprite);
    }
    
}

var initialized:Boolean = false;// marks whether or not the class has been initialized
var keysDown:Object = new Object();// stores key codes of all keys pressed
function isDown(keyCode:uint):Boolean {
	return Boolean(keyCode in keysDown);
}
function keyPressed(event:KeyboardEvent):void {
       	keysDown[event.keyCode] = true;
}
function keyReleased(event:KeyboardEvent):void {
	if (event.keyCode in keysDown) {
		delete keysDown[event.keyCode];
	}
}
class Arwing extends Shape3D implements Primitive3D {
		private var l:Geometry3D;

		private function f(v1:Number,v2:Number,v3:Number,uv00:Number,uv01:Number,uv10:Number,uv11:Number,uv20:Number,uv21:Number,normX:Number,normY:Number,normZ:Number):void {
			var uv1:Number = l.getNextUVCoordID();
			var uv2:Number = uv1 + 1;
			var uv3:Number = uv2 + 1;

			l.setUVCoords(uv1,uv00,1-uv01);
			l.setUVCoords(uv2,uv10,1-uv11);
			l.setUVCoords(uv3,uv20,1-uv21);

			l.setFaceVertexIds(l.getNextFaceID(), v1,v2,v3);
			l.setFaceUVCoordsIds(l.getNextFaceUVCoordID(), uv1,uv2,uv3);
			l.setFaceNormal(l.getNextFaceNormalID(), normX,normZ,normY);
		}

		private function f2(v1:Number,v2:Number,v3:Number):void {
			l.setFaceVertexIds(l.getNextFaceID(), v1,v2,v3);
		}

		private function v(vx:Number,vy:Number,vz:Number):void {
			l.setVertex(l.getNextVertexID(),vx,vz,vy);
		}

		public function Arwing( p_Name:String=null ) {
			super( p_Name );
			geometry = generate();
		}

		public function generate(... arguments):Geometry3D {
			l = new Geometry3D();
			v(1.000000,1.000000,-0.683356);
			v(0.944110,-1.095600,-0.645164);
			v(-0.944111,-1.095600,-0.645164);
			v(-1.000000,1.000000,-0.683356);
			v(1.000000,0.999999,0.683356);
			v(0.944110,-1.095600,0.645164);
			v(-0.944111,-1.095600,0.645164);
			v(-1.000000,1.000000,0.683356);
			v(-0.679618,-4.902941,0.464420);
			v(0.679615,-4.902942,0.464420);
			v(-0.679618,-4.902941,-0.464421);
			v(0.679616,-4.902941,-0.464421);
			v(0.065945,-8.797762,-0.045066);
			v(-0.065950,-8.797762,-0.045066);
			v(0.065945,-8.797762,0.045065);
			v(-0.065950,-8.797762,0.045065);
			v(-1.000000,-1.000000,0.204147);
			v(-1.000000,1.000000,0.204147);
			v(1.000000,0.999999,0.204147);
			v(0.999999,-1.000001,0.204147);
			v(-1.000000,1.000000,-0.204147);
			v(-1.000000,-1.000000,-0.204147);
			v(1.000000,-1.000000,-0.204147);
			v(1.000000,1.000000,-0.204147);
			v(2.083799,-1.000000,-0.204147);
			v(2.083799,1.000000,-0.204147);
			v(2.083800,0.999999,0.204147);
			v(2.083798,-1.000001,0.204147);
			v(-2.083798,1.000000,-0.204147);
			v(-2.083799,-1.000000,-0.204147);
			v(-2.083800,-1.000000,0.204147);
			v(-2.083798,1.000000,0.204147);
			v(-2.222009,-1.535249,0.123641);
			v(-2.222008,1.535249,0.123641);
			v(2.222010,1.535248,0.123641);
			v(2.222007,-1.535251,0.123641);
			v(-2.222008,1.535250,-0.123641);
			v(-2.222009,-1.535249,-0.123641);
			v(2.222008,-1.535249,-0.123641);
			v(2.222008,1.535249,-0.123641);
			v(4.019095,1.491733,-0.098951);
			v(4.019095,-0.121116,-0.098951);
			v(4.019097,1.491732,0.098950);
			v(4.019093,-0.121116,0.098950);
			v(-4.019095,-0.121115,-0.098951);
			v(-4.019093,1.491733,-0.098951);
			v(-4.019096,-0.121115,0.098950);
			v(-4.019094,1.491733,0.098950);
			v(-4.111470,-0.121115,0.098950);
			v(-4.111467,1.491733,0.098950);
			v(4.111471,1.491732,0.098950);
			v(4.111466,-0.121116,0.098950);
			v(-4.111467,1.491733,-0.098951);
			v(-4.111469,-0.121115,-0.098951);
			v(4.111469,-0.121116,-0.098951);
			v(4.111469,1.491733,-0.098951);
			v(5.027250,-0.494357,-0.068746);
			v(5.027250,1.118492,-0.068746);
			v(5.027252,1.118491,0.068746);
			v(5.027246,-0.494357,0.068746);
			v(-5.027248,-0.494357,-0.068746);
			v(-5.027246,1.118492,-0.068746);
			v(-5.027249,-0.494357,0.068746);
			v(-5.027246,1.118492,0.068746);
			v(-5.693155,-1.072972,0.039673);
			v(-5.693151,1.107409,0.039673);
			v(5.693157,1.107409,0.039673);
			v(5.693150,-1.072973,0.039673);
			v(-5.693151,1.107410,-0.039674);
			v(-5.693153,-1.072972,-0.039674);
			v(5.693154,-1.072972,-0.039674);
			v(5.693154,1.107409,-0.039674);
			v(7.845545,0.625659,-0.019098);
			v(7.845545,0.384196,-0.019098);
			v(7.845547,0.625659,0.019098);
			v(7.845538,0.384196,0.019098);
			v(-7.845544,0.384196,-0.019098);
			v(-7.845539,0.625659,-0.019098);
			v(-7.845545,0.384196,0.019098);
			v(-7.845539,0.625659,0.019098);
			v(-0.696005,-0.680794,0.748494);
			v(-0.696005,0.770009,1.053621);
			v(0.696004,-0.680795,0.748494);
			v(0.696005,0.770009,1.053621);
			v(0.372146,-0.646706,0.855366);
			v(0.372146,0.557490,1.738617);
			v(-0.372146,0.557491,1.738617);
			v(-0.372146,-0.646706,0.855366);
			v(0.045225,3.751054,0.030905);
			v(-0.045224,3.751054,0.030905);
			v(-0.045224,3.751054,-0.030904);
			v(0.045225,3.751054,-0.030904);
			v(-1.975420,-0.800000,0.218665);
			v(-1.975419,0.800000,0.218665);
			v(1.975420,0.799999,0.218665);
			v(1.975418,-0.800001,0.218665);
			v(-1.108380,0.800000,0.218665);
			v(-1.108380,-0.800000,0.218665);
			v(1.108379,-0.800001,0.218665);
			v(1.108380,0.799999,0.218665);
			v(-1.498548,5.517805,1.838372);
			v(-1.498548,-5.517756,0.497377);
			v(1.498547,-5.517806,0.497371);
			v(1.498548,5.517756,1.838366);
			v(1.585251,5.517756,1.838366);
			v(1.585251,-5.517806,0.497371);
			v(-1.585252,-5.517756,0.497377);
			v(-1.585251,5.517805,1.838372);

			f2(101,100,107);
			f2(101,107,106);
			f2(103,102,105);
			f2(103,105,104);
			f2(93,92,106);
			f2(93,106,107);
			f2(95,94,105);
			f2(94,104,105);
			f2(96,93,107);
			f2(96,107,100);
			f2(92,97,101);
			f2(92,101,106);
			f2(98,95,105);
			f2(98,105,102);
			f2(94,99,103);
			f2(94,103,104);
			f2(99,98,102);
			f2(99,102,103);
			f2(97,96,101);
			f2(96,100,101);
			f2(16,17,96);
			f2(16,96,97);
			f2(18,19,98);
			f2(18,98,99);
			f2(26,18,94);
			f2(18,99,94);
			f2(19,27,98);
			f2(27,95,98);
			f2(30,16,92);
			f2(16,97,92);
			f2(17,31,96);
			f2(31,93,96);
			f2(27,26,94);
			f2(27,94,95);
			f2(31,30,92);
			f2(31,92,93);
			f2(88,91,90);
			f2(88,90,89);
			f2(0,3,90);
			f2(0,90,91);
			f2(4,0,88);
			f2(0,91,88);
			f2(3,7,89);
			f2(3,89,90);
			f2(7,4,88);
			f2(7,88,89);
			f2(85,86,87);
			f2(85,87,84);
			f2(81,80,87);
			f2(81,87,86);
			f2(80,82,87);
			f2(82,84,87);
			f2(83,81,85);
			f2(81,86,85);
			f2(82,83,84);
			f2(83,85,84);
			f2(5,4,82);
			f2(4,83,82);
			f2(4,7,81);
			f2(4,81,83);
			f2(6,5,82);
			f2(6,82,80);
			f2(7,6,80);
			f2(7,80,81);
			f2(76,78,79);
			f2(76,79,77);
			f2(72,74,73);
			f2(74,75,73);
			f2(64,65,78);
			f2(65,79,78);
			f2(66,67,75);
			f2(66,75,74);
			f2(65,68,77);
			f2(65,77,79);
			f2(69,64,76);
			f2(64,78,76);
			f2(68,69,76);
			f2(68,76,77);
			f2(67,70,75);
			f2(70,73,75);
			f2(71,66,72);
			f2(66,74,72);
			f2(70,71,73);
			f2(71,72,73);
			f2(56,57,71);
			f2(56,71,70);
			f2(57,58,71);
			f2(58,66,71);
			f2(59,56,67);
			f2(56,70,67);
			f2(61,60,68);
			f2(60,69,68);
			f2(60,62,69);
			f2(62,64,69);
			f2(63,61,68);
			f2(63,68,65);
			f2(58,59,66);
			f2(59,67,66);
			f2(62,63,65);
			f2(62,65,64);
			f2(48,49,63);
			f2(48,63,62);
			f2(50,51,58);
			f2(51,59,58);
			f2(49,52,61);
			f2(49,61,63);
			f2(53,48,60);
			f2(48,62,60);
			f2(52,53,61);
			f2(53,60,61);
			f2(51,54,59);
			f2(54,56,59);
			f2(55,50,57);
			f2(50,58,57);
			f2(54,55,57);
			f2(54,57,56);
			f2(41,40,55);
			f2(41,55,54);
			f2(40,42,55);
			f2(42,50,55);
			f2(43,41,51);
			f2(41,54,51);
			f2(45,44,52);
			f2(44,53,52);
			f2(44,46,53);
			f2(46,48,53);
			f2(47,45,52);
			f2(47,52,49);
			f2(42,43,51);
			f2(42,51,50);
			f2(46,47,49);
			f2(46,49,48);
			f2(32,33,46);
			f2(33,47,46);
			f2(34,35,43);
			f2(34,43,42);
			f2(33,36,45);
			f2(33,45,47);
			f2(37,32,44);
			f2(32,46,44);
			f2(36,37,44);
			f2(36,44,45);
			f2(35,38,43);
			f2(38,41,43);
			f2(39,34,40);
			f2(34,42,40);
			f2(38,39,41);
			f2(39,40,41);
			f2(24,25,39);
			f2(24,39,38);
			f2(25,26,34);
			f2(25,34,39);
			f2(27,24,38);
			f2(27,38,35);
			f2(28,29,37);
			f2(28,37,36);
			f2(29,30,37);
			f2(30,32,37);
			f2(31,28,33);
			f2(28,36,33);
			f2(26,27,34);
			f2(27,35,34);
			f2(30,31,33);
			f2(30,33,32);
			f2(17,20,28);
			f2(17,28,31);
			f2(21,16,29);
			f2(16,30,29);
			f2(20,21,28);
			f2(21,29,28);
			f2(19,22,27);
			f2(22,24,27);
			f2(23,18,25);
			f2(18,26,25);
			f2(22,23,25);
			f2(22,25,24);
			f2(1,0,22);
			f2(0,23,22);
			f2(0,4,18);
			f2(0,18,23);
			f2(5,1,19);
			f2(1,22,19);
			f2(3,2,21);
			f2(3,21,20);
			f2(2,6,21);
			f2(6,16,21);
			f2(7,3,20);
			f2(7,20,17);
			f2(4,5,19);
			f2(4,19,18);
			f2(6,7,16);
			f2(7,17,16);
			f2(12,14,15);
			f2(12,15,13);
			f2(9,8,15);
			f2(9,15,14);
			f2(8,10,15);
			f2(10,13,15);
			f2(11,9,12);
			f2(9,14,12);
			f2(10,11,12);
			f2(10,12,13);
			f2(2,1,11);
			f2(2,11,10);
			f2(1,5,11);
			f2(5,9,11);
			f2(6,2,8);
			f2(2,10,8);
			f2(5,6,8);
			f2(5,8,9);
			f2(0,1,2);
			f2(0,2,3);

			this.x = 0.000000;
			this.y = 0.000000;
			this.z = 0.000000;

			this.rotateX = 0.000000;
			this.rotateY = 0.000000;
			this.rotateZ = 0.000000;

			this.scaleX = 50.000000;
			this.scaleY = 50.000000;
			this.scaleZ = 50.000000;
			return (l);
		}
	}

class BasicEnemy1 extends Shape3D implements Primitive3D {
		private var l:Geometry3D;

		private function f(v1:Number,v2:Number,v3:Number,uv00:Number,uv01:Number,uv10:Number,uv11:Number,uv20:Number,uv21:Number,normX:Number,normY:Number,normZ:Number):void {
			var uv1:Number = l.getNextUVCoordID();
			var uv2:Number = uv1 + 1;
			var uv3:Number = uv2 + 1;

			l.setUVCoords(uv1,uv00,1-uv01);
			l.setUVCoords(uv2,uv10,1-uv11);
			l.setUVCoords(uv3,uv20,1-uv21);

			l.setFaceVertexIds(l.getNextFaceID(), v1,v2,v3);
			l.setFaceUVCoordsIds(l.getNextFaceUVCoordID(), uv1,uv2,uv3);
			l.setFaceNormal(l.getNextFaceNormalID(), normX,normZ,normY);
		}

		private function f2(v1:Number,v2:Number,v3:Number):void {
			l.setFaceVertexIds(l.getNextFaceID(), v1,v2,v3);
		}

		private function v(vx:Number,vy:Number,vz:Number):void {
			l.setVertex(l.getNextVertexID(),vx,vz,vy);
		}

		public function BasicEnemy1( p_Name:String=null ) {
			super( p_Name );
			geometry = generate();
		}

		public function generate(... arguments):Geometry3D {
			l = new Geometry3D();
			v(0.346457,0.086613,-0.707120);
			v(0.346457,-0.606302,-0.707120);
			v(-0.346457,-0.606302,-0.707120);
			v(-0.346457,0.086613,-0.707120);
			v(1.000000,0.999999,0.015341);
			v(0.999999,-2.202131,0.056095);
			v(-1.000000,-2.202130,0.056095);
			v(-1.000000,1.000000,0.015341);
			v(-1.117323,-2.262512,0.773255);
			v(-1.339531,1.000000,0.657432);
			v(1.117322,-2.262513,0.773255);
			v(1.339532,0.999999,0.657432);
			v(2.784543,-1.193082,0.122345);
			v(2.784544,0.663639,0.122345);
			v(2.784544,0.663639,0.508227);
			v(2.784543,-1.193082,0.508227);
			v(-2.784544,0.663640,0.122345);
			v(-2.784544,-1.193082,0.122345);
			v(-2.784544,-1.193082,0.508227);
			v(-2.784544,0.663640,0.508227);
			v(-5.725144,-3.028431,0.155846);
			v(5.725143,-3.028431,0.155846);
			v(-0.000001,-2.796015,0.387788);
			v(-0.000001,-2.645047,0.086207);
			v(0.999999,-1.007476,1.353194);
			v(1.000000,0.620361,1.128460);
			v(-1.000000,0.620361,1.128460);
			v(-1.000000,-1.007476,1.353194);
			v(-0.151609,0.620361,1.128460);
			v(-0.151609,-0.696661,1.423103);
			v(0.151609,-0.696661,1.423103);
			v(-0.151609,1.000000,0.615231);
			v(0.151609,0.620361,1.128460);
			v(0.151609,0.999999,0.615231);
			v(-0.021496,1.089991,2.153404);
			v(0.021499,1.089991,2.153404);
			v(0.021499,0.520902,2.498386);
			v(0.021499,-0.280928,2.807672);
			v(-0.021496,0.520902,2.498386);
			v(-0.021496,-0.280928,2.807673);

			f2(17,20,16);
			f2(18,20,17);
			f2(19,20,18);
			f2(16,20,19);
			f2(13,21,12);
			f2(14,21,13);
			f2(15,21,14);
			f2(12,21,15);
			f2(10,8,22);
			f2(6,5,23);
			f2(36,38,39);
			f2(36,39,37);
			f2(35,34,38);
			f2(35,38,36);
			f2(28,29,38);
			f2(29,39,38);
			f2(29,30,37);
			f2(29,37,39);
			f2(31,28,34);
			f2(28,38,34);
			f2(30,32,36);
			f2(30,36,37);
			f2(32,33,35);
			f2(32,35,36);
			f2(33,31,34);
			f2(33,34,35);
			f2(11,9,33);
			f2(9,31,33);
			f2(25,11,33);
			f2(25,33,32);
			f2(24,25,30);
			f2(25,32,30);
			f2(9,26,31);
			f2(26,28,31);
			f2(27,24,29);
			f2(24,30,29);
			f2(26,27,29);
			f2(26,29,28);
			f2(9,8,27);
			f2(9,27,26);
			f2(8,10,24);
			f2(8,24,27);
			f2(10,11,24);
			f2(11,25,24);
			f2(8,6,22);
			f2(6,23,22);
			f2(5,10,22);
			f2(5,22,23);
			f2(7,16,9);
			f2(16,19,9);
			f2(9,19,18);
			f2(9,18,8);
			f2(8,18,17);
			f2(8,17,6);
			f2(6,17,7);
			f2(17,16,7);
			f2(5,12,10);
			f2(12,15,10);
			f2(10,15,11);
			f2(15,14,11);
			f2(11,14,13);
			f2(11,13,4);
			f2(4,13,12);
			f2(4,12,5);
			f2(4,7,9);
			f2(4,9,11);
			f2(4,0,3);
			f2(4,3,7);
			f2(2,6,7);
			f2(2,7,3);
			f2(1,5,6);
			f2(1,6,2);
			f2(0,4,1);
			f2(4,5,1);
			f2(0,1,2);
			f2(0,2,3);

			this.x = 0;
			this.y = 0;
			this.z = 0;

			this.rotateX = 0;
			this.rotateY = 0;
			this.rotateZ = 0;

			this.scaleX = 30;
			this.scaleY = 30;
			this.scaleZ = 30;
			return (l);
		}
	}
class Laser extends Shape3D implements Primitive3D {
		private var l:Geometry3D;
		private function v(x:Number,y:Number,z:Number):void {
			l.setVertex(l.getNextVertexID(),x,y,z );
		}
		private function vn(nx:Number,ny:Number,nz:Number):void {
			l.setVertexNormal(l.getNextVertexNormalID(),nx,ny,nz );
		}
		private function uv(u:Number,v:Number):void {
			l.setUVCoords(l.getNextUVCoordID(),u,v);
		}
		private function f(vn0:int, vn1:int, vn2:int, uvn0:int, uvn1:int,uvn2:int):void {
			l.setFaceVertexIds(l.getNextFaceID(), vn0, vn1,vn2);
			l.setFaceUVCoordsIds( l.getNextFaceUVCoordID(), uvn0,uvn1,uvn2);
		}
		public function Laser( p_Name:String=null ) {
			super( p_Name );

			geometry = generate() ;
		}

		public function generate(... arguments):Geometry3D {
			l = new Geometry3D();
			v(0.0,-2.06958e-006,47.3464);
			v(2.50081,-2.06958e-006,47.3464);
			v(-1.2504,-2.16577,47.3464);
			v(-1.2504,2.16576,47.3464);
			v(4.80655,-1.72654e-006,39.4986);
			v(-2.40328,-4.1626,39.4986);
			v(-2.40328,4.1626,39.4986);
			v(4.80655,-3.4304e-007,7.84785);
			v(-2.40328,-4.1626,7.84785);
			v(-2.40328,4.1626,7.84785);
			v(2.50081,0.0,0.0);
			v(-1.2504,-2.16577,0.0);
			v(-1.2504,2.16577,0.0);
			v(0.0,0.0,0.0);
			uv(0.5,0.5);
			uv(0.760146,0.5);
			uv(0.369927,0.274707);
			uv(0.369927,0.725293);
			uv(1.0,0.5);
			uv(0.25,0.0669873);
			uv(0.25,0.933013);
			uv(0.0,0.0);
			uv(0.333333,0.0);
			uv(0.666667,0.0);
			uv(1.0,0.0);
			uv(0.0,1.0);
			uv(0.333333,1.0);
			uv(0.666667,1.0);
			uv(1.0,1.0);
			uv(1.0,0.5);
			uv(0.25,0.0669873);
			uv(0.25,0.933013);
			uv(0.760146,0.5);
			uv(0.369927,0.274707);
			uv(0.369927,0.725293);
			uv(0.5,0.5);
			f(0,1,2,0,1,2);
			f(0,2,3,0,2,3);
			f(0,3,1,0,3,1);
			f(1,4,5,1,4,5);
			f(1,5,2,1,5,2);
			f(2,5,6,2,5,6);
			f(2,6,3,2,6,3);
			f(3,6,4,3,6,4);
			f(3,4,1,3,4,1);
			f(4,7,8,7,11,12);
			f(4,8,5,7,12,8);
			f(5,8,9,8,12,13);
			f(5,9,6,8,13,9);
			f(6,9,7,9,13,14);
			f(6,7,4,9,14,10);
			f(7,10,11,15,18,19);
			f(7,11,8,15,19,16);
			f(8,11,12,16,19,20);
			f(8,12,9,16,20,17);
			f(9,12,10,17,20,18);
			f(9,10,7,17,18,15);
			f(10,13,11,18,21,19);
			f(11,13,12,19,21,20);
			f(12,13,10,20,21,18);
			this.x = 0;
			this.y = 0;
			this.z = 0;

			this.rotateX = 0;
			this.rotateY = 0;
			this.rotateZ = 0;

			this.scaleX = 5;
			this.scaleY = 5;
			this.scaleZ = 5;
			return l;
		}
	}

// using an edited version of Sandy3d's Color Material
	class ColorMaterial2 extends Material
	{
		private var m_nColor:Number;
		private var m_nAlpha:Number;
		private var m_nArray:Array;
		private var firstPolygonId:int = -1;
		

		/**
		 * Creates a new ColorMaterial.
		 *
		 * @param p_nColor 	The color for this material in hexadecimal notation
		 * @param p_nAlpha	The alpha value in percent of full opacity ( 0 - 1 )
		 * @param p_oAttr	The attributes for this material
		 */
		public function ColorMaterial2( p_nColor:uint = 0x00, p_nAlpha:Number = 1, p_oAttr:MaterialAttributes = null, p_nArray:Array = null)
		{
			super(p_oAttr);
			// --
			m_oType = MaterialType.COLOR;
			// --
			m_nColor = p_nColor;
			m_nAlpha = p_nAlpha;
			m_nArray = p_nArray;
		}

		/**
		 * Renders this material on the face it dresses
		 *
		 * @param p_oScene		The current scene
		 * @param p_oPolygon	The face to be rendered
		 * @param p_mcContainer	The container to draw on
		 */
		public override function renderPolygon( p_oScene:Scene3D, p_oPolygon:Polygon, p_mcContainer:Sprite ):void
		{
			if(firstPolygonId  > p_oPolygon.id || firstPolygonId == -1){
				firstPolygonId = p_oPolygon.id;
				//trce(firstPolygonId);
			}
			const l_points:Array = (p_oPolygon.isClipped) ? p_oPolygon.cvertices : p_oPolygon.vertices;
			if( !l_points.length ) return;
			var l_oVertex:Vertex;
			var lId:int = l_points.length;
			var l_graphics:Graphics = p_mcContainer.graphics;
			// --
			l_graphics.lineStyle();
			l_graphics.beginFill( m_nArray[p_oPolygon.id-firstPolygonId], m_nAlpha );
			l_graphics.moveTo( l_points[0].sx, l_points[0].sy );
			while( l_oVertex = l_points[ --lId ] )
				l_graphics.lineTo( l_oVertex.sx, l_oVertex.sy );
			l_graphics.endFill();
			// --
			if( attributes )  attributes.draw( l_graphics, p_oPolygon, this, p_oScene ) ;

		}

		/**
		 * @private
		 */
		public function get alpha():Number
		{
			return m_nAlpha;
		}

		/**
		 * @private
		 */
		public function get color():Number
		{
			return m_nColor;
		}


		/**
		 * The alpha value for this material ( 0 - 1 )
		 *
		 * Alpha = 0 means fully transparent, alpha = 1 fully opaque.
		 */
		public function set alpha(p_nValue:Number):void
		{
			m_nAlpha = p_nValue;
			m_bModified = true;
		}

		/**
		 * The color of this material
		 */
		public function set color(p_nValue:Number):void
		{
			m_nColor = p_nValue;
			m_bModified = true;
		}
		
	}