Excerpts from the Gotcha source, with some extra comments added:
In include/init.bgt:
void game_init()
{
...
menu.allow_escape = true;
menu.wrap_x = true;
menu.wrap_y = false;
menu.max_pan = 10;
menu.set_callback(menu_checks, "");
menu.open_path = lib.sound_path + "/menu_open." + lib.default_extension;
menu.close_path = lib.sound_path + "/menu_close." + lib.default_extension;
menu.move_path = lib.sound_path + "/step1." + lib.default_extension;
menu.wrap_path = lib.sound_path + "/step2." + lib.default_extension;
...
menu.set_tts_object(speech.sapi);
menu.set_speech_mode(speech.mode);
...
} // game_init
In include/menus.bgt:
void main_menu()
{
string menu_position="start";
...
while (true)
{
...
menu.reset(false);
menu.resize(5,1); // Five menu options along the X axis (Horizontal menu.)
/*
Note here that add_item_2d and add_item_tts_2d can take x and y coordinates after the option name, though they are optional. If left out, the methods will use the next available option object.
If you're not going to use horizontal menus, you don't need to call resize.
*/
menu.add_item_tts_2d("Start game", "start");
menu.add_item_tts_2d("Load game", "load");
menu.add_item_tts_2d("Test speakers", "test");
menu.add_item_tts_2d("Options", "options");
menu.add_item_tts_2d("Exit", "exit");
menu_position = menu.run_extended("Main menu. Use left/right arrow keys to select an option, enter to activate.", true, menu_position, true);
// run/run_extended return "err" if an error occurs, or "esc" if the escape key is pressed.
speech.stop();
if (menu_position == "err")
{
log.fatal("main_menu", "Failed to run menu.");
} // if
else if (menu_position == "start")
{
start_game();
} // else if
else if (menu_position == "load")
{
load_game();
} // else if
else if (menu_position == "test")
{
test_speakers();
} // else if
else if (menu_position == "options")
{
options_menu();
} // else if
else
{
exit_game();
} // else
} // while
} // main_menu
Excerpts from the Giftanum source (So far unreleased version):
In include/menus.bgt:
void main_menu()
{
string menu_position;
menu.open_path = "s/023";
menu.close_path = "s/022";
menu.move_path = "s/006";
menu_position = "start";
...
while (true)
{
...
menu.reset(false);
menu.add_item_tts_1d("Start game", "start");
menu.add_item_tts_1d("Load game", "load");
menu.add_item_tts_1d("View scoreboards", "view");
menu.add_item_tts_1d("Test speakers", "test");
menu.add_item_tts_1d("Options", "options");
menu.add_item_tts_1d("Exit", "exit");
menu_position = menu.run_extended("Main menu. Use arrow keys to select an option, enter to activate.", true, menu_position, true);
speech.stop();
if (menu_position == "err")
{
log.fatal("main_menu", "Failed to run menu.");
} // if
else if (menu_position == "start")
{
difficulty_menu();
} // else if
else if (menu_position == "load")
{
load_game();
} // else if
else if (menu_position == "view")
{
scoreboard_menu();
} // else if
else if (menu_position == "test")
{
test_speakers();
} // else if
else if (menu_position == "options")
{
options_menu();
} // else if
else
{
exit_game();
} // else
} // while
} // main_menu
I hope these examples help you.