//////////////////////
// Cube Explode    //
//Code By Totorman//
///////////////////
function part11(){
    this.canvaspart ;
    this.initdone = 0 ;
    this.vbl = 0 ;
    this.text = new text_cursor() ;

    var vbl_startcoming = 0 ;
    var vbl_endcoming = 30 ;
    var vbl_startturning = 30 ;
    var vbl_endturning = 300 ;
    var vbl_startshaking = 300 ;
    var vbl_stopshaking = 500 ;
    var vbl_startexploding = 500 ;
    var vbl_stopexploding = 800 ;

    var mycanvas_3D;
    var mycanvas_3D2;
    var my3d ;
    var my3d2 ;

    var VIEW_ANGLE = 40 ;
    var angle = 1.5 ;
    var vbl = 0 ;
    var vbl2 = 0 ;
    var anglex = 0 ;
    var angley = 0 ;
    var anglez = 0 ;
    var mymove = 0 ;
    var exploded = 0 ;

    var mystarfield;
    var mycanvas_stars;

    var mycubes = new Array() ;

    function addcube(myobj3d,x,y,z,sz) {
        var myobj = new Array();
        var myobjvert = new Array();
        myobjvert=[
                {x:-1, y: 1, z: 1},
                {x:-1, y:-1, z: 1},
                {x: 1, y:-1, z: 1},
                {x: 1, y: 1, z: 1}, 
                {x: 1, y: 1, z:-1},
                {x: 1, y:-1, z:-1},
                {x:-1, y:-1, z:-1},
                {x:-1, y: 1, z:-1}, 
               ];

        myobj=[ 
         {p1:0, p2:1, p3:2, p4:3, params:new MeshLambertMaterial({ color: 0xa1e65e, opacity:1, shading: FlatShading})},
            {p1:3, p2:2, p3:5, p4:4, params:new MeshLambertMaterial({ color: 0xe68e5e, opacity:1, shading: FlatShading})},
            {p1:7, p2:6, p3:1, p4:0, params:new MeshLambertMaterial({ color: 0xe65ed4, opacity:1, shading: FlatShading})},
            {p1:7, p2:0, p3:3, p4:4, params:new MeshLambertMaterial({ color: 0x5ec4e6, opacity:1, shading: FlatShading})},
            {p1:1, p2:6, p3:5, p4:2, params:new MeshLambertMaterial({ color: 0xab5ee6, opacity:1, shading: FlatShading})},	
            {p1:4, p2:5, p3:6, p4:7, params:new MeshLambertMaterial({ color: 0xe6c85e, opacity:1, shading: FlatShading})},	
              ];    

        var geom = new THREE.Geometry(); 
        for(var i=0; i<myobjvert.length; i++){
            geom.vertices.push(new THREE.Vector3( myobjvert[i].x,  myobjvert[i].y,  myobjvert[i].z));
        }

        for(var i=0; i<myobj.length; i++){
            myobj[i].params.overdraw = false;
            geom.materials.push(myobj[i].params);
            geom.faces.push( new THREE.Face4( myobj[i].p1,myobj[i].p2,myobj[i].p3, myobj[i].p4, null, null,i ));
            if(typeof(myobj[i].v4)!='undefined'){
                geom.faceVertexUvs[ 0 ].push( [
                    new THREE.UV( myobj[i].u1,myobj[i].v1 ),
                    new THREE.UV( myobj[i].u2,myobj[i].v2 ),
                    new THREE.UV( myobj[i].u3,myobj[i].v3 ),
                    new THREE.UV( myobj[i].u4,myobj[i].v4 )
                ] );
            }			
        }

        geom.computeFaceNormals();
        geom.computeCentroids();
        geom.computeVertexNormals();

        form = new THREE.Mesh( geom, new THREE.MeshFaceMaterial());
        form.position.x = x ;
        form.position.y = y ;
        form.position.z = z ;
        myobj3d.group.add(form );
    }

    function mycube() {
        this.x = 0 ;
        this.y = 0 ;
        this.z = 0 ;
        this.a = 0 ;
        this.b = 0 ;
        this.c = 0 ;
    }

 function base3D(){frequency=2*Math.PI/100;Math.sin(frequency*vbl+2+anglex);Math.sin(frequency*vbl+0+angley);Math.sin(frequency*vbl+4+anglez);anglex+=0.03;angley+=0.02;anglez+=0.04;angle+=0.03}function cubeiscoming(a,b){base3D();my3d2.group.position.y=-20*(vbl_endcoming-a)/(vbl_endcoming-vbl_startcoming);my3d2.group.rotation.x=anglex;my3d2.group.rotation.y=angley;my3d2.group.rotation.z=anglez;my3d2.camera.lookAt({x:0,y:0,z:0});mycanvas3D2.clear();my3d2.draw();mycanvas3D2.draw(b)}
function cubeisturning(a,b){base3D();my3d2.group.rotation.x=anglex;my3d2.group.rotation.y=angley;my3d2.group.rotation.z=anglez;my3d2.camera.lookAt({x:0,y:0,z:0});mycanvas3D2.clear();my3d2.draw();mycanvas3D2.draw(b)}
function cubeisshaking(a,b){if(0==a){for(var c=0;c<mycubes.length;c++)my3d.group.children[c].position.x=my3d2.group.children[c].position.x,my3d.group.children[c].position.y=my3d2.group.children[c].position.y,my3d.group.children[c].position.z=my3d2.group.children[c].position.z,my3d.group.children[c].rotation.x=my3d2.group.children[c].rotation.x,my3d.group.children[c].rotation.y=my3d2.group.children[c].rotation.y,my3d.group.children[c].rotation.z=my3d2.group.children[c].rotation.z,my3d.group.position.x=
my3d2.group.position.x,my3d.group.position.y=my3d2.group.position.y,my3d.group.position.z=my3d2.group.position.z;my3d.camera.lookAt({x:0,y:0,z:0})}base3D();my3d.group.rotation.x=anglex;my3d.group.rotation.y=angley;my3d.group.rotation.z=anglez;my3d.camera.lookAt({x:mymove*Math.sin(100*angle)/400,y:mymove*Math.cos(50*angle)/300,z:0});0==a%3&&mymove++;mycanvas3D.clear();my3d.draw();mycanvas3D.draw(b);a==vbl_stopshaking-vbl_startshaking-1&&(vbl2=vbl_startexploding,exploded=mymove=0)}
function explodeobj(a){for(var b=0;b<mycubes.length;b++){var c=mycubes[b].x*Math.sin(mycubes[b].a),d=mycubes[b].y*Math.sin(mycubes[b].b),e=-mycubes[b].z*Math.sin(mycubes[b].c);my3d.group.children[b].position.x+=c*a/60;my3d.group.children[b].position.y+=d*a/60;my3d.group.children[b].position.z+=e*a/60;my3d.group.children[b].rotation.x=anglex;my3d.group.children[b].rotation.y=angley;my3d.group.children[b].rotation.z=anglez}a>=vbl_stopexploding-vbl_startexploding-1&&(exploded=1,vbl2=0)}
function reinit3d(){for(var a=0;a<mycubes.length;a++)my3d.group.children[a].position.x=my3d2.group.children[a].position.x,my3d.group.children[a].position.y=my3d2.group.children[a].position.y,my3d.group.children[a].position.z=my3d2.group.children[a].position.z,my3d.group.children[a].rotation.x=my3d2.group.children[a].rotation.x,my3d.group.children[a].rotation.y=my3d2.group.children[a].rotation.y,my3d.group.children[a].rotation.z=my3d2.group.children[a].rotation.z}
function cubeisexploding(a,b){base3D();explodeobj(a);mycanvas3D.clear();my3d.draw();mycanvas3D.draw(b);a==vbl_stopexploding-1&&(exploded=0)}
this.init=function(a){this.text.init(choix_text[4],10,8,font_key);mycanvas3D=new canvas(640,400);mycanvas3D2=new canvas(640,400);my3d=new codef3D(mycanvas3D,50,VIEW_ANGLE,0.1,600);my3d.addAmbiLight(4473924);my3d.addDirLight(-0.5,-0.5,1,16777215);my3d.camera.position.x=0;my3d.camera.position.y=0;my3d.camera.position.z=20;my3d.camera.lookAt({x:0,y:0,z:0});my3d.matrixAutoUpdate=!0;my3d2=new codef3D(mycanvas3D2,50,VIEW_ANGLE,0.1,600);my3d2.addAmbiLight(4473924);my3d2.addDirLight(-0.5,-0.5,1,16777215);
my3d2.camera.position.x=0;my3d2.camera.position.y=0;my3d2.camera.position.z=20;my3d2.camera.lookAt({x:0,y:0,z:0});my3d2.matrixAutoUpdate=!0;for(z=a=0;5>z;z++)for(y=0;5>y;y++)for(x=0;5>x;x++){addcube(my3d,x-2.5,y-2.5,z-2.5,1.1);addcube(my3d2,x-2.5,y-2.5,z-2.5,1.1);mycubes[a]=new mycube;var b=mycubes[a++];b.x=x-2.5;b.y=y-2.5;b.z=z-2.5;b.a=2*Math.random()*Math.PI;b.b=2*Math.random()*Math.PI;b.c=2*Math.random()*Math.PI}mycanvas_stars=new canvas(640,400);mystarfield=new starfield3D(mycanvas_stars,500,
4,640,400,320,200,"#999999",200,0,0);this.initdone=1};
this.render=function(a){0==this.initdone&&(this.canvaspart=new canvas(600,400),this.init(this.canvaspart));this.canvaspart.fill("#000000");mycanvas_stars.clear();mystarfield.draw();mycanvas_stars.draw(this.canvaspart,0,0);vbl2>=vbl_startexploding&&0==exploded&&cubeisexploding(vbl2-vbl_startexploding,this.canvaspart);vbl>=vbl_startcoming&&vbl<vbl_endcoming&&cubeiscoming(vbl-vbl_startcoming,this.canvaspart);vbl>=vbl_startturning&&vbl<vbl_endturning&&cubeisturning(vbl-vbl_startturning,this.canvaspart);
vbl>=vbl_startshaking&&vbl<vbl_stopshaking&&cubeisshaking(vbl-vbl_startshaking,this.canvaspart);vbl++;vbl2++;vbl>=vbl_stopexploding-280&&(vbl=0);this.text.render(this.canvaspart,choix_pos[4].x,choix_pos[4].y);this.canvaspart.draw(a,60,88);100>this.vbl&&mycanvasblack.draw(a,60,88,1-this.vbl/100);this.vbl>intro_parts[part_running].part_duration-100&&mycanvasblack.draw(a,60,88,1-(intro_parts[part_running].part_duration-this.vbl)/100);this.vbl++};
}
///////////////
//END PART11//
/////////////
