To play music, you can also use playlists. This will bring more variation to your soundtrack, and also allows you to switch between playlists when the mood of the game changes. Just examine the code below to see how it works:
// defined play lists
Playlist Battle , // battle playlist
Explore, // exploring playlist
Calm ; // calm playlist
5
void InitPre()
{
EE_INIT();
}
10
bool Init()
{
if(!Battle.songs()) // create ’Battle’ playlist if not yet created
{
15 Battle += (=== drop action music ===); // add ”battle0”
Battle += (=== same here ===); // add ”battle1”
}
if(!Explore.songs()) // create ’Explore’ playlist if not yet created
{
20 Explore+= (=== drop tranquil music ===); // add ”explore” track
}
if(!Calm.songs()) // create ’Calm’ playlist if not yet created
{
Calm += (=== a very relaxed soundtrack ===); // add ”calm”
25 }
return true;
}
void Shut()
30{
}
bool Update()
{
35 if(Kb.bp(KB_ESC))return false;
if(Kb.c(’1’))Music.play(Battle );
if(Kb.c(’2’))Music.play(Explore);
if(Kb.c(’3’))Music.play(Calm );
if(Kb.c(’4’))Music.play(null );
40 return true;
}
void Draw()
{
45 D.clear(TURQ);
if(Music.playlist()) // if any playlist playing
{
D.text(0, 0, S+”time ” +Music.time()+” / ”+Music.length()+” length”);
50 }else
{
D.text(0, 0, ”No playlist playing”);
}
D.text(0, -0.2, ”Press 1-battle, 2-explore, 3-calm, 4-none”);
55}