public void Update(GameLoop game, MainMenu mainMenu) { //Gets the current state of the mouse MouseState newMState = Mouse.GetState(); KeyboardState newKState = Keyboard.GetState(); kArray = oldKState.GetPressedKeys(); Keys pressedKey = Keys.A; if (kArray.Length > 0) { pressedKey = kArray[kArray.Length - 1]; } //Checks if the mouse has just been clicked by comparing the current state with the previous state if (newMState.LeftButton == ButtonState.Pressed && oldMState.LeftButton == ButtonState.Released) { //Logs click coordinates int x = newMState.X; int y = newMState.Y; mainMenu.CheckClick(x, y, game); } //Resets old mouse state oldMState = newMState; //Checks if keys have been pressed to end the game if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) { game.Exit(); } if ((newKState.IsKeyUp(Keys.Left) && oldKState.IsKeyDown(Keys.Left)) || (newKState.IsKeyUp(Keys.Right) && oldKState.IsKeyDown(Keys.Right)) || (newKState.IsKeyUp(Keys.Down) && oldKState.IsKeyDown(Keys.Down)) || (newKState.IsKeyUp(Keys.Up) && oldKState.IsKeyDown(Keys.Up))) { } oldKState = newKState; }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); mainMenu = new MainMenu(Content, screenWidth, screenHeight); // Instantiates class using window size board = new Board(Content, spriteBatch, screenWidth, screenHeight); }