Пример #1
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            _player = new Player();

            _bgLayer1       = new ParallaxingBackground();
            _bgLayer2       = new ParallaxingBackground();
            _rectBackground = new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);

            TouchPanel.EnabledGestures = GestureType.FreeDrag;

            // init our laser
            laserBeams = new List <Laser>();
            const float SECONDS_IN_MINUTE = 60f;
            const float RATE_OF_FIRE      = 200f;

            laserSpawnTime         = TimeSpan.FromSeconds(SECONDS_IN_MINUTE / RATE_OF_FIRE);
            previousLaserSpawnTime = TimeSpan.Zero;

            // Initialize the enemies list
            enemies = new List <Enemy>();

            //used to determine how fast the enemies will respawn.
            enemySpawnTime = TimeSpan.FromSeconds(1.0f);

            // init our random number generator
            random = new Random();

            base.Initialize();
        }
Пример #2
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            _scene            = new GraphicScene();
            _collisionManager = new CollisionManager();
            _weaponManager    = new WeaponManager();
            _enemyFactory     = new EnemyFactory();

            _player = new Player();
            _scene.Add(_player);
            _collisionManager.Add(_player);
            _weapon = new Weapon(this, _player);

            _bgLayer1       = new ParallaxingBackground();
            _bgLayer2       = new ParallaxingBackground();
            _rectBackground = new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);

            TouchPanel.EnabledGestures = GestureType.FreeDrag;

            // init our laser
            laserBeams = new EntityList <Laser>(_scene, _collisionManager);

            // Initialize the enemies list
            enemies = new EntityList <Enemy>(_scene, _collisionManager);

            //used to determine how fast the enemies will respawn.
            enemySpawnTime = TimeSpan.FromSeconds(1.0f);

            // init our random number generator
            random = new Random();

            explosions = new EntityList <Explosion>(_scene, _collisionManager);

            base.Initialize();

            ConfigurationManager.logConfiguration();

            var task2 = readJson("enemies");

            task2.ContinueWith(task =>
            {
                var content = task.Result;

                try
                {
                    JsonArray config = (JsonArray)JsonArray.Parse(content);
                    _enemyFactory.Initialize(config);
                }
                catch (Exception e)
                {
                }
            });
        }