private void HighlightMatchingTiles(IEnumerable <Tile> tiles, FloatRectangle bounds) { IList <Square> squares = new List <Square>(); foreach (Tile tile in tiles) { FloatRectangle intersection = (Rectangle)FloatRectangle.Intersect(bounds, tile.Bounds); bool intersects = intersection.Width > 0 && intersection.Height > 0; Square square = new Square { Alpha = 0.7f, Bounds = tile.Bounds, Color = intersects ? Color.MediumPurple : Color.MintCream }; squares.Add(square); } matchGrid = new SquareGrid(squares); }
public List <Collision> GetCollisions(List <CollisionStats> collisionTiles) { List <Collision> collisions = new List <Collision>(); foreach (CollisionStats first in collisionTiles) { foreach (CollisionStats second in collisionTiles) { if (!first.entity.Equals(second.entity) && IsTargetInRange(first.entity, second.entity)) { foreach (TimeFrame firstFrame in first.frames) { foreach (TimeFrame secondFrame in second.frames) { if (FloatRectangle.Intersects(firstFrame.entityRectangle, secondFrame.entityRectangle)) { if (firstFrame.time == secondFrame.time) { Collision c = new Collision(); c.entity1 = first.entity; c.entity2 = second.entity; c.intersection = FloatRectangle.Intersect(firstFrame.entityRectangle, secondFrame.entityRectangle); c.frame = firstFrame; if (!ContainsCollision(collisions, c)) { collisions.Add(c); c.entity1.WasHit = true; c.entity2.WasHit = true; } } } } } } } } return(collisions); }
private void HighlightIntersection(IEnumerable <Tile> tiles, FloatRectangle bounds) { IList <Square> squares = new List <Square>(); foreach (Tile tile in tiles) { Rectangle intersection = (Rectangle)FloatRectangle.Intersect(bounds, tile.Bounds); bool intersects = intersection.Width > 0 && intersection.Height > 0; if (!intersects) { continue; } Square square = new Square { Alpha = 1f, Bounds = intersection, Color = Color.DarkRed }; squares.Add(square); } intersectionGrid = new SquareGrid(squares); }