Exemple #1
0
        /// <summary>
        /// Создает наполнение уровня
        /// </summary>
        public void Load()
        {
            GameLogger(console, "Load Start");
            Bullets   = new List <Bullet>();
            Asteroids = new List <Asteroid>();

            _ship = new Ship(new Point(80, 350), new Point(0, 350), new Point(80, 400), 15);
            _objs = new Star[STARS_INITIAL_AMOUNT];


            for (int i = 0; i < _objs.Length; i++)
            {
                int r = rnd.Next(5, 50);
                _objs[i] = new Star(new Point(STARS_X_SPAWNPOINT, rnd.Next(0, Height)), new Point(-r, r), new Size(3, 3));
            }

            for (int i = 0; i < ASTEROIDS_INITIAL_AMOUNT; i++)
            {
                int r = rnd.Next(5, 50);
                Asteroids.Add(new Asteroid(new Point(Width + ASTEROIDS_X_SPAWNPOINT, rnd.Next(0, Height)), new Point(-r / 5, r), new Size(r, r)));
            }

            Point p = new Point(40, rnd.Next(100, game.Height - 100));

            _medKit = new MedKit(p, new Point(), new Size(10, 10));

            GameLogger(console, "Load End");
        }
Exemple #2
0
        /// <summary>
        /// Игровая логика
        /// </summary>
        private void Update()
        {
            if (_medKit != null && _ship.Collision(_medKit))
            {
                _ship.Heal(_medKit.Power);
                _medKit = null;
            }

            for (int i = 0; i < Bullets.Count; i++)
            {
                var b = Bullets[i];
                b?.Update();
                if (b != null && b.OutOfFrame())
                {
                    b = null;
                }
            }

            foreach (Star bo in _objs)
            {
                bo.Update();
            }

            for (int iA = 0; iA < Asteroids.Count; iA++)
            {
                if (Asteroids[iA] == null)
                {
                    continue;
                }

                Asteroid a = Asteroids[iA];
                a.Update();

                for (int iB = 0; iB < Bullets.Count; iB++)
                {
                    if (Bullets[iB] != null && a.Collision(Bullets[iB]))
                    {
                        System.Media.SystemSounds.Hand.Play();
                        a.Destroy();
                        score        += a.Power;
                        Asteroids[iA] = null;
                        ASTEROIDS_COUNTER--;
                        Bullets[iB] = null;
                    }
                }

                if (_ship.Collision(a))
                {
                    _ship.EnergyLow(rnd.Next(1, 10));
                    Asteroids[iA] = null;
                    System.Media.SystemSounds.Asterisk.Play();
                    if (_ship.Energy <= 0)
                    {
                        _ship.Die();
                    }
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Спавнит/респавнит астероиды и аптечки
        /// </summary>
        private void Repopulate()
        {
            if (ASTEROIDS_COUNTER <= 0)
            {
                Asteroids.Clear();
                ASTEROIDS_COUNTER = ASTEROIDS_INITIAL_AMOUNT + 3;

                for (int i = 0; i <= ASTEROIDS_COUNTER; i++)
                {
                    int r = rnd.Next(5, 50);
                    Asteroids.Add(new Asteroid(new Point(Width + ASTEROIDS_X_SPAWNPOINT, rnd.Next(0, Height)), new Point(-r / 5, r), new Size(r, r)));
                }
            }


            if (_medKit == null)
            {
                Point p = new Point(40, rnd.Next(100, game.Height - 100));
                _medKit = new MedKit(p, new Point(), new Size(10, 10));
                GameLogger(console, "New medKit spawned at " + p);
            }
        }