private void moveCursor() { //Move the cursor bool cursorMovedWithMouse = false; #if MOUSE //If user moves the mouse then show it MouseState mouse = Mouse.GetState(); if (mouse.X != lastMouseX && mouse.Y != lastMouseY) { //TODO: Doesn't seem to actually show the mouse until you move outside //the window and back in. Game.IsMouseVisible = true; } //if the mouse is visible then track the cursor with the mouse if (Game.IsMouseVisible) { //Find which marble is under the cursor cursorMovedWithMouse = moveCursorWithMouse(mouse.X, mouse.Y); lastMouseX = mouse.X; lastMouseY = mouse.Y; } #endif //Move the cursor with keyboard/gamepad bool cursorMovedWithGamePad = false; if (InputHelper.GamePads[PlayerIndex.One].LeftPressed) { cursorMovedWithGamePad = FindNextMarbleX(-1); } if (InputHelper.GamePads[PlayerIndex.One].RightPressed) { cursorMovedWithGamePad = FindNextMarbleX(1); } if (InputHelper.GamePads[PlayerIndex.One].UpPressed) { cursorMovedWithGamePad = FindNextMarbleY(-1); } if (InputHelper.GamePads[PlayerIndex.One].DownPressed) { cursorMovedWithGamePad = FindNextMarbleY(1); } //if anything moved we play the move sound if (cursorMovedWithGamePad || cursorMovedWithMouse) { Sound.Play(SoundEntry.Navigate); FindSelectedMarbles(); } #if MOUSE //If the user goes back to moving with the keyboard/gamepad //then hide the mouse if (cursorMovedWithGamePad) { Game.IsMouseVisible = false; } #endif }
/// <summary> /// Called when the GameComponent needs to be updated. /// Game Board update performs animation on the marbles, checks for cursor /// movement. Most of the game logic is here or called from here /// </summary> /// <param name="gameTime">Current game time</param> public override void Update(GameTime gameTime) { if (gameTime == null) { return; } base.Update(gameTime); if (!GameOver) { Marble.UpdateStatic(gameTime); foreach (Marble marble in Marbles) { if (marble != null) { marble.Update(gameTime); } } switch (AnimationState) { case Animation.Breaking: { //Fade the score scoreFadeFactor = (float)((gameTime.TotalGameTime - scoreFadeStart.TotalGameTime).TotalSeconds / Marble.BreakTime); //Wait until all marbles are broken. bool stillBreaking = false; foreach (Marble marble in Marbles) { if (marble != null) { if (marble.Animation == Animation.Breaking) { stillBreaking = true; break; } } } //Done breaking - do the 'fall' and 'slide' if (!stillBreaking) { FallAndSlide(); totalSelected = 0; FindCursorPosition(); FindSelectedMarbles(); Sound.Play(SoundEntry.LandMarbles); AnimationState = Animation.None; } break; } case Animation.None: { moveCursor(); BreakMarbles(gameTime); break; } } } }