Advertisement
CaptainLepidus

Menu Extended

Mar 25th, 2012
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. objMenu
  2.  
  3. Create Event:
  4.  
  5. execute code:
  6.  
  7. {
  8.     menu[ 0 , 0 ] = 'Play';//Text
  9.     menu[ 0 , 1 ] = 'room_goto_next()';//Code
  10.     menu[ 1 , 0 ] = 'Help';
  11.     menu[ 1 , 1 ] = 'show_info()';
  12.     menu[ 2 , 0 ] = 'Quit';
  13.     menu[ 2 , 1 ] = 'game_end()';
  14.     menu_max = 3;//Number of options
  15.     menu_sel = 0;//Current option selected
  16.     sep = 20;//How many pixels in between options
  17. }
  18.  
  19. Step Event:
  20.  
  21. execute code:
  22.  
  23. {
  24.     if keyboard_check_pressed(vk_up)
  25.     {
  26.         menu_sel = menu_sel - 1;//Move up
  27.     }
  28.     if keyboard_check_pressed(vk_down)
  29.     {
  30.         menu_sel = menu_sel + 1;//Move down
  31.     }
  32.     if menu_sel >= menu_max
  33.     {
  34.         menu_sel = menu_sel - menu_max;//Wrap around to the top
  35.     }
  36.     if menu_sel < 0
  37.     {
  38.         menu_sel = menu_max + menu_sel;//Wrap around to the bottom
  39.     }
  40.     if keyboard_check_pressed( vk_enter )
  41.     {
  42.         execute_string( menu[ menu_sel , 1 ] );//Execute the code
  43.     }
  44. }
  45.  
  46. Draw Event:
  47.  
  48. execute code:
  49.  
  50. {
  51.     var i;
  52.     for(i=0;i<menu_max;i=i+1)//Go through all options
  53.         {
  54.         draw_set_color( c_black );//Set normal color
  55.         if ( i == menu_sel )
  56.         {
  57.             draw_set_color( c_yellow );//Set selected color
  58.         }
  59.     draw_text( x , y + i * sep , menu[ i , 0 ] );//Draw the text
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement