step1:搜尋nehe
step2:開啟右側Lesson 32
step3:移至最下方下載
DOWNLOAD Visual C++ Code For This Lesson.
step4:解壓縮檔案
step5:跑lesson32.ee的程式
hw2:使遊戲有聲音
step1:開啟codeblocks
step2:新增一個GLUT專案
step3:新增聲音程式碼
#include <mmsystem.h>///Multimedia System
void mouse(int button, int state, int x, int y)///Add a mouse Function
{
PlaySound("C:\\Users\\user\\Desktop\\lesson32\\Lesson32\\data/shot.wav", NULL, SND_ASYNC);///Copy this line
///要把檔名裡面的目錄裡面的斜線,從\變成(A)\\ or (B)/
}
glutMouseFunc(mouse);///Add a mouse Function
hw3:新增do re mi fa so聲音
step1:
void keyboard(unsigned char key, int x, int y)
{
if(key=='1') PlaySound("C:\\Users\\user\\Desktop\\freeglut\\bin/do.wav", NULL, SND_ASYNC);
if(key=='2') PlaySound("C:\\Users\\user\\Desktop\\freeglut\\bin/re.wav", NULL, SND_ASYNC);
if(key=='3') PlaySound("C:\\Users\\user\\Desktop\\freeglut\\bin/mi.wav", NULL, SND_ASYNC);
if(key=='4') PlaySound("C:\\Users\\user\\Desktop\\freeglut\\bin/fa.wav", NULL, SND_ASYNC);
if(key=='5') PlaySound("C:\\Users\\user\\Desktop\\freeglut\\bin/so.wav", NULL, SND_ASYNC);
}
下面glutKeyboardFunc(key);
改為glutKeyboardFunc(keyboard);
hw4:播放自己的音樂
step1:
加這兩行#include "CMP3_MCI.h"///(1)放在同一個程式碼專案的目錄中
CMP3_MCI myMP3;///(2)宣告一個變數,叫myMP3
myMP3.Load("C:\\Users\\user\\Downloads/PLAYINGWITHFIRE.mp3");
myMP3.Play();
step1:
void keyboard(unsigned char key, int x, int y)
{
if(key=='1') PlaySound("C:\\Users\\user\\Desktop\\freeglut\\bin/do.wav", NULL, SND_ASYNC);
if(key=='2') PlaySound("C:\\Users\\user\\Desktop\\freeglut\\bin/re.wav", NULL, SND_ASYNC);
if(key=='3') PlaySound("C:\\Users\\user\\Desktop\\freeglut\\bin/mi.wav", NULL, SND_ASYNC);
if(key=='4') PlaySound("C:\\Users\\user\\Desktop\\freeglut\\bin/fa.wav", NULL, SND_ASYNC);
if(key=='5') PlaySound("C:\\Users\\user\\Desktop\\freeglut\\bin/so.wav", NULL, SND_ASYNC);
}
下面glutKeyboardFunc(key);
改為glutKeyboardFunc(keyboard);
hw4:播放自己的音樂
step1:
加這兩行#include "CMP3_MCI.h"///(1)放在同一個程式碼專案的目錄中
CMP3_MCI myMP3;///(2)宣告一個變數,叫myMP3
myMP3.Load("C:\\Users\\user\\Downloads/PLAYINGWITHFIRE.mp3");
myMP3.Play();
沒有留言:
張貼留言