Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Very simple menu with no sub-menus
- // Struct
- function MenuItem(_label, _action) constructor
- {
- Label = _label;
- Execute = _action;
- function Draw(_x, _y, _c)
- {
- draw_text_color(_x, _y, Label, _c, _c, _c, _c, 1);
- }
- }
- // Create
- MenuChoice = 0;
- Menu =
- [
- new MenuItem("Start Game", function() { room_goto(RMGame)}),
- new MenuItem("Exit Game", game_end )
- ];
- // Step
- MenuChoice += (keyboard_check_pressed(vk_up) - keyboard_check_pressed(vk_down));
- var _length = array_length(Menu);
- MenuChoice = (_length + MenuChoice) mod _length; // Looping clamp
- if keyboard_check_pressed(vk_space) Menu[MenuChoice].Execute();
- // Draw
- for (var _i = 0, _h = string_height("H"), _length = array_length(Menu); _i < _length; _i++)
- Menu[_i].Draw(x, y + _i * _h, c_white);
- Menu[MenuChoice].Draw(x, y + MenuChoice * _h, c_yellow);
Add Comment
Please, Sign In to add comment