Menu music added.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "sound_pool.nvgt"
|
||||
#include "virtual_dialogs.nvgt"
|
||||
#include "music.nvgt"
|
||||
|
||||
// Audio
|
||||
// Increased pool size to 300 to prevent sound cutoffs and missing sounds
|
||||
@@ -41,18 +42,79 @@ sound_pool p(300);
|
||||
#include "src/learn_sounds.nvgt"
|
||||
#include "src/bosses/adventure_system.nvgt"
|
||||
|
||||
const string MAIN_MENU_MUSIC_TRACK = "sounds/menu/Draugnorak.ogg; loop; f=1";
|
||||
const int MAIN_MENU_MUSIC_FADE_IN_MS = 1;
|
||||
const int MAIN_MENU_MUSIC_FADE_OUT_MS = 800;
|
||||
music_manager mainMenuMusic;
|
||||
|
||||
const int MAIN_MENU_NEW_GAME = 0;
|
||||
const int MAIN_MENU_LOAD_GAME = 1;
|
||||
const int MAIN_MENU_LEARN_SOUNDS = 2;
|
||||
const int MAIN_MENU_EXIT = 3;
|
||||
|
||||
void start_main_menu_music() {
|
||||
if (mainMenuMusic.resume(MAIN_MENU_MUSIC_FADE_IN_MS)) return;
|
||||
if (mainMenuMusic.playing) {
|
||||
mainMenuMusic.pause(0);
|
||||
mainMenuMusic.resume(MAIN_MENU_MUSIC_FADE_IN_MS);
|
||||
return;
|
||||
}
|
||||
mainMenuMusic.play(MAIN_MENU_MUSIC_TRACK);
|
||||
}
|
||||
|
||||
void stop_main_menu_music() {
|
||||
if (!mainMenuMusic.playing) return;
|
||||
mainMenuMusic.pause(MAIN_MENU_MUSIC_FADE_OUT_MS);
|
||||
}
|
||||
|
||||
int run_main_menu() {
|
||||
start_main_menu_music();
|
||||
speak_with_history("Draugnorak. Main menu.", true);
|
||||
|
||||
int selection = 0;
|
||||
string load_label = has_save_game() ? "Load Game" : "Load Game (no saves found)";
|
||||
string[] options = {"New Game", load_label, "Learn Sounds", "Exit"};
|
||||
int exit_index = options.length() - 1;
|
||||
string[] options;
|
||||
string[] entry_paths;
|
||||
int[] entry_types; // 0 = action, 1 = document
|
||||
int[] action_ids;
|
||||
|
||||
options.insert_last("New Game");
|
||||
entry_paths.insert_last("");
|
||||
entry_types.insert_last(0);
|
||||
action_ids.insert_last(MAIN_MENU_NEW_GAME);
|
||||
|
||||
options.insert_last(load_label);
|
||||
entry_paths.insert_last("");
|
||||
entry_types.insert_last(0);
|
||||
action_ids.insert_last(MAIN_MENU_LOAD_GAME);
|
||||
|
||||
options.insert_last("Learn Sounds");
|
||||
entry_paths.insert_last("");
|
||||
entry_types.insert_last(0);
|
||||
action_ids.insert_last(MAIN_MENU_LEARN_SOUNDS);
|
||||
|
||||
string[] doc_labels;
|
||||
string[] doc_paths;
|
||||
int[] doc_types;
|
||||
add_doc_entries(doc_labels, doc_paths, doc_types);
|
||||
for (uint i = 0; i < doc_labels.length(); i++) {
|
||||
options.insert_last(doc_labels[i]);
|
||||
entry_paths.insert_last(doc_paths[i]);
|
||||
entry_types.insert_last(1);
|
||||
action_ids.insert_last(-1);
|
||||
}
|
||||
|
||||
options.insert_last("Exit");
|
||||
entry_paths.insert_last("");
|
||||
entry_types.insert_last(0);
|
||||
action_ids.insert_last(MAIN_MENU_EXIT);
|
||||
int exit_action = MAIN_MENU_EXIT;
|
||||
|
||||
speak_with_history(options[selection], true);
|
||||
|
||||
while(true) {
|
||||
wait(5);
|
||||
mainMenuMusic.loop();
|
||||
|
||||
if (key_pressed(KEY_DOWN)) {
|
||||
play_menu_move_sound();
|
||||
@@ -70,15 +132,24 @@ int run_main_menu() {
|
||||
|
||||
if (key_pressed(KEY_RETURN)) {
|
||||
play_menu_select_sound();
|
||||
return selection;
|
||||
if (entry_types[selection] == 1) {
|
||||
stop_main_menu_music();
|
||||
text_reader_file(entry_paths[selection], options[selection], true);
|
||||
start_main_menu_music();
|
||||
speak_with_history(options[selection], true);
|
||||
continue;
|
||||
}
|
||||
stop_main_menu_music();
|
||||
return action_ids[selection];
|
||||
}
|
||||
|
||||
if (key_pressed(KEY_ESCAPE)) {
|
||||
return exit_index;
|
||||
stop_main_menu_music();
|
||||
return exit_action;
|
||||
}
|
||||
}
|
||||
|
||||
return exit_index;
|
||||
return exit_action;
|
||||
}
|
||||
|
||||
void run_game()
|
||||
@@ -97,14 +168,14 @@ void run_game()
|
||||
while (!game_started) {
|
||||
int selection = run_main_menu();
|
||||
|
||||
if (selection == 0) {
|
||||
if (selection == MAIN_MENU_NEW_GAME) {
|
||||
if (!setup_new_character()) {
|
||||
continue;
|
||||
}
|
||||
start_new_game();
|
||||
speak_with_history("New game started.", true);
|
||||
game_started = true;
|
||||
} else if (selection == 1) {
|
||||
} else if (selection == MAIN_MENU_LOAD_GAME) {
|
||||
if (!has_save_game()) {
|
||||
ui_info_box("Draugnorak", "Load Game", "No saves found.");
|
||||
continue;
|
||||
@@ -121,7 +192,7 @@ void run_game()
|
||||
if (message == "") message = "Unable to load save.";
|
||||
ui_info_box("Draugnorak", "Load Game", message);
|
||||
}
|
||||
} else if (selection == 2) {
|
||||
} else if (selection == MAIN_MENU_LEARN_SOUNDS) {
|
||||
run_learn_sounds_menu();
|
||||
continue;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user