Esempio n. 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);
        }
Esempio n. 2
0
        protected override void OnLoad()
        {
            Logger.Print("Space scene start load");

            EventManager <ThrowObjectWaveEventArgs> .AddEventListener(GameEvents.WAVE_NEXT_OBJECT, OnNextObject);

            EventManager.AddEventListener(GameEvents.SHOOT, Shoot);
            EventManager.AddEventListener(GameEvents.STAGE_COMPLETE, OnStageCompleted);
            EventManager.AddEventListener(GameEvents.STAGE_GENERATED, OnStageGenerated);
            EventManager.AddEventListener(GameEvents.STAGE_GENERATE, OnStageGenerate);

            _generateWaveState.Init(_objects);
            _throwObjectWaveState.Init(_objects);
            _waitForNewWaveState.Init(_objects);

            _player = new Player();

            _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();

            AddDrawable(_stars);
            AddDrawable(_ship);

            AddUpdatable(_stars);

            EventManager.DispatchEvent(GameEvents.STAGE_GENERATE);
        }