Page 2 of 2

Re: Menu

Posted: Mon Feb 23, 2009 9:24 pm
by trufun202
Right now I'm writing a game in C#, so I'm taking advantage of the use of delegates (function pointers). So when I add a menu item, I pass in the function that will execute when it's selected, such as:

Code: Select all

TitleMenu.MenuItems.Add("Battle Mode",
                delegate()
                {
                    TitleMenu.Visible = false;
                    currentScreen = Screen.CharacterSelection;
                    InitializeGameMode(GameMode.BattleMode);
                    startingMatch = true;
                    gameState = GameState.Running;
                });
TitleMenu.MenuItems.Add("Credits",
                delegate()
                {
                    TitleMenu.Visible = false;
                    currentScreen = Screen.Credits;
                });
TitleMenu.MenuItems.Add("Quit",
                delegate()
                {
                    this.Exit();
                });
In Golvellius, I'm essentially doing the same thing by specifying Lua methods with each menu item - which I prefer, but I'm not using Lua on this game so delegates are a happy medium.

Re: Menu

Posted: Mon Feb 23, 2009 10:10 pm
by Arce
so I'm taking advantage of the use of delegates (function pointers).
Sounds like my plan back when I was designing my RTS. Haven't waded through the code, but how's that method working for ya? ;p

Re: Menu

Posted: Mon Feb 23, 2009 10:20 pm
by trufun202
Arce wrote:Haven't waded through the code, but how's that method working for ya? ;p
It works well! ...and I was proud enough of it to share with others, so that says something I suppose. :P

Re: Menu

Posted: Tue Feb 24, 2009 4:38 am
by Ratstail91
trufun202 wrote:Right now I'm writing a game in C#, so I'm taking advantage of the use of delegates (function pointers). So when I add a menu item, I pass in the function that will execute when it's selected, such as:

Code: Select all

TitleMenu.MenuItems.Add("Battle Mode",
                delegate()
                {
                    TitleMenu.Visible = false;
                    currentScreen = Screen.CharacterSelection;
                    InitializeGameMode(GameMode.BattleMode);
                    startingMatch = true;
                    gameState = GameState.Running;
                });
TitleMenu.MenuItems.Add("Credits",
                delegate()
                {
                    TitleMenu.Visible = false;
                    currentScreen = Screen.Credits;
                });
TitleMenu.MenuItems.Add("Quit",
                delegate()
                {
                    this.Exit();
                });
In Golvellius, I'm essentially doing the same thing by specifying Lua methods with each menu item - which I prefer, but I'm not using Lua on this game so delegates are a happy medium.
honestly, I don't even know anything about anything. I'm just learning C, and I suck at it. :(

Re: Menu

Posted: Tue Feb 24, 2009 10:41 am
by dandymcgee
Ratstail91 wrote: honestly, I don't even know anything about anything. I'm just learning C, and I suck at it. :(
That's what we're here for. :mrgreen:

What do you suck at? If you're working with some code and can't figure out what's going wrong just post it on the forums. ;)