Esempio n. 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.
            this.IsMouseVisible = true;

            // Window size.
            _graphics.PreferredBackBufferWidth = (int)Helper.WIDTH * 10;
            _graphics.PreferredBackBufferHeight = (int)Helper.HEIGHT * 18;
            _graphics.ApplyChanges();

            //Initialize the game.
            _input = new InputState();
            _blocks = new List<Block>();
            _gravity = Helper.GRAVITY;
            _gameOver = false;

            //Add the first figure.
            _currentFigure = Helper.RandomFigure();
            _currentFigure.Move(new Vector2(Helper.WIDTH * 15, 0));
            _blocks.AddRange(_currentFigure.Blocks);

            //Set the debug figure.
            _debugFigure = _currentFigure;

            base.Initialize();
        }
Esempio n. 2
0
        /// <summary>
        /// Let the figure handle user input.
        /// </summary>
        /// <param name="input">The current state of input.</param>
        public void HandleInput(InputState input)
        {
            //Check for rotation and movement input.
            if (!IsSleeping)
            {
                //Whether new input has arrived.
                MovementAction action = MovementAction.None;

                if (input.IsNewKeyPress(Keys.Up)) { action = MovementAction.Rotate; }
                else if (input.IsNewKeyPress(Keys.Right)) { action = MovementAction.Right; }
                else if (input.IsNewKeyPress(Keys.Left)) { action = MovementAction.Left; }
                else if (input.IsKeyDown(Keys.Down)) { action = MovementAction.Down; }

                //If a new action has been commanded, save it and reset the time buffer.
                if (action != MovementAction.None)
                {
                    ElapsedMovementTime = 0;
                    Action = action;
                }
            }
        }