一、玩遊戲(射擊)
1.點滑鼠有槍聲
首先要打
#include <mmsystem.h>
匯入mmsystem.h
之後在main函式加入,開啟滑鼠函式
int main(int argc, char *argv[])
{
glutMouseFunc(mouse);
}
再新增mouse函式
void mouse(int button,int state,int x,int y)
{
PlaySound("C:/Users/user/Desktop/freeglut/awp1",NULL,SND_ASYNC);
}
之後點滑鼠就會有槍聲
全部程式碼:
#include <mmsystem.h>
void mouse(int button,int state,int x,int y)
{
PlaySound("C:/Users/user/Desktop/freeglut/awp1",NULL,SND_ASYNC);
}
int main(int argc, char *argv[])
{
glutMouseFunc(mouse);
}
2.點鍵盤會有do re mi fa so
加入程式碼,開啟鍵盤函式
int main(int argc, char *argv[])
{
glutKeyboardFunc(keyboard);
}
再新增keyboard函式
void keyboard(unsigned char key,int x,int y)
{
if(key=='1') PlaySound("C:/Users/user/Desktop/freeglut/music/do.wav",NULL,SND_ASYNC);
if(key=='2') PlaySound("C:/Users/user/Desktop/freeglut/music/re.wav",NULL,SND_ASYNC);
if(key=='3') PlaySound("C:/Users/user/Desktop/freeglut/music/mi.wav",NULL,SND_ASYNC);
if(key=='4') PlaySound("C:/Users/user/Desktop/freeglut/music/fa.wav",NULL,SND_ASYNC);
if(key=='5') PlaySound("C:/Users/user/Desktop/freeglut/music/so.wav",NULL,SND_ASYNC);
}
全部程式碼:
void keyboard(unsigned char key,int x,int y)
{
if(key=='1') PlaySound("C:/Users/user/Desktop/freeglut/music/do.wav",NULL,SND_ASYNC);
if(key=='2') PlaySound("C:/Users/user/Desktop/freeglut/music/re.wav",NULL,SND_ASYNC);
if(key=='3') PlaySound("C:/Users/user/Desktop/freeglut/music/mi.wav",NULL,SND_ASYNC);
if(key=='4') PlaySound("C:/Users/user/Desktop/freeglut/music/fa.wav",NULL,SND_ASYNC);
if(key=='5') PlaySound("C:/Users/user/Desktop/freeglut/music/so.wav",NULL,SND_ASYNC);
}
沒有留言:
張貼留言