/// <summary> /// Determine if two positions are within a 40x40 box. /// </summary> /// <param name="position1">The first position.</param> /// <param name="position2">The second position.</param> /// <returns>true if position 2 is within a 40x40 box around position 1.</returns> public static bool IsNear(NovaPoint position1, NovaPoint position2) { NovaPoint topCorner = new NovaPoint(position1); topCorner.Offset(-20, -20); Rectangle scanArea = new Rectangle(topCorner.X, topCorner.Y, 40, 40); if (InBox(position2, scanArea)) { return(true); } return(false); }
/// <summary> /// Determine if a point is within a bounding box. /// </summary> /// <param name="p">The <see cref="NovaPoint"/> in question.</param> /// <param name="box">The <see cref="Rectangle"/> defining the space to check.</param> /// <returns>True if point p is in the box.</returns> public static bool InBox(NovaPoint p, Rectangle box) { NovaPoint upperLeft = new NovaPoint(box.Location); NovaPoint bottomRight = new NovaPoint(box.Location); bottomRight.Offset(box.Width, box.Height); if (((p.X > upperLeft.X) && (p.X < bottomRight.X)) && ((p.Y > upperLeft.Y) && (p.Y < bottomRight.Y))) { return(true); } return(false); }
/// <param name="graphics"></param> /// <Summary> /// Draws every object on the playing map to the graphics buffer. /// </Summary> /// <remarks> /// This does not actually render the map. Only draws to /// the buffer which is drawn later /// /// We just do simple painting so the order that things are drawn is important /// (otherwise items may get overwritten and become invisible): /// /// (1) All long-range scanners (planets and ships) owned by the player. /// (2) All short-range scanners (ships only) owned by the player. /// (3) Minefields visible to the player (with transparency) /// (4) All fleets visible to the player. /// (5) Stars (including a starbase and orbiting fleets indication). /// (6) The selection cursor. /// </remarks> private void DrawEverything(Graphics g) { if (this.isinitialized == false) { return; } // Erase previous drawings. g.Clear(Color.Black); // (0) Draw the image backdrop and universe borders NovaPoint backgroundOrigin = LogicalToDevice(new NovaPoint(0, 0)); backgroundOrigin.Offset(-20, -20); NovaPoint backgroundExtent = LogicalToDevice(logical); backgroundExtent.Offset(20, 20); Size renderSize = new Size(); renderSize.Height = backgroundExtent.Y - backgroundOrigin.Y; renderSize.Width = backgroundExtent.X - backgroundOrigin.X; g.Clip = new Region(new Rectangle((Point)backgroundOrigin, renderSize)); // This is the specified area which represents the playing universe Rectangle backgroundArea = new Rectangle((Point)backgroundOrigin, renderSize); if (this.displayBackground == true) { Image backdrop = Nova.Properties.Resources.Plasma; g.DrawImage(backdrop, backgroundArea); // Free the image after using it. This prevents a nasty // memory leak under Mono on Linux. backdrop.Dispose(); } if (this.displayBorders == true) { Pen borderPen = new Pen(Brushes.DimGray); borderPen.DashStyle = DashStyle.Dot; g.DrawRectangle(borderPen, backgroundArea); borderPen.Dispose(); } Color lrScancolor = Color.FromArgb(128, 128, 0, 0); SolidBrush lrScanBrush = new SolidBrush(lrScancolor); Color srScancolor = Color.FromArgb(128, 128, 128, 0); SolidBrush srScanBrush = new SolidBrush(srScancolor); // (1a) Planetary long-range scanners. foreach (Star report in clientState.EmpireState.OwnedStars.Values) { if (report.Owner == clientState.EmpireState.Id) { DrawCircle(g, lrScanBrush, (Point)report.Position, report.ScanRange); } } // (1b) Fleet non-pen scanners. foreach (Fleet fleet in clientState.EmpireState.OwnedFleets.Values) { if (fleet.Owner == clientState.EmpireState.Id) { DrawCircle(g, lrScanBrush, (Point)fleet.Position, fleet.ScanRange); } } // (2) Fleet pen-scanners scanners. foreach (Fleet fleet in clientState.EmpireState.OwnedFleets.Values) { if (fleet.Owner == clientState.EmpireState.Id) { DrawCircle(g, srScanBrush, (Point)fleet.Position, fleet.PenScanRange); } } // (3) Minefields foreach (Minefield minefield in this.visibleMinefields.Values) { Color cb; Color cf; if (minefield.Owner == clientState.EmpireState.Id) { cb = Color.FromArgb(0, 0, 0, 0); cf = Color.FromArgb(128, 0, 128, 0); } else { cb = Color.FromArgb(0, 0, 0, 0); cf = Color.FromArgb(128, 128, 0, 128); } HatchStyle style = HatchStyle.DiagonalCross | HatchStyle.Percent50; HatchBrush srMineBrush = new HatchBrush(style, cf, cb); int radius = minefield.Radius; DrawCircle(g, srMineBrush, (Point)minefield.Position, radius); } // (4) Visible fleets. foreach (FleetIntel report in clientState.EmpireState.FleetReports.Values) { if (report.Type != ItemType.Starbase) { DrawFleet(g, report); } } // (5) Stars plus starbases and orbiting fleet indications that are // the results of scans. foreach (StarIntel report in clientState.EmpireState.StarReports.Values) { DrawStar(g, report); DrawOrbitingFleets(g, report); } // (6) Cursor. NovaPoint position = LogicalToDevice(this.cursorPosition); position.Y += 5; g.TranslateTransform(position.X, position.Y); g.RotateTransform(180f); g.FillPolygon(Brushes.Yellow, cursorShape); g.ResetTransform(); // g.DrawImage(this.cursorBitmap, (Point)position); // (7) Zoom/Scroll/Cursor info for debugging. DrawDebugInfo(g); }