public bool IsOffScreen(Viewport viewport, Camera camera) { if (camera == null) { return(X < 0 - Width || X > viewport.Width || Y < 0 - Height || Y > viewport.Height); } else { Vector2 screenPosition = Vector2.Transform(PrecisePosition, camera.get_transformation(viewport)); return(screenPosition.X < 0 - Width || screenPosition.X > viewport.Width || screenPosition.Y < 0 - Height || screenPosition.Y > viewport.Height); } }
public bool IsOffScreen(Viewport viewport, Camera camera) { if (camera == null) return (X < 0 - Width || X > viewport.Width || Y < 0 - Height || Y > viewport.Height); else { Vector2 screenPosition = Vector2.Transform(PrecisePosition, camera.get_transformation(viewport)); return (screenPosition.X < 0 - Width || screenPosition.X > viewport.Width || screenPosition.Y < 0 - Height || screenPosition.Y > viewport.Height); } }
public static void Update(Viewport viewport, Camera camera) { if (!enabled) { return; } //Vector2 halfOfViewPort = new Vector2(Game1.Game.GraphicsDevice.Viewport.Width / 2f, Game1.Game.GraphicsDevice.Viewport.Height / 2f); //Vector2 mousePosition = new Vector2(Mouse.GetState().X, Mouse.GetState().Y) + (cameraOffset); Vector2 mousePosition = new Vector2(Mouse.GetState().X, Mouse.GetState().Y); Vector2 mouseWorldPosition = Vector2.Transform(mousePosition, Matrix.Invert(camera.get_transformation(viewport))); if (Mouse.GetState().LeftButton == ButtonState.Released) { selecting = false; return; } else if (selecting == false)// && graphics.GraphicsDevice.Viewport.Bounds.Contains(new Point(Mouse.GetState().X, Mouse.GetState().Y))) { selecting = true; selectPoint1 = selectPoint2 = new Rectangle((int)mouseWorldPosition.X, (int)mouseWorldPosition.Y, 1, 1); drawPoint1 = drawPoint2 = new Rectangle((int)mousePosition.X, (int)mousePosition.Y, 1, 1); } else { selectPoint2 = new Rectangle((int)mouseWorldPosition.X, (int)mouseWorldPosition.Y, 1, 1); drawPoint2 = new Rectangle((int)mousePosition.X, (int)mousePosition.Y, 1, 1); } /*selectBox.X = selectPoint1.X; * selectBox.Y = selectPoint1.Y; * selectBox.Width = (int)Vector2.Distance(new Vector2(selectPoint1.X, 0), new Vector2(selectPoint2.X, 0)); * selectBox.Height = (int)Vector2.Distance(new Vector2(0, selectPoint1.Y), new Vector2(0, selectPoint2.Y)); * selectBox.Rotation = camera.Rotation + (float)Math.PI;*/ selectBox.Rectangle = Rectangle.Union(selectPoint1, selectPoint2); selectBox.Rotation = camera.Rotation + (float)Math.PI; drawBox = Rectangle.Union(drawPoint1, drawPoint2); }
void updatePlacingStructure() { if (!placingStructure) { return; } Vector2 mousePosition = new Vector2(mouseState.X, mouseState.Y); mousePosition = Vector2.Transform(mousePosition, Matrix.Invert(camera.get_transformation(worldViewport))); placingStructureLocation.X = (int)Math.Round(MathHelper.Clamp(mousePosition.X / map.TileSize - placingStructureType.Size / 2f, 0, map.Width - 1)); placingStructureLocation.Y = (int)Math.Round(MathHelper.Clamp(mousePosition.Y / map.TileSize - placingStructureType.Size / 2f, 0, map.Height - 1)); placingStructureCenterPoint.X = placingStructureLocation.X * map.TileSize + (placingStructureType.Size * map.TileSize) / 2; placingStructureCenterPoint.Y = placingStructureLocation.Y * map.TileSize + (placingStructureType.Size * map.TileSize) / 2; placingStructurePathNodes.Clear(); placingStructureBlockedPathNodes.Clear(); allowPlacingStructure = true; Circle collisionCircle = new Circle(new Vector2(placingStructureLocation.X * map.TileSize + (placingStructureType.Size / 2) * map.TileSize, placingStructureLocation.Y * map.TileSize + (placingStructureType.Size / 2) * map.TileSize), placingStructureType.Size * map.TileSize); //placingStructureCenterPoint = collisionCircle.CenterPoint; if (placingStructureType == StructureType.TownHall) { foreach (Resource resource in Resource.Resources) { if (Vector2.Distance(collisionCircle.CenterPoint, resource.CenterPoint) < map.TileSize * 9) { allowPlacingStructure = false; tooCloseToResource = true; } } } else { tooCloseToResource = false; } for (int x = placingStructureLocation.X; x < placingStructureLocation.X + placingStructureType.Size; x++) { for (int y = placingStructureLocation.Y; y < placingStructureLocation.Y + placingStructureType.Size; y++) { PathNode node = Rts.pathFinder.PathNodes[(int)MathHelper.Clamp(y, 0, map.Height - 1), (int)MathHelper.Clamp(x, 0, map.Width - 1)]; if (collisionCircle.Intersects(node.Tile)) { placingStructurePathNodes.Add(node); } } } // remove corners if (placingStructureType.CutCorners) { placingStructurePathNodes.Remove(Rts.pathFinder.PathNodes[placingStructureLocation.Y, placingStructureLocation.X]); if (placingStructureLocation.X + placingStructureType.Size <= map.Width - 1) { placingStructurePathNodes.Remove(Rts.pathFinder.PathNodes[placingStructureLocation.Y, placingStructureLocation.X + placingStructureType.Size - 1]); } else { allowPlacingStructure = false; } if (placingStructureLocation.Y + placingStructureType.Size <= map.Height - 1) { placingStructurePathNodes.Remove(Rts.pathFinder.PathNodes[placingStructureLocation.Y + placingStructureType.Size - 1, placingStructureLocation.X]); } else { allowPlacingStructure = false; } if (allowPlacingStructure) { placingStructurePathNodes.Remove(Rts.pathFinder.PathNodes[placingStructureLocation.Y + placingStructureType.Size - 1, placingStructureLocation.X + placingStructureType.Size - 1]); } } for (int i = 0; i < placingStructurePathNodes.Count;) { PathNode node = placingStructurePathNodes[i]; if (!node.Tile.Walkable || (node.Blocked && node.Blocker is Structure && ((Structure)node.Blocker).Visible) || (node.Blocked && node.Blocker is Resource)) { allowPlacingStructure = false; placingStructurePathNodes.Remove(node); placingStructureBlockedPathNodes.Add(node); } else { i++; } } }
public static void Update(Viewport viewport, Camera camera) { if (!enabled) return; //Vector2 halfOfViewPort = new Vector2(Game1.Game.GraphicsDevice.Viewport.Width / 2f, Game1.Game.GraphicsDevice.Viewport.Height / 2f); //Vector2 mousePosition = new Vector2(Mouse.GetState().X, Mouse.GetState().Y) + (cameraOffset); Vector2 mousePosition = new Vector2(Mouse.GetState().X, Mouse.GetState().Y); Vector2 mouseWorldPosition = Vector2.Transform(mousePosition, Matrix.Invert(camera.get_transformation(viewport))); if (Mouse.GetState().LeftButton == ButtonState.Released) { selecting = false; return; } else if (selecting == false)// && graphics.GraphicsDevice.Viewport.Bounds.Contains(new Point(Mouse.GetState().X, Mouse.GetState().Y))) { selecting = true; selectPoint1 = selectPoint2 = new Rectangle((int)mouseWorldPosition.X, (int)mouseWorldPosition.Y, 1, 1); drawPoint1 = drawPoint2 = new Rectangle((int)mousePosition.X, (int)mousePosition.Y, 1, 1); } else { selectPoint2 = new Rectangle((int)mouseWorldPosition.X, (int)mouseWorldPosition.Y, 1, 1); drawPoint2 = new Rectangle((int)mousePosition.X, (int)mousePosition.Y, 1, 1); } /*selectBox.X = selectPoint1.X; selectBox.Y = selectPoint1.Y; selectBox.Width = (int)Vector2.Distance(new Vector2(selectPoint1.X, 0), new Vector2(selectPoint2.X, 0)); selectBox.Height = (int)Vector2.Distance(new Vector2(0, selectPoint1.Y), new Vector2(0, selectPoint2.Y)); selectBox.Rotation = camera.Rotation + (float)Math.PI;*/ selectBox.Rectangle = Rectangle.Union(selectPoint1, selectPoint2); selectBox.Rotation = camera.Rotation + (float)Math.PI; drawBox = Rectangle.Union(drawPoint1, drawPoint2); }