全螢幕+射擊聲
#include <stdio.h>
#include <GL/glut.h>
#include <mmsystem.h>
void display(){
glClearColor(0.5,0.5,1,0);
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
void keyboard(unsigned char key, int x, int y){
exit(0);
}
void mouse(int button, int state, int x, int y){ //,mouseFUC
if(state==GLUT_DOWN){
PlaySound("Data/Shot.wav",NULL,SND_ASYNC); //音訊位置
printf("Shot!!!\n");
}
}
int main(int argc, char**argv){
glutInit(&argc, argv);
glutCreateWindow("hellow");
glutFullScreen(); //全螢幕
glutDisplayFunc(display); //引入
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMainLoop();
}
#include <stdio.h>
#include <GL/glut.h>
#include <mmsystem.h>
float potX=-1, potY=0;
void display(){
glClearColor(0.5,0.5,1,0);
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix();
glTranslatef(potX, potY, 0); //瓶子
glutSolidTeapot(0.05);
glPopMatrix();
glFlush();
potX+=0.001;
if(potX>1.1) potX=-1.1;
}
void keyboard(unsigned char key, int x, int y){
exit(0);
}
void mouse(int button, int state, int x, int y){ //,mouseFUC
if(state==GLUT_DOWN){
PlaySound("Data/Shot.wav",NULL,SND_ASYNC); //音訊位置
printf("Shot!!!\n");
float mouseX=2*x/1280.0-1, mouseY=-(2*y/1024.0 -1);
if(abs(mouseX-potX)<0.001 &&abs(mouseY-potY)<0.001){ //範圍
printf("YA! Got it\n");
PlaySound("Data/potbrk.wav",NULL,SND_ASYNC);
}
}
}
int main(int argc, char**argv){
glutInit(&argc, argv);
glutCreateWindow("hellow");
glutFullScreen(); //全螢幕
glutDisplayFunc(display); //引入
glutIdleFunc(display);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMainLoop();
}
沒有留言:
張貼留言