Exemplo n.º 1
0
        /// <summary>
        /// Обновление состояний и действий объектов для вызова через интервал вызовов в таймере
        /// </summary>
        public static void Update()
        {
            for (int i = 0; i < _asteroids.Length; i++) //foreach (Asteroid astr in _asteroids)
            {
                if (_asteroids[i] == null)
                {
                    continue;
                }
                _asteroids[i].Update();

                if (!(_bullet is null) && _asteroids[i].Collision(_bullet))
                {
                    _ship.Score++;
                    System.Media.SystemSounds.Hand.Play();
                    _asteroids[i] = null;
                    _bullet       = null;
                    continue;
                }
                ;
                if (_ship.Collision(_asteroids[i]))
                {
                    _ship?.GetEnergy(_asteroids[i].Power);
                    System.Media.SystemSounds.Asterisk.Play();
                }
                if (_ship.Energy <= 0)
                {
                    _ship?.Die();
                }
            }

            for (int i = 0; i < _aids.Length; i++) //foreach (Asteroid astr in _asteroids)
            {
                if (_aids[i] == null)
                {
                    continue;
                }
                _aids[i].Update();

                if (!(_bullet is null) && _aids[i].Collision(_bullet))
                {
                    System.Media.SystemSounds.Question.Play();
                    _aids[i] = null;
                    _bullet  = null;
                    continue;
                }
                if (_ship.Collision(_aids[i]))
                {
                    _ship?.GetEnergy(_aids[i].Power);
                    System.Media.SystemSounds.Exclamation.Play();
                }
            }

            foreach (BaseObject obj in _objs)
            {
                obj.Update();
            }

            _bullet?.Update();
        }
Exemplo n.º 2
0
 private static void Form_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.ControlKey)
     {
         _bullet = new Bullet(new Point(_ship.Rect.X + 10, _ship.Rect.Y + 4), new Point(50, 0), new Size(20, 1));
         _ship.GetEnergy(rnd.Next(-3, -1));
     }
     if (e.KeyCode == Keys.Up)
     {
         _ship.Up();
     }
     if (e.KeyCode == Keys.Down)
     {
         _ship.Down();
     }
 }