Example #1
0
        /// <summary>Обновление состояния объектов сцены</summary>
        public static void Update()
        {
            foreach (var visual_object in __GameObjects)
            {
                visual_object?.Update();
            }

            __Bullet.Update();
            if (__Bullet.Position.X > Width)
            {
                __Bullet = new Bullet(new Random().Next(Width));
            }

            for (var i = 0; i < __GameObjects.Length; i++)
            {
                var obj = __GameObjects[i];
                if (obj is ICollision) // Применить "сопоставление с образцом"!
                {
                    var collision_object = (ICollision)obj;
                    if (__Bullet.CheckCollision(collision_object))
                    {
                        __Bullet         = new Bullet(new Random().Next(Width));
                        __GameObjects[i] = null;
                        MessageBox.Show("Астероид уничтожен!", "Столкновение", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
            }
        }
Example #2
0
        public static void Update()
        {
            foreach (var game_object in __GameObjects)
            {
                game_object?.Update();
            }

            __Bullet?.Update();
            if (__Bullet is null || __Bullet.Rect.Left > Width)
            {
                var rnd = new Random();
                __Bullet = new Bullet(rnd.Next(0, Height));
            }

            for (var i = 0; i < __GameObjects.Length; i++)
            {
                var obj = __GameObjects[i];
                if (obj is ICollision)
                {
                    var collision_object = (ICollision)obj;
                    if (__Bullet != null)
                    {
                        if (__Bullet.CheckCollision(collision_object))
                        {
                            __Bullet         = null;
                            __GameObjects[i] = null;
                            System.Media.SystemSounds.Beep.Play();
                        }
                    }
                }
            }
        }
Example #3
0
        public static void Update()
        {
            if (__CtrlKeyPressed > 0)
            {
                for (var i = 0; i < __CtrlKeyPressed; i++)
                {
                    __Bullets.Add(new Bullet(__Ship.Position.Y));
                }
            }

            foreach (var visual_object in __GameObjects)
            {
                visual_object?.Update();
            }
            foreach (var visual_object in __StarObjects)
            {
                visual_object?.Update();
            }

            __Bullet?.Update();


            //if (__Bullet.Position.X > Width)
            //    __Bullet = new Bullet(new Random().Next(Width));
            //foreach (var visual_object in __GameObjectsSmall)
            //    visual_object.Update();

            for (var i = 0; i < __StarObjects.Length; i++)
            {
                var obj = __StarObjects[i];

                if (obj is ICollision)
                {
                    var collision_object = (ICollision)obj;
                    __Ship.CheckCollision(collision_object);

                    if (__Bullet != null && __Bullet.CheckCollision(collision_object))
                    {
                        count_Stars++;
                        __Bullet = null;
                        //__Bullet = new Bullet(new Random().Next(Width));
                        __StarObjects[i] = null;
                        MessageBox.Show("Объект уничтожен!", "Столкновение", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    }
                }
            }
            if (__StarObjects.Length == 0)
            {
                Console.Clear();
            }
        }