Example #1
0
        /// <summary>
        /// Initializes the screen
        /// </summary>
        public override void Initialize()
        {
            this.TransitionOnTime = TimeSpan.FromSeconds(.5f);
            this.TransitionOffTime = TimeSpan.FromSeconds(.5f);
            this.IsPopup = false;

            base.Initialize();

            // Get service
            _timeline = (Timeline)this.Game.Services.GetService(typeof(Timeline));

            // Create Field
            _field = new Data.Field(this.Game, _timeline, 10, 24);
            _field.Initialize();
            DummyField dummyField = new Data.DummyField(this.Game, 5, 5 + SpriteField.HiddenRows);

            // Create Sprites
            _spriteField = new SpriteField(this.Game, _field) { Position = Vector2.One * SpriteField.GridCellSize * 3 };
            _spriteGhostBlock = new SpriteGhostBlock(this.Game, _field.CurrentBlock) { Position = _spriteField.Position };
            _spriteFallingBlock = new SpriteFallingBlock(this.Game, _field.CurrentBlock) { Position = _spriteField.Position };

            // Next Block and HoldBlock Boundaries
            _spriteNextBlockBoundary = new SpriteField(this.Game, dummyField) { Position = _spriteField.Position + (Vector2.UnitX * (_field.Width + 2)) * SpriteField.GridCellSize, };
            _spriteHoldBlockBoundary = new SpriteField(this.Game, dummyField) { Position = _spriteField.Position + (Vector2.UnitX * (_field.Width + 2) + Vector2.UnitY * (6 + 1)) * SpriteField.GridCellSize, };

            // Next BLock
            _spriteNextBlock = new SpriteBlock(this.Game, _field.NextBlock) { Position = _spriteNextBlockBoundary.Position + Vector2.One * SpriteField.GridCellSize, };
            _field.NextBlock.OnTypeChanged += new BlockTypeDelegate(NextBlock_OnTypeChanged);
            _spriteHoldBlock = new SpriteNullableBlock(this.Game) { Position = _spriteHoldBlockBoundary.Position + Vector2.One * SpriteField.GridCellSize, };

            _spriteField.Initialize();
            _spriteGhostBlock.Initialize();
            _spriteFallingBlock.Initialize();
            _spriteNextBlockBoundary.Initialize();
            _spriteHoldBlockBoundary.Initialize();
            _spriteNextBlock.Initialize();
            _spriteHoldBlock.Initialize();

            _spriteScorePopups = new List<SpriteScorePopup>();

            // Player controller
            _controller = new KeyboardController(this.Game, Keys.S, Keys.A, Keys.D, Keys.W, Keys.Q, Keys.E, Keys.Space, Keys.Enter);
            _controller.Initialize();

            _field.OnGameEnded += new EventHandler(_field_OnGameEnded);
            _field.OnRowsCleared += new RowsDelegate(_field_OnRowsCleared);
            _field.OnPointsEarned += new PointsDelegate(_field_OnPointsEarned);

            // Start the level
            _timeline.Start();
        }
Example #2
0
        /// <summary>
        /// Initializes the screen
        /// </summary>
        public override void Initialize()
        {
            this.TransitionOnTime  = TimeSpan.FromSeconds(.5f);
            this.TransitionOffTime = TimeSpan.FromSeconds(.5f);
            this.IsPopup           = false;

            base.Initialize();

            // Get service
            _timeline = (Timeline)this.Game.Services.GetService(typeof(Timeline));

            // Create Field
            _field = new Data.Field(this.Game, _timeline, 10, 24);
            _field.Initialize();
            DummyField dummyField = new Data.DummyField(this.Game, 5, 5 + SpriteField.HiddenRows);

            // Create Sprites
            _spriteField = new SpriteField(this.Game, _field)
            {
                Position = Vector2.One * SpriteField.GridCellSize * 3
            };
            _spriteGhostBlock = new SpriteGhostBlock(this.Game, _field.CurrentBlock)
            {
                Position = _spriteField.Position
            };
            _spriteFallingBlock = new SpriteFallingBlock(this.Game, _field.CurrentBlock)
            {
                Position = _spriteField.Position
            };

            // Next Block and HoldBlock Boundaries
            _spriteNextBlockBoundary = new SpriteField(this.Game, dummyField)
            {
                Position = _spriteField.Position + (Vector2.UnitX * (_field.Width + 2)) * SpriteField.GridCellSize,
            };
            _spriteHoldBlockBoundary = new SpriteField(this.Game, dummyField)
            {
                Position = _spriteField.Position + (Vector2.UnitX * (_field.Width + 2) + Vector2.UnitY * (6 + 1)) * SpriteField.GridCellSize,
            };

            // Next BLock
            _spriteNextBlock = new SpriteBlock(this.Game, _field.NextBlock)
            {
                Position = _spriteNextBlockBoundary.Position + Vector2.One * SpriteField.GridCellSize,
            };
            _field.NextBlock.OnTypeChanged += new BlockTypeDelegate(NextBlock_OnTypeChanged);
            _spriteHoldBlock = new SpriteNullableBlock(this.Game)
            {
                Position = _spriteHoldBlockBoundary.Position + Vector2.One * SpriteField.GridCellSize,
            };

            _spriteField.Initialize();
            _spriteGhostBlock.Initialize();
            _spriteFallingBlock.Initialize();
            _spriteNextBlockBoundary.Initialize();
            _spriteHoldBlockBoundary.Initialize();
            _spriteNextBlock.Initialize();
            _spriteHoldBlock.Initialize();

            _spriteScorePopups = new List <SpriteScorePopup>();

            // Player controller
            _controller = new KeyboardController(this.Game, Keys.S, Keys.A, Keys.D, Keys.W, Keys.Q, Keys.E, Keys.Space, Keys.Enter);
            _controller.Initialize();

            _field.OnGameEnded    += new EventHandler(_field_OnGameEnded);
            _field.OnRowsCleared  += new RowsDelegate(_field_OnRowsCleared);
            _field.OnPointsEarned += new PointsDelegate(_field_OnPointsEarned);

            // Start the level
            _timeline.Start();
        }