Example #1
0
        /// <summary>
        /// Inits the menu.
        /// </summary>
        private void InitMenu()
        {
            var start    = new MenuScreen("Asteroids", null);
            var about    = new MenuScreen("About", null);
            var planet   = new MenuScreen("Planet", null);
            var options  = new MenuScreen("Options", null);
            var inverted = new MenuScreen("Inverted Controls", options);
            var debug    = new MenuScreen("Debug Mode", options);

            _pause    = new MenuScreen("Paused", null);
            _gameOver = new MenuScreen("Game Over", null);
            var controls = new MenuScreen("Controls", null);

            var e = new Dictionary <string, Action>
            {
                {
                    "On", () =>
                    {
                        _invertedControls        = true;
                        _menu.SelectedMenuScreen = _menu.Screens.IndexOf(options);
                    }
                },
                {
                    "Off", () =>
                    {
                        _invertedControls        = false;
                        _menu.SelectedMenuScreen = _menu.Screens.IndexOf(options);
                    }
                }
            };

            inverted.Elements = e;


            e = new Dictionary <string, Action>
            {
                {
                    "On", () =>
                    {
                        _debug = true;
                        _menu.SelectedMenuScreen = _menu.Screens.IndexOf(options);
                    }
                },
                {
                    "Off", () =>
                    {
                        _debug = false;
                        _menu.SelectedMenuScreen = _menu.Screens.IndexOf(options);
                    }
                }
            };
            debug.Elements = e;

            e = new Dictionary <string, Action>
            {
                {
                    "Start Game", () =>
                    {
                        _menu.MainMenuIndex      = _menu.Screens.IndexOf(_pause);
                        _menu.SelectedMenuScreen = _menu.MainMenuIndex;
                        NewGame();
                    }
                },
                { "Planet", () => { _menu.SelectedMenuScreen = _menu.Screens.IndexOf(planet); } },
                { "Options", () => { _menu.SelectedMenuScreen = _menu.Screens.IndexOf(options); } },
                { "About", () => { _menu.SelectedMenuScreen = _menu.Screens.IndexOf(about); } },
                { "Controls", () => { _menu.SelectedMenuScreen = _menu.Screens.IndexOf(controls); } },
                { "Quit", Exit }
            };

            start.Elements = e;

            e = new Dictionary <string, Action>
            {
                {
                    "Inverted Controls", () =>
                    {
                        inverted.SelectedIndex   = _invertedControls ? 0 : 1;
                        _menu.SelectedMenuScreen = _menu.Screens.IndexOf(inverted);
                    }
                },
                {
                    "Debug Mode", () =>
                    {
                        debug.SelectedIndex      = _debug ? 0 : 1;
                        _menu.SelectedMenuScreen = _menu.Screens.IndexOf(debug);
                    }
                }
            };

            options.Elements = e;

            e = new Dictionary <string, Action>
            {
                { "Resume", () => { _running = true; } },
                { "New Game", NewGame },
                { "Planet", () => { _menu.SelectedMenuScreen = _menu.Screens.IndexOf(planet); } },
                { "Options", () => { _menu.SelectedMenuScreen = _menu.Screens.IndexOf(options); } },
                { "About", () => { _menu.SelectedMenuScreen = _menu.Screens.IndexOf(about); } },
                { "Controls", () => { _menu.SelectedMenuScreen = _menu.Screens.IndexOf(controls); } },
                { "Quit", Exit }
            };

            _pause.Elements = e;

            e = new Dictionary <string, Action>
            {
                { "New game", NewGame },
                { "Quit", Exit }
            };

            _gameOver.Elements = e;

            e = new Dictionary <string, Action>
            {
                { "Samuel Lewis & Thomas Kempton", null },
                { "Simulation and Game Development", null },
                { "Project - Post-Protoplanetary Disk Lander", null }
            };

            about.Elements = e;

            e = new Dictionary <string, Action>
            {
                { "Control Lander - WASD/Left thumb stick", null },
                { "Main Thruster - Space/Right trigger", null },
                { "Buy Fuel - F/X", null },
                { "Rotate Camera - Direction Keys/Right thumb stick", null },
                { "Menu movement - WASD/D-pad", null },
                { "Menu Select - Space/A", null }
            };

            controls.Elements = e;

            e = _gravity.ToList().ToDictionary <KeyValuePair <string, Body>, string, Action>(
                pair =>
                string.Format(@"{0, 10} G: {1:0.##}mpsps W: {2:0.##}kph", pair.Key, -pair.Value.Gravity.Y,
                              pair.Value.Wind.Length() * 3.6 * Metre.Y),
                pair => (() =>
            {
                _lem.Body = pair.Value;
                _currentGravity = pair.Value;
                _menu.SelectedMenuScreen = _menu.MainMenuIndex;
                NewGame();
            }));
            planet.Elements = e;

            _menu.AddMenuScreen(start);
            _menu.AddMenuScreen(_gameOver);
            _menu.AddMenuScreen(inverted);
            _menu.AddMenuScreen(debug);
            _menu.AddMenuScreen(options);
            _menu.AddMenuScreen(about);
            _menu.AddMenuScreen(_pause);
            _menu.AddMenuScreen(controls);
            _menu.AddMenuScreen(planet);

            _menu.SelectedMenuScreen = _menu.Screens.IndexOf(start);
            _menu.MainMenuIndex      = _menu.Screens.IndexOf(start);
        }
Example #2
0
 /// <summary>
 /// Adds the menu screen.
 /// </summary>
 /// <param name="screen">The screen.</param>
 public void AddMenuScreen(MenuScreen screen)
 {
     Screens.Add(screen);
 }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MenuScreen"/> class.
 /// </summary>
 /// <param name="title">The title.</param>
 /// <param name="parent">The parent.</param>
 public MenuScreen(String title, MenuScreen parent)
 {
     Title  = title;
     Parent = parent;
 }
Example #4
0
        /// <summary>
        /// Updates the Entity.
        /// </summary>
        /// <param name="graphics">The graphics.</param>
        /// <param name="input">The input.</param>
        /// <param name="delta">The delta.</param>
        public void Update(GraphicsDevice graphics, Input input, long delta)
        {
            MenuScreen screen = Screens[SelectedMenuScreen];
            int        max    = (Screens[SelectedMenuScreen] == Screens[MainMenuIndex])
                          ? screen.Elements.Count
                          : screen.Elements.Count + 1;

            if (input.Down())
            {
                if (_down == false)
                {
                    _down = true;
                    _menuMove.Play();
                    screen.SelectedIndex += 1;
                    if (screen.SelectedIndex >= max)
                    {
                        screen.SelectedIndex = 0;
                    }
                }
            }
            else
            {
                _down = false;
            }
            if (input.Up())
            {
                if (_up == false)
                {
                    _up = true;
                    _menuMove.Play();
                    screen.SelectedIndex -= 1;
                    if (screen.SelectedIndex < 0)
                    {
                        screen.SelectedIndex = max - 1;
                    }
                }
            }
            else
            {
                _up = false;
            }
            if (input.Select())
            {
                if (_enter == false)
                {
                    _enter = true;
                    Action[] actions = screen.Elements.Values.ToArray();
                    if (screen.SelectedIndex == actions.Count())
                    {
                        _menuBack.Play();
                        SelectedMenuScreen = screen.Parent == null ? MainMenuIndex : Screens.IndexOf(screen.Parent);
                    }
                    else
                    {
                        Action action = screen.Elements.Values.ToArray()[screen.SelectedIndex];
                        if (action != null)
                        {
                            _menuSelect.Play();
                            action();
                        }
                    }
                }
            }
            else
            {
                _enter = false;
            }

            if (input.Escape())
            {
                if (_escape == false)
                {
                    _escape = true;
                    if (screen.Parent != null)
                    {
                        _menuBack.Play();

                        SelectedMenuScreen = Screens.IndexOf(screen.Parent);
                    }
                    else if (screen != Screens[MainMenuIndex])
                    {
                        _menuBack.Play();
                        SelectedMenuScreen = MainMenuIndex;
                    }
                }
            }
            else
            {
                _escape = false;
            }
        }