Пример #1
0
        /// <summary>
        /// Changed the current player on screen to the next one in the list
        /// </summary>
        private void ChangePlayer()
        {
            if (_currentPlayerIndex >= 3)
            {
                _currentPlayerIndex = 0;
            }
            else
            {
                _currentPlayerIndex++;
            }
            var currentPos = WorldPlayer.Position;
            var health     = WorldPlayer.Health;
            var currDir    = WorldPlayer.CurrentDirection;
            var isFalling  = WorldPlayer.IsFalling;

            WorldPlayer.RemoveControls();
            WorldPlayer.ChangePlayer = false;
            WorldPlayer.ShotsFired   = new List <Shot>();
            WorldPlayer           = _players[_currentPlayerIndex];
            WorldPlayer.IsFalling = isFalling;
            WorldPlayer.Health    = health;
            WorldPlayer.SetPosition(currentPos);
            WorldPlayer.SetDirection(currDir);
            WorldPlayer.AddControls();
            WorldPlayer.SetWaitToMax();
        }
Пример #2
0
 /// <summary>
 /// Reset the game world scene
 /// </summary>
 /// <param name="numOfLives">The number of lives remaining</param>
 /// <param name="spawnEnemies">Do the enemies need to be respawned</param>
 private void Reset(int numOfLives, bool spawnEnemies)
 {
     NumberOfPlayerLives = numOfLives;
     WorldPlayer.Health  = 100;
     WorldPlayer.SetPosition(WorldMap.PlayerInitialPosition);
     if (spawnEnemies)
     {
         EnemiesOnMap = SpawnEnemies();
     }
     _displayLives       = true;
     _dispControllerTime = true;
 }
Пример #3
0
 /// <summary>
 /// Load the new map and map assets
 /// </summary>
 private void LoadNewMap()
 {
     try
     {
         WorldMap = AssetManager.LoadGameMap(CurrentMap, _worldView);
         WorldPlayer.SetPosition(WorldMap.PlayerInitialPosition);
         EnemiesOnMap = SpawnEnemies();
         NpCsOnMap    = SpawnNpcs();
         if (InitLoadText == null)
         {
             var font = AssetManager.LoadFont("OrangeJuice");
             InitLoadText = new Text()
             {
                 Position = new Vector2f(0, 0), DisplayedString = AssetManager.GetMessage(WorldMap.Name), Color = Color.Black, Font = font, CharacterSize = 60
             };
         }
         else
         {
             InitLoadText.DisplayedString = AssetManager.GetMessage(WorldMap.Name);
         }
         IsInitialMapLoad = true;
         _localPause      = false;
         _loading         = false;
         _madeItToEnd     = false;
         _displayLives    = true;
         WorldPlayer.AddControls();
     }
     catch (Exception ex)
     {
         LogManager.LogError("Failed to load new map. Error mess:\n" + ex.Message);
     }
     finally
     {
         LogManager.Log("New Map Loaded!");
     }
 }
Пример #4
0
        /// <summary>
        /// Load the game from a save file
        /// </summary>
        /// <param name="currentMap">The map to load</param>
        /// <param name="score">The saved score</param>
        /// <param name="lives">The remaining number of player lives</param>
        /// <param name="player">The player last drawn on the map</param>
        /// <param name="ene">The remaining enemies on the map</param>
        /// <param name="items">The remaining items on the map</param>
        public void LoadGame(int currentMap, long score, int lives, XElement player, XElement[] ene, XElement[] items)
        {
            WorldMap            = AssetManager.LoadGameMap(currentMap, _worldView);
            Score               = score;
            NumberOfPlayerLives = lives;
            var playerAttr = player.Attributes().ToDictionary(attr => attr.Name.LocalName, attr => attr.Value);

            string[] playerName = new string[4];
            switch (playerAttr["name"])
            {
            case "Mack":
                playerName[0] = "Mack";
                playerName[1] = "Sergi";
                playerName[2] = "Trent";
                playerName[3] = "Jaun";
                break;

            case "Sergi":
                playerName[0] = "Sergi";
                playerName[1] = "Trent";
                playerName[2] = "Jaun";
                playerName[3] = "Mack";
                break;

            case "Trent":
                playerName[0] = "Trent";
                playerName[1] = "Jaun";
                playerName[2] = "Mack";
                playerName[3] = "Sergi";
                break;

            case "Juan":
                playerName[0] = "Jaun";
                playerName[1] = "Mack";
                playerName[2] = "Sergi";
                playerName[3] = "Trent";
                break;
            }
            _players = new[]
            {
                AssetManager.LoadPlayer(playerName[0], WinInstance),
                AssetManager.LoadPlayer(playerName[1], WinInstance),
                AssetManager.LoadPlayer(playerName[2], WinInstance),
                AssetManager.LoadPlayer(playerName[3], WinInstance)
            };
            for (var i = 1; i < _players.Length; i++)
            {
                _players[i].RemoveControls();
                _players[i].ResetWaitTime();
                switch (_players[i].Name)
                {
                case "Mack":
                    _players[i].EnemyICanAttack = Enemy.EnemyType.Nurse;
                    break;

                case "Sergi":
                    _players[i].EnemyICanAttack = Enemy.EnemyType.Teenager;
                    break;

                case "Trent":
                    _players[i].EnemyICanAttack = Enemy.EnemyType.FuneralHomeDirector;
                    break;

                case "Jaun":
                    _players[i].EnemyICanAttack = Enemy.EnemyType.GrimReeper;
                    break;
                }
            }
            WorldPlayer        = _players[0];
            WorldPlayer.Health = float.Parse(playerAttr["health"]);
            WorldPlayer.SetDirection(Direction.Right);
            var pos = playerAttr["position"].Split(',');

            WorldPlayer.SetPosition(new Vector2f(float.Parse(pos[0]), float.Parse(pos[1])));
            if (ene.Length > 0)
            {
                foreach (var enemy in WorldMap.EnemySpawns)
                {
                    foreach (var eneXml in ene)
                    {
                        var enePos   = eneXml.FirstAttribute.Value.Split(',');
                        var floatPos = new[] { float.Parse(enePos[0]), float.Parse(enePos[1]) };
                        if (Math.Abs(enemy.Position.X - floatPos[0]) > 0.0001f && Math.Abs(enemy.Position.Y - floatPos[1]) > 0.0001f)
                        {
                            WorldMap.EnemySpawns.Remove(enemy);
                        }
                    }
                }
                EnemiesOnMap = SpawnEnemies();
            }
            else if (ene.Length == 0)
            {
                EnemiesOnMap = new List <Enemy>();
            }
            if (items.Length > 0)
            {
                foreach (var item in WorldMap.ItemsOnMap)
                {
                    foreach (var itemXml in items)
                    {
                        var itemPos  = itemXml.FirstAttribute.Value.Split(',');
                        var floatPos = new[] { float.Parse(itemPos[0]), float.Parse(itemPos[1]) };
                        if (Math.Abs(item.Position.X - floatPos[0]) > 0.0001f && Math.Abs(item.Position.Y - floatPos[1]) > 0.0001f && item.Name.Equals(itemXml.LastAttribute.Value))
                        {
                            WorldMap.ItemsOnMap.Remove(item);
                        }
                    }
                }
            }
            else if (items.Length == 0)
            {
                WorldMap.ItemsOnMap = new List <MapItem>();
            }
            _worldView.Center = WorldPlayer.Position;
            BgColor           = WorldMap.BgColor;
            NpCsOnMap         = SpawnNpcs();
            var win = WinInstance;

            _healthBar = new HealthBar(ref win, WorldPlayer.Position);
            _scoreDisp = new ScoreDisplay(ref win, WorldPlayer.Position);
            var font = AssetManager.LoadFont("OrangeJuice");

            InitLoadText = new Text()
            {
                Position = new Vector2f(0, 0), DisplayedString = AssetManager.GetMessage(WorldMap.Name), Color = Color.Black, Font = font, CharacterSize = 60
            };
            IsInitialMapLoad = true;
            WorldPlayer.ResetWaitTime();
            foreach (var enemy in EnemiesOnMap)
            {
                enemy.ResetWaitTime();
            }
            StartWorld();
            GameMaster.IsMainMenuOpen = false;
            _displayLives             = true;
            _dispControllerTime       = true;
        }
Пример #5
0
        /// <summary>
        /// Setup a new game enviroment
        /// </summary>
        /// <param name="playerName">The player to load</param>
        public void NewGame(string[] playerName)
        {
            CurrentMap = 0;
            WorldMap   = AssetManager.LoadGameMap(CurrentMap, _worldView);
            _players   = new[]
            {
                AssetManager.LoadPlayer(playerName[0], WinInstance),
                AssetManager.LoadPlayer(playerName[1], WinInstance),
                AssetManager.LoadPlayer(playerName[2], WinInstance),
                AssetManager.LoadPlayer(playerName[3], WinInstance)
            };

            for (var i = 1; i < _players.Length; i++)
            {
                if (_players[i] == null)
                {
                    continue;
                }
                _players[i].RemoveControls();
                _players[i].ResetWaitTime();
                switch (_players[i].Name)
                {
                case "Mack":
                    _players[i].EnemyICanAttack = Enemy.EnemyType.Nurse;
                    break;

                case "Sergi":
                    _players[i].EnemyICanAttack = Enemy.EnemyType.FuneralHomeDirector;
                    break;

                case "Trent":
                    _players[i].EnemyICanAttack = Enemy.EnemyType.GrimReeper;
                    break;

                case "Jaun":
                    _players[i].EnemyICanAttack = Enemy.EnemyType.Teenager;
                    break;
                }
            }
            WorldPlayer = _players[0];
            WorldPlayer.SetPosition(WorldMap.PlayerInitialPosition);
            EnemiesOnMap      = SpawnEnemies();
            NpCsOnMap         = SpawnNpcs();
            _worldView.Center = WorldPlayer.Position;
            BgColor           = WorldMap.BgColor;
            StartWorld();
            var win = WinInstance;

            _healthBar = new HealthBar(ref win, WorldPlayer.Position);
            _scoreDisp = new ScoreDisplay(ref win, WorldPlayer.Position);
            var font = AssetManager.LoadFont("OrangeJuice");

            InitLoadText = new Text()
            {
                Position = new Vector2f(0, 0), DisplayedString = AssetManager.GetMessage(WorldMap.Name), Color = Color.Black, Font = font, CharacterSize = 60
            };
            IsInitialMapLoad = true;
            WorldPlayer.ResetWaitTime();
            foreach (var enemy in EnemiesOnMap)
            {
                enemy.ResetWaitTime();
            }
            _displayLives       = true;
            _dispControllerTime = true;
        }