private void HandleInputGameTypeSwapper() { var mouseState = Mouse.GetState(); // if you've just clicked select the current tile if (mouseState.LeftButton == ButtonState.Pressed && oldMouseState.LeftButton == ButtonState.Released) { foreach (var tile in tiles.Where(x => x.isHome == false).OrderByDescending(x => x.sprite.Depth)) { if (tile.GetBoundingBox().Contains(mouseState.Position)) { // If No tile is selected, select the tile. if (selectedTile == null) { selectedTile = tile; } else if (selectedTile.Position == tile.Position) { selectedTile = null; } else //swap tile positions and deselect Tile. { Vector2 selectedTilePosition = selectedTile.Position; selectedTile.Position = tile.Position; tile.Position = selectedTilePosition; selectedTile = null; } break; } } } // Right Click for Rotation if (gameSettings.randomlyRotateTiles && mouseState.RightButton == ButtonState.Pressed && oldMouseState.RightButton == ButtonState.Released && selectedTile == null) { foreach (var tile in tiles.Where(x => x.isHome == false).OrderByDescending(x => x.sprite.Depth)) { if (tile.GetBoundingBox().Contains(mouseState.Position) && tile.isHome == false) { tile.rotation = RotationHelper.Rotate90Degrees(tile.rotation); // Handle Snapping if (tile.rotation == 0f) { CircleF circle = new CircleF(tile.homePosition, 20f); if (circle.Contains(tile.Position)) { tile.Position = tile.homePosition; tile.isHome = true; tile.sprite.Depth = Constants.Depth.GameDepthVariance; UpdatePercentageComplete(); } } break; } } } // Right Click for Rotation while holding left click and having a tile selected if (gameSettings.randomlyRotateTiles && mouseState.LeftButton == ButtonState.Pressed && oldMouseState.LeftButton == ButtonState.Pressed && selectedTile != null && mouseState.RightButton == ButtonState.Pressed && oldMouseState.RightButton == ButtonState.Released) { selectedTile.rotation = RotationHelper.Rotate90Degrees(selectedTile.rotation); } oldMouseState = mouseState; }
private void HandleInputGameTypeShuffle() { var mouseState = Mouse.GetState(); // if you've just clicked select the current tile if (mouseState.LeftButton == ButtonState.Pressed && oldMouseState.LeftButton == ButtonState.Released) { foreach (var tile in tiles.Where(x => x.isHome == false).OrderByDescending(x => x.sprite.Depth)) { if (tile.GetBoundingBox().Contains(mouseState.Position)) { RectangleF shadowTileHitBox = shadowTile.GetBoundingBox(); var minX = shadowTileHitBox.X - (shadowTileHitBox.Width * 1.1f); var minY = shadowTileHitBox.Y - (shadowTileHitBox.Height * 1.1f); var maxX = shadowTileHitBox.X + shadowTileHitBox.Width + (shadowTileHitBox.Width * 1.1f); var maxY = shadowTileHitBox.Y + shadowTileHitBox.Height + (shadowTileHitBox.Height * 1.1f); if (minX < 0) { minX = 0; } if (minY < 0) { minY = 0; } var width = maxX - minX; var height = maxY - minY; // Two hitboxes create a + shape hitbox to exclude diagonals. RectangleF extendedHitboxX = new RectangleF(minX, shadowTileHitBox.Y, width, shadowTileHitBox.Height); RectangleF extendedHitboxY = new RectangleF(shadowTileHitBox.X, minY, shadowTileHitBox.Width, height); if (extendedHitboxX.Contains(tile.GetBoundingBox().Center) || extendedHitboxY.Contains(tile.GetBoundingBox().Center)) // if close to shadowTile { Vector2 selectedTilePosition = tile.Position; tile.Position = shadowTile.Position; shadowTile.Position = selectedTilePosition; selectedTile = null; } break; } } } // Right Click for Rotation if (gameSettings.randomlyRotateTiles && mouseState.RightButton == ButtonState.Pressed && oldMouseState.RightButton == ButtonState.Released && selectedTile == null) { foreach (var tile in tiles.Where(x => x.isHome == false).OrderByDescending(x => x.sprite.Depth)) { if (tile.GetBoundingBox().Contains(mouseState.Position) && tile.isHome == false) { tile.rotation = RotationHelper.Rotate90Degrees(tile.rotation); // Handle Snapping if (tile.rotation == 0f) { CircleF circle = new CircleF(tile.homePosition, 20f); if (circle.Contains(tile.Position)) { tile.Position = tile.homePosition; tile.isHome = true; tile.sprite.Depth = Constants.Depth.GameDepthVariance; UpdatePercentageComplete(); } } break; } } } // Right Click for Rotation while holding left click and having a tile selected if (gameSettings.randomlyRotateTiles && mouseState.LeftButton == ButtonState.Pressed && oldMouseState.LeftButton == ButtonState.Pressed && selectedTile != null && mouseState.RightButton == ButtonState.Pressed && oldMouseState.RightButton == ButtonState.Released) { selectedTile.rotation = RotationHelper.Rotate90Degrees(selectedTile.rotation); } oldMouseState = mouseState; }