示例#1
0
        protected override void OnLoad()
        {
            Logger.Print("Space scene start load");

            EventManager.AddEventListener(EventManager.Events.ShootEvent, Shoot);
            EventManager.AddEventListener(EventManager.Events.ChangeScoreEvent, OnChangeScore);

            Score = 0;

            _stars.Clear();
            _asteroids.Clear();
            _bullets.Clear();

            for (var i = 0; i < 100; i++)
            {
                _stars.Add(GameObjectsFactory.CreateStar());
            }

            Logger.Print("Created {0} stars", _stars.Count);

            _ship = GameObjectsFactory.CreateSpaceShip();

            var random = new Random();

            _timer          = new Timer();
            _timer.Interval = 2000;
            _timer.Tick    += (sender, args) =>
            {
                GameObjects obj;
                var         next = random.Next(100);
                if (next % 2 == 0)
                {
                    obj = GameObjectsFactory.CreateAsteroid();
                    _asteroids.Add(obj as Asteroid);
                    AddUpdatable(obj);
                }
                else
                {
                    obj = GameObjectsFactory.CreateMedic();
                    _medics.Add(obj as Medic);
                }

                AddDrawable(obj);
            };
            _timer.Start();

            AddDrawable(_stars);
            AddDrawable(_ship);

            AddUpdatable(_stars);
        }
示例#2
0
        protected override void OnUpdate()
        {
            var random = new Random();

            for (int i = 0; i < BaseObjectsCount + _wave; i++)
            {
                GameObjects obj;
                var         next = random.Next(100);
                if (next % 10 == 0)
                {
                    obj = GameObjectsFactory.CreateMedic();
                }
                else
                {
                    obj = GameObjectsFactory.CreateAsteroid();
                }

                _objects.Enqueue(obj);
            }
            _wave++;
            Logger.Print("Волна создана {0}", _wave);
            EventManager.DispatchEvent(GameEvents.STAGE_GENERATED);
        }