void restore() /****恢复屏幕到主菜单****/ { int i; cleardevice(); putimage(0,0,logo,COPY_PUT); for (i=0;i<STARNUM;i++) drawstar(star); outchinese(400,80,s_cn,EOF,4,0); drawmenu(mm); drawmouse(mousex,mousey); if (Music_on) play(2); else noplay(); }
void kbd(unsigned char key, int x, int y) { if(key == 'q' || key == 'Q') { exit(0); //quite the program } //if the "q" key is pressed, quit the program if(key == 'z') { // pos -= 1; eye[1] -= 2.0; //point[1]-=cameraspeed; } if(key == 'x') { // pos += 1; eye[1] +=2.0; //point[1]+=cameraspeed; } if(key =='l' || key =='L'){ if (lightOn == true) { glEnable(GL_LIGHTING); lightOn = false; } else if(lightOn == false) { glDisable(GL_LIGHTING); lightOn = true; } } if(key =='1' || key =='1'){ glPushMatrix(); glTranslatef(0, 0, 0); glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'G'); glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'A'); glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'M'); glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'E'); glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,' '); glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'O'); glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'V'); glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'E'); glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18,'R'); glPopMatrix(); } if(key =='2' || key =='2'){ drawstar(); drawRocks(); } if (key == 'w' || key == 'W') { planepos[1] = planepos[1]+25; } if (key == 's' || key == 'S') { planepos[1] = planepos[1]-25; } if (key == 'a' || key == 'A') { planepos[0] = planepos[0]-25; } if (key == 'd' || key == 'D') { planepos[0] = planepos[0]+25; } }
void display() { /*---------------------------------------Lighting ------------------------------------------------*/ typedef struct materialStruct { float ambient[4]; float diffuse[4]; float specular[4]; float emission[4]; float m_amb[4]; float m_diff[4]; float m_spec[4] ; float shininess; } materialStruct; materialStruct redPlastic = { {0.0, 0.0, 0.3, 1.0}, {0.0, 0.4, 0.1, 1.0}, {0.6, 0.6, 0.8, 1.0}, {0.0, 0.0, 0.0, 0.0}, {0.03, 0.22, 0.03, 1.0}, {0.18, 0.77, 0.1, 1.0}, {0.10, 0.41, 0.29, 1.0}, 50.0 }; // glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glLightfv(GL_LIGHT0, GL_POSITION, light_pos); //First light point glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLightfv(GL_LIGHT0, GL_AMBIENT, redPlastic.ambient); glLightfv(GL_LIGHT0, GL_DIFFUSE, redPlastic.diffuse); glLightfv(GL_LIGHT0, GL_SPECULAR, redPlastic.specular); glEnable(GL_LIGHT1); glLightfv(GL_LIGHT1, GL_POSITION, light_pos1); //Second Light point glLightfv(GL_LIGHT1, GL_AMBIENT, redPlastic.ambient); glLightfv(GL_LIGHT1, GL_DIFFUSE, redPlastic.diffuse); glLightfv(GL_LIGHT1, GL_SPECULAR, redPlastic.specular); typedef struct materialStruct2 { float ambient[4]; float diffuse[4]; float specular[4]; float emission[4]; float m_amb[4]; float m_diff[4]; float m_spec[4] ; float shininess; } materialStruct2; materialStruct2 redPlastic2 = { {0.0, 0.0, 0.3, 1.0}, {0.6, 0.1, 0.1, 1.0}, {0.6, 0.6, 0.8, 1.0}, {0.0, 0.0, 0.0, 0.0}, {0.03, 0.02, 0.33, 1.0}, {0.78, 0.17, 0.21, 1.0}, {0.30, 0.11, 0.19, 1.0}, 50.0 }; glEnable(GL_LIGHT2); glLightfv(GL_LIGHT2, GL_POSITION, light_pos2); //Third Light point glLightfv(GL_LIGHT2, GL_AMBIENT, redPlastic2.ambient); glLightfv(GL_LIGHT2, GL_DIFFUSE, redPlastic2.diffuse); glLightfv(GL_LIGHT2, GL_SPECULAR, redPlastic2.specular); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, redPlastic2.ambient); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, redPlastic2.diffuse); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, redPlastic2.specular); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, redPlastic2.shininess); //clear the screen glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode (GL_MODELVIEW); glLoadIdentity(); if (deltaMove) computePos(deltaMove); if (deltaAngle) computeDir(deltaAngle); //gluLookAt(0, 30, 70, 0, 0, 0, 0, 1, 0); gluLookAt(eye[0],eye[1],eye[2],eye[0]+point[0],eye[1],eye[2]+point[2],0,1,0); camerapos [0] = eye[0]; camerapos[2] = eye[2]; //optionally draw the axis //glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, "SPACE Helicopter PRO"); //drawAxis(); drawstar(); drawRocks(); glPushMatrix(); /*---------------------------------------Solar system-----------------------------------------*/ //Venus glRotatef(ang/200, 0, 1, 1); glTranslatef(100, 0, 0); glColor3f(1, 0, 0); glScalef(2, 2, 2); drawsphere(); glPopMatrix(); glPushMatrix(); //Earth glRotatef(ang/250, 0, 1, 1); glTranslatef(150, 0, 0); glColor3f(0, 0, 1); glScalef(3, 3, 3); drawsphere(); //moon glRotatef(ang/80, 0, 1, 1); glTranslatef(75, 0, 0); glColor3f(1, .5, .5); glScalef(1, 1, 1); drawsphere(); glPopMatrix(); glPushMatrix(); //Mars glRotatef(ang/500, 0, 1, 0); glTranslatef(200, 0, 0); glColor3f(1, 0, 0); glScalef(5, 5, 5); drawsphere(); glRotatef(ang/800, 0, 1, 1); glTranslatef(-500, 0, 0); glColor3f(.5, .5, .5); glScalef(3, 3, 3); drawsphere(); glPopMatrix(); glRotatef(ang/800, 0, 1, 1); glTranslatef(500, 0, 0); glColor3f(.5, .5, .5); glScalef(3, 3, 3); drawsphere(); glRotatef(ang/550, 0, 1, 1); glTranslatef(-200, 0, 0); //glRotatef(ang, 0, 1, 0); glScalef(5, 5, 5); glPopMatrix(); glPopMatrix(); glPopMatrix(); /*---------------------------------------Draw Light Source-----------------------------------------*/ glPushMatrix(); glTranslated(light_pos2[0], light_pos2[1], light_pos2[2]); glColor3f(1, 1, 0); glPopMatrix(); glutSwapBuffers(); glutPostRedisplay(); }
void beforegame() /******游戏主界面*******/ { int i,j; fire(); ShowBmp256(70,65,".\\source\\login.bmp",1,0); InitGraph(); star=malloc(sizeof(struct STAR)*STARNUM); initstar(star); InitMouse(0,0,maxx,maxy); getdat(); handler=getvect(0x1c); mousex=getmaxx()/2; mousey=getmaxy()/2; logo=bmp_to_dat(".\\source\\snooker.bmp"); vs1=bmp_to_dat(".\\source\\head0.bmp"); vs2=bmp_to_dat(".\\source\\head1.bmp"); play(1); for (i=0;i<3;i++) { putimage(0,0,logo,NOT_PUT); for (j=20;j<=1000;j+=10) { delay(1000); } delay(3000); putimage(0,0,logo,COPY_PUT); for (j=1000;j>=20;j-=10) { delay(2000); } delay(3000); } putimage(0,0,logo,COPY_PUT); for (i=0;i<STARNUM;i++) drawstar(star); outchinese(400,80,s_cn,EOF,4,2); putimage(300,280,vs1,COPY_PUT); putimage(520,280,vs2,COPY_PUT); settextstyle(1,0,12); setcolor(GREEN); outtextxy(380,260,"Vs"); drawmouse(mousex,mousey); play(2); drawmenu(mm); while(1) { while(bioskey(1)!=0) getch(); position(1); mm=fill(); drawmouse(mousex,mousey); if (button==1) { switch (mm) { case 0: { free(logo); free(star); cleardevice(); return; } case 1: { practice(); restore(); break; } case 2: { noplay(); option(); break; } case 3: { noplay(); toprank(); restore(); break; } case 4: { if (Music_on==1) play(0); showhelp(); break; } case 5: { position(0); End(1); drawmouse(mousex,mousey); break; } } } button=0; } }