GLProgramming.com

home :: about :: development guides :: irc :: forums :: search :: paste :: links :: contribute :: code dump

-> Click here to learn how to get live help <-


New Paste :: Recent Pastes:: No Line Numbers


tetris problem by ashmawy
1
 
void myDisplay()
{
    //printf("%s", reachedFloor ? "true" : "false");
    if(dropedItemY==endItemDown)
    {
        reachedFloor=true;
        printf("here");
    }

    if(reachedFloor)
    {
        item = rand()%7;
        dropedItemY=SIZE_OF_Y;
        dropedItemX=0;
        switch(item)
        {
            case 0: //I
                endItemDown=-SIZE_OF_Y;
                endItemLeft=-SIZE_OF_X;
                endItemRight=SIZE_OF_X-(3*SIZE_OF_SQUARE);
                break;
            case 1: //T
                endItemDown=-SIZE_OF_Y+(SIZE_OF_SQUARE);
                endItemLeft=-SIZE_OF_X;
                endItemRight=SIZE_OF_X-(2*SIZE_OF_SQUARE);
                break;
            case 2: //O
                endItemDown=-SIZE_OF_Y+SIZE_OF_SQUARE;
                endItemLeft=-SIZE_OF_X;
                endItemRight=SIZE_OF_X-(2*SIZE_OF_SQUARE);
                break;
            case 3: //L
                endItemDown=-SIZE_OF_Y+(SIZE_OF_SQUARE);
                endItemLeft=-SIZE_OF_X;
                endItemRight=SIZE_OF_X-(2*SIZE_OF_SQUARE);
                break;
            case 4: //J
                endItemDown=-SIZE_OF_Y+(SIZE_OF_SQUARE);
                endItemLeft=-SIZE_OF_X;
                endItemRight=SIZE_OF_X-(2*SIZE_OF_SQUARE);
                break;
            case 5: //S
                endItemDown=-SIZE_OF_Y+(2*SIZE_OF_SQUARE);
                endItemLeft=-SIZE_OF_X;
                endItemRight=SIZE_OF_X-(2*SIZE_OF_SQUARE);
                break;
            case 6: //Z
                endItemDown=-SIZE_OF_Y+(SIZE_OF_SQUARE);
                endItemLeft=-SIZE_OF_X;
                endItemRight=SIZE_OF_X-(2*SIZE_OF_SQUARE);
                break;
        }
        reachedFloor=false;
    }
    if(!reachedFloor)
    {
        glMatrixMode(GL_PROJECTION); 
        glLoadIdentity(); 
        gluOrtho2D(-SIZE_OF_X,SIZE_OF_X,-SIZE_OF_Y,SIZE_OF_Y); 
        glutTimerFunc(10,myTimer, 1); 
        dropedItemY--;
    }

    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();
    if(item==0)
        DrawI(dropedItemX,dropedItemY);
    else if(item==1)
        DrawT(dropedItemX,dropedItemY);
    else if(item==2)
        DrawO(dropedItemX,dropedItemY);
    else if(item==3)
        DrawL(dropedItemX,dropedItemY);
    else if(item==4)
        DrawJ(dropedItemX,dropedItemY);
    else if(item==5)
        DrawS(dropedItemX,dropedItemY);
    else if(item==6)
        DrawZ(dropedItemX,dropedItemY);

    glPopMatrix();

    glFlush();
    
}