IsPointInsideAnyBody() public method

public IsPointInsideAnyBody ( Vector2 point ) : bool
point Vector2
return bool
Example #1
0
        public void UpdateTarget(Physics physics, double elapsed)
        {
            Vector2 direction; float distance;

            distance = (position - player.position).Length();

            if (!player.popped && player.hurt == 0 && distance < 2)
            {
                target.X = player.position.X;
                target.Y = player.position.Y;
            }
            else
            {
                direction = body.position - target;
                distance = direction.Length();

                if (distance < radius || velocity.Length() < 0.1f)
                {
                    Vector2 point = new Vector2(position.X, position.Y);
                    point.X += (float)(rand.NextDouble() - 0.5f) * radius * 15;
                    point.Y += (float)(rand.NextDouble() - 0.5f) * radius * 15;

                    if (!physics.IsPointInsideAnyBody(point))
                    {
                        target = point;
                    }
                }
            }

            direction = target - body.position;
            direction.Normalize();

            body.velocity.X += (float)(direction.X * elapsed) * 3;
            body.velocity.Y += (float)(direction.Y * elapsed) * 3;
        }