Example #1
0
        public PlatformGame()
        {
            #if (DEBUG)
            #endif
            GameState = GameState.MAINMENU;
            MenuState = MenuState.MAIN;
            /*
             * Blank level generator
             */
            //for (int y = 0; y < 8; y++)
            //{
            //    for (int x = 0; x < 8; x++)
            //    {
            //        string test = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<XnaContent>\n\t\t<Asset Type=\"Platformer.Level\">\n\t\t<Backgrounds>\n\t\t\t<Item Type=\"Platformer.Background\">\n\t\t\t\t<ID>0</ID>\n\t\t\t\t<Velocity>0 0</Velocity>\n\t\t\t\t<Position>0 0</Position>\n\t\t\t</Item>\n\t\t</Backgrounds>\n\t\t<StaticObjects>\n\t\t</StaticObjects>\n\t\t<DynamicObjects>\n\t\t</DynamicObjects>\n\t</Asset>\n</XnaContent>";
            //        FileStream fs = new FileStream("..\\..\\..\\..\\CoopContent\\Level\\" + x.ToString() + "_" + y.ToString() + ".xml", FileMode.Create);
            //        fs.Write(System.Text.ASCIIEncoding.ASCII.GetBytes(test), 0, System.Text.ASCIIEncoding.ASCII.GetBytes(test).Length);
            //        fs.Close();
            //    }
            //}
            //this.Exit();
            _graphics = new GraphicsDeviceManager(this);
            _graphics.PreferredBackBufferWidth = 1280;
            _graphics.PreferredBackBufferHeight = 720;
            IsMouseVisible = true;
            Content.RootDirectory = "Content";
            _world = new World(new Vector2(0, -10));
            TargetElapsedTime = new TimeSpan(0, 0, 0, 0, 10);
            _blockScreenSize = new Vector2(_graphics.PreferredBackBufferWidth / 32.0f, _graphics.PreferredBackBufferHeight / 32.0f);
            _currentScreen = new Vector2(-1, -1);
            _nextScreen = new Vector2(0, 0);

            #if (DEBUG)
            _debugView = new DebugViewXNA(_world);
            #endif
        }
Example #2
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit

            #if (false)
            if (Mouse.GetState().LeftButton == ButtonState.Pressed && _mouseStatePrevious.LeftButton == ButtonState.Released)
            {
                _firstClick = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);
            }
            else if (Mouse.GetState().LeftButton == ButtonState.Pressed)
            {
                _release = new Vector2(Mouse.GetState().X, Mouse.GetState().Y) - _firstClick;
            }
            else
            {
                _firstClick = Vector2.Zero;
                _release = Vector2.Zero;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.E))
            {
                _firstClick.X += 0.1f;
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.A))
            {
                _firstClick.X -= 0.1f;
            }
            if (Keyboard.GetState().IsKeyDown(Keys.OemComma))
            {
                _firstClick.Y -= 0.1f;
            }
            else if (Keyboard.GetState().IsKeyDown(Keys.O))
            {
                _firstClick.Y += 0.1f;
            }
            #endif

            switch (GameState)
            {
                case GameState.MAINMENU:
                    switch (MenuState)
                    {
                        case MenuState.MAIN:
                            if (GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.Start)
                                || GamePad.GetState(PlayerIndex.Two).IsButtonDown(Buttons.Start))
                                MenuState = MenuState.NEWLOAD;
                            if ((!GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.Back)
                                    && _gamePadStatePrevious.IsButtonDown(Buttons.Back))
                                || (!GamePad.GetState(PlayerIndex.Two).IsButtonDown(Buttons.Back)
                                    && _gamePadStatePreviousP2.IsButtonDown(Buttons.Back)))
                            {
                                //this.Exit();
                            }
                            break;
                        case MenuState.NEWLOAD:
                            if ((!GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.Back)
                                    && _gamePadStatePrevious.IsButtonDown(Buttons.Back))
                                || (!GamePad.GetState(PlayerIndex.Two).IsButtonDown(Buttons.Back)
                                    && _gamePadStatePreviousP2.IsButtonDown(Buttons.Back)))
                            {
                                MenuState = MenuState.MAIN;
                            }
            #if (XBOX360)
                            if (!Guide.IsVisible && !_storageDeviceWaiting && _storageDevice == null)
                            {
                                _storageResult = StorageDevice.BeginShowSelector(PlayerIndex.One, null, null);
                                _storageDeviceWaiting = true;
                            }
            #endif
                            if ((GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.LeftThumbstickDown) &&
                                    !_gamePadStatePrevious.IsButtonDown(Buttons.LeftThumbstickDown))
                                || (GamePad.GetState(PlayerIndex.Two).IsButtonDown(Buttons.LeftThumbstickDown) &&
                                    !_gamePadStatePreviousP2.IsButtonDown(Buttons.LeftThumbstickDown)))
                            {
                                _menuOption++;
            #if (!XBOX360)
                                if (_menuOption == 1)
                                    _menuOption = 2;
            #endif
                                if (_menuOption > 2)
                                    _menuOption = 0;
                            }
                            else if ((GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.LeftThumbstickUp) &&
                                      !_gamePadStatePrevious.IsButtonDown(Buttons.LeftThumbstickUp))
                                  || (GamePad.GetState(PlayerIndex.Two).IsButtonDown(Buttons.LeftThumbstickUp) &&
                                      !_gamePadStatePreviousP2.IsButtonDown(Buttons.LeftThumbstickUp)))
                            {
                                _menuOption--;
            #if (!XBOX360)
                                if (_menuOption == 1)
                                    _menuOption = 0;
            #endif
                                if (_menuOption < 0)
                                    _menuOption = 2;
                            }

                            if ((GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.A)
                                    && !_gamePadStatePrevious.IsButtonDown(Buttons.A))
                                || (GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.B)
                                    && !_gamePadStatePrevious.IsButtonDown(Buttons.B))
                                || (GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.X)
                                    && !_gamePadStatePrevious.IsButtonDown(Buttons.X))
                                || (GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.Y)
                                    && !_gamePadStatePrevious.IsButtonDown(Buttons.Y))
                                || (GamePad.GetState(PlayerIndex.Two).IsButtonDown(Buttons.A)
                                    && !_gamePadStatePreviousP2.IsButtonDown(Buttons.A))
                                || (GamePad.GetState(PlayerIndex.Two).IsButtonDown(Buttons.B)
                                    && !_gamePadStatePreviousP2.IsButtonDown(Buttons.B))
                                || (GamePad.GetState(PlayerIndex.Two).IsButtonDown(Buttons.X)
                                    && !_gamePadStatePreviousP2.IsButtonDown(Buttons.X))
                                || (GamePad.GetState(PlayerIndex.Two).IsButtonDown(Buttons.Y)
                                    && !_gamePadStatePreviousP2.IsButtonDown(Buttons.Y)))
                            {
                                if (_menuOption == 0)
                                {
            #if (XBOX360)
                                    if (_storageDevice != null)
                                    {
                                        MenuState = MenuState.NEW;
                                    }
            #else
                                    SaveGame saveGame = new SaveGame();
                                    saveGame.PlayerOne = new PlayerLoad();
                                    saveGame.PlayerOne.Position = new Vector2(-2, -6);
                                    saveGame.PlayerOne.NextScreen = new Vector2(6, 3);
                                    saveGame.PlayerTwo = new PlayerLoad();
                                    saveGame.PlayerTwo.Position = new Vector2(2, -6);
                                    saveGame.PlayerTwo.NextScreen = new Vector2(6, 3);
                                    saveGame.Health = 100;
                                    saveGame.PlayerOne.Collectables = Collectable.JUMP;
                                    saveGame.PlayerTwo.Collectables = Collectable.GRAB;
                                    CurrentSave = saveGame;

                                    _health = new Health();
                                    _health.MaxHealth = CurrentSave.Health;
                                    _health.CurrentHealth = CurrentSave.Health;

                                    _playerOne = new PlayerOne() { SaveGame = CurrentSave };
                                    _playerOne.Position = CurrentSave.PlayerOne.Position;
                                    _playerOne.NextScreen = CurrentSave.PlayerOne.NextScreen;
                                    _playerOne.Collectables = CurrentSave.PlayerOne.Collectables;
                                    _playerOne._content = Content;

                                    _playerTwo = new PlayerTwo() { SaveGame = CurrentSave };
                                    _playerTwo.Position = CurrentSave.PlayerTwo.Position;
                                    _playerTwo.NextScreen = CurrentSave.PlayerTwo.NextScreen;
                                    _playerTwo.Collectables = CurrentSave.PlayerTwo.Collectables;
                                    _playerTwo._content = Content;

                                    GameSwitches = CurrentSave.GameSwitches;

                                    UpdateGameSave();

                                    _playerOne.Create(_world);
                                    _playerTwo.Create(_world);

                                    _playerOne.SharedHealth = _health;
                                    _playerTwo.SharedHealth = _health;

                                    _playerOne._textures = _textures;
                                    _playerTwo._textures = _textures;
                                    GameState = GameState.PLAY;
            #endif

            #if (XBOX360)
            #endif

                                }
                                else if (_menuOption == 1)
                                {
            #if (XBOX360)
                                    if (_storageDevice != null)
                                    {
                                        MenuState = MenuState.LOAD;
                                    }
            #else
                                    MenuState = MenuState.LOAD;
            #endif
                                }
                                else
                                {
                                    // Instructions
                                    MenuState = MenuState.INSTRUCTIONS;
                                }
                            }
            #if (XBOX360)

                            //if (_storageWaiting && _storageResult.IsCompleted)
                            //{
                            //    _storageContainer = _storageDevice.EndOpenContainer(_storageResult);

                            //    Stream saveFile = _storageContainer.OpenFile(((int)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds).ToString() + ".xml", FileMode.Create);
                            //    SaveGame saveGame = new SaveGame();
                            //    saveGame.Health = 100;
                            //    saveGame.PlayerOne = new PlayerLoad();
                            //    saveGame.PlayerOne.NextScreen = new Vector2(6, 3);
                            //    saveGame.PlayerOne.Position = new Vector2(0, 0);
                            //    saveGame.PlayerTwo = new PlayerLoad();
                            //    saveGame.PlayerTwo.NextScreen = new Vector2(6, 3);
                            //    saveGame.PlayerTwo.Position = new Vector2(0, 0);
                            //    XmlSerializer xmlSerializer = new XmlSerializer(saveGame.GetType());
                            //    xmlSerializer.Serialize(saveFile, saveGame);
                            //    saveFile.Close();

                            //    _storageWaiting = false;
                            //    _storageContainer.Dispose();
                            //}
                            if (_storageDeviceWaiting && _storageResult.IsCompleted)
                            {
                                _storageDevice = StorageDevice.EndShowSelector(_storageResult);
                                if (_storageDevice != null && _storageDevice.IsConnected)
                                {
                                    _storageDeviceWaiting = false;
                                }
                            }

            #endif
                            break;
                        case MenuState.INSTRUCTIONS:
                            if ((!GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.Back)
                                    && _gamePadStatePrevious.IsButtonDown(Buttons.Back))
                                || (!GamePad.GetState(PlayerIndex.Two).IsButtonDown(Buttons.Back)
                                    && _gamePadStatePreviousP2.IsButtonDown(Buttons.Back)))
                            {
                                MenuState = MenuState.NEWLOAD;
                            }
                            break;
                        case MenuState.NEW:
            #if (XBOX360)
                            if (!_storageWaiting && (_storageContainer == null || _storageContainer.IsDisposed))
                            {
                                _storageResult = _storageDevice.BeginOpenContainer("Fariss_SaveData", null, null);
                                _storageWaiting = true;
                            }

                            if (_storageWaiting && _storageResult.IsCompleted)
                            {
                                _storageContainer = _storageDevice.EndOpenContainer(_storageResult);

                                Stream fileStream = _storageContainer.CreateFile(((int)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds).ToString() + ".xml");
                                SaveGame saveGame = new SaveGame();
                                saveGame.Health = 100;
                                saveGame.PlayerOne = new PlayerLoad();
                                saveGame.PlayerOne.NextScreen = new Vector2(6, 3);
                                saveGame.PlayerOne.Position = new Vector2(3, -6);
                                saveGame.PlayerOne.Collectables = Collectable.JUMP;
                                saveGame.PlayerTwo = new PlayerLoad();
                                saveGame.PlayerTwo.NextScreen = new Vector2(6, 3);
                                saveGame.PlayerTwo.Position = new Vector2(8, -6);
                                saveGame.PlayerTwo.Collectables = Collectable.GRAB;
                                XmlSerializer xmlSerializer = new XmlSerializer(saveGame.GetType());
                                xmlSerializer.Serialize(fileStream, saveGame);
                                fileStream.Close();

                                CurrentSave = saveGame;

                                _health = new Health();
                                _health.MaxHealth = CurrentSave.Health;
                                _health.CurrentHealth = CurrentSave.Health;

                                _playerOne = new PlayerOne() { SaveGame = CurrentSave };
                                _playerOne.Position = CurrentSave.PlayerOne.Position;
                                _playerOne.NextScreen = CurrentSave.PlayerOne.NextScreen;
                                _playerOne.Collectables = CurrentSave.PlayerOne.Collectables;
                                _playerOne._content = Content;

                                _playerTwo = new PlayerTwo() { SaveGame = CurrentSave };
                                _playerTwo.Position = CurrentSave.PlayerTwo.Position;
                                _playerTwo.NextScreen = CurrentSave.PlayerTwo.NextScreen;
                                _playerTwo.Collectables = CurrentSave.PlayerTwo.Collectables;
                                _playerTwo._content = Content;

                                GameSwitches = CurrentSave.GameSwitches;

                                UpdateGameSave();

                                _playerOne.Create(_world);
                                _playerTwo.Create(_world);

                                _playerOne.SharedHealth = _health;
                                _playerTwo.SharedHealth = _health;

                                _playerOne._textures = _textures;
                                _playerTwo._textures = _textures;

                                GameState = GameState.PLAY;

                                _storageContainer.Dispose();
                                _storageWaiting = false;
                            }
            #endif
                            break;
                        case MenuState.LOAD:

                            if (_saveFiles.Count <= 0 && !_noSaves)
                            {
                                _menuOption = 0;
            #if (XBOX360)
                                if (!_storageWaiting && (_storageContainer == null || _storageContainer.IsDisposed))
                                {
                                    _storageResult = _storageDevice.BeginOpenContainer("Fariss_SaveData", null, null);
                                    _storageWaiting = true;
                                }

                                if (_storageWaiting && _storageResult.IsCompleted)
                                {
                                    _storageContainer = _storageDevice.EndOpenContainer(_storageResult);

                                    string[] fileList = _storageContainer.GetFileNames("*.xml");
                                    if (fileList.Length <= 0)
                                    {
                                        _noSaves = true;
                                        break;
                                    }
                                    foreach (string fileName in fileList)
                                    {
                                        _saveFiles.Add(fileName);
                                    }

                                    _saveFiles.Sort();
                                    _saveFiles.Reverse();

                                    _storageWaiting = false;
                                }
            #else
                                //DirectoryInfo directoryInfo = new DirectoryInfo("SaveGames");
                                //FileInfo[] directoryFiles = directoryInfo.GetFiles("*.xml");
                                //foreach (FileInfo file in directoryFiles)
                                //{
                                //    saveFiles.Add(file);
                                //    Console.WriteLine(file.Name);
                                //}
            #endif
                            }
                            if ((GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.LeftThumbstickDown) &&
                                    !_gamePadStatePrevious.IsButtonDown(Buttons.LeftThumbstickDown))
                                || (GamePad.GetState(PlayerIndex.Two).IsButtonDown(Buttons.LeftThumbstickDown) &&
                                    !_gamePadStatePreviousP2.IsButtonDown(Buttons.LeftThumbstickDown)))
                            {
                                if (_menuOption + 1 < _saveFiles.Count)
                                    _menuOption++;
                            }
                            else if ((GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.LeftThumbstickUp) &&
                                      !_gamePadStatePrevious.IsButtonDown(Buttons.LeftThumbstickUp))
                                  || (GamePad.GetState(PlayerIndex.Two).IsButtonDown(Buttons.LeftThumbstickUp) &&
                                      !_gamePadStatePreviousP2.IsButtonDown(Buttons.LeftThumbstickUp)))
                            {
                                if (_menuOption > 0)
                                    _menuOption--;
                            }

                            if ((GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.A)
                                    && !_gamePadStatePrevious.IsButtonDown(Buttons.A))
                                || (GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.B)
                                    && !_gamePadStatePrevious.IsButtonDown(Buttons.B))
                                || (GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.X)
                                    && !_gamePadStatePrevious.IsButtonDown(Buttons.X))
                                || (GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.Y)
                                    && !_gamePadStatePrevious.IsButtonDown(Buttons.Y))
                                || (GamePad.GetState(PlayerIndex.Two).IsButtonDown(Buttons.A)
                                    && !_gamePadStatePreviousP2.IsButtonDown(Buttons.A))
                                || (GamePad.GetState(PlayerIndex.Two).IsButtonDown(Buttons.B)
                                    && !_gamePadStatePreviousP2.IsButtonDown(Buttons.B))
                                || (GamePad.GetState(PlayerIndex.Two).IsButtonDown(Buttons.X)
                                    && !_gamePadStatePreviousP2.IsButtonDown(Buttons.X))
                                || (GamePad.GetState(PlayerIndex.Two).IsButtonDown(Buttons.Y)
                                    && !_gamePadStatePreviousP2.IsButtonDown(Buttons.Y)))
                            {
                                // Load selected save file
            #if (XBOX360)
                                if (_saveFiles.Count > 0)
                                {
                                    if (_storageContainer != null)
                                    {
                                        Stream fileStream = _storageContainer.OpenFile(_saveFiles[_menuOption], FileMode.OpenOrCreate);
                                        SaveGame saveGame = new SaveGame();
                                        XmlSerializer xmlSerializer = new XmlSerializer(saveGame.GetType());
                                        saveGame = (SaveGame)xmlSerializer.Deserialize(fileStream);
                                        CurrentSave = saveGame;

                                        _health = new Health();
                                        _health.MaxHealth = CurrentSave.Health;
                                        _health.CurrentHealth = CurrentSave.Health;

                                        _playerOne = new PlayerOne() { SaveGame = CurrentSave };
                                        _playerOne.Position = CurrentSave.PlayerOne.Position;
                                        _playerOne.NextScreen = CurrentSave.PlayerOne.NextScreen;
                                        _playerOne.Collectables = CurrentSave.PlayerOne.Collectables;
                                        _playerOne._content = Content;

                                        _playerTwo = new PlayerTwo() { SaveGame = CurrentSave };
                                        _playerTwo.Position = CurrentSave.PlayerTwo.Position;
                                        _playerTwo.NextScreen = CurrentSave.PlayerTwo.NextScreen;
                                        _playerTwo.Collectables = CurrentSave.PlayerTwo.Collectables;
                                        _playerTwo._content = Content;

                                        GameSwitches = CurrentSave.GameSwitches;
                                        CurrentSave.CurrentGameSwitches = CurrentSave.GameSwitches;

                                        _playerOne.Create(_world);
                                        _playerTwo.Create(_world);

                                        _playerOne.SharedHealth = _health;
                                        _playerTwo.SharedHealth = _health;

                                        _playerOne._textures = _textures;
                                        _playerTwo._textures = _textures;

                                        UpdateGameSave();

                                        _storageContainer.Dispose();
                                        GameState = GameState.PLAY;
                                        _saveFiles.Clear();
                                    }
                                }
            #endif

                            }
                            // Exit
                            if ((!GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.Back)
                                    && _gamePadStatePrevious.IsButtonDown(Buttons.Back))
                                || (!GamePad.GetState(PlayerIndex.Two).IsButtonDown(Buttons.Back)
                                    && _gamePadStatePreviousP2.IsButtonDown(Buttons.Back)))
                            {
            #if (XBOX360)
                                _storageDeviceWaiting = false;
                                _storageWaiting = false;
                                _noSaves = false;
                                _saveFiles.Clear();
                                if (_storageContainer != null && !_storageContainer.IsDisposed)
                                    _storageContainer.Dispose();
            #endif
                                MenuState = MenuState.NEWLOAD;
                            }
                            break;
                        case MenuState.GAMEOVER:
                            UnloadLevel((int)_playerOne.NextScreen.X, (int)_playerOne.NextScreen.Y);
                            UnloadLevel((int)_playerTwo.NextScreen.X, (int)_playerTwo.NextScreen.Y);
                            _playerOne.Dispose();
                            _playerTwo.Dispose();
                            if (_gameInitialOverTimer <= 2000)
                            {
                                _gameInitialOverTimer += gameTime.ElapsedGameTime.TotalMilliseconds;
                            }
                            if (_gameInitialOverTimer > 2000)
                            {
                                _gameOverTimer += gameTime.ElapsedGameTime.TotalMilliseconds;
                                if (_gameOverTimer > 100)
                                {
                                    _gameOverTimer = 0;
                                    _gameOverColour = new Color(255, 255, 255, _gameOverColour.A - 25);
                                }
                                if (_gameOverColour.A == 0)
                                {
                                    _gameOverColour = Color.White;
                                    _gameOverTimer = 0;
                                    MenuState = MenuState.MAIN;
                                }
                            }
                            break;
                        default:
                            break;
                    }
                    break;
                case GameState.PLAY:
                    if ((CurrentSave.CurrentGameSwitches & GameSwitches.GOT_COG) == GameSwitches.GOT_COG
                        && (CurrentSave.CurrentGameSwitches & GameSwitches.GOT_BLOB) == GameSwitches.GOT_BLOB
                        && (CurrentSave.CurrentGameSwitches & GameSwitches.GOT_POWER_CELL) == GameSwitches.GOT_POWER_CELL)
                    {
                        UnloadLevel((int)_playerOne.NextScreen.X, (int)_playerOne.NextScreen.Y);
                        UnloadLevel((int)_playerTwo.NextScreen.X, (int)_playerTwo.NextScreen.Y);
                        GameState = GameState.MAINMENU;
                        MenuState = MenuState.GAMEOVER;
                    }
            #if (XBOX360)
                    if (_trySave && _storageResult != null && _storageResult.IsCompleted)
                    {
                        _trySave = false;

                        _storageContainer = _storageDevice.EndOpenContainer(_storageResult);
                        CurrentSave.GameSwitches = CurrentSave.CurrentGameSwitches;
                        CurrentSave.PlayerOne.Position = _playerOne.Position;
                        CurrentSave.PlayerOne.NextScreen = _playerOne.NextScreen;
                        CurrentSave.PlayerOne.Collectables = _playerOne.Collectables;
                        CurrentSave.PlayerTwo.Position = _playerTwo.Position;
                        CurrentSave.PlayerTwo.NextScreen = _playerTwo.NextScreen;
                        CurrentSave.PlayerTwo.Collectables = _playerTwo.Collectables;
                        CurrentSave.Health = _playerOne.SharedHealth.MaxHealth;

                        Stream stream = _storageContainer.CreateFile(((int)(DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds).ToString() + ".xml");
                        XmlSerializer xmlSerializer = new XmlSerializer(CurrentSave.GetType());
                        xmlSerializer.Serialize(stream, CurrentSave);
                        _storageContainer.Dispose();
                    }
                    if (!_trySave
                        && GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.Y) && _playerOne.SavePointContact
                        && GamePad.GetState(PlayerIndex.Two).IsButtonDown(Buttons.Y) && _playerTwo.SavePointContact)
                    {
                        _trySave = true;
                        _storageResult = _storageDevice.BeginOpenContainer("Fariss_SaveData", null, null);
                    }
            #endif

                    // If both players are holding back, increment counter
                    if (GamePad.GetState(PlayerIndex.One).IsButtonDown(Buttons.Back) && GamePad.GetState(PlayerIndex.Two).IsButtonDown(Buttons.Back))
                    {
                        _backCounter += gameTime.ElapsedGameTime.TotalMilliseconds;
                    }
                    else
                    {
                        _backCounter = 0;
                    }

                    if (_backCounter > 500)
                    {
                        _playerOne.Dispose();
                        _playerTwo.Dispose();
                        UnloadLevel((int)_playerOne.NextScreen.X, (int)_playerOne.NextScreen.Y);
                        UnloadLevel((int)_playerTwo.NextScreen.X, (int)_playerTwo.NextScreen.Y);
                        GameState = GameState.MAINMENU;
                        MenuState = MenuState.MAIN;
                    }

                    // Check players haven't gameovered
                    if (_health.CurrentHealth <= 0)
                    {
                        UnloadLevel((int)_playerOne.NextScreen.X, (int)_playerOne.NextScreen.Y);
                        UnloadLevel((int)_playerTwo.NextScreen.X, (int)_playerTwo.NextScreen.Y);
                        GameState = GameState.MAINMENU;
                        MenuState = MenuState.GAMEOVER;
                    }
                    // Check player hasn't gone off screen and stuff
                    UpdatePlayerScreen(_playerOne, _playerTwo);
                    UpdatePlayerScreen(_playerTwo, _playerOne);

                    // If both players are transitioning to new screens
                    if (_playerOne.NextScreen != _playerOne.CurrentScreen && _playerTwo.NextScreen != _playerTwo.CurrentScreen)
                    {
                        _playerOne.HeldObject = null;
                        _playerTwo.HeldObject = null;
                        // If both are transitioning to the same screen
                        if (_playerOne.NextScreen == _playerTwo.NextScreen)
                        {
                            // Then use virtual screen one
                            if (_playerOne.VirtualScreen == VirtualScreen.TWO)
                                _playerOne.X -= _blockScreenSize.X * 2;
                            if (_playerTwo.VirtualScreen == VirtualScreen.TWO)
                                _playerTwo.X -= _blockScreenSize.X * 2;
                            _playerOne.VirtualScreen = VirtualScreen.ONE;
                            _playerTwo.VirtualScreen = VirtualScreen.ONE;
                            UnloadLevel((int)_playerOne.CurrentScreen.X, (int)_playerOne.CurrentScreen.Y);
                            UnloadLevel((int)_playerTwo.CurrentScreen.X, (int)_playerTwo.CurrentScreen.Y);
                            LoadLevel((int)_playerOne.NextScreen.X, (int)_playerOne.NextScreen.Y, 0);
                        }
                        // If they're transitioning to different screens
                        else
                        {
                            if (_playerOne.VirtualScreen == VirtualScreen.TWO)
                                _playerOne.X -= _blockScreenSize.X * 2;
                            if (_playerTwo.VirtualScreen == VirtualScreen.ONE)
                                _playerTwo.X += _blockScreenSize.X * 2;
                            _playerOne.VirtualScreen = VirtualScreen.ONE;
                            _playerTwo.VirtualScreen = VirtualScreen.TWO;
                            UnloadLevel((int)_playerOne.CurrentScreen.X, (int)_playerOne.CurrentScreen.Y);
                            UnloadLevel((int)_playerTwo.CurrentScreen.X, (int)_playerTwo.CurrentScreen.Y);
                            LoadLevel((int)_playerOne.NextScreen.X, (int)_playerOne.NextScreen.Y, 0);
                            LoadLevel((int)_playerTwo.NextScreen.X, (int)_playerTwo.NextScreen.Y, _blockScreenSize.X * 2.0f);
                        }
                    }
                    // If just one of them is
                    else if (_playerOne.NextScreen != _playerOne.CurrentScreen || _playerTwo.NextScreen != _playerTwo.CurrentScreen)
                    {
                        // If it's player one
                        if (_playerOne.NextScreen != _playerOne.CurrentScreen)
                        {
                            _playerOne.HeldObject = null;
                            // If they're moving to the same screen as player two
                            if (_playerOne.NextScreen == _playerTwo.CurrentScreen)
                            {
                                if (_playerOne.VirtualScreen == VirtualScreen.TWO && _playerTwo.VirtualScreen == VirtualScreen.ONE)
                                    _playerOne.X -= _blockScreenSize.X * 2;
                                else if (_playerOne.VirtualScreen == VirtualScreen.ONE && _playerTwo.VirtualScreen == VirtualScreen.TWO)
                                    _playerOne.X += _blockScreenSize.X * 2;
                                _playerOne.VirtualScreen = _playerTwo.VirtualScreen;
                                UnloadLevel((int)_playerOne.CurrentScreen.X, (int)_playerOne.CurrentScreen.Y);
                            }
                            // Otherwise if player two is on virtual screen one
                            else if (_playerTwo.VirtualScreen == VirtualScreen.ONE)
                            {
                                // Load level on virtual screen 2
                                if (_playerOne.VirtualScreen == VirtualScreen.ONE)
                                    _playerOne.X += _blockScreenSize.X * 2;
                                _playerOne.VirtualScreen = VirtualScreen.TWO;
                                LoadLevel((int)_playerOne.NextScreen.X, (int)_playerOne.NextScreen.Y, _blockScreenSize.X * 2);
                                if (_playerOne.CurrentScreen != _playerTwo.CurrentScreen)
                                    UnloadLevel((int)_playerOne.CurrentScreen.X, (int)_playerOne.CurrentScreen.Y);
                            }
                            else
                            {
                                // Load level on virtual screen 1
                                if (_playerOne.VirtualScreen == VirtualScreen.TWO)
                                    _playerOne.X -= _blockScreenSize.X * 2;
                                _playerOne.VirtualScreen = VirtualScreen.ONE;
                                LoadLevel((int)_playerOne.NextScreen.X, (int)_playerOne.NextScreen.Y, 0);
                                if (_playerOne.CurrentScreen != _playerTwo.CurrentScreen)
                                    UnloadLevel((int)_playerOne.CurrentScreen.X, (int)_playerOne.CurrentScreen.Y);
                            }
                        }
                        // Otherwise if it's player 2
                        else
                        {
                            _playerTwo.HeldObject = null;
                            // If they're moving to the same screen as player one
                            if (_playerTwo.NextScreen == _playerOne.CurrentScreen)
                            {
                                if (_playerTwo.VirtualScreen == VirtualScreen.TWO && _playerOne.VirtualScreen == VirtualScreen.ONE)
                                    _playerTwo.X -= _blockScreenSize.X * 2;
                                else if (_playerTwo.VirtualScreen == VirtualScreen.ONE && _playerOne.VirtualScreen == VirtualScreen.TWO)
                                    _playerTwo.X += _blockScreenSize.X * 2;
                                _playerTwo.VirtualScreen = _playerOne.VirtualScreen;
                                UnloadLevel((int)_playerTwo.CurrentScreen.X, (int)_playerTwo.CurrentScreen.Y);
                            }
                            // Otherwise if player one is on virtual screen one
                            else if (_playerOne.VirtualScreen == VirtualScreen.ONE)
                            {
                                // Load level on virtual screen 2
                                if (_playerTwo.VirtualScreen == VirtualScreen.ONE)
                                    _playerTwo.X += _blockScreenSize.X * 2;
                                _playerTwo.VirtualScreen = VirtualScreen.TWO;
                                LoadLevel((int)_playerTwo.NextScreen.X, (int)_playerTwo.NextScreen.Y, _blockScreenSize.X * 2);
                                if (_playerTwo.CurrentScreen != _playerOne.CurrentScreen)
                                    UnloadLevel((int)_playerTwo.CurrentScreen.X, (int)_playerTwo.CurrentScreen.Y);
                            }
                            else
                            {
                                // Load level on virtual screen 1
                                if (_playerTwo.VirtualScreen == VirtualScreen.TWO)
                                    _playerTwo.X -= _blockScreenSize.X * 2;
                                _playerTwo.VirtualScreen = VirtualScreen.ONE;
                                LoadLevel((int)_playerTwo.NextScreen.X, (int)_playerTwo.NextScreen.Y, 0);
                                if (_playerTwo.CurrentScreen != _playerOne.CurrentScreen)
                                    UnloadLevel((int)_playerTwo.CurrentScreen.X, (int)_playerTwo.CurrentScreen.Y);
                            }
                        }
                    }
                    _playerOne.CurrentScreen = _playerOne.NextScreen;
                    _playerTwo.CurrentScreen = _playerTwo.NextScreen;

                    _playerOneLevel = _levels[(int)_playerOne.CurrentScreen.X, (int)_playerOne.CurrentScreen.Y];
                    _playerTwoLevel = _levels[(int)_playerTwo.CurrentScreen.X, (int)_playerTwo.CurrentScreen.Y];

            #if (DEBUG)
                    if (GamePad.GetState(PlayerIndex.One).Buttons.B == ButtonState.Released && _gamePadStatePrevious.Buttons.B == ButtonState.Pressed)
                        _debugViewVisible = !_debugViewVisible;
            #endif

                    _playerOne.Update(gameTime);
                    _playerTwo.Update(gameTime);
                    UpdateView(_playerOne, _playerTwo);

                    _playerOneLevel.Update(gameTime);
                    if (_playerOne.CurrentScreen != _playerTwo.CurrentScreen)
                        _playerTwoLevel.Update(gameTime);

                    _world.Step((float)gameTime.ElapsedGameTime.TotalMilliseconds * 0.001f);

                    break;
                default:
                    this.Exit();
                    break;
            }

            _mouseStatePrevious = Mouse.GetState();
            _gamePadStatePrevious = GamePad.GetState(PlayerIndex.One);
            _gamePadStatePreviousP2 = GamePad.GetState(PlayerIndex.Two);

            base.Update(gameTime);
        }
Example #3
0
 private void MenuGoToHighscoreMenu(object aSender, EventArgs aEventArgs)
 {
     MenuState = MenuState.Highscore;
 }
Example #4
0
 private void InitializeNonParameterMemberVariables()
 {
     MenuState = MenuState.Main;
 }
Example #5
0
 private void MenuGoToMenu(object aSender, EventArgs aEventArgs)
 {
     MenuState = MenuState.Main;
 }