forked from 0ad/0ad
Play victory/defeat music at appropriate times.
Stop ambient sounds when returning to main menu. This was SVN commit r8404.
This commit is contained in:
parent
7b7e98ea7b
commit
eca237647e
@ -1,4 +1,7 @@
|
|||||||
var g_CurrentMusic = null;
|
var g_CurrentMusic = null;
|
||||||
|
var g_CurrentAmbient = null;
|
||||||
|
|
||||||
|
var g_MusicGain = 0.3;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* At some point, this ought to be extended to do dynamic music selection and
|
* At some point, this ought to be extended to do dynamic music selection and
|
||||||
@ -8,19 +11,33 @@ var g_CurrentMusic = null;
|
|||||||
|
|
||||||
function startMusic()
|
function startMusic()
|
||||||
{
|
{
|
||||||
var ambient1 = new Sound("audio/ambient/dayscape/day_temperate_gen_03.ogg");
|
g_CurrentAmbient = new Sound("audio/ambient/dayscape/day_temperate_gen_03.ogg");
|
||||||
if (ambient1)
|
if (g_CurrentAmbient)
|
||||||
{
|
{
|
||||||
ambient1.loop();
|
g_CurrentAmbient.loop();
|
||||||
ambient1.setGain(0.8);
|
g_CurrentAmbient.setGain(0.8);
|
||||||
}
|
}
|
||||||
|
|
||||||
var gain = 0.3;
|
|
||||||
g_CurrentMusic = new Sound("audio/music/germanic_peace_1.ogg");
|
g_CurrentMusic = new Sound("audio/music/germanic_peace_1.ogg");
|
||||||
if (g_CurrentMusic)
|
if (g_CurrentMusic)
|
||||||
{
|
{
|
||||||
g_CurrentMusic.loop();
|
g_CurrentMusic.loop();
|
||||||
g_CurrentMusic.fade(0.0, gain, 10.0);
|
g_CurrentMusic.fade(0.0, g_MusicGain, 10.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function switchMusic(track, fadeInPeriod)
|
||||||
|
{
|
||||||
|
if (g_CurrentMusic)
|
||||||
|
g_CurrentMusic.fade(-1, 0.0, 5.0);
|
||||||
|
|
||||||
|
g_CurrentMusic = new Sound("audio/music/" + track + ".ogg");
|
||||||
|
|
||||||
|
if (g_CurrentMusic)
|
||||||
|
{
|
||||||
|
g_CurrentMusic.loop();
|
||||||
|
if (fadeInPeriod)
|
||||||
|
g_CurrentMusic.fade(0.0, g_MusicGain, fadeInPeriod);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,4 +48,10 @@ function stopMusic()
|
|||||||
g_CurrentMusic.fade(-1, 0.0, 5.0);
|
g_CurrentMusic.fade(-1, 0.0, 5.0);
|
||||||
g_CurrentMusic = null;
|
g_CurrentMusic = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (g_CurrentAmbient)
|
||||||
|
{
|
||||||
|
g_CurrentAmbient.fade(-1, 0.0, 5.0);
|
||||||
|
g_CurrentAmbient = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -163,12 +163,14 @@ function checkPlayerState()
|
|||||||
if (playerState.state == "defeated")
|
if (playerState.state == "defeated")
|
||||||
{
|
{
|
||||||
g_GameEnded = true;
|
g_GameEnded = true;
|
||||||
|
switchMusic("loss_1", 0.0);
|
||||||
messageBox(400, 200, "You have been defeated... Do you want to leave the game now?",
|
messageBox(400, 200, "You have been defeated... Do you want to leave the game now?",
|
||||||
"Defeat", 0, ["Yes", "No!"], [leaveGame, null]);
|
"Defeat", 0, ["Yes", "No!"], [leaveGame, null]);
|
||||||
}
|
}
|
||||||
else if (playerState.state == "won")
|
else if (playerState.state == "won")
|
||||||
{
|
{
|
||||||
g_GameEnded = true;
|
g_GameEnded = true;
|
||||||
|
switchMusic("win_1", 0.0);
|
||||||
messageBox(400, 200, "You have won the battle! Do you want to leave the game now?",
|
messageBox(400, 200, "You have won the battle! Do you want to leave the game now?",
|
||||||
"Victory", 0, ["Yes", "No!"], [leaveGame, null]);
|
"Victory", 0, ["Yes", "No!"], [leaveGame, null]);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user