/// <summary>
        /// Title screen constructor.
        /// </summary>
        public SaveScreen(GameMain parent)
        {
            List <Base.GameState> allStates = GameStateManager.LoadData();
            int i = 0;

            _window = Rectangle.Empty;
            _parent = parent;

            _list = new ComponentList();
            _list.ComponentHeight = 80;

            if (allStates.Count < 5)
            {
                _list.AddComponent(new Button("New Save", new SelectDelegate(() =>
                {
                    GameStateManager.SaveData(-1);
                    _parent.ChangeState(GameState.Playing);
                })));
            }
            foreach (Base.GameState state in allStates)
            {
                _list.AddComponent(new SaveDataButton("saveButton" + (i++), state, new SelectDelegate(() =>
                {
                    GameStateManager.SaveDataOverwriting(state);
                    _parent.ChangeState(GameState.Playing);
                })));
            }

            _list.AddComponent(new Button("Cancel", new SelectDelegate(() =>
            {
                OptionsManager.LoadOptions();
                _parent.ChangeState(GameState.Playing);
            })));
        }
        /// <summary>
        /// Title screen constructor.
        /// </summary>
        public LoadScreen(GameMain parent)
        {
            _window = Rectangle.Empty;
            _parent = parent;
            int x = 0;

            _list = new ComponentList();
            _list.ComponentHeight = 80;

            foreach (Base.GameState state in GameStateManager.LoadData())
            {
                //TODO: Create specific component.
                _list.AddComponent(new SaveDataButton("saveButton" + (x++), state, new SelectDelegate(() =>
                {
                    GameStateManager.SelectSaveData(state);
                    _parent.ChangeState(GameState.LoadingGame);
                })));
            }

            _list.AddComponent(new Button("Cancel", new SelectDelegate(() =>
            {
                OptionsManager.LoadOptions();
                _parent.ChangeState(GameState.MainMenu);
            })));
        }
        /// <summary>
        /// Title screen constructor.
        /// </summary>
        public OptionsScreen(GameMain parent)
        {
            _list = new ComponentList();

            SelectionBox resolution = new SelectionBox("Resolution");

            resolution.AddOption("800x600");
            resolution.AddOption("1280x720");
            resolution.AddOption("1920x1080");
            resolution.SelectOption(OptionsManager.CurrentOptions.ResolutionWidth + "x" + OptionsManager.CurrentOptions.ResolutionHeight);
            _list.AddComponent(resolution);

            SelectionBox fullscreen = new SelectionBox("Fullscreen");

            fullscreen.AddOption("On");
            fullscreen.AddOption("Off");
            fullscreen.SelectOption(OptionsManager.CurrentOptions.Fullscreen ? "On" : "Off");
            _list.AddComponent(fullscreen);

            SelectionBox inverted = new SelectionBox("Inverted Aim");

            inverted.AddOption("On");
            inverted.AddOption("Off");
            inverted.SelectOption(OptionsManager.CurrentOptions.InvertAim ? "On" : "Off");
            _list.AddComponent(inverted);

            _list.ValueChanged += new ValueChangeDelegate(() =>
            {
                string res = _list.GetValue("Resolution");
                string ful = _list.GetValue("Fullscreen");
                string aim = _list.GetValue("Inverted Aim");

                OptionsManager.CurrentOptions.ResolutionWidth  = Convert.ToInt32(res.Split('x')[0]);
                OptionsManager.CurrentOptions.ResolutionHeight = Convert.ToInt32(res.Split('x')[1]);
                OptionsManager.CurrentOptions.Fullscreen       = (ful == "On");
                OptionsManager.CurrentOptions.InvertAim        = (aim == "On");
            });

            _list.AddComponent(new Button("Delete All Save Data", new SelectDelegate(() =>
            {
                GameStateManager.DeleteAllSaves();
            })));

            _list.AddComponent(new Button("Save", new SelectDelegate(() =>
            {
                OptionsManager.SaveOptions();
                _parent.ChangeState(GameState.MainMenu);
            })));

            _list.AddComponent(new Button("Cancel", new SelectDelegate(() =>
            {
                OptionsManager.LoadOptions();
                _parent.ChangeState(GameState.MainMenu);
            })));

            _window = Rectangle.Empty;

            _parent = parent;
        }
        public void SearchForGame()
        {
            if (Gamer.SignedInGamers.Count == 0)
            {
                SignIn();
            }
            else
            {
                if (_session != null)
                {
                    _session.Dispose();
                }
                AvailableNetworkSessionCollection sessions = NetworkSession.Find(NetworkSessionType.SystemLink, 1, null);
                if (sessions.Count > 0)
                {
                    try
                    {
                        AvailableNetworkSession mySession = sessions[0];
                        _session            = NetworkSession.Join(mySession);
                        _session.GamerLeft += new EventHandler <GamerLeftEventArgs>(Client_GamerLeft);

                        GameMain.ChangeState(GameState.PlayingClient);

                        IsHost = false;
                    }
                    catch (Exception ex)
                    {
                        // Not the best solution, but...
                        GameMain.ChangeState(GameState.TitleScreen);
                    }
                }
            }
        }
Example #5
0
 /// <summary>
 /// Updates component position.
 /// </summary>
 /// <param name="gameTime">Game time.</param>
 public void Update(GameTime gameTime)
 {
     if (_input.CancelButton)
     {
         _parent.ChangeState(GameState.MainMenu);
     }
 }
        void Client_GamerLeft(object sender, GamerLeftEventArgs e)
        {
            _session.Dispose();

            if (_session.RemoteGamers.Count <= 0)
            {
                GameMain.ChangeState(GameState.TitleScreen);
            }
        }
 void Host_GamerJoined(object sender, GamerJoinedEventArgs e)
 {
     /*if (GameMain.CurrentState == GameState.WaitingPlayers &&
      * _session.RemoteGamers.Count == GameMain.PlayerCount)*/
     if (_session.RemoteGamers.Count >= 1)
     {
         GameMain.ChangeState(GameState.PlayingHost);
         _session.StartGame();
     }
 }
        public void CreateSession()
        {
            if (_session != null)
            {
                _session.Dispose();
            }
            if (Gamer.SignedInGamers.Count == 0)
            {
                SignIn();
            }
            else
            {
                _session              = NetworkSession.Create(NetworkSessionType.SystemLink, 1, 2);
                _session.GamerJoined += new EventHandler <GamerJoinedEventArgs>(Host_GamerJoined);
                _session.GamerLeft   += new EventHandler <GamerLeftEventArgs>(Host_GamerLeft);

                GameMain.ChangeState(GameState.WaitingPlayers);

                IsHost = true;
            }
        }
Example #9
0
        /// <summary>
        /// Updates component position.
        /// </summary>
        /// <param name="gameTime">Game time.</param>
        public void Update(GameTime gameTime)
        {
            SoundManager.PlayBGM("Rising Game");

            if (_input.CancelButton || _input.ConfirmButton || _input.PauseButton)
            {
                _parent.ChangeState(GameState.MainMenu);
            }

            if (_showningTime > 0)
            {
                _showningTime -= gameTime.ElapsedGameTime.Milliseconds;
            }
            else if (_fadingTime > 0)
            {
                _fadingTime -= gameTime.ElapsedGameTime.Milliseconds;
            }
            else
            {
                _list.Update(gameTime);
            }
        }
        /// <summary>
        /// Title screen constructor.
        /// </summary>
        public TitleScreen(GameMain parent)
        {
            _logo = GameContent.LoadContent <Texture2D>("images/title.png");

            _list = new ComponentList();

            _list.ComponentHeight = 50;

            _list.AddComponent(new Button("New Game", () => _parent.ChangeState(GameState.NewGame)));
            _list.AddComponent(new Button("Load Game", () => _parent.ChangeState(GameState.LoadGame)));
            _list.AddComponent(new Button("Demo Mode", () => _parent.ChangeState(GameState.DemoMode)));
            _list.AddComponent(new Button("Options", () => _parent.ChangeState(GameState.Options)));
            _list.AddComponent(new Button("How to Play", () => _parent.ChangeState(GameState.HowToPlay)));
            _list.AddComponent(new Button("Credits", () => _parent.ChangeState(GameState.Credits)));
            _list.AddComponent(new Button("Quit Game", () => _parent.ChangeState(GameState.Quiting)));

            _window = Rectangle.Empty;

            _parent = parent;
        }
Example #11
0
        public void Update(GameTime gameTime)
        {
            #region Entity Control
            // Adds new entities.
            while (_toAdd.Count != 0)
            {
                _entities.Add(_toAdd.Pop());
            }

            // Removes old entities on to remove list.
            while (_toRemove.Count != 0)
            {
                _entities.Remove(_toRemove.Pop());
            }
            #endregion Entity Control

            #region Endgame Control
            // Checks for game exit/reset.
            if (!_gameEnded)
            {
                if (_connDelayTime > 0)
                {
                    _connDelayTime -= gameTime.ElapsedGameTime.Milliseconds;
                }
                else
                {
                    // Check if someone won.
                    var players = _entities.OfType <Player>().Where(pl => !pl.Dead);
                    int count   = players.Count();
                    if (count <= 1)
                    {
                        if (players.Count() == 0)
                        {
                            _winnerColor = Color.White;
                            _winnerText  = "Draw!";
                        }
                        else
                        {
                            Player player = players.First();
                            _winnerColor = player.Color;
                            _winnerText  = player.Name + " Wins!";
                        }

                        _winnerTimer = 5000;

                        _textOrigin = (_winFont.MeasureString(_winnerText) / 2);
                        _gameEnded  = true;
                    }
                }
            }
            else
            {
                _winnerTimer -= gameTime.ElapsedGameTime.Milliseconds;

                if (_winnerTimer < 0.0f)
                {
                    GameMain.ChangeState(GameState.TitleScreen);
                }
            }
            #endregion Endgame Control

            // And finally, updates all entities.
            foreach (Entity entity in _entities)
            {
                entity.Update(gameTime);
            }
        }
Example #12
0
 public void FinishLevel(Player loser)
 {
     _game.ChangeState(GameState.GameOver, Players.Where((p) => p != loser).First());
 }
Example #13
0
        public TitleScreen(string background, int width, int height)
        {
            #region Title Screen Assets initialization

            _bounds     = new Rectangle(0, 0, width, height);
            _background = GameContent.LoadContent <Texture2D>(background);
            _logo       = GameContent.LoadContent <Texture2D>("Images/Logo");
            _font       = GameContent.LoadContent <SpriteFont>("Fonts/SmallFont");

            Vector2 bg_center     = new Vector2(_logo.Width / 2.0f, _logo.Height / 2.0f);
            Vector2 screen_center = new Vector2(width / 2.0f, height / 2.0f);
            _titlePosition = new Rectangle((int)(screen_center.X - bg_center.X),
                                           (int)(screen_center.Y * 0.5 - bg_center.Y),
                                           (int)(_logo.Width),
                                           (int)(_logo.Height));

            _startMessage = "Press START or ENTER to start the game";
            Vector2 startSize = _font.MeasureString(_startMessage);
            _startOrigin   = new Vector2(startSize.X / 2, startSize.Y / 2);
            _startPosition = new Vector2(screen_center.X, screen_center.Y * 1.7f);

            _transparency     = 0.9f;
            _transparencyDiff = 0.001f;

            #endregion Title Screen Assets initialization

            #region Options Initialization

            _options = new ComponentList();

            SelectionBox controller = new SelectionBox("Use Keyboard?");
            controller.AddOption("Yes");
            controller.AddOption("No");
            controller.SelectOption(GameMain.UseKeyboard ? "Yes" : "No");
            _options.AddComponent(controller);

            SelectionBox players = new SelectionBox("Players");
            players.AddOption("2");
            players.AddOption("3");
            players.AddOption("4");

            /*players.AddOption("5");
            *  players.AddOption("6");
            *  players.AddOption("7");
            *  players.AddOption("8");*/
            players.SelectOption(GameMain.PlayerCount.ToString());
            _options.AddComponent(players);

            _options.ValueChanged += () =>
            {
                string useKeyboard  = _options.GetValue("Use Keyboard?");
                string playersCount = _options.GetValue("Players");

                GameMain.UseKeyboard = (useKeyboard == "Yes");
                GameMain.PlayerCount = int.Parse(playersCount.Replace('*', '\0'));

                if (GameMain.PlayerCount > 2)
                {
                    _options.GetComponent <Button>("Search For Game").Visible = false;
                    _options.GetComponent <Button>("Host Game").Visible       = false;
                }
                else
                {
                    _options.GetComponent <Button>("Search For Game").Visible = true;
                    _options.GetComponent <Button>("Host Game").Visible       = true;
                }
            };

            _options.AddComponent(new Button("Play Local", () =>
            {
                _showOptions = false;
                GameMain.ChangeState(GameState.PlayingLocal);
            }));

            _options.AddComponent(new Button("Search For Game", () =>
            {
                // TODO: Add network logic.
                _showOptions = false;
                GameMain.ChangeState(GameState.SearchingGame);
            }));

            _options.AddComponent(new Button("Host Game", () =>
            {
                if (GameMain.CurrentState != GameState.TitleScreen)
                {
                    return;
                }

                // TODO: Add network logic.
                _showOptions = false;
                GameMain.ChangeState(GameState.CreatingHost);
            }));

            _options.Position = new Rectangle(30, 200, width - 60, height - 220);
            _showOptions      = false;
            #endregion Options Initialization

            _firstKeyUp = false;
        }