Exemple #1
0
        public static void Load()
        {
            _objs = new BaseObject[30];

            //bullet = new Bullet(new Point(0, 200), new Point(5, 0), new Size(6, 2));
            asteroids = new Asteroid[5];


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

            for (int i = 0; i < asteroids.Length; i++)
            {
                asteroids[i] = CreateAsteroid();
            }

            aidKit = new AidKit(new Point(Game.Width, random.Next(0, Game.Height)), new Point(-random.Next(5, 50) / 5, random.Next(5, 50)), new Size(10, 10));
        }
Exemple #2
0
        public static void Update()
        {
            foreach (BaseObject obj in _objs)
            {
                obj.Update();
            }


            bullet?.Update();

            if (aidKit == null)
            {
                if (cooldown >= 5)
                {
                    aidKit   = CreateAidKit();
                    cooldown = 0;
                }
            }
            else
            {
                aidKit.Update();

                if (aidKit.Collision(ship))
                {
                    ship.AddEnergy(aidKit.Power);
                    aidKit = null;
                }
            }

            for (var i = 0; i < asteroids.Length; i++)
            {
                if (asteroids[i] == null)
                {
                    asteroids[i] = CreateAsteroid();
                    continue;
                }
                asteroids[i].Update();

                if (bullet != null && bullet.Collision(asteroids[i]))
                {
                    System.Media.SystemSounds.Hand.Play();
                    asteroids[i] = null;
                    bullet       = null;
                    IncreaseScore();
                    continue;
                }

                if (!ship.Collision(asteroids[i]))
                {
                    continue;
                }

                var rnd = new Random();

                ship?.EnergyLow(rnd.Next(1, 10));
                System.Media.SystemSounds.Asterisk.Play();
                if (ship.Energy <= 0)
                {
                    ship?.Die();
                }
            }

            cooldown++;
        }