# HG changeset patch # User alys # Date 2021-04-01 03:06:01 # Node ID 222a32473921bde5a3589d602753b84b99b62b8e # Parent ada0c9356941a095b5916556e311e24530ca53de Add code for drawing outlines of an arbitrary set of squares. diff --git a/isometric-park-fna/FNAGame.cs b/isometric-park-fna/FNAGame.cs --- a/isometric-park-fna/FNAGame.cs +++ b/isometric-park-fna/FNAGame.cs @@ -739,9 +739,13 @@ Tile.OutlineSquare(batch, 5, 1, Color.Green, 2); Tile.OutlineSquare(batch, 7, 1, Color.Orange, 2); Tile.OutlineSquare(batch, 9, 1, Color.Orange, 3); - Tile.OutlineSquare2(batch, 12, 1, Color.Orange, 2); + // Tile.OutlineSquare2(batch, 12, 1, Color.Orange, 2); + + //Tile.drawEdge(batch, new Edge {Start=new Vector2(14, 1), End= new Vector2(15, 1)}, Color.Orange); - Tile.drawEdge(batch, new Edge {Start=new Vector2(14, 1), End= new Vector2(15, 1)}, Color.Orange); + //donut + //Tile.DrawOutlinedSquares(batch, new Vector2[] {new Vector2(19, 1), new Vector2(19, 2), new Vector2(20, 1), new Vector2(21, 1), + // new Vector2(21, 2), new Vector2(19, 3), new Vector2(20, 3), new Vector2(21, 3)}, Color.Purple); #endif diff --git a/isometric-park-fna/Tile.cs b/isometric-park-fna/Tile.cs --- a/isometric-park-fna/Tile.cs +++ b/isometric-park-fna/Tile.cs @@ -1,4 +1,6 @@ using System; +using System.Collections.Generic; +using System.Linq; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -7,8 +9,23 @@ { public struct Edge { - public Vector2 Start; - public Vector2 End; + public Vector2 Start; + public Vector2 End; + + public static bool operator == (Edge left, Edge right) { + return (left.Start == right.Start && left.End == right.End) || + (left.Start == right.End && left.End == right.Start); + } + + public static bool operator != (Edge left, Edge right) { + return !(left == right); + } + + public bool Equals(Object other) { + return ((other != null) + && ! this.GetType().Equals(other.GetType()) + && this == (Edge)other); //we just confirmed the types match so this is okay + } } public class Tile @@ -150,6 +167,25 @@ } } + public static void DrawOutlinedSquares(SpriteBatch batch, Vector2[] squares, Color color) { + List edges = new List(); + + foreach (Vector2 square in squares) { + //upper right + edges.Add(new Edge {Start=square, End=square + new Vector2(1, 0)}); + //lower right + edges.Add(new Edge {Start=square + new Vector2(1, 0), End=square + new Vector2(1, 1)}); + //lower left + edges.Add(new Edge {Start=square + new Vector2(0, 1), End=square + new Vector2(1, 1)}); + //upper left + edges.Add(new Edge {Start=square, End=square + new Vector2(0, 1)}); + } + + edges = edges.GroupBy(x => x).Where(grp => grp.Count() == 1).Select(grp => grp.Key).ToList(); + + drawEdges(batch, edges.ToArray(), color); + } + public static void drawTileAt(SpriteBatch batch, int x, int y, int tileIndex, int height, float depth) {