mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-07-20 12:06:38 +00:00
Added pseudo-random music playback.
This was SVN commit r1365.
This commit is contained in:
@@ -11,6 +11,9 @@
|
||||
-->
|
||||
|
||||
<!-- Generic utilities -->
|
||||
<script file="gui/test/functions_utility.js"><![CDATA[
|
||||
]]></script>
|
||||
|
||||
<script file="gui/test/functions_utility_object.js"><![CDATA[
|
||||
]]></script>
|
||||
|
||||
|
||||
@@ -13,8 +13,15 @@
|
||||
<object type="empty" name="pregame_gui" size="0 0 100% 100%" z="1" hidden="false">
|
||||
<action on="Load"><![CDATA[
|
||||
// Play main 0 A.D. theme when the main menu starts.
|
||||
// curr_music = new Sound("audio/music/menu_track.ogg");
|
||||
// curr_music.loop();
|
||||
curr_music = newRandomSound("music", "theme");
|
||||
curr_music.loop();
|
||||
curr_music.free(); // Close main theme when starting game session.
|
||||
curr_session_playlist_1 = newRandomSound("music", "peace");
|
||||
curr_session_playlist_1.play();
|
||||
curr_session_playlist_1.free();
|
||||
curr_session_playlist_2 = newRandomSound("music", "peace");
|
||||
curr_session_playlist_2.play();
|
||||
curr_session_playlist_2.free();
|
||||
]]></action>
|
||||
|
||||
<object type="image" name="pregame-mainmenu-background-image" sprite="pregame-mainmenu-background" size="0 0 100% 100%" z="100" hidden="false" />
|
||||
@@ -25,9 +32,6 @@
|
||||
GUIObjectUnhide("session_gui");
|
||||
GUIObjectHide("pregame_gui");
|
||||
FlipGUI(GUIType);
|
||||
// curr_music.free(); // Close main theme when starting game session.
|
||||
curr_session_music = new Sound("audio/music/germanic_peace_2.ogg");
|
||||
curr_session_music.play();
|
||||
]]></action>
|
||||
<action on="MouseEnter"><![CDATA[
|
||||
tooltipObject = getGUIObjectByName("pregame-mainmenu-tooltip");
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
function getRandom(randomMin, randomMax)
|
||||
{
|
||||
// Returns a random whole number in a min..max range.
|
||||
// NOTE: There should probably be an engine function for this,
|
||||
// since we'd need to keep track of random seeds for replays.
|
||||
|
||||
randomNum = randomMin + (randomMax-randomMin)*Math.random(); // num is random, from A to B
|
||||
return Math.round(randomNum);
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
@@ -12,3 +12,51 @@
|
||||
|
||||
// Close "s" and free it from memory (use in conjunction with loop()):
|
||||
// s.free();
|
||||
|
||||
function newRandomSound(soundType, soundSubType)
|
||||
{
|
||||
switch (soundType)
|
||||
{
|
||||
case "music":
|
||||
randomSoundPath = "audio/music/"
|
||||
switch (soundSubType)
|
||||
{
|
||||
case "peace":
|
||||
// Get a random number within the sound's range.
|
||||
// (Later we'll need to change this to an array selection of filenames.)
|
||||
randomSound = getRandom(1, 4);
|
||||
|
||||
switch (randomSound)
|
||||
{
|
||||
case 1:
|
||||
randomFileName = "germanic_peace_1.ogg"
|
||||
break;
|
||||
case 2:
|
||||
randomFileName = "germanic_peace_2.ogg"
|
||||
break;
|
||||
case 3:
|
||||
randomFileName = "germanic_peace_3.ogg"
|
||||
break;
|
||||
case 4:
|
||||
randomFileName = "roman_peace_1.ogg"
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "theme":
|
||||
randomFileName = "menu_track.ogg"
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Build path to random audio file.
|
||||
randomSoundPath += randomFileName;
|
||||
|
||||
console.write("Playing " + randomSoundPath + " ...");
|
||||
|
||||
return new Sound(randomSoundPath);
|
||||
}
|
||||
@@ -27,3 +27,5 @@ function GUIObjectToggle(objectName)
|
||||
GUIObject.hidden = !GUIObject.hidden;
|
||||
}
|
||||
|
||||
// ====================================================================
|
||||
|
||||
|
||||
Reference in New Issue
Block a user