2015年4月15日 星期三

02160040_周子伍,Week08

今天老師教的是做出一種射擊遊戲
以一種全螢幕的方式讓物體滑動,設定點擊範圍,由點擊滑鼠鎖定滑動目標來發出聲音效果!!


#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.01;
    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)
{
    if(state==GLUT_DOWN){
        PlaySound("Data/Shot", NULL, SND_ASYNC);
        printf("shot!!!\n");
    }
}
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    glutCreateWindow("02160040");
    glutFullScreen();
    glutDisplayFunc(display);
    glutIdleFunc(display);
    glutKeyboardFunc(keyboard);
    glutMouseFunc(mouse);
    glutMainLoop();
}

沒有留言:

張貼留言