public IEnumerable <Collision> Cast(Bounds bounds) { foreach (Collider rigidbody in _colliders.Get(bounds)) { var intersection = bounds.intersection(rigidbody.bounds); if (intersection.HasValue) { yield return(new Collision(rigidbody, intersection.Value)); } } }
private ISpatial Cast <T>(int x0, int y0, int x1, int y1, out Vector2 finalPoint) { int dx = Math.Abs(x1 - x0); int dy = Math.Abs(y1 - y0); int sx = 0; int sy = 0; if (x0 < x1) { sx = 1; } else { sx = -1; } if (y0 < y1) { sy = 1; } else { sy = -1; } int err = dx - dy; int e2; while (true) { finalPoint = new Vector2(x0, y0); var res = _mapSpatialCollection.GetMany(finalPoint).OfType <T>(); if (res.Count() > 0) { return(_mapSpatialCollection.Get(finalPoint)); } if ((x0 == x1) && (y0 == y1)) { break; } e2 = err << 1; if (e2 > -dy) { err = err - dy; x0 = x0 + sx; } if (e2 < dx) { err = err + dx; y0 = y0 + sy; } } return(null); }
/// <summary> /// Gets the first <see cref="IUsableEntity"/> that intersects a specified area. /// </summary> /// <param name="c">The <see cref="ISpatialCollection"/>.</param> /// <param name="rect"><see cref="Rectangle"/> of the area to check.</param> /// <param name="charEntity"><see cref="CharacterEntity"/> that must be able to use the /// <see cref="IUsableEntity"/>.</param> /// <returns>First <see cref="IUsableEntity"/> that intersects the specified area that the /// <paramref name="charEntity"/> is able to use, or null if none.</returns> public static IUsableEntity GetUsable(this ISpatialCollection c, Rectangle rect, CharacterEntity charEntity) { return(c.Get <IUsableEntity>(rect, x => x.CanUse(charEntity))); }