예제 #1
0
 public override void LoadContent()
 {
     sprite = new Sprite(game.Content.Load <Texture2D>("bullet"), this);
     SpriteRenderer.Sprites.Add(sprite);
     SetStartPosition();
     Collider = new Collisions.BoundingCircle(Position, sprite.texture.Width / 2);
 }
예제 #2
0
        public static bool Collides(BoundingCircle c, BoundingRectangle r)
        {
            float nearestX = MathHelper.Clamp(c.Center.X, r.Left, r.Right);
            float nearestY = MathHelper.Clamp(c.Center.Y, r.Top, r.Bottom);

            return(Math.Pow(c.Radius, 2) >= Math.Pow(c.Center.X - nearestX, 2) + Math.Pow(c.Center.Y - nearestY, 2));
        }
예제 #3
0
 public bool CollidesWith(BoundingCircle other)
 {
     return(CollisionHelper.Collides(this, other));
 }
예제 #4
0
 public static bool Collides(BoundingRectangle r, BoundingCircle c) => Collides(c, r);
예제 #5
0
 /// <summary>
 /// Detects collision between 2 bouding circles
 /// </summary>
 /// <param name="a">First bounding circle</param>
 /// <param name="b">Second bounding circle</param>
 /// <returns>True for collision, false otherwise</returns>
 public static bool Collides(BoundingCircle a, BoundingCircle b)
 {
     return(Math.Pow(a.Radius + b.Radius, 2) >=
            Math.Pow(a.Center.X - b.Center.X, 2) +
            Math.Pow(a.Center.Y - b.Center.Y, 2));
 }