예제 #1
0
        public void Update(TimeSpan elapsed)
        {
            //On modifie le nombre de zombies en fonction du moment de la journée
            var period = World.World.Instance.DayLight.GetDayPeriod();
            if (period == World.DayPeriod.Night)
            {
                m_ennemiesCount = m_ennemiesCountInitial * 10;
            }
            else
            {
                m_ennemiesCount = m_ennemiesCountInitial;
            }

            var size = Engine.Display.GetSize();
            var player = World.World.Instance.Player;
            var vecteur = player.Location.Position + size / 2 - player.Location.Position;
            MaxDistance = Math.Sqrt(Math.Pow(vecteur.X, 2) + Math.Pow(vecteur.Y, 2)) + 20;

            if (m_ennemies.Any(x => !x.Life.IsAlive && !x.Life.HasTakenDamage.HasValue))
            {
                m_ennemies.RemoveAll(x => !x.Life.IsAlive && !x.Life.HasTakenDamage.HasValue);

                m_renderer.Clear();

                foreach (var ennemy in m_ennemies)
                {
                    ennemy.SetSprite(m_renderer);
                }
            }

            //S'il manque des zombies on complète
            for (var i = 0; i < m_ennemiesCount - m_ennemies.Count; i++)
            {
                Ennemy z = null;

                var zType = m_random.Next(1, 7);

                switch (zType)
                {
                    case 1:
                        z = new Zombie1();
                        break;
                    case 2:
                        z = new Zombie2();
                        break;
                    case 3:
                        z = new Zombie3();
                        break;
                    case 4:
                        z = new Zombie4();
                        break;
                    case 5:
                        z = new Zombie5();
                        break;
                    case 6:
                        z = new Zombie6();
                        break;
                }

                //On le met en dehors de l'écran

                //On choisit d'abords sur quel coté
                var side = m_random.Next(1, 5);

                var x = player.Location.Position.X;
                var y = player.Location.Position.Y;
                var ecart = m_random.Next(10, 200);

                switch (side)
                {
                    case 1:
                        x = player.Location.Position.X - size.X / 2 - ecart;
                        y = player.Location.Position.Y + m_random.Next(-size.Y/2, size.Y/2);
                        break;
                    case 2:
                        x = player.Location.Position.X + size.X / 2 + ecart;
                        y = player.Location.Position.Y + m_random.Next(-size.Y / 2, size.Y / 2);
                        break;
                    case 3:
                        x = player.Location.Position.X + m_random.Next(-size.X / 2, size.X / 2);
                        y = player.Location.Position.Y - size.Y / 2 - ecart;
                        break;
                    case 4:
                        x = player.Location.Position.X + m_random.Next(-size.X / 2, size.X / 2);
                        y = player.Location.Position.Y + size.Y / 2 + ecart;
                        break;
                }

                z.SetPosition(new Vector2(x, y));

                z.SetTarget(player);

                EnnemyManager.Instance.AddEnnemy(z);
            }

            Parallel.ForEach(m_ennemies, x => x.Update(elapsed));
        }
예제 #2
0
        public void Update(TimeSpan elapsed)
        {
            //On modifie le nombre de zombies en fonction du moment de la journée
            var period = World.World.Instance.DayLight.GetDayPeriod();

            if (period == World.DayPeriod.Night)
            {
                m_ennemiesCount = m_ennemiesCountInitial * 10;
            }
            else
            {
                m_ennemiesCount = m_ennemiesCountInitial;
            }

            var size    = Engine.Display.GetSize();
            var player  = World.World.Instance.Player;
            var vecteur = player.Location.Position + size / 2 - player.Location.Position;

            MaxDistance = Math.Sqrt(Math.Pow(vecteur.X, 2) + Math.Pow(vecteur.Y, 2)) + 20;

            if (m_ennemies.Any(x => !x.Life.IsAlive && !x.Life.HasTakenDamage.HasValue))
            {
                m_ennemies.RemoveAll(x => !x.Life.IsAlive && !x.Life.HasTakenDamage.HasValue);

                m_renderer.Clear();

                foreach (var ennemy in m_ennemies)
                {
                    ennemy.SetSprite(m_renderer);
                }
            }

            //S'il manque des zombies on complète
            for (var i = 0; i < m_ennemiesCount - m_ennemies.Count; i++)
            {
                Ennemy z = null;

                var zType = m_random.Next(1, 7);

                switch (zType)
                {
                case 1:
                    z = new Zombie1();
                    break;

                case 2:
                    z = new Zombie2();
                    break;

                case 3:
                    z = new Zombie3();
                    break;

                case 4:
                    z = new Zombie4();
                    break;

                case 5:
                    z = new Zombie5();
                    break;

                case 6:
                    z = new Zombie6();
                    break;
                }

                //On le met en dehors de l'écran

                //On choisit d'abords sur quel coté
                var side = m_random.Next(1, 5);

                var x     = player.Location.Position.X;
                var y     = player.Location.Position.Y;
                var ecart = m_random.Next(10, 200);

                switch (side)
                {
                case 1:
                    x = player.Location.Position.X - size.X / 2 - ecart;
                    y = player.Location.Position.Y + m_random.Next(-size.Y / 2, size.Y / 2);
                    break;

                case 2:
                    x = player.Location.Position.X + size.X / 2 + ecart;
                    y = player.Location.Position.Y + m_random.Next(-size.Y / 2, size.Y / 2);
                    break;

                case 3:
                    x = player.Location.Position.X + m_random.Next(-size.X / 2, size.X / 2);
                    y = player.Location.Position.Y - size.Y / 2 - ecart;
                    break;

                case 4:
                    x = player.Location.Position.X + m_random.Next(-size.X / 2, size.X / 2);
                    y = player.Location.Position.Y + size.Y / 2 + ecart;
                    break;
                }

                z.SetPosition(new Vector2(x, y));

                z.SetTarget(player);

                EnnemyManager.Instance.AddEnnemy(z);
            }

            Parallel.ForEach(m_ennemies, x => x.Update(elapsed));
        }