Beispiel #1
0
        /// <summary>
        /// Constructs a new Enemy.
        /// </summary>
        public Enemy(Level level, Vector2 position, string spriteSet)
        {
            this.level = level;
            this.position = position;

            LoadContent(spriteSet);
        }
        public WinnerTile(Level level, Vector2 position)
        {
            this.level = level;
            this.position = position;

            LoadContent();
        }
Beispiel #3
0
        /// <summary>
        /// Constructs a new gem.
        /// </summary>
        public Gem(Level level, Vector2 position)
        {
            this.level = level;
            this.basePosition = position;

            LoadContent();
        }
Beispiel #4
0
        /// <summary>
        /// Constructs a new Corpse.
        /// </summary>
        public Corpse(Level level, Vector2 position, string textureFile)
        {
            this.level = level;
            this.basePosition = position;

            LoadContent(textureFile);
        }
 public MovableTile(Level level, Vector2 position, TileCollision collision)
 {
     this.level = level;
     this.position = position;
     this.collision = collision;
     LoadContent();
 }
Beispiel #6
0
        /// <summary>
        /// Constructs a new Spike
        /// </summary>
        public Spike(Level level, Vector2 position)
        {
            this.level = level;
            this.position = position;

            LoadContent();
        }
Beispiel #7
0
        /// <summary>
        /// Constructors a new player.
        /// </summary>
        public Player(Level level, Vector2 position)
        {
            this.level = level;

            LoadContent();

            Reset(position);
        }
Beispiel #8
0
 public Enemy(Level level, Vector2 position, string spriteSet)
 {
     Level = level;
     Position = position;
     IsAlive = true;
     sprite = new AnimationPlayer();
     LoadContent(spriteSet);
 }
Beispiel #9
0
        /// <summary>
        /// Constructs a new Enemy.
        /// </summary>
        public Enemy(Level level, Vector2 position, string spriteSet)
        {
            this.level = level;
            this.position = position;
            // Set the enemy to be alive as well
            this.alive = true;

            LoadContent(spriteSet);
        }
Beispiel #10
0
        /// <summary>
        /// Constructs a new Enemy.
        /// </summary>
        public Bowser(Level level, Vector2 position, string spriteSet)
            : base(level, position, spriteSet)
        {
            State = EntityState.IDLE;
            velocity = Vector2.Zero;
            IsAlive = true;

            for (int i = 0; i < MAX_FIRE; i++)
            {
                _bullets.Add(new BowserFire(level.Game, position));
            }
        }
Beispiel #11
0
        public Gem(Level level, Vector2 position, bool isPowerUp)
        {
            IsPowerUp = isPowerUp;
            Level = level;
            this.basePosition = position;

            if (IsPowerUp)
            {
                PointValue = 100;
                Color = Color.Red;
            }
            else
            {
                PointValue = 30;
                Color = Color.Yellow;
            }

            LoadContent();
        }
        private void LoadNextLevel()
        {
            heart.Pause();
            victoryMusic.Pause();
            rock.Pause();
            /*levelIndex = (levelIndex + 1) % numberOfLevels;
            if (currentLevel == 0)
            {
                using (Stream fileStream = TitleContainer.OpenStream("Content/Levels/0.txt"))
                    level = new Level(Services, fileStream, levelIndex);
            }
            else if (currentLevel == 1)
            {
                using (Stream fileStream = TitleContainer.OpenStream("Content/Levels/1.txt"))
                    level = new Level(Services, fileStream, levelIndex);
            }
            else if (currentLevel == 2)
            {
                using (Stream fileStream = TitleContainer.OpenStream("Content/Levels/2.txt"))
                    level = new Level(Services, fileStream, levelIndex);
            }
            else if (currentLevel == 3)
            {
                using (Stream fileStream = TitleContainer.OpenStream("Content/Levels/3.txt"))
                    level = new Level(Services, fileStream, levelIndex);
            }*/
            // move to the next level
            if (levelIndex == 5)
                levelIndex = 0;
            else
                levelIndex = (levelIndex + 1) % numberOfLevels;

            // Unloads the content for the current level before loading the next one.
            if (level != null)
                level.Dispose();

            // Load the level.
            if (levelIndex != 5)
            {
                heart.Play();
                rock.Play();
            }
            else
            {
                victoryMusic.Play();
            }
            string levelPath = string.Format("Content/Levels/{0}.txt", levelIndex); //"Content/Levels/" + currentLevel + ".txt";//
            //string levelPath = "Content/Levels/5.txt";
            using (Stream fileStream = TitleContainer.OpenStream(levelPath))
                level = new Level(Services, fileStream, levelIndex);
        }
Beispiel #13
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);
        }
 private void LoadNextLevel()
 {
     // move to the next level
     levelIndex = (levelIndex + 1);
     if (levelIndex < numberOfLevels)
     {
         // Unloads the content for the current level before loading the next one.
         if (level != null)
             level.Dispose();
         scoreTillLastLevel = GlobalContext.totalScore;
         // Load the level.
         string levelPath = string.Format("Content/{0}.txt", levelIndex);
         using (Stream fileStream = TitleContainer.OpenStream(levelPath))
             level = new Level(contentManager, fileStream, levelIndex);
     }
     else
     {
         btnContinue.Visibility = Visibility.Collapsed;
         tblCongratsMessage.Visibility = Visibility.Visible;
         //TODO:Game Over and submit the score.
     }
 }
Beispiel #15
0
        private void LoadNextLevel()
        {
            // move to the next level
            levelIndex = (levelIndex + 1) % numberOfLevels;

            // Unloads the content for the current level before loading the next one.
            if (level != null)
                level.Dispose();

            // Load the level.
            string levelPath = string.Format("Content/Levels/{0}.txt", levelIndex);
            using (Stream fileStream = TitleContainer.OpenStream(levelPath))
                level = new Level(Services, fileStream, levelIndex);
        }
 public void LoadNextLevel(int number)
 {
     levelIndex = 0;
     currentLevel = 0;
     level.Dispose();
     string levelPath = string.Format("Content/Levels/0.txt");
     using (Stream fileStream = TitleContainer.OpenStream(levelPath))
         level = new Level(Services, fileStream, levelIndex);
 }
Beispiel #17
0
        /// <summary>
        /// Constructors a new player.
        /// </summary>
        public Player(Level level, Vector2 position)
        {
            this.level = level;
            Stress = new StressOMeter();
            LoadContent();

            Reset(position);
        }
Beispiel #18
0
 public Camera2d(Level level, float pos)
 {
     this.level = level;
     this.cameraPosition = pos;
 }
        private void LoadNextLevel()
        {
            // move to the next level
            levelIndex = (levelIndex + 1) % levelsData.Count;

            // Unloads the content for the current level before loading the next one.
            if (currentLevel != null)
                currentLevel.Dispose();

            // Load the level.
            currentLevel = new Level(Services, levelsData[levelIndex]);
        }
Beispiel #20
0
        /// <summary>
        /// Constructors a new player.
        /// </summary>
        public Player(Level level, Vector2 start, ReplayData replay)
        {
            this.replayData = new ReplayData();

            int positionsToCreate = (replay == null ? 0 : replay.StreamCount);

            this.ghostData = replay;
            for (int i = 0; i <= positionsToCreate; i++)
            {
                this.sprites.Add(new AnimationPlayer());
                this.playerPositions.Add(Vector2.Zero);
                this.playerVelocities.Add(Vector2.Zero);
                this.isOnGround.Add(true);
                this.previousBottom.Add(0.0f);
                this.jumpTime.Add(0.0f);
                this.isJumping.Add(false);
                this.wasJumping.Add(false);
                this.movement.Add(0.0f);
                this.flips.Add(true);
                this.playerStates.Add(PlayerState.Alive);
            }

            this.level = level;

            LoadContent();

            Reset(null, start);
        }
Beispiel #21
0
		private void LoadNextLevel()
		{
			// Find the path of the next level.
			string levelPath;

			// Loop here so we can try again when we can't find a level.
			while (true)
			{
				// Try to find the next level. They are sequentially numbered txt files.
				levelPath = String.Format("Levels/{0}.txt", ++levelIndex);
				levelPath = Path.Combine(StorageContainer.TitleLocation, "Content/" + levelPath);
					break;

				// If there isn't even a level 0, something has gone wrong.
				if (levelIndex == 0)
					throw new Exception("No levels found.");

				// Whenever we can't find a level, start over again at 0.
				break;
			}

			// Unloads the content for the current level before loading the next one.
			if (level != null)
				level.Dispose();

			// Load the level.
			level = new Level(Services, levelPath);
		}