2015年4月15日 星期三

2015/4/15 week8 課堂作業 黃志楷



目標:試玩遊戲



目標:點擊物件會有聲響



#include<GL/glut.h>///宣告
#include<stdio.h>///宣告
#include<mmsystem.h>///宣告
float px=-1,py=0;
void display()///函式
{
    glClear(GL_COLOR_BUFFER_BIT);
    glPushMatrix();
        glTranslatef(px,py,0);
        glutSolidTeapot(0.03);
    glPopMatrix();
    glFlush();
    px+=0.0001;
    if(px>1.1)px=-1.1;
}
void keyboard(unsigned char key,int x,int y)
{
    exit(0);
}
void mouse(int button,int state,int x,int y)
{
    if(state==GLUT_DOWN)
    PlaySound("Data/Shot.wav",NULL,SND_ASYNC);
        printf("go");
        float mx=5*x/1280.0-1,my=-(3*y/1024.0-1);
        if(abs(mx-px)<0.01 && abs(my-py)<0.01)
        {
            PlaySound("wolf.wav",NULL,SND_ASYNC);
        }
}
int main(int argc,char *argv[])
{
    glutInit(&argc,argv);
    glutCreateWindow("02160421");
    glutIdleFunc(display);
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    glutMouseFunc(mouse);
    glutMainLoop();
}


沒有留言:

張貼留言