void drawScene() { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); GLfloat ambientColor[] = {0.8f, 1.0f, 0.8f, 1.0f}; //Color (0.2, 0.2, 0.2) glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientColor); //Add directed light //GLfloat lightColor0[] = {1.0f, 1.0f, 1.0f, 1.0f}; //Color (0.5, 0.2, 0.2) //Coming from the direction (-1, 0.5, 0.5) //GLfloat lightPos0[] = {-5.0f, 10.0f, -5.0f, 0.0f}; //glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor0); //glLightfv(GL_LIGHT0, GL_POSITION, lightPos0); p.drawPerson(); // p1.drawPerson(); glTranslatef(-4*1.5, 0.0, 4*1.5); //******** printf("man coordinates %f %f\n******************\n",(p.manx+14)*0.4,(p.manz-14)*0.4); int x,block=0; for(float j=10.0;j>(-15*1.5);j-=1.5) { for(i=-width_screen/2;i<width_screen/2;i+=1.5) { glPushMatrix(); glTranslatef(i,-1.0,j); f.draw_BlackArea(); glPopMatrix(); } } /************** DRAW WALL **************/ for(float j=0.0;j>(-8*1.5);j-=1.5) { k++; for(i=0.0;i<(4*3.0);i+=3.0) { block++; if(block==tile_rise[0] || block==tile_rise[1] || block==tile_rise[2] || block==tile_rise[3]) { tile_height=backup; if(tile_height<1 && tile_up) tile_up=1; else tile_up=0; } for( x=0;x<holes;x++) { if(holeslist[x]==block) { break; } } /******************* MAKE GIFTS **************************/ if((p.manx+14)*0.4 >= g.x-0.5 &&(p.manx+14)*0.4 <= g.x+0.5 && (p.manz-14)*0.4>=g.z-0.5 && (p.manz-14)*0.4<=g.z+0.5) { gift_count++; g.set_gift_coord(); g.make_gift(); } else { g.make_gift(); } /************ WALL DETECTION **************/ if((p.manx+14)*0.4 < 0 && !((p.manz-14)*0.4<=-3 && (p.manz-14)*0.4>=-4.5) && !((p.manz-14)*0.4<=-9 && (p.manz-14)*0.4>=-10.5) ) { p.manx+=0.05; // p.fall=1; } else if((p.manx+14)*0.4 < 0) p.fall=1; if((p.manx+14)*0.4>11 && !((p.manz-14)*0.4<=-3 && (p.manz-14)*0.4>=-4.5) && !((p.manz-14)*0.4<=-9 && (p.manz-14)*0.4>=-10.5) ) { p.manx-=0.05; } else if((p.manx+14)*0.4>11 ) p.fall=1; if((p.manz-14)*0.4 >0 && !((p.manx+14)*0.4>=3 && (p.manx+14)*0.4<=4.5) && !((p.manx+14)*0.4>=9 && (p.manx+14)*0.4<=10.5)) { p.manz-=0.05; // p.fall=1; } else if((p.manz-14)*0.4 >0 ) p.fall=1; if((p.manz-14)*0.4 < -11 && !((p.manx+14)*0.4>=3 && (p.manx+14)*0.4<=4.5) && !((p.manx+14)*0.4>=9 && (p.manx+14)*0.4<=10.5)) { p.manz+=0.05; // p.fall=1; } else if((p.manz-14)*0.4 < -11 ) p.fall=1; /****************** MIDDLE WALL DETECTION ********************/ if((p.manx+14)*0.4<=6.5 && (p.manx+14)*0.4>=5 && ((int)p.mrotate/90)%4==1 && !((p.manz-14)*0.4<=-3 && (p.manz-14)*0.4>=-4.5) && !((p.manz-14)*0.4<=-9 && (p.manz-14)*0.4>=-10.5)) p.manx-=0.05; if((p.manz-14)*0.4>=-6.5 && (p.manz-14)*0.4<=-5 && ((int)p.mrotate/90)%4==2 && !((p.manx+14)*0.4>=3 && (p.manx+14)*0.4<=4.5) && !((p.manx+14)*0.4>=9 && (p.manx+14)*0.4<=10.5)) p.manz+=0.05; if((p.manx+14)*0.4<=6.5 && (p.manx+14)*0.4>=5 && ((int)p.mrotate/90)%4==3 && !((p.manz-14)*0.4<=-3 && (p.manz-14)*0.4>=-4.5) && !((p.manz-14)*0.4<=-9 && (p.manz-14)*0.4>=-10.5)) p.manx+=0.05; if((p.manz-14)*0.4>=-6.5 && (p.manz-14)*0.4<=-5 && ((int)p.mrotate/90)%4==0 && !((p.manx+14)*0.4>=3 && (p.manx+14)*0.4<=4.5) && !((p.manx+14)*0.4>=9 && (p.manx+14)*0.4<=10.5)) p.manz-=0.05; /************ HOLES DETECTION **************/ if(x<holes && k%2==0) { if((p.manx+14)*0.4>i-0.5 && (p.manx+14)*0.4< i+1.5 && (p.manz-14)*0.4>j-1.5 && (p.manz-14)*0.4<j+0.5 && p.jump!=1) { // printf("p.fall\n"); p.fall=1; } } else if(x<holes && k%2!=0) { if((p.manx + 14)*0.4>i+1.5-0.5 && (p.manx+14)*0.4 < i+3 && (p.manz-14)*0.4>j-1.5 && (p.manz-14)*0.4<j+0.5 && p.jump!=1) { p.fall=1; } } /************ BLOCK DETECTION ********************/ if(tile_height>0.1 && k%2==0) { if((p.manx + 14)*0.4>i-0.5 && (p.manx+14)*0.4 < i+1.5 && (p.manz-14)*0.4>j-1.5 && (p.manz-14)*0.4<j+0.5) { if(((int)p.mrotate/90)%4==1 ) p.manx-=0.55; if(((int)p.mrotate/90)%4==2 ) p.manz+=0.55; if(((int)p.mrotate/90)%4==3 ) p.manx+=0.55; if(((int)p.mrotate/90)%4==0 ) p.manz-=0.55; } } /*********************** DETECT COLLISION WITH BLOCKS **********************/ if(tile_height>0.1 && k%2!=0) { if((p.manx + 14)*0.4>i+1.5-0.5 && (p.manx+14)*0.4 < i+3 && (p.manz-14)*0.4>j-1.5 && (p.manz-14)*0.4<j+0.5) { if(((int)p.mrotate/90)%4==1 ) p.manx-=0.55; if(((int)p.mrotate/90)%4==2 ) p.manz+=0.55; if(((int)p.mrotate/90)%4==3 ) p.manx+=0.55; if(((int)p.mrotate/90)%4==0 ) p.manz-=0.55; } } if(k%2==0 && x>=holes) { glPushMatrix(); glTranslatef(i,0.0,j); r.draw_BlackArea(); glPopMatrix(); } else if(x>=holes) { glPushMatrix(); glTranslatef(i+1.5,0.0,j); r.draw_BlackArea(); glPopMatrix(); } tile_height=0; } } for(float j=0.0;j>(-8*1.5);j-=1.5) { k++; for(i=0.0;i<(4*3.0);i+=3.0) { block++; if(block==tile_rise[0] || block==tile_rise[1] || block==tile_rise[2] || block==tile_rise[3]) { tile_height=backup; if(tile_height<1 && tile_up) tile_up=1; else tile_up=0; } for( x=0;x<holes;x++) if(holeslist[x]==block) break; /********** HOLES DETECTION *************/ if(x<holes && k%2!=0) { if((p.manx +14)*0.4 >i-0.5 && (p.manx +14)*0.4 < i+1.5 && (p.manz-14)*0.4>j-1.5 && (p.manz-14)*0.4<j+0.5 && p.jump!=1) { p.fall=1; } } else if(x<holes && k%2==0) { if((p.manx +14)*0.4 >i+1.5-0.5 && (p.manx +14)*0.4 < i+3 && (p.manz-14)*0.4>j-1.5 && (p.manz-14)*0.4<j+0.5 && p.jump!=1) { // printf("p.fall\n"); p.fall=1; } } /************ BLOCK DETECTION ********************/ if(tile_height>0.1 && k%2!=0) { if((p.manx + 14)*0.4>i-0.5 && (p.manx+14)*0.4 < i+1.5 && (p.manz-14)*0.4>j-1.5 && (p.manz-14)*0.4<j+0.5) { if(((int)p.mrotate/90)%4==1 ) p.manx-=0.55; if(((int)p.mrotate/90)%4==2 ) p.manz+=0.55; if(((int)p.mrotate/90)%4==3 ) p.manx+=0.55; if(((int)p.mrotate/90)%4==0 ) p.manz-=0.55; } } if(tile_height>0.1 && k%2==0) { if((p.manx + 14)*0.4>i+1.5-0.5 && (p.manx+14)*0.4 < i+3 && (p.manz-14)*0.4>j-1.5 && (p.manz-14)*0.4<j+0.5) { if(((int)p.mrotate/90)%4==1 ) p.manx-=0.55; if(((int)p.mrotate/90)%4==2 ) p.manz+=0.55; if(((int)p.mrotate/90)%4==3 ) p.manx+=0.55; if(((int)p.mrotate/90)%4==0 ) p.manz-=0.55; } } if(k%2!=0 && x>=holes) { glPushMatrix(); glTranslatef(i,0.0,j); r.draw_whiteArea(); glPopMatrix(); } else if(x>=holes) { glPushMatrix(); glTranslatef(i+1.5,0.0,j); r.draw_whiteArea(); glPopMatrix(); } tile_height=0; } } tile_rise_count=0; r.construct_four_walls();//constructing wall around room glutSwapBuffers(); }
void drawScene() { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_LIGHT1); glEnable(GL_NORMALIZE); /* GLuint texture = LoadGLTexture("water.bmp", 396, 734); glEnable(GL_TEXTURE_2D); glBindTexture( GL_TEXTURE_2D, texture );*/ //Add ambient light /* GLfloat ambientColor[] = {0.2f, 0.2f, 0.2f, 1.0f}; //Color(0.2, 0.2, 0.2) glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientColor); //Add positioned light GLfloat lightColor0[] = {0.5f, 0.5f, 0.5f, 1.0f}; //Color (0.5, 0.5, 0.5) GLfloat lightPos0[] = {4.0f, 0.0f, 8.0f, 1.0f}; //Positioned at (4, 0, 8) glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor0); glLightfv(GL_LIGHT0, GL_POSITION, lightPos0); //Add directed light GLfloat lightColor1[] = {0.5f, 0.2f, 0.2f, 1.0f}; //Color (0.5, 0.2, 0.2) //Coming from the direction (-1, 0.5, 0.5) GLfloat lightPos1[] = {-1.0f, 0.5f, 0.5f, 0.0f}; glLightfv(GL_LIGHT1, GL_DIFFUSE, lightColor1); glLightfv(GL_LIGHT1, GL_POSITION, lightPos1);*/ glRotatef(-0.0, 0.0f, 1.0f, 0.0f); glTranslatef(-4*1.5, 0.0, 4*1.5); //int gifts_x1 = -1, gifts_x2 = -1, gifts_z1 = -1, gifts_z2 = -1; int g=0,h=0,gg=-1,hh=-2,fl1=0,fl2=0,kk=0; int tile_x1=-1,tile_z1=-1; int tile_x2=-1,tile_z2=-1,c*k = 0; int obs_x1=-1,obs_z1=-1,obs_x2=-1,obs_z2=-1; //int gifts_x1=-1,gifts_z1=-1,gifts_x2=-1,gifts_z2=-1; p1.drawtree(-40.0,0.0,-40.0); p1.drawtree(-30.0,0.0,-40.0); p1.drawtree(-20.0,0.0,-40.0); p1.drawtree(-10.0,0.0,-40.0); p1.drawtree(0.0,0.0,-40.0); p1.drawtree(10.0,0.0,-40.0); p1.drawtree(20.0,0.0,-40.0); p1.drawtree(30.0,0.0,-40.0); p1.drawtree(40.0,0.0,-40.0); p1.drawtree(0.0,0.0,0.0); p1.drawtree(12.0,0.0,0.0); glPushMatrix(); glTranslatef(-50*1.5, 0.0, 50*1.5); //change = 10.0f; for(float j=0.0;j>(-100*1.5);j-=1.5) { k++; for(i=0.0;i<(50*3.0);i+=3.0) { glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, x); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_NEAREST); if(k%2==0) { glPushMatrix(); glTranslatef(i,-1.0,j); p1.draw_BlackArea(); //Add commands for drawing a black area to the display list // glCallList(_displayListId_blackArea); glPopMatrix(); } else { glPushMatrix(); glTranslatef(i+1.5,-1.0,j); p1.draw_BlackArea(); //Add commands for drawing a black area to the display list // glCallList(_displayListId_blackArea); glPopMatrix(); } glDisable(GL_TEXTURE_2D); } } for(float j=0.0;j>(-100*1.5);j-=1.5) { k++; for(i=0.0;i<(50*3.0);i+=3.0) { glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, x); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_NEAREST); if(k%2!=0) { glPushMatrix(); glTranslatef(i,-1.0,j); p1.draw_whiteArea(); //Add commands for drawing a black to the display list // glCallList(_displayListId_whiteArea); glPopMatrix(); } else { glPushMatrix(); glTranslatef(i+1.5,-1.0,j); p1.draw_whiteArea(); //Add commands for drawing a black to the display list // glCallList(_displayListId_whiteArea); glPopMatrix(); } glDisable(GL_TEXTURE_2D); } } glPopMatrix(); k=0; change = 1.0; if(mode == 2) { for(float j=0.0;j>(-8*1.5);j-=1.5) { k++;kk++; if(kk%2==0) { fl1 = 1; } if(kk%2==1 && kk>1) c*k =1; for(i=0.0;i<(4*3.0);i+=3.0) { g++; if(fl1 == 1) { fl1=0; gg = gg + 1; } else if(c*k == 1) { c*k = 0; gg = gg +3; } else gg = gg + 2; //if(call_randb == g) //{ tile_x1 = gg%8; tile_z1 = gg/8; //} //else{ if((tile_x1 == sx && tile_z1 == sz && gir == 1) || (sx < 0) || (sx > 7) || (sz < 0) || (sz > 7)) { flag_exit = 1; } else{ glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, grassTextureId); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); if(k%2==0) { if(obs_b == g) { obs_x1=gg%8; obs_z1=gg/8; p1.obstacle(i,j); } glPushMatrix(); glTranslatef(i,0.0,j); glCallList(_displayListId_blackArea); glPopMatrix(); } else { if(obs_b == g) { obs_x1=gg%8; obs_z1=gg/8; p1.obstacle(i+1.5,j); } glPushMatrix(); glTranslatef(i+1.5,0.0,j); glCallList(_displayListId_blackArea); glPopMatrix(); } } //} } } kk=0;int dnt = 0; for(float j=0.0;j>(-8*1.5);j-=1.5) { k++;kk++; if(kk%2==1 && kk>1) { fl2 = 1; } if(kk%2==0) dnt =1; for(i=0.0;i<(4*3.0);i+=3.0) { h++; if(fl2 == 1) { fl2=0; hh = hh + 1; } else if(dnt ==1) { dnt =0; hh = hh +3; } else hh = hh +2; //if(call_randw == h) //{ tile_x2 = hh%8; tile_z2 = hh/8; //} //else{ if( (tile_x2 == sx && tile_z2 == sz && gir == 1) || (sx < 0) || (sx > 7) || (sz < 0) || (sz > 7)) { flag_exit = 1; } else{ glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, grassTextureId); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); if(k%2!=0) { if(obs_w == h) { obs_x2=hh%8; obs_z2=hh/8; p1.obstacle(i,j); } glPushMatrix(); glTranslatef(i,0.0,j); glCallList(_displayListId_whiteArea); glPopMatrix(); } else { if(obs_w == h) { obs_x2=hh%8; obs_z2=hh/8; p1.obstacle(i+1.5,j); } glPushMatrix(); glTranslatef(i+1.5,0.0,j); glCallList(_displayListId_whiteArea); glPopMatrix(); } } //} } } } if(mode == 1) { for(float j=0.0;j>(-8*1.5);j-=1.5) { k++;kk++; if(kk%2==0) { fl1 = 1; // printf("-------------in----------\n"); } if(kk%2==1 && kk>1) c*k =1; for(i=0.0;i<(4*3.0);i+=3.0) { g++; if(fl1 == 1) { fl1=0; gg = gg + 1; } else if(c*k == 1) { c*k = 0; gg = gg +3; } else gg = gg + 2; // printf("gg: %d\n", gg); if(call_randb == g) { // printf("------------------GG is %d\n",gg); tile_x1 = gg%8; tile_z1 = gg/8; } else{ glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, grassTextureId); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // tile_x1 = gg%8; // tile_z1 = gg/8; if(k%2==0) { if(obs_b == g) { obs_x1=gg%8; obs_z1=gg/8; p1.obstacle(i,j); } /* if(gift_b == g) { gifts_x1=gg%8; gifts_z1=gg/8; p1.gifts(i,j); }*/ glPushMatrix(); glTranslatef(i,0.0,j); glCallList(_displayListId_blackArea); glPopMatrix(); } else { if(obs_b == g) { obs_x1=gg%8; obs_z1=gg/8; p1.obstacle(i+1.5,j); } /*if(gift_b == g) { gifts_x1=gg%8; gifts_z1=gg/8; p1.gifts(i+1.5,j); }*/ glPushMatrix(); glTranslatef(i+1.5,0.0,j); glCallList(_displayListId_blackArea); glPopMatrix(); } } } } kk=0;int dnt = 0; for(float j=0.0;j>(-8*1.5);j-=1.5) { k++;kk++; if(kk%2==1 && kk>1) { fl2 = 1; // printf("---------------in----------------\n"); } if(kk%2==0) dnt =1; for(i=0.0;i<(4*3.0);i+=3.0) { h++; if(fl2 == 1) { fl2=0; hh = hh + 1; } else if(dnt ==1) { dnt =0; hh = hh +3; } else hh = hh +2; // printf("hh:%d\n",hh); if(call_randw == h) { // printf("------------------HH is %d\n",hh); tile_x2 = hh%8; tile_z2 = hh/8; } else{ glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, grassTextureId); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // tile_x2 = hh%8; // tile_z2 = hh/8; if(k%2!=0) { if(obs_w == h) { obs_x2=hh%8; obs_z2=hh/8; p1.obstacle(i,j); } /*if(gift_w == h) { gifts_x2=hh%8; gifts_z2=hh/8; p1.gifts(i,j); }*/ glPushMatrix(); glTranslatef(i,0.0,j); glCallList(_displayListId_whiteArea); glPopMatrix(); } else { if(obs_w == h) { obs_x2=hh%8; obs_z2=hh/8; p1.obstacle(i+1.5,j); } /*if(gift_w == h) { gifts_x2=hh%8; gifts_z2=hh/8; p1.gifts(i+1.5,j); }*/ glPushMatrix(); glTranslatef(i+1.5,0.0,j); glCallList(_displayListId_whiteArea); glPopMatrix(); } } } } } else if(mode == 0) { for(float j=0.0;j>(-8*1.5);j-=1.5) { k++; for(i=0.0;i<(4*3.0);i+=3.0) { glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, grassTextureId); //Bottom glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); if(k%2==0) { glPushMatrix(); glTranslatef(i,0.0,j); glCallList(_displayListId_blackArea); glPopMatrix(); } else { glPushMatrix(); glTranslatef(i+1.5,0.0,j); glCallList(_displayListId_blackArea); glPopMatrix(); } } } for(float j=0.0;j>(-8*1.5);j-=1.5) { k++; for(i=0.0;i<(4*3.0);i+=3.0) { glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, grassTextureId); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); if(k%2!=0) { glPushMatrix(); glTranslatef(i,0.0,j); glCallList(_displayListId_whiteArea); glPopMatrix(); } else { glPushMatrix(); glTranslatef(i+1.5,0.0,j); glCallList(_displayListId_whiteArea); glPopMatrix(); } } } } if(mode == 0 || mode ==1) { if((tile_x1 == sx && tile_z1 == sz) ||( tile_x2 == sx && tile_z2 == sz) || (sx < 0) || (sx > 7) || (sz < 0) || (sz > 7)) { flag_exit = 1; } if((sx == obs_x1 && sz == obs_z1) || (sx == obs_x2 && sz == obs_z2)) { printf("You are DEAD !!!\nLOL!!!!!\n"); exit(0); } } glPushMatrix(); glTranslatef(0.0f, 0.0f, -5.0f); // Push eveything 5 units back into the scene, otherwise we won't see the primitive gluLookAt (0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); p1.drawPerson(); //p1.obstacle(); //p1.gifts(1,1); glPopMatrix(); glutSwapBuffers(); angle++; }