This is a game component that implements IUpdateable.
Inheritance: Monster
Beispiel #1
0
        // --- Private methods ---
        private void AddEnemy()
        {
            var random = new Random();
            Monster enemy;
            Vector3 newPosition;
            var i = 0;
            do
            {
                if (i++ > 100) return; // try 100 times before giving up
                newPosition = Hero.Position;
                if (random.NextDouble() > 0.5)
                {
                    newPosition += Vector3.UnitZ * ((float)random.NextDouble() * 2 + (random.NextDouble() > 0.5 ? 3 : -5));
                    newPosition += Vector3.UnitX * ((float) random.NextDouble()*10 - 5);
                } else
                {
                    newPosition += Vector3.UnitZ * ((float) random.NextDouble()*10 - 5);
                    newPosition += Vector3.UnitX * ((float)random.NextDouble() * 2 + (random.NextDouble() > 0.5 ? 3 : -5));
                }
                enemy = new WeakSkeleton(_game, this, newPosition);
            } while (!enemy.isValidPositionToMoveTo(newPosition.X, newPosition.Z));

            monsters.Add(enemy);
            _game.Components.Add(enemy);
        }
        private void UnserializeMonsters(List<MonsterData> newMonstersData)
        {
            // delete current monsters
            foreach (var monster in _inGame.monsters)
            {
                _inGame._game.Components.Remove(monster);
            }

            var newMonsters = new List<Creature>();
            foreach (var monsterData in newMonstersData)
            {
                Monster monster;
                if (monsterData.type == "Swordening.WeakSkeleton")
                {
                    monster = new WeakSkeleton(_inGame._game, _inGame, monsterData.Position);
                } else continue;
                newMonsters.Add(monster);
                _inGame._game.Components.Add(monster);
            }
            _inGame.monsters = newMonsters;
        }