Description:
Add code for drawing outlines of an arbitrary set of squares.
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r154:222a32473921 -

@@ -739,9 +739,13
739 739 Tile.OutlineSquare(batch, 5, 1, Color.Green, 2);
740 740 Tile.OutlineSquare(batch, 7, 1, Color.Orange, 2);
741 741 Tile.OutlineSquare(batch, 9, 1, Color.Orange, 3);
742 Tile.OutlineSquare2(batch, 12, 1, Color.Orange, 2);
742 // Tile.OutlineSquare2(batch, 12, 1, Color.Orange, 2);
743
744 //Tile.drawEdge(batch, new Edge {Start=new Vector2(14, 1), End= new Vector2(15, 1)}, Color.Orange);
743 745
744 Tile.drawEdge(batch, new Edge {Start=new Vector2(14, 1), End= new Vector2(15, 1)}, Color.Orange);
746 //donut
747 //Tile.DrawOutlinedSquares(batch, new Vector2[] {new Vector2(19, 1), new Vector2(19, 2), new Vector2(20, 1), new Vector2(21, 1),
748 // new Vector2(21, 2), new Vector2(19, 3), new Vector2(20, 3), new Vector2(21, 3)}, Color.Purple);
745 749 #endif
746 750
747 751
@@ -1,4 +1,6
1 1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
2 4
3 5 using Microsoft.Xna.Framework;
4 6 using Microsoft.Xna.Framework.Graphics;
@@ -7,8 +9,23
7 9 {
8 10
9 11 public struct Edge {
10 public Vector2 Start;
11 public Vector2 End;
12 public Vector2 Start;
13 public Vector2 End;
14
15 public static bool operator == (Edge left, Edge right) {
16 return (left.Start == right.Start && left.End == right.End) ||
17 (left.Start == right.End && left.End == right.Start);
18 }
19
20 public static bool operator != (Edge left, Edge right) {
21 return !(left == right);
22 }
23
24 public bool Equals(Object other) {
25 return ((other != null)
26 && ! this.GetType().Equals(other.GetType())
27 && this == (Edge)other); //we just confirmed the types match so this is okay
28 }
12 29
13 30 }
14 31 public class Tile
@@ -150,6 +167,25
150 167 }
151 168 }
152 169
170 public static void DrawOutlinedSquares(SpriteBatch batch, Vector2[] squares, Color color) {
171 List<Edge> edges = new List<Edge>();
172
173 foreach (Vector2 square in squares) {
174 //upper right
175 edges.Add(new Edge {Start=square, End=square + new Vector2(1, 0)});
176 //lower right
177 edges.Add(new Edge {Start=square + new Vector2(1, 0), End=square + new Vector2(1, 1)});
178 //lower left
179 edges.Add(new Edge {Start=square + new Vector2(0, 1), End=square + new Vector2(1, 1)});
180 //upper left
181 edges.Add(new Edge {Start=square, End=square + new Vector2(0, 1)});
182 }
183
184 edges = edges.GroupBy(x => x).Where(grp => grp.Count() == 1).Select(grp => grp.Key).ToList<Edge>();
185
186 drawEdges(batch, edges.ToArray(), color);
187 }
188
153 189
154 190 public static void drawTileAt(SpriteBatch batch, int x, int y, int tileIndex, int height, float depth)
155 191 {
You need to be logged in to leave comments. Login now