/// <summary>Is the mouse over the button?</summary> public bool isHovered(InputHelper input) { return btnBox.Contains((int)input.MousePosition.X, (int)input.MousePosition.Y); }
/// <summary>Initialize non-content related variables and objects.</summary> protected override void Initialize() { base.Initialize(); input = new InputHelper(150); // gamestates gameState = GameStates.Menu; reserveGameState = GameStates.Menu; // field fieldWidth = 12; fieldHeight = 20; // timers moveTimerLim = moveTimerLimBase; newBlockTimer = newBlockTimerLim; // score keeping pointsPerColor = new float[] { 2.5f, 2.5f, 2.5f, 2.5f, 2.5f, 2.5f }; }
/// <summary>Is the button being clicked?</summary> public bool isClicked(InputHelper input) { return input.MouseLeftButtonPressed() && // mouseclick btnBox.Contains((int)input.MousePosition.X, (int)input.MousePosition.Y); // over the button }
/// <summary>Handle user inputs and automatic movement.</summary> public bool handleMovement(GameTime gameTime, InputHelper input) { // handle user inputs // go left if (input.KeyPressed(Keys.A) && field.canBlockMove(this, Movement.Left)) { move(Movement.Left); } // go right if (input.KeyPressed(Keys.D) && field.canBlockMove(this, Movement.Right)) { move(Movement.Right); } // go down if (input.KeyPressed(Keys.S)) { if (field.canBlockMove(this, Movement.Down)) // can still go lower { move(); moveTimer = 0; } else { return false; } // may no longer move } // go all the way down if (input.IsKeyDown(Keys.W)) { // move all the way down while (field.canBlockMove(this, Movement.Down)) { move(); } moveTimer = 0; return false; // may no longer move } // rotate if (input.KeyPressed(Keys.Q)) { turnAntiClockwise(); } if (input.KeyPressed(Keys.E)) { turnClockwise(); } //movement tick if (moveTimer >= moveTimerLim) { moveTimer = moveTimer % moveTimerLim; //move block if (field.canBlockMove(this, Movement.Down)) { move(); } else { return false; } // may no longer move } else { moveTimer += gameTime.ElapsedGameTime.Milliseconds; } return true; // was able to go down if it had to }