Example #1
0
        public static void Load()
        {
            _objs = new BaseObject[30];
            for (int i = 0; i < _objs.Length; i++)
            {
                _objs[i] = new Star();
            }

            for (int i = 0; i < _maxAsteroids; i++)
            {
                asteroids.Add(new Asteroid());
            }

            _healingBoxs = new HealingBox[1];
            for (int i = 0; i < _healingBoxs.Length; i++)
            {
                _healingBoxs[i] = new HealingBox();
            }
        }
Example #2
0
        private static void Update()
        {
            if (GamePoints > 20)
            {
                _ship.Win();
            }
            foreach (BaseObject obj in _objs)
            {
                obj.Update();
            }

            for (int i = 0; i < bullet.Count; i++)
            {
                bullet[i].Update();
                if (bullet[i].afterGameLockation)
                {
                    bullet.RemoveAt(i);
                    i--;
                }
            }

            if (asteroids.Count <= 0)
            {
                _maxAsteroids++;
                for (int j = 0; j < _maxAsteroids; j++)
                {
                    asteroids.Add(new Asteroid());
                }
            }

            for (int i = 0; i < asteroids.Count; i++)
            {
                if (asteroids[i] != null)
                {
                    asteroids[i].Update();
                    for (int j = 0; j < bullet.Count; j++)
                    {
                        if (i >= 0 && bullet[j].Collision(asteroids[i]))
                        {
                            SystemSounds.Hand.Play();
                            asteroids.RemoveAt(i);
                            i--;
                            bullet.RemoveAt(j);
                            j--;
                            GamePoints++;
                        }
                    }

                    if (i >= 0 && asteroids.Count > 0 && _ship.Collision(asteroids[i]))
                    {
                        _ship.EnergyLow(asteroids[i].Power);
                        SystemSounds.Asterisk.Play();
                        if (_ship.Energy <= 0)
                        {
                            _ship.Die();
                        }
                        asteroids.RemoveAt(i);
                        i--;
                    }
                }
            }

            for (int i = 0; i < _healingBoxs.Length; i++)
            {
                if (_healingBoxs[i] != null)
                {
                    _healingBoxs[i].Update();
                    if (_healingBoxs[i].Collision(_ship))
                    {
                        _ship.EnergyUp(rnd.Next(1, 3));
                        _healingBoxs[i] = null;
                    }
                }
                else
                {
                    _healingBoxs[i] = new HealingBox();
                }
            }
        }