1.模擬考,期中考
2.用範例學習
3. NeHe Lesson 32 小遊戲
#include <GL/glut.h>
#include <mmsystem.h>
#include <stdio.h>
void mouse (int button, int state, int x, int y)
{
if(state==GLUT_DOWN)
{
PlaySound("Shot.wav",NULL, SND_ASYNC);
printf("Shot!\n");
}
}
void keyboard(unsigned char key, int x, int y)
{
exit(0);
}
void display()
{
glClearColor(0.5, 0.5, 1, 0);
glClear(GL_COLOR_BUFFER_BIT);
glFlush();
}
int main (int argc, char**argv)
{
glutInit(&argc, argv);
glutCreateWindow("HI~");
glutFullScreen();
glutDisplayFunc(display);
glutKeyboardFunc(keyboard);
glutMouseFunc(mouse);
glutMainLoop();
}
打中有另一個聲音 ( 能判斷有沒有打中) (另外加幾行程式)
#include <math.h>
float potX=-1, potY=0;
void mouse (int button, int state, int x, int y)
{
if(state==GLUT_DOWN)
{
PlaySound("Shot.wav",NULL, SND_ASYNC);
printf("Shot!\n");
float mouseX=2*x/1280.0 -1, mouseY=2*y/1024.0 -1;
if( fabs(mouseX-potX)<0.1 && fabs(mouseY-potY)<0.1)
{
PlaySound("BOTTLE.wav",NULL, SND_ASYNC);
printf("Your got it!\n");
}
}
沒有留言:
張貼留言