Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

Results 1 to 2 of 2

Thread: as3 chess tille game problem!!!!

  1. #1

    as3 chess tille game problem!!!!

    okay i am make my chess tile game with scripted drawing.

    i found this totoral online very use full
    ww. kirupa.com/developer/actionscript/rpgprogramming6.htm

    but i canot seem to get to work it with my scripted drawings?

    oh and my game is in 3d

    my code be ward it 2000+ lines of hand writen code

    i want to be able to move all player 1 pice at one time and play2 pices on his turn

    how would i do this
    code
    PHP Code:
    var vertsArray:Array=[];

    var 
    facesArray:Array=[];


    var 
    fLen:Number=2000;

    /*
    The next two variables store the number of vertices and the number
    of polygonal faces for our surface. Since we are drawing a chessboard,
    the values are 8 and 6.
    */

    var numVertices:uint=8;

    var 
    numFaces:uint=6;

    /*
     define's a new Sprite, spBoard, in which all dynamic drawings will reside.
     are adding spBoard to the Display List and positioning it within the main movie.
    */

    var spBoard:Sprite=new Sprite();

    this.addChild(spBoard);

    spBoard.x=500;

    spBoard.y=400;



    /*
    Our cube will be drawn in a child of spBoard called shCube.
    */

    var shCube:Shape=new Shape();

    spBoard.addChild(shCube);

    /*
    doRotate remembers if the user is rotating the cube with the mouse or not.
    prevX, prevY store the latest mouse coordinates. curPhi, curTheta store
    the current view angles, faceColors the colors of the cube's sides.
    */

    var doRotate:Boolean=false;

    var 
    prevX:Number;
    var 
    prevY:Number;


    var 
    curTheta:Number=100;
    var 
    curPhi:Number=100;


    var 
    curTheta2:Number=0;
    var 
    curPhi2:Number=0;




    var 
    facesColors:Array=[0xFFFFCC,0x00FF66,0x0066FF,0x33FFFF,0x9A7DDF,0xFFCCFF];




    /*
    the functions that define the vertices and the faces
    of the cube in 3D space, and then the function that renders an
    initial view. The three functions are defined and described below.
    */

    setVertices();

    setFaces();

    renderView(curTheta,curPhi);

    // player 1
    var reflectY2:Number 460;
    var 
    reflectX2:Number 100;

    var 
    reflectYI:Number 460;
    var 
    reflectXI:Number 250;

    var 
    reflectYII:Number 460;
    var 
    reflectXII:Number 400;

    var 
    reflectYMM:Number 460;
    var 
    reflectXMM:Number 550;


    // player 2
    var reflectYPP:Number 290;
    var 
    reflectXPP:Number 650;

    var 
    reflectYQQ:Number 290;
    var 
    reflectXQQ:Number 500;

    var 
    reflectYRR:Number 290;
    var 
    reflectXRR:Number 350;

    var 
    reflectYTT:Number 290;
    var 
    reflectXTT:Number 200;

    function 
    setVertices():void 
    {
        
        
    vertsArray[0]=[400,-10,400];    
        
    vertsArray[1]=[400,10,400];    
        
    vertsArray[2]=[-400,10,400];    
        
    vertsArray[3]=[-400,-10,400];    
        
    vertsArray[4]=[400,-10,-400];    
        
    vertsArray[5]=[400,10,-400];    
        
    vertsArray[6]=[-400,10,-400];    
        
    vertsArray[7]=[-400,-10,-400];
        
    }



    function 
    setFaces():void 
    {
        
        
    facesArray[0]=[0,4,5,1];    
        
    facesArray[1]=[1,5,6,2];    
        
    facesArray[2]=[2,6,7,3];    
        
    facesArray[3]=[3,7,4,0];    
        
    facesArray[4]=[4,5,6,7];    
        
    facesArray[5]=[0,1,2,3];
        
    }



    // redering the 3d bored

    function renderView(t:Number,p:Number):void
    {
        
        
    //defining local variables.
        
        
    var i:int;
        
        var 
    distArray=[];
        
        var 
    dispArray=[];
        
        var 
    vertsNewArray=[];
        
        var 
    midPoint:Array=[];

        var 
    dist:Number;
        
        var 
    curFace:uint;
        
        
    //rortates th chess board
        
    t=t*Math.PI/200;  // rotes on the Y cordantes. 
        
        
    p=p*Math.PI/110//rotes on the X cordantes.
        
        //We clear the previous view of the cube.
        
    shCube.graphics.clear();
        
        for(
    i=0;i<numVertices;i++)
        {
            
            
    /*
            For each vertex, we calculate its coordinates in the new coordinate system
            corresponding to the new position of the observer given by the angles t and p.
            The calculations are done by the function pointNewView. From now on,
            all positions are going to be relative to the new coordinate system.
            */
            
            
    vertsNewArray[i]=pointNewView(vertsArray[i],t,p); 
            
        }
        
        
        
        for(
    i=0;i<numFaces;i++)
        {
            
            
    /*
            For each face calculate its midpoint in 3D by taking the averages of
            the corresponding coordinates of each vertex.the number of vertices
            for each face is 4 and is hard-wired here.
            
            A face is defined as an array of numbers of vertices. That is,
            facesArray[i][0] is the position of the first vertex of the face i
            in the vertices array vertsNewArray.
            */
            
                    
            
    midPoint[0]=(vertsNewArray[facesArray[i][0]][0]+vertsNewArray[facesArray[i][1]][0]+vertsNewArray[facesArray[i][2]][0]+vertsNewArray[facesArray[i][3]][0])/4;        
            
    midPoint[1]=(vertsNewArray[facesArray[i][0]][1]+vertsNewArray[facesArray[i][1]][1]+vertsNewArray[facesArray[i][2]][1]+vertsNewArray[facesArray[i][3]][1])/4;        
            
    midPoint[2]=(vertsNewArray[facesArray[i][0]][2]+vertsNewArray[facesArray[i][1]][2]+vertsNewArray[facesArray[i][2]][2]+vertsNewArray[facesArray[i][3]][2])/4;        
            
    /*
            to calculate the distance of each face from the observer. That is, the distance
            of its midpoint from the observer. The observer in the old as well as in the new coordinate
            system is located on the positive x-axis at the distance from the origin.
            */
            
            
    dist=Math.sqrt(Math.pow(fLen-midPoint[0],2)+Math.pow(midPoint[1],2)+Math.pow(midPoint[2],2));
            
            
    /*
            distArray is an array of two-element arrays. The first element is the distance
            of the i-th face from the observer, the second the number of the face (as stored in facesArray).
            */
            
            
    distArray[i]=[dist,i];
            
        }
        
        
    /*
        to sort distArray according to the function byDist defined later in the script.
        The sorted distArray, has faces that are farther from the observer appearing first.
        We will draw them first so they will appear behind faces which are closer to the observer.
        */
        
        
    distArray.sort(byDist);

        for(
    i=0;i<numVertices;i++)
        {
            
            
    /*
            to projecting vertices onto the view plane. In the new coordinate
            system the second and the third coordinates of each vertex give the projection.
            We multiply the coordinates by fLen/(fLen-vertsNewArray[i][0]) which gives
            the perspective effect.
            */
            
            
    dispArray[i]=[fLen/(fLen-vertsNewArray[i][0])*vertsNewArray[i][1],-fLen/(fLen-vertsNewArray[i][0])*vertsNewArray[i][2]];
            
        }
        
        for(
    i=0;i<numFaces;i++)
        {
            
            
    /*
            After projecting on the view plane,drawing each face in the order determined
            by the sorted distArray (from back to front). using what is known as the
            "painter's algorithm".
            */
            
            
    shCube.graphics.lineStyle(1,0xCC0000);
            
            
    curFace=distArray[i][1]; 
            
            
    shCube.graphics.beginFill(facesColors[curFace],0.8);
            
            
    shCube.graphics.moveTo(dispArray[facesArray[curFace][0]][0],dispArray[facesArray[curFace][0]][1]);        
            
    shCube.graphics.lineTo(dispArray[facesArray[curFace][1]][0],dispArray[facesArray[curFace][1]][1]);        
            
    shCube.graphics.lineTo(dispArray[facesArray[curFace][2]][0],dispArray[facesArray[curFace][2]][1]);        
            
    shCube.graphics.lineTo(dispArray[facesArray[curFace][3]][0],dispArray[facesArray[curFace][3]][1]);        
            
    shCube.graphics.lineTo(dispArray[facesArray[curFace][0]][0],dispArray[facesArray[curFace][0]][1]);        
            
    shCube.graphics.endFill();
            
        }
        
    }

    /*
    Below are a few helper functions: for sorting distArray, for projecting a point
    onto the new view plane, and for calculating coordinates a point's
    coordinates in a new coordinate system corresponding to
    the new position of the observer. The tranformation matrix
    is what it is because of the choice of the new coordinate system.
    */

    function byDist(v:Array,w:Array):Number 
    {
        
        if (
    v[0]>w[0])
        {
            
            return -
    1;
            
        }
        else if (
    v[0]<w[0])
        {
            
            return 
    1;
        
        } 
        else 
        {
            
            return 
    0;
         }
          
      }


    function 
    pointNewView(v:Array,theta:Number,phi:Number):Array 
    {
        
        var 
    newCoords:Array=[];    
        
    newCoords[0]=v[0]*Math.cos(theta)*Math.sin(phi)+v[1]*Math.sin(theta)*Math.sin(phi)+v[2]*Math.cos(phi);    
        
    newCoords[1]=-v[0]*Math.sin(theta)+v[1]*Math.cos(theta);    
        
    newCoords[2]=-v[0]*Math.cos(theta)*Math.cos(phi)-v[1]*Math.sin(theta)*Math.cos(phi)+v[2]*Math.sin(phi);    
        return 
    newCoords;
        
        
    }

    /*
    add listeners to rotate the cube.
    horizotal and vertical changes in the position
    */
         
         
    // change all mouse function meith keypress functions;     

    stage.addEventListener(KeyboardEvent.KEY_DOWNdetect);
    function 
    detect(evt:KeyboardEvent): void 
    {
        if(
    evt.keyCode == Keyboard.UP)
        {    
                    
            
    curTheta2=100;
                    
            
    curPhi2100;
                    
            
    renderView(curTheta2,curPhi2);
                    
            
    evt.updateAfterEvent();
            
            
    reflectX2 100;
            
    reflectY2 460;
            
    spBoard2.x=reflectX2;//reflect the bored peaces.
            
    spBoard2.y=reflectY2;//reflect the bored peaces.
            
            
            
    reflectXI 250;
            
    reflectYI 460;
            
    spBoardI.x=reflectXI;//reflect the bored peaces.
            
    spBoardI.y=reflectYI;//reflect the bored peaces.
            
            
    reflectXII 400;
            
    reflectYII 460;
            
    spBoardII.x=reflectXII;//reflect the bored peaces.
            
    spBoardII.y=reflectYII;//reflect the bored peaces.
            
            
    reflectXMM 550;
            
    reflectYMM 460;
            
    spBoardMM.x=reflectXMM;//reflect the bored peaces.
            
    spBoardMM.y=reflectYMM;//reflect the bored peaces.
            
            
            // player 2
            
    reflectYPP 290;
            
    reflectXPP 650;
            
    spBoardPP.x=reflectXPP;//reflect the bored peaces.
            
    spBoardPP.y=reflectYPP;//reflect the bored peaces.

            
    reflectYQQ 290;
            
    reflectXQQ 500;
            
    spBoardQQ.x=reflectXQQ;//reflect the bored peaces.
            
    spBoardQQ.y=reflectYQQ;//reflect the bored peaces.
            
            
    reflectYRR 290;
            
    reflectXRR 350;
            
    spBoardRR.x=reflectXRR;//reflect the bored peaces.
            
    spBoardRR.y=reflectYRR;//reflect the bored peaces.
            
            
    reflectYTT 290;
            
    reflectXTT 200;
            
    spBoardTT.x=reflectXTT;//reflect the bored peaces.
            
    spBoardTT.y=reflectYTT;//reflect the bored peaces.

        
    }
        
        if(
    evt.keyCode == Keyboard.DOWN)
        {
            
    curTheta2= -100;
                    
            
    curPhi2= -10;
                    
            
    renderView(curTheta2,curPhi2);
                    
            
            
            
    reflectX2200;
            
    reflectY2 290;
            
    spBoard2.x=reflectX2;//reflect the bored peaces.
            
    spBoard2.y=reflectY2;//reflect the bored peaces.
            
            
    reflectXI 350;
            
    reflectYI 290;
            
    spBoardI.x=reflectXI;//reflect the bored peaces.
            
    spBoardI.y=reflectYI;//reflect the bored peaces.
            
            
            
    reflectXII 500;
            
    reflectYII 290;        
            
    spBoardII.x=reflectXII;//reflect the bored peaces.
            
    spBoardII.y=reflectYII;//reflect the bored peaces.
            
            
    reflectXMM 650;
            
    reflectYMM 290;
            
    spBoardMM.x=reflectXMM;//reflect the bored peaces.
            
    spBoardMM.y=reflectYMM;//reflect the bored peaces.
            
            
            // player 2
            
    reflectYPP 460;
            
    reflectXPP 550;
            
    spBoardPP.x=reflectXPP;//reflect the bored peaces.
            
    spBoardPP.y=reflectYPP;//reflect the bored peaces.

            
    reflectYQQ 460;
            
    reflectXQQ 400;
            
    spBoardQQ.x=reflectXQQ;//reflect the bored peaces.
            
    spBoardQQ.y=reflectYQQ;//reflect the bored peaces.
            
            
    reflectYRR 460;
            
    reflectXRR 250;
            
    spBoardRR.x=reflectXRR;//reflect the bored peaces.
            
    spBoardRR.y=reflectYRR;//reflect the bored peaces.
            
            
    reflectYTT 460;
            
    reflectXTT 100;
            
    spBoardTT.x=reflectXTT;//reflect the bored peaces.
            
    spBoardTT.y=reflectYTT;//reflect the bored peaces.

            
            
        
    }    
        

        
    }

    /*

    //3d  bord mouse move. 
         
    spBoard.addEventListener(MouseEvent.ROLL_OUT,boardOut);
            
    spBoard.addEventListener(MouseEvent.MOUSE_MOVE,boardMove);
            
    spBoard.addEventListener(MouseEvent.MOUSE_DOWN,boardDown);
            
    spBoard.addEventListener(MouseEvent.MOUSE_UP,boardUp);

    stage.addEventListener(MouseEvent.MOUSE_WHEEL, onMouseWheelEvent);

    function onMouseWheelEvent(event:Event):void
    {                
        trace("scrolled");
        
    }
        
        function boardOut(e:MouseEvent):void 
        {
                
                doRotate=false;
                
        }
        
         function boardDown(e:MouseEvent):void 
         {            
                
                prevX=spBoard.mouseX;
                
                prevY=spBoard.mouseY;
                    
                doRotate=true;
                
        }
        
        function boardUp(e:MouseEvent):void 
        {
                
                doRotate=false;
                
        }
        
         function boardMove(e:MouseEvent):void 
         {
             
                    var locX:Number=prevX;
                    
                    var locY:Number=prevY;
            
                    if(doRotate)
                    {
                    
                        prevX=spBoard.mouseX;
                        
                        prevY=spBoard.mouseY;
                    
                        curTheta+=(prevX-locX);
                    
                        curPhi+=(prevY-locY);
                    
                        renderView(curTheta,curPhi);
                    
                        e.updateAfterEvent();
                    
                    }
        }

    */

    //game peaces PLAYER1;
    var vertsArray2:Array=[];
    var 
    facesArray2:Array=[];


    var 
    fLen2:Number=2000;


    var 
    numVertices2:uint=8;
    var 
    numFaces2:uint=6;



    var 
    spBoard2:Sprite=new Sprite();
    this.addChild(spBoard2);
    spBoard2.x=reflectX2;
    spBoard2.y=reflectY2;



    var 
    shBack2:Shape=new Shape();
    spBoard2.addChild(shBack2);




    var 
    shCube2:Shape=new Shape();
    spBoard2.addChild(shCube2);


    var 
    doRotate2:Boolean=false;

    var 
    prevX2:Number;
    var 
    prevY2:Number;

    var 
    curTheta3:Number=120;
    var 
    curPhi3:Number=70;

    var 
    facesColors2:Array=[0xFFFFCC,0x00FF66,0x0066FF,0x33FFFF,0x9A7DDF,0xFFCCFF];


    setVertices2();
    setFaces2();
    renderView2(curTheta3,curPhi3);



    function 
    setVertices2():void
    {
        
        
    vertsArray2[0]=[50,-50,50];    
        
    vertsArray2[1]=[50,50,50];
        
    vertsArray2[2]=[-50,50,50];
        
    vertsArray2[3]=[-50,-50,50];
        
    vertsArray2[4]=[50,-50,-50];
        
    vertsArray2[5]=[50,50,-50];
        
    vertsArray2[6]=[-50,50,-50];
        
    vertsArray2[7]=[-50,-50,-50];
        
    }



    function 
    setFaces2():void 
    {
        
        
    facesArray2[0]=[0,4,5,1];
        
    facesArray2[1]=[1,5,6,2];
        
    facesArray2[2]=[2,6,7,3];
        
    facesArray2[3]=[3,7,4,0];
        
    facesArray2[4]=[4,5,6,7];
        
    facesArray2[5]=[0,1,2,3];
        
    }



    function 
    renderView2(tt:Number,pp:Number):void
    {
        
        
    //We define local variables whose meaning will become clear below.
        
        
    var i:int;
        
        var 
    distArray2=[];    
        var 
    dispArray2=[];
        
        var 
    vertsNewArray2=[];
        
        var 
    midPoint2:Array=[];

        var 
    dist:Number;
        
        var 
    curFace2:uint;
        
        
    //We convert t and p into radians.
        
    tt=tt*Math.PI/79;    
        
    pp=pp*Math.PI/180;
        
        
    //We clear the previous view of the cube.
        
    shCube2.graphics.clear();
        
        for(
    i=0;i<numVertices2;i++)
        {        
            
    vertsNewArray2[i]=pointNewView2(vertsArray2[i],tt,pp); 
            
        }
        
        for(
    i=0;i<numFaces2;i++)
        {
                
            
    midPoint2[0]=(vertsNewArray2[facesArray2[i][0]][0]+vertsNewArray2[facesArray2[i][1]][0]+vertsNewArray2[facesArray2[i][2]][0]+vertsNewArray2[facesArray2[i][3]][0])/4;        
            
    midPoint2[1]=(vertsNewArray2[facesArray2[i][0]][1]+vertsNewArray2[facesArray2[i][1]][1]+vertsNewArray2[facesArray2[i][2]][1]+vertsNewArray2[facesArray2[i][3]][1])/4;        
            
    midPoint2[2]=(vertsNewArray2[facesArray2[i][0]][2]+vertsNewArray2[facesArray2[i][1]][2]+vertsNewArray2[facesArray2[i][2]][2]+vertsNewArray2[facesArray2[i][3]][2])/4;        
            
            
    dist=Math.sqrt(Math.pow(fLen2-midPoint2[0],2)+Math.pow(midPoint2[1],2)+Math.pow(midPoint2[2],2));    
            
    distArray2[i]=[dist,i];
        }
        
        
    distArray2.sort(byDist2);

        for(
    i=0;i<numVertices2;i++)
        {        
            
    dispArray2[i]=[fLen2/(fLen2-vertsNewArray2[i][0])*vertsNewArray2[i][1],-fLen2/(fLen2-vertsNewArray2[i][0])*vertsNewArray2[i][2]];
        }
        
        for(
    i=0;i<numFaces2;i++)
        {
            
    shCube2.graphics.lineStyle(1,0xCC0000);
            
            
    curFace2=distArray2[i][1]; 
            
            
    shCube2.graphics.beginFill(facesColors2[curFace2],0.8);
            
    shCube2.graphics.moveTo(dispArray2[facesArray2[curFace2][0]][0],dispArray2[facesArray2[curFace2][0]][1]);
            
    shCube2.graphics.lineTo(dispArray2[facesArray2[curFace2][1]][0],dispArray2[facesArray2[curFace2][1]][1]);
            
    shCube2.graphics.lineTo(dispArray2[facesArray2[curFace2][2]][0],dispArray2[facesArray2[curFace2][2]][1]);        
            
    shCube2.graphics.lineTo(dispArray2[facesArray2[curFace2][3]][0],dispArray2[facesArray2[curFace2][3]][1]);    
            
    shCube2.graphics.lineTo(dispArray2[facesArray2[curFace2][0]][0],dispArray2[facesArray2[curFace2][0]][1]);        
            
    shCube2.graphics.endFill();
            
        }
        
    }


    function 
    byDist2(v:Array,w:Array):Number 
    {
        if (
    v[0]>w[0])
        {
            return -
    1;
        }
        else if (
    v[0]<w[0])
        {
            return 
    1;
        } 
       else 
        {
           return 
    0;
        }  
    }


    function 
    pointNewView2(v:Array,theta:Number,phi:Number):Array
    {
        
        var 
    newCoords:Array=[];    
        
    newCoords[0]=v[0]*Math.cos(theta)*Math.sin(phi)+v[1]*Math.sin(theta)*Math.sin(phi)+v[2]*Math.cos(phi);
        
    newCoords[1]=-v[0]*Math.sin(theta)+v[1]*Math.cos(theta);
        
    newCoords[2]=-v[0]*Math.cos(theta)*Math.cos(phi)-v[1]*Math.sin(theta)*Math.cos(phi)+v[2]*Math.sin(phi);
        return 
    newCoords;
        
        
    }




    //game peace
    var vertsArrayI:Array=[];
    var 
    facesArrayI:Array=[];


    var 
    fLenI:Number=2000;
    var 
    numVerticesI:uint=8;
    var 
    numFacesI:uint=6;



    var 
    spBoardI:Sprite=new Sprite();
    this.addChild(spBoardI);
    spBoardI.x=reflectXI;
    spBoardI.y=reflectYI;



    var 
    shBackI:Shape=new Shape();
    spBoardI.addChild(shBackI);




    var 
    shCubeI:Shape=new Shape();

    spBoardI.addChild(shCubeI);


    var 
    doRotateI:Boolean=false;

    var 
    prevXI:Number;

    var 
    prevYI:Number;

    var 
    curThetaI:Number=119;

    var 
    curPhiI:Number=69;

    var 
    facesColorsI:Array=[0xFFFFCC,0x00FF66,0x0066FF,0x33FFFF,0x9A7DDF,0xFFCCFF];


    setVerticesI();

    setFacesI();

    renderViewI(curThetaI,curPhiI);



    function 
    setVerticesI():void
    {
        
    vertsArrayI[0]=[50,-50,50];    
        
    vertsArrayI[1]=[50,50,50];    
        
    vertsArrayI[2]=[-50,50,50];    
        
    vertsArrayI[3]=[-50,-50,50];    
        
    vertsArrayI[4]=[50,-50,-50];    
        
    vertsArrayI[5]=[50,50,-50];    
        
    vertsArrayI[6]=[-50,50,-50];    
        
    vertsArrayI[7]=[-50,-50,-50];
        
    }



    function 
    setFacesI():void 
    {    
        
    facesArrayI[0]=[0,4,5,1];    
        
    facesArrayI[1]=[1,5,6,2];    
        
    facesArrayI[2]=[2,6,7,3];    
        
    facesArrayI[3]=[3,7,4,0];    
        
    facesArrayI[4]=[4,5,6,7];    
        
    facesArrayI[5]=[0,1,2,3];
    }



    function 
    renderViewI(tt:Number,pp:Number):void
    {
        
        
    //We define local variables whose meaning will become clear below.
        
        
    var i:int;
        
        var 
    distArray2=[];
        
        var 
    dispArray2=[];
        
        var 
    vertsNewArray2=[];
        
        var 
    midPoint2:Array=[];

        var 
    dist:Number;
        
        var 
    curFace2:uint;
        
        
    //We convert t and p into radians.
        
        
    tt=tt*Math.PI/79;
        
        
    pp=pp*Math.PI/180;
        
        
    //We clear the previous view of the cube.
        
        
    shCubeI.graphics.clear();
        
        for(
    i=0;i<numVerticesI;i++)
        {
            
    vertsNewArray2[i]=pointNewViewI(vertsArrayI[i],tt,pp);     
        }
        
        
        
        for(
    i=0;i<numFacesI;i++)
        {
            
            
                    
            
    midPoint2[0]=(vertsNewArray2[facesArrayI[i][0]][0]+vertsNewArray2[facesArrayI[i][1]][0]+vertsNewArray2[facesArrayI[i][2]][0]+vertsNewArray2[facesArrayI[i][3]][0])/4;
            
    midPoint2[1]=(vertsNewArray2[facesArrayI[i][0]][1]+vertsNewArray2[facesArrayI[i][1]][1]+vertsNewArray2[facesArrayI[i][2]][1]+vertsNewArray2[facesArrayI[i][3]][1])/4;
            
    midPoint2[2]=(vertsNewArray2[facesArrayI[i][0]][2]+vertsNewArray2[facesArrayI[i][1]][2]+vertsNewArray2[facesArrayI[i][2]][2]+vertsNewArray2[facesArrayI[i][3]][2])/4;
            
            
            
            
    dist=Math.sqrt(Math.pow(fLenI-midPoint2[0],2)+Math.pow(midPoint2[1],2)+Math.pow(midPoint2[2],2));
            
            
            
    distArray2[i]=[dist,i];
            
        }
        
        
        
        
    distArray2.sort(byDistI);

        for(
    i=0;i<numVerticesI;i++)
        {        
            
    dispArray2[i]=[fLenI/(fLenI-vertsNewArray2[i][0])*vertsNewArray2[i][1],-fLenI/(fLenI-vertsNewArray2[i][0])*vertsNewArray2[i][2]];
        }
        
        for(
    i=0;i<numFacesI;i++)
        {
            
    shCubeI.graphics.lineStyle(1,0xCC0000);
            
            
    curFace2=distArray2[i][1]; 
            
            
    shCubeI.graphics.beginFill(facesColorsI[curFace2],0.8);
            
    shCubeI.graphics.moveTo(dispArray2[facesArrayI[curFace2][0]][0],dispArray2[facesArrayI[curFace2][0]][1]);
            
    shCubeI.graphics.lineTo(dispArray2[facesArrayI[curFace2][1]][0],dispArray2[facesArrayI[curFace2][1]][1]);
            
    shCubeI.graphics.lineTo(dispArray2[facesArrayI[curFace2][2]][0],dispArray2[facesArrayI[curFace2][2]][1]);
            
    shCubeI.graphics.lineTo(dispArray2[facesArrayI[curFace2][3]][0],dispArray2[facesArrayI[curFace2][3]][1]);
            
    shCubeI.graphics.lineTo(dispArray2[facesArrayI[curFace2][0]][0],dispArray2[facesArrayI[curFace2][0]][1]);
            
    shCubeI.graphics.endFill();
            
        }
        
    }


    function 
    byDistI(v:Array,w:Array):Number 
    {
        
        if (
    v[0]>w[0])
        {
            
            return -
    1;
            
          }
          else if (
    v[0]<w[0])
          {
            
            return 
    1;
        
           } 
           else 
           {
            
            return 
    0;
          }
          
      }


    function 
    pointNewViewI(v:Array,theta:Number,phi:Number):Array
    {
        
        var 
    newCoords:Array=[];
        
    newCoords[0]=v[0]*Math.cos(theta)*Math.sin(phi)+v[1]*Math.sin(theta)*Math.sin(phi)+v[2]*Math.cos(phi);
        
    newCoords[1]=-v[0]*Math.sin(theta)+v[1]*Math.cos(theta);
        
    newCoords[2]=-v[0]*Math.cos(theta)*Math.cos(phi)-v[1]*Math.sin(theta)*Math.cos(phi)+v[2]*Math.sin(phi);
        
        return 
    newCoords;
        
        
    }

    //game peaces;
    var vertsArrayII:Array=[];
    var 
    facesArrayII:Array=[];


    var 
    fLenII:Number=2000;
    var 
    numVerticesII:uint=8;
    var 
    numFacesII:uint=6;



    var 
    spBoardII:Sprite=new Sprite();
    this.addChild(spBoardII);
    spBoardII.x=reflectXII;
    spBoardII.y=reflectYII;



    var 
    shBackII:Shape=new Shape();
    spBoardII.addChild(shBackII);




    var 
    shCubeII:Shape=new Shape();
    spBoardII.addChild(shCubeII);


    var 
    doRotateII:Boolean=false;

    var 
    prevXII:Number;

    var 
    prevYII:Number;

    var 
    curThetaII:Number=118;

    var 
    curPhiII:Number=70;

    var 
    facesColorsII:Array=[0xFFFFCC,0x00FF66,0x0066FF,0x33FFFF,0x9A7DDF,0xFFCCFF];


    setVerticesII();

    setFacesII();

    renderViewII(curThetaII,curPhiII);



    function 
    setVerticesII():void
    {
        
        
    vertsArrayII[0]=[50,-50,50];
        
    vertsArrayII[1]=[50,50,50];
        
    vertsArrayII[2]=[-50,50,50];
        
    vertsArrayII[3]=[-50,-50,50];
        
    vertsArrayII[4]=[50,-50,-50];
        
    vertsArrayII[5]=[50,50,-50];
        
    vertsArrayII[6]=[-50,50,-50];
        
    vertsArrayII[7]=[-50,-50,-50];
        
    }



    function 
    setFacesII():void 
    {
        
    facesArrayII[0]=[0,4,5,1];
        
    facesArrayII[1]=[1,5,6,2];
        
    facesArrayII[2]=[2,6,7,3];
        
    facesArrayII[3]=[3,7,4,0];
        
    facesArrayII[4]=[4,5,6,7];
        
    facesArrayII[5]=[0,1,2,3];
        
    }



    function 
    renderViewII(tt:Number,pp:Number):void
    {
        
        
    //We define local variables whose meaning will become clear below.
        
        
    var i:int;
        
        var 
    distArray2=[];
        
        var 
    dispArray2=[];
        
        var 
    vertsNewArray2=[];
        
        var 
    midPoint2:Array=[];

        var 
    dist:Number;
        
        var 
    curFace2:uint;
        
        
    //We convert t and p into radians.
        
        
    tt=tt*Math.PI/79;
        
        
    pp=pp*Math.PI/180;
        
        
    //We clear the previous view of the cube.
        
        
    shCubeII.graphics.clear();
        
        for(
    i=0;i<numVerticesII;i++)
        {
            
    vertsNewArray2[i]=pointNewViewII(vertsArrayII[i],tt,pp); 
        }
        
        
        
        for(
    i=0;i<numFacesII;i++)
        {    
            
    midPoint2[0]=(vertsNewArray2[facesArrayII[i][0]][0]+vertsNewArray2[facesArrayII[i][1]][0]+vertsNewArray2[facesArrayII[i][2]][0]+vertsNewArray2[facesArrayII[i][3]][0])/4;
            
    midPoint2[1]=(vertsNewArray2[facesArrayII[i][0]][1]+vertsNewArray2[facesArrayII[i][1]][1]+vertsNewArray2[facesArrayII[i][2]][1]+vertsNewArray2[facesArrayII[i][3]][1])/4;        
            
    midPoint2[2]=(vertsNewArray2[facesArrayII[i][0]][2]+vertsNewArray2[facesArrayII[i][1]][2]+vertsNewArray2[facesArrayII[i][2]][2]+vertsNewArray2[facesArrayII[i][3]][2])/4;
            
            
    dist=Math.sqrt(Math.pow(fLenII-midPoint2[0],2)+Math.pow(midPoint2[1],2)+Math.pow(midPoint2[2],2));
            
            
            
    distArray2[i]=[dist,i];
            
        }
        
        
        
        
    distArray2.sort(byDistII);

        for(
    i=0;i<numVerticesII;i++)
        {        
            
    dispArray2[i]=[fLenII/(fLenII-vertsNewArray2[i][0])*vertsNewArray2[i][1],-fLenII/(fLenII-vertsNewArray2[i][0])*vertsNewArray2[i][2]];
        }
        
        for(
    i=0;i<numFacesII;i++)
        {
            
    shCubeII.graphics.lineStyle(1,0xCC0000);
            
            
    curFace2=distArray2[i][1]; 
            
            
    shCubeII.graphics.beginFill(facesColorsII[curFace2],0.8);
            
    shCubeII.graphics.moveTo(dispArray2[facesArrayII[curFace2][0]][0],dispArray2[facesArrayII[curFace2][0]][1]);
            
    shCubeII.graphics.lineTo(dispArray2[facesArrayII[curFace2][1]][0],dispArray2[facesArrayII[curFace2][1]][1]);
            
    shCubeII.graphics.lineTo(dispArray2[facesArrayII[curFace2][2]][0],dispArray2[facesArrayII[curFace2][2]][1]);
            
    shCubeII.graphics.lineTo(dispArray2[facesArrayII[curFace2][3]][0],dispArray2[facesArrayII[curFace2][3]][1]);
            
    shCubeII.graphics.lineTo(dispArray2[facesArrayII[curFace2][0]][0],dispArray2[facesArrayII[curFace2][0]][1]);
            
    shCubeII.graphics.endFill();
            
        }
        
    }


    function 
    byDistII(v:Array,w:Array):Number 
    {
        
        if (
    v[0]>w[0])
        {
            
            return -
    1;
            
          }
          else if (
    v[0]<w[0])
          {
            
            return 
    1;
        
           } 
           else 
           {
            
            return 
    0;
          }
          
      }


    function 
    pointNewViewII(v:Array,theta:Number,phi:Number):Array
    {
        
        var 
    newCoords:Array=[];
        
    newCoords[0]=v[0]*Math.cos(theta)*Math.sin(phi)+v[1]*Math.sin(theta)*Math.sin(phi)+v[2]*Math.cos(phi);
        
    newCoords[1]=-v[0]*Math.sin(theta)+v[1]*Math.cos(theta);
        
    newCoords[2]=-v[0]*Math.cos(theta)*Math.cos(phi)-v[1]*Math.sin(theta)*Math.cos(phi)+v[2]*Math.sin(phi);
        return 
    newCoords;
        
        
    }



    //game peace 4
    var vertsArrayMM:Array=[];
    var 
    facesArrayMM:Array=[];


    var 
    fLenMM:Number=2000;
    var 
    numVerticesMM:uint=8;
    var 
    numFacesMM:uint=6;



    var 
    spBoardMM:Sprite=new Sprite();
    this.addChild(spBoardMM);
    spBoardMM.x=reflectXMM;
    spBoardMM.y=reflectYMM;



    var 
    shBackMM:Shape=new Shape();
    spBoardMM.addChild(shBackMM);




    var 
    shCubeMM:Shape=new Shape();
    spBoardMM.addChild(shCubeMM);


    var 
    doRotateMM:Boolean=false;

    var 
    prevXMM:Number;

    var 
    prevYMM:Number;

    var 
    curThetaMM:Number=118;

    var 
    curPhMMI:Number=70;

    var 
    facesColorsMM:Array=[0xFFFFCC,0x00FF66,0x0066FF,0x33FFFF,0x9A7DDF,0xFFCCFF];


    setVerticesMM();

    setFacesMM();

    renderViewMM(curThetaMM,curPhMMI);



    function 
    setVerticesMM():void
    {
        
        
    vertsArrayMM[0]=[50,-50,50];
        
    vertsArrayMM[1]=[50,50,50];
        
    vertsArrayMM[2]=[-50,50,50];
        
    vertsArrayMM[3]=[-50,-50,50];
        
    vertsArrayMM[4]=[50,-50,-50];
        
    vertsArrayMM[5]=[50,50,-50];
        
    vertsArrayMM[6]=[-50,50,-50];
        
    vertsArrayMM[7]=[-50,-50,-50];
    }



    function 
    setFacesMM():void 
    {
        
        
    facesArrayMM[0]=[0,4,5,1];
        
    facesArrayMM[1]=[1,5,6,2];
        
    facesArrayMM[2]=[2,6,7,3];
        
    facesArrayMM[3]=[3,7,4,0];
        
    facesArrayMM[4]=[4,5,6,7];
        
    facesArrayMM[5]=[0,1,2,3];
        
    }



    function 
    renderViewMM(tt:Number,pp:Number):void
    {
        
        
    //We define local variables whose meaning will become clear below.
        
        
    var i:int;
        
        var 
    distArray2=[];
        
        var 
    dispArray2=[];
        
        var 
    vertsNewArray2=[];
        
        var 
    midPoint2:Array=[];

        var 
    dist:Number;
        
        var 
    curFace2:uint;
        
        
    //We convert t and p into radians.
        
        
    tt=tt*Math.PI/79;
        
        
    pp=pp*Math.PI/180;
        
        
    //We clear the previous view of the cube.
        
        
    shCubeMM.graphics.clear();
        
        for(
    i=0;i<numVerticesMM;i++)
        {
            
    vertsNewArray2[i]=pointNewViewMM(vertsArrayMM[i],tt,pp); 
        }
        
        
        
        for(
    i=0;i<numFacesMM;i++)
        {
            
            
                    
            
    midPoint2[0]=(vertsNewArray2[facesArrayMM[i][0]][0]+vertsNewArray2[facesArrayMM[i][1]][0]+vertsNewArray2[facesArrayMM[i][2]][0]+vertsNewArray2[facesArrayMM[i][3]][0])/4;
            
    midPoint2[1]=(vertsNewArray2[facesArrayMM[i][0]][1]+vertsNewArray2[facesArrayMM[i][1]][1]+vertsNewArray2[facesArrayMM[i][2]][1]+vertsNewArray2[facesArrayMM[i][3]][1])/4;
            
    midPoint2[2]=(vertsNewArray2[facesArrayMM[i][0]][2]+vertsNewArray2[facesArrayMM[i][1]][2]+vertsNewArray2[facesArrayMM[i][2]][2]+vertsNewArray2[facesArrayMM[i][3]][2])/4;
            
            
            
            
    dist=Math.sqrt(Math.pow(fLenMM-midPoint2[0],2)+Math.pow(midPoint2[1],2)+Math.pow(midPoint2[2],2));
            
    distArray2[i]=[dist,i];
            
        }
        
        
        
        
    distArray2.sort(byDistMM);

        for(
    i=0;i<numVerticesMM;i++)
        {        
            
    dispArray2[i]=[fLenMM/(fLenMM-vertsNewArray2[i][0])*vertsNewArray2[i][1],-fLenMM/(fLenMM-vertsNewArray2[i][0])*vertsNewArray2[i][2]];
        }
        
        for(
    i=0;i<numFacesMM;i++)
        {
            
    shCubeMM.graphics.lineStyle(1,0xCC0000);
            
            
    curFace2=distArray2[i][1]; 
            
            
    shCubeMM.graphics.beginFill(facesColorsMM[curFace2],0.8);
            
    shCubeMM.graphics.moveTo(dispArray2[facesArrayMM[curFace2][0]][0],dispArray2[facesArrayMM[curFace2][0]][1]);
            
    shCubeMM.graphics.lineTo(dispArray2[facesArrayMM[curFace2][1]][0],dispArray2[facesArrayMM[curFace2][1]][1]);
            
    shCubeMM.graphics.lineTo(dispArray2[facesArrayMM[curFace2][2]][0],dispArray2[facesArrayMM[curFace2][2]][1]);
            
    shCubeMM.graphics.lineTo(dispArray2[facesArrayMM[curFace2][3]][0],dispArray2[facesArrayMM[curFace2][3]][1]);
            
    shCubeMM.graphics.lineTo(dispArray2[facesArrayMM[curFace2][0]][0],dispArray2[facesArrayMM[curFace2][0]][1]);    
            
    shCubeMM.graphics.endFill();
            
        }
        
    }


    function 
    byDistMM(v:Array,w:Array):Number 
    {
        
        if (
    v[0]>w[0])
        {
            
            return -
    1;
            
          }
          else if (
    v[0]<w[0])
          {
            
            return 
    1;
        
           } 
           else 
           {
            
            return 
    0;
          }
          
      }


    function 
    pointNewViewMM(v:Array,theta:Number,phi:Number):Array
    {
        
        var 
    newCoords:Array=[];
        
    newCoords[0]=v[0]*Math.cos(theta)*Math.sin(phi)+v[1]*Math.sin(theta)*Math.sin(phi)+v[2]*Math.cos(phi);
        
    newCoords[1]=-v[0]*Math.sin(theta)+v[1]*Math.cos(theta);
        
    newCoords[2]=-v[0]*Math.cos(theta)*Math.cos(phi)-v[1]*Math.sin(theta)*Math.cos(phi)+v[2]*Math.sin(phi);
        return 
    newCoords;
    }



    //player 2
    var vertsArrayPP:Array=[];
    var 
    facesArrayPP:Array=[];


    var 
    fLenPP:Number=2000;
    var 
    numVerticesPP:uint=8;
    var 
    numFacesPP:uint=6;



    var 
    spBoardPP:Sprite=new Sprite();
    this.addChild(spBoardPP);
    spBoardPP.x=reflectXPP;
    spBoardPP.y=reflectYPP;



    var 
    shBackPP:Shape=new Shape();
    spBoardPP.addChild(shBackPP);




    var 
    shCubePP:Shape=new Shape();
    spBoardPP.addChild(shCubePP);


    var 
    doRotatePP:Boolean=false;

    var 
    prevXPP:Number;

    var 
    prevYPP:Number;

    var 
    curThetaPP:Number=118;

    var 
    curPhPPI:Number=70;

    var 
    facesColorsPP:Array=[0xFFFFCC,0x00FF66,0x0066FF,0x33FFFF,0x9A7DDF,0xFFCCFF];


    setVerticesPP();

    setFacesPP();

    renderViewPP(curThetaPP,curPhPPI);



    function 
    setVerticesPP():void
    {
        
        
    vertsArrayPP[0]=[50,-50,50];
        
    vertsArrayPP[1]=[50,50,50];
        
    vertsArrayPP[2]=[-50,50,50];
        
    vertsArrayPP[3]=[-50,-50,50];
        
    vertsArrayPP[4]=[50,-50,-50];
        
    vertsArrayPP[5]=[50,50,-50];
        
    vertsArrayPP[6]=[-50,50,-50];
        
    vertsArrayPP[7]=[-50,-50,-50];
        
    }



    function 
    setFacesPP():void 
    {
        
        
    facesArrayPP[0]=[0,4,5,1];
        
    facesArrayPP[1]=[1,5,6,2];
        
    facesArrayPP[2]=[2,6,7,3];
        
    facesArrayPP[3]=[3,7,4,0];
        
    facesArrayPP[4]=[4,5,6,7];
        
    facesArrayPP[5]=[0,1,2,3];
        
    }



    function 
    renderViewPP(tt:Number,pp:Number):void
    {
        
        
    //We define local variables whose meaning will become clear below.
        
        
    var i:int;
        
        var 
    distArray2=[];
        
        var 
    dispArray2=[];
        
        var 
    vertsNewArray2=[];
        
        var 
    midPoint2:Array=[];

        var 
    dist:Number;
        
        var 
    curFace2:uint;
        
        
    //We convert t and p into radians.
        
        
    tt=tt*Math.PI/79;
        
        
    pp=pp*Math.PI/180;
        
        
    //We clear the previous view of the cube.
        
        
    shCubePP.graphics.clear();
        
        for(
    i=0;i<numVerticesPP;i++)
        {
            
    vertsNewArray2[i]=pointNewViewPP(vertsArrayPP[i],tt,pp); 
            
        }
        
        
        
        for(
    i=0;i<numFacesPP;i++)
        {
            
    midPoint2[0]=(vertsNewArray2[facesArrayPP[i][0]][0]+vertsNewArray2[facesArrayPP[i][1]][0]+vertsNewArray2[facesArrayPP[i][2]][0]+vertsNewArray2[facesArrayPP[i][3]][0])/4;
            
    midPoint2[1]=(vertsNewArray2[facesArrayPP[i][0]][1]+vertsNewArray2[facesArrayPP[i][1]][1]+vertsNewArray2[facesArrayPP[i][2]][1]+vertsNewArray2[facesArrayPP[i][3]][1])/4;
            
    midPoint2[2]=(vertsNewArray2[facesArrayPP[i][0]][2]+vertsNewArray2[facesArrayPP[i][1]][2]+vertsNewArray2[facesArrayPP[i][2]][2]+vertsNewArray2[facesArrayPP[i][3]][2])/4;
            

            
    dist=Math.sqrt(Math.pow(fLenPP-midPoint2[0],2)+Math.pow(midPoint2[1],2)+Math.pow(midPoint2[2],2));
            
    distArray2[i]=[dist,i];
            
        }
        
        
        
        
    distArray2.sort(byDistPP);

        for(
    i=0;i<numVerticesPP;i++)
        {        
            
    dispArray2[i]=[fLenPP/(fLenPP-vertsNewArray2[i][0])*vertsNewArray2[i][1],-fLenPP/(fLenPP-vertsNewArray2[i][0])*vertsNewArray2[i][2]];
        }
        
        for(
    i=0;i<numFacesPP;i++)
        {
            
            
            
    shCubePP.graphics.lineStyle(1,0xCC0000);
            
            
    curFace2=distArray2[i][1]; 
            
            
    shCubePP.graphics.beginFill(facesColorsPP[curFace2],0.8);
            
    shCubePP.graphics.moveTo(dispArray2[facesArrayPP[curFace2][0]][0],dispArray2[facesArrayPP[curFace2][0]][1]);
            
    shCubePP.graphics.lineTo(dispArray2[facesArrayPP[curFace2][1]][0],dispArray2[facesArrayPP[curFace2][1]][1]);
            
    shCubePP.graphics.lineTo(dispArray2[facesArrayPP[curFace2][2]][0],dispArray2[facesArrayPP[curFace2][2]][1]);
            
    shCubePP.graphics.lineTo(dispArray2[facesArrayPP[curFace2][3]][0],dispArray2[facesArrayPP[curFace2][3]][1]);
            
    shCubePP.graphics.lineTo(dispArray2[facesArrayPP[curFace2][0]][0],dispArray2[facesArrayPP[curFace2][0]][1]);
            
    shCubePP.graphics.endFill();
            
        }
        
    }


    function 
    byDistPP(v:Array,w:Array):Number 
    {
        
        if (
    v[0]>w[0])
        {
            
            return -
    1;
            
          }
          else if (
    v[0]<w[0])
          {
            
            return 
    1;
          } 
         
         else 
          {
            
            return 
    0;
          }
          
      }


    function 
    pointNewViewPP(v:Array,theta:Number,phi:Number):Array
    {
        
        var 
    newCoords:Array=[];
        
    newCoords[0]=v[0]*Math.cos(theta)*Math.sin(phi)+v[1]*Math.sin(theta)*Math.sin(phi)+v[2]*Math.cos(phi);
        
    newCoords[1]=-v[0]*Math.sin(theta)+v[1]*Math.cos(theta);
        
    newCoords[2]=-v[0]*Math.cos(theta)*Math.cos(phi)-v[1]*Math.sin(theta)*Math.cos(phi)+v[2]*Math.sin(phi);
        return 
    newCoords;
        
        
    }



    //player 2 peace 2
    var vertsArrayQQ:Array=[];

    var 
    facesArrayQQ:Array=[];


    var 
    fLenQQ:Number=2000;


    var 
    numVerticesQQ:uint=8;

    var 
    numFacesQQ:uint=6;



    var 
    spBoardQQ:Sprite=new Sprite();

    this.addChild(spBoardQQ);

    spBoardQQ.x=reflectXQQ;

    spBoardQQ.y=reflectYQQ;



    var 
    shBackQQ:Shape=new Shape();

    spBoardQQ.addChild(shBackQQ);




    var 
    shCubeQQ:Shape=new Shape();

    spBoardQQ.addChild(shCubeQQ);


    var 
    doRotateQQ:Boolean=false;

    var 
    prevXQQ:Number;

    var 
    prevYQQ:Number;

    var 
    curThetaQQ:Number=118;

    var 
    curPhQQI:Number=70;

    var 
    facesColorsQQ:Array=[0xFFFFCC,0x00FF66,0x0066FF,0x33FFFF,0x9A7DDF,0xFFCCFF];


    setVerticesQQ();

    setFacesQQ();

    renderViewQQ(curThetaQQ,curPhQQI);



    function 
    setVerticesQQ():void
    {
        
        
    vertsArrayQQ[0]=[50,-50,50];
        
    vertsArrayQQ[1]=[50,50,50];
        
    vertsArrayQQ[2]=[-50,50,50];
        
    vertsArrayQQ[3]=[-50,-50,50];
        
    vertsArrayQQ[4]=[50,-50,-50];
        
    vertsArrayQQ[5]=[50,50,-50];
        
    vertsArrayQQ[6]=[-50,50,-50];
        
    vertsArrayQQ[7]=[-50,-50,-50];
        
    }



    function 
    setFacesQQ():void 
    {
        
        
    facesArrayQQ[0]=[0,4,5,1];
        
    facesArrayQQ[1]=[1,5,6,2];
        
    facesArrayQQ[2]=[2,6,7,3];
        
    facesArrayQQ[3]=[3,7,4,0];
        
    facesArrayQQ[4]=[4,5,6,7];
        
    facesArrayQQ[5]=[0,1,2,3];
        
    }



    function 
    renderViewQQ(tt:Number,QQ:Number):void
    {
        
        
    //We define local variables whose meaning will become clear below.
        
        
    var i:int;
        
        var 
    distArray2=[];
        
        var 
    dispArray2=[];
        
        var 
    vertsNewArray2=[];
        
        var 
    midPoint2:Array=[];

        var 
    dist:Number;
        
        var 
    curFace2:uint;
        
        
    //We convert t and p into radians.
        
        
    tt=tt*Math.PI/79;
        
        
    QQ=QQ*Math.PI/180;
        
        
    //We clear the previous view of the cube.
        
        
    shCubeQQ.graphics.clear();
        
        for(
    i=0;i<numVerticesQQ;i++)
        {
            
    vertsNewArray2[i]=pointNewViewQQ(vertsArrayQQ[i],tt,QQ); 
        }
        
        
        
        for(
    i=0;i<numFacesQQ;i++)
        {
            
    midPoint2[0]=(vertsNewArray2[facesArrayQQ[i][0]][0]+vertsNewArray2[facesArrayQQ[i][1]][0]+vertsNewArray2[facesArrayQQ[i][2]][0]+vertsNewArray2[facesArrayQQ[i][3]][0])/4;
            
    midPoint2[1]=(vertsNewArray2[facesArrayQQ[i][0]][1]+vertsNewArray2[facesArrayQQ[i][1]][1]+vertsNewArray2[facesArrayQQ[i][2]][1]+vertsNewArray2[facesArrayQQ[i][3]][1])/4;        
            
    midPoint2[2]=(vertsNewArray2[facesArrayQQ[i][0]][2]+vertsNewArray2[facesArrayQQ[i][1]][2]+vertsNewArray2[facesArrayQQ[i][2]][2]+vertsNewArray2[facesArrayQQ[i][3]][2])/4;
            
            
            
            
    dist=Math.sqrt(Math.pow(fLenQQ-midPoint2[0],2)+Math.pow(midPoint2[1],2)+Math.pow(midPoint2[2],2));
            
    distArray2[i]=[dist,i];
        }
        
        
        
        
    distArray2.sort(byDistQQ);

        for(
    i=0;i<numVerticesQQ;i++)
        {        
            
    dispArray2[i]=[fLenQQ/(fLenQQ-vertsNewArray2[i][0])*vertsNewArray2[i][1],-fLenQQ/(fLenQQ-vertsNewArray2[i][0])*vertsNewArray2[i][2]];
        }
        
        for(
    i=0;i<numFacesQQ;i++)
        {
            
            
            
    shCubeQQ.graphics.lineStyle(1,0xCC0000);
            
            
    curFace2=distArray2[i][1]; 
            
            
    shCubeQQ.graphics.beginFill(facesColorsQQ[curFace2],0.8);
            
    shCubeQQ.graphics.moveTo(dispArray2[facesArrayQQ[curFace2][0]][0],dispArray2[facesArrayQQ[curFace2][0]][1]);
            
    shCubeQQ.graphics.lineTo(dispArray2[facesArrayQQ[curFace2][1]][0],dispArray2[facesArrayQQ[curFace2][1]][1]);
            
    shCubeQQ.graphics.lineTo(dispArray2[facesArrayQQ[curFace2][2]][0],dispArray2[facesArrayQQ[curFace2][2]][1]);
            
    shCubeQQ.graphics.lineTo(dispArray2[facesArrayQQ[curFace2][3]][0],dispArray2[facesArrayQQ[curFace2][3]][1]);    
            
    shCubeQQ.graphics.lineTo(dispArray2[facesArrayQQ[curFace2][0]][0],dispArray2[facesArrayQQ[curFace2][0]][1]);
            
    shCubeQQ.graphics.endFill();
            
        }
        
    }


    function 
    byDistQQ(v:Array,w:Array):Number 
    {
        
        if (
    v[0]>w[0])
        {
            
            return -
    1;
            
          }
          else if (
    v[0]<w[0])
          {
            
            return 
    1;
        
           } 
           else 
           {
            
            return 
    0;
          }
          
      }


    function 
    pointNewViewQQ(v:Array,theta:Number,phi:Number):Array
    {
        
        var 
    newCoords:Array=[];
        
    newCoords[0]=v[0]*Math.cos(theta)*Math.sin(phi)+v[1]*Math.sin(theta)*Math.sin(phi)+v[2]*Math.cos(phi);
        
    newCoords[1]=-v[0]*Math.sin(theta)+v[1]*Math.cos(theta);
        
    newCoords[2]=-v[0]*Math.cos(theta)*Math.cos(phi)-v[1]*Math.sin(theta)*Math.cos(phi)+v[2]*Math.sin(phi);
        return 
    newCoords;
        
        
    }



    //player 2 peace 3
    var vertsArrayRR:Array=[];
    var 
    facesArrayRR:Array=[];


    var 
    fLenRR:Number=2000;
    var 
    numVerticesRR:uint=8;
    var 
    numFacesRR:uint=6;



    var 
    spBoardRR:Sprite=new Sprite();
    this.addChild(spBoardRR);
    spBoardRR.x=reflectXRR;
    spBoardRR.y=reflectYRR;



    var 
    shBackRR:Shape=new Shape();
    spBoardRR.addChild(shBackRR);




    var 
    shCubeRR:Shape=new Shape();
    spBoardRR.addChild(shCubeRR);


    var 
    doRotateRR:Boolean=false;

    var 
    prevXRR:Number;
    var 
    prevYRR:Number;

    var 
    curThetaRR:Number=118;
    var 
    curPhRRI:Number=70;

    var 
    facesColorsRR:Array=[0xFFFFCC,0x00FF66,0x0066FF,0x33FFFF,0x9A7DDF,0xFFCCFF];
    setVerticesRR();
    setFacesRR();
    renderViewRR(curThetaRR,curPhRRI);


    function 
    setVerticesRR():void
    {
        
        
    vertsArrayRR[0]=[50,-50,50];    
        
    vertsArrayRR[1]=[50,50,50];    
        
    vertsArrayRR[2]=[-50,50,50];    
        
    vertsArrayRR[3]=[-50,-50,50];    
        
    vertsArrayRR[4]=[50,-50,-50];
        
    vertsArrayRR[5]=[50,50,-50];    
        
    vertsArrayRR[6]=[-50,50,-50];    
        
    vertsArrayRR[7]=[-50,-50,-50];
        
    }



    function 
    setFacesRR():void 
    {
        
        
    facesArrayRR[0]=[0,4,5,1];    
        
    facesArrayRR[1]=[1,5,6,2];    
        
    facesArrayRR[2]=[2,6,7,3];    
        
    facesArrayRR[3]=[3,7,4,0];    
        
    facesArrayRR[4]=[4,5,6,7];    
        
    facesArrayRR[5]=[0,1,2,3];
        
    }



    function 
    renderViewRR(tt:Number,RR:Number):void
    {
        
        
    //We define local variables whose meaning will become clear below.
        
        
    var i:int;
        
        var 
    distArray2=[];
        
        var 
    dispArray2=[];
        
        var 
    vertsNewArray2=[];
        
        var 
    midPoint2:Array=[];

        var 
    dist:Number;
        
        var 
    curFace2:uint;
        
        
    //We convert t and p into radians.
        
        
    tt=tt*Math.PI/79;
        
        
    RR=RR*Math.PI/180;
        
        
    //We clear the previous view of the cube.
        
        
    shCubeRR.graphics.clear();
        
        for(
    i=0;i<numVerticesRR;i++)
        {
            
            
            
    vertsNewArray2[i]=pointNewViewRR(vertsArrayRR[i],tt,RR); 
            
        }
        
        
        
        for(
    i=0;i<numFacesRR;i++)
        {
            
            
                    
            
    midPoint2[0]=(vertsNewArray2[facesArrayRR[i][0]][0]+vertsNewArray2[facesArrayRR[i][1]][0]+vertsNewArray2[facesArrayRR[i][2]][0]+vertsNewArray2[facesArrayRR[i][3]][0])/4;        
            
    midPoint2[1]=(vertsNewArray2[facesArrayRR[i][0]][1]+vertsNewArray2[facesArrayRR[i][1]][1]+vertsNewArray2[facesArrayRR[i][2]][1]+vertsNewArray2[facesArrayRR[i][3]][1])/4;
            
    midPoint2[2]=(vertsNewArray2[facesArrayRR[i][0]][2]+vertsNewArray2[facesArrayRR[i][1]][2]+vertsNewArray2[facesArrayRR[i][2]][2]+vertsNewArray2[facesArrayRR[i][3]][2])/4;

            
    dist=Math.sqrt(Math.pow(fLenRR-midPoint2[0],2)+Math.pow(midPoint2[1],2)+Math.pow(midPoint2[2],2));
            
    distArray2[i]=[dist,i];
            
        }
        
        
        
        
    distArray2.sort(byDistRR);

        for(
    i=0;i<numVerticesRR;i++)
        {        
            
    dispArray2[i]=[fLenRR/(fLenRR-vertsNewArray2[i][0])*vertsNewArray2[i][1],-fLenRR/(fLenRR-vertsNewArray2[i][0])*vertsNewArray2[i][2]];
        }
        
        for(
    i=0;i<numFacesRR;i++)
        {
            
            
            
    shCubeRR.graphics.lineStyle(1,0xCC0000);
            
            
    curFace2=distArray2[i][1]; 
            
            
    shCubeRR.graphics.beginFill(facesColorsRR[curFace2],0.8);        
            
    shCubeRR.graphics.moveTo(dispArray2[facesArrayRR[curFace2][0]][0],dispArray2[facesArrayRR[curFace2][0]][1]);        
            
    shCubeRR.graphics.lineTo(dispArray2[facesArrayRR[curFace2][1]][0],dispArray2[facesArrayRR[curFace2][1]][1]);        
            
    shCubeRR.graphics.lineTo(dispArray2[facesArrayRR[curFace2][2]][0],dispArray2[facesArrayRR[curFace2][2]][1]);        
            
    shCubeRR.graphics.lineTo(dispArray2[facesArrayRR[curFace2][3]][0],dispArray2[facesArrayRR[curFace2][3]][1]);
            
    shCubeRR.graphics.lineTo(dispArray2[facesArrayRR[curFace2][0]][0],dispArray2[facesArrayRR[curFace2][0]][1]);
            
    shCubeRR.graphics.endFill();
            
        }
        
    }


    function 
    byDistRR(v:Array,w:Array):Number 
    {
        
        if (
    v[0]>w[0])
        {
            
            return -
    1;
            
          }
          else if (
    v[0]<w[0])
          {
            
            return 
    1;
        
           } 
           else 
           {
            
            return 
    0;
          }
          
      }


    function 
    pointNewViewRR(v:Array,theta:Number,phi:Number):Array
    {
        var 
    newCoords:Array=[];
        
    newCoords[0]=v[0]*Math.cos(theta)*Math.sin(phi)+v[1]*Math.sin(theta)*Math.sin(phi)+v[2]*Math.cos(phi);
        
    newCoords[1]=-v[0]*Math.sin(theta)+v[1]*Math.cos(theta);
        
    newCoords[2]=-v[0]*Math.cos(theta)*Math.cos(phi)-v[1]*Math.sin(theta)*Math.cos(phi)+v[2]*Math.sin(phi);
        return 
    newCoords;
    }



    //player 2 peace 4
    var vertsArrayTT:Array=[];

    var 
    facesArrayTT:Array=[];


    var 
    fLenTT:Number=2000;


    var 
    numVerticesTT:uint=8;

    var 
    numFacesTT:uint=6;



    var 
    spBoardTT:Sprite=new Sprite();

    this.addChild(spBoardTT);

    spBoardTT.x=reflectXTT;

    spBoardTT.y=reflectYTT;



    var 
    shBackTT:Shape=new Shape();

    spBoardTT.addChild(shBackTT);




    var 
    shCubeTT:Shape=new Shape();

    spBoardTT.addChild(shCubeTT);


    var 
    doRotateTT:Boolean=false;

    var 
    prevXTT:Number;

    var 
    prevYTT:Number;

    var 
    curThetaTT:Number=118;

    var 
    curPhTTI:Number=70;

    var 
    facesColorsTT:Array=[0xFFFFCC,0x00FF66,0x0066FF,0x33FFFF,0x9A7DDF,0xFFCCFF];


    setVerticesTT();

    setFacesTT();

    renderViewTT(curThetaTT,curPhTTI);



    function 
    setVerticesTT():void
    {
        
        
    vertsArrayTT[0]=[50,-50,50];
        
    vertsArrayTT[1]=[50,50,50];
        
    vertsArrayTT[2]=[-50,50,50];
        
    vertsArrayTT[3]=[-50,-50,50];
        
    vertsArrayTT[4]=[50,-50,-50];
        
    vertsArrayTT[5]=[50,50,-50];
        
    vertsArrayTT[6]=[-50,50,-50];
        
    vertsArrayTT[7]=[-50,-50,-50];
        
    }



    function 
    setFacesTT():void 
    {
        
        
    facesArrayTT[0]=[0,4,5,1];
        
    facesArrayTT[1]=[1,5,6,2];
        
    facesArrayTT[2]=[2,6,7,3];
        
    facesArrayTT[3]=[3,7,4,0];
        
    facesArrayTT[4]=[4,5,6,7];
        
    facesArrayTT[5]=[0,1,2,3];
        
    }



    function 
    renderViewTT(tt:Number,TT:Number):void
    {
        
        
    //We define local variables whose meaning will become clear below.
        
        
    var i:int;
        
        var 
    distArray2=[];
        
        var 
    dispArray2=[];
        
        var 
    vertsNewArray2=[];
        
        var 
    midPoint2:Array=[];

        var 
    dist:Number;
        
        var 
    curFace2:uint;
        
        
    //We convert t and p into radians.
        
        
    tt=tt*Math.PI/79;
        
        
    TT=TT*Math.PI/180;
        
        
    //We clear the previous view of the cube.
        
        
    shCubeTT.graphics.clear();
        
        for(
    i=0;i<numVerticesTT;i++)
        {
            
    vertsNewArray2[i]=pointNewViewTT(vertsArrayTT[i],tt,TT); 
        }
        
        
        
        for(
    i=0;i<numFacesTT;i++)
        {
            
    midPoint2[0]=(vertsNewArray2[facesArrayTT[i][0]][0]+vertsNewArray2[facesArrayTT[i][1]][0]+vertsNewArray2[facesArrayTT[i][2]][0]+vertsNewArray2[facesArrayTT[i][3]][0])/4;
            
    midPoint2[1]=(vertsNewArray2[facesArrayTT[i][0]][1]+vertsNewArray2[facesArrayTT[i][1]][1]+vertsNewArray2[facesArrayTT[i][2]][1]+vertsNewArray2[facesArrayTT[i][3]][1])/4;        
            
    midPoint2[2]=(vertsNewArray2[facesArrayTT[i][0]][2]+vertsNewArray2[facesArrayTT[i][1]][2]+vertsNewArray2[facesArrayTT[i][2]][2]+vertsNewArray2[facesArrayTT[i][3]][2])/4;
            
            
            
            
    dist=Math.sqrt(Math.pow(fLenTT-midPoint2[0],2)+Math.pow(midPoint2[1],2)+Math.pow(midPoint2[2],2));
            
    distArray2[i]=[dist,i];
        }
        
        
        
        
    distArray2.sort(byDistTT);

        for(
    i=0;i<numVerticesTT;i++)
        {        
            
    dispArray2[i]=[fLenTT/(fLenTT-vertsNewArray2[i][0])*vertsNewArray2[i][1],-fLenTT/(fLenTT-vertsNewArray2[i][0])*vertsNewArray2[i][2]];
        }
        
        for(
    i=0;i<numFacesTT;i++)
        {
            
            
            
    shCubeTT.graphics.lineStyle(1,0xCC0000);
            
            
    curFace2=distArray2[i][1]; 
            
            
    shCubeTT.graphics.beginFill(facesColorsTT[curFace2],0.8);
            
    shCubeTT.graphics.moveTo(dispArray2[facesArrayTT[curFace2][0]][0],dispArray2[facesArrayTT[curFace2][0]][1]);
            
    shCubeTT.graphics.lineTo(dispArray2[facesArrayTT[curFace2][1]][0],dispArray2[facesArrayTT[curFace2][1]][1]);
            
    shCubeTT.graphics.lineTo(dispArray2[facesArrayTT[curFace2][2]][0],dispArray2[facesArrayTT[curFace2][2]][1]);
            
    shCubeTT.graphics.lineTo(dispArray2[facesArrayTT[curFace2][3]][0],dispArray2[facesArrayTT[curFace2][3]][1]);    
            
    shCubeTT.graphics.lineTo(dispArray2[facesArrayTT[curFace2][0]][0],dispArray2[facesArrayTT[curFace2][0]][1]);
            
    shCubeTT.graphics.endFill();
            
        }
        
    }


    function 
    byDistTT(v:Array,w:Array):Number 
    {
        
        if (
    v[0]>w[0])
        {
            
            return -
    1;
            
          }
          else if (
    v[0]<w[0])
          {
            
            return 
    1;
        
           } 
           else 
           {
            
            return 
    0;
          }
          
      }


    function 
    pointNewViewTT(v:Array,theta:Number,phi:Number):Array
    {
        
        var 
    newCoords:Array=[];
        
    newCoords[0]=v[0]*Math.cos(theta)*Math.sin(phi)+v[1]*Math.sin(theta)*Math.sin(phi)+v[2]*Math.cos(phi);
        
    newCoords[1]=-v[0]*Math.sin(theta)+v[1]*Math.cos(theta);
        
    newCoords[2]=-v[0]*Math.cos(theta)*Math.cos(phi)-v[1]*Math.sin(theta)*Math.cos(phi)+v[2]*Math.sin(phi);
        return 
    newCoords;


  2. #2
    k i figer out what to try first i try find out how to link a drawn sprite to the linkage function then it can move i think

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012