Esempio n. 1
0
        private bool IntersectsWith(CirlceCollider circleCollider)
        {
            int xDistance = (int)Math.Abs(circleCollider.Center.X - Center.X);
            int yDistance = (int)Math.Abs(circleCollider.Center.Y - Center.Y);

            if (xDistance > (RectCollider.Width / 2 + circleCollider.Radius))
            {
                return(false);
            }
            if (yDistance > (RectCollider.Height / 2 + circleCollider.Radius))
            {
                return(false);
            }
            if (xDistance <= (RectCollider.Width / 2))
            {
                return(true);
            }
            if (yDistance <= (RectCollider.Height / 2))
            {
                return(true);
            }
            double dX             = xDistance - RectCollider.Width / 2;
            double dY             = yDistance - RectCollider.Height / 2;
            double cornerDistance = Math.Sqrt((dX * dX + dY * dY));

            return(cornerDistance <= (circleCollider.Radius * circleCollider.Radius));
        }
Esempio n. 2
0
        public bool IntersectsWith(CirlceCollider circleCollider)
        {
            float radius = (float)(Radius + circleCollider.Radius);
            float deltaX = (float)(Center.X - circleCollider.Center.X);
            float deltaY = (float)(Center.Y - circleCollider.Center.Y);

            return(deltaX * deltaX + deltaY * deltaY <= radius * radius);
        }
Esempio n. 3
0
        private void DamageEnemiesInRange()
        {
            var centerOfExplosion = CollisionTester.CollidingObject.Collider.Center;

            Collider = new CirlceCollider(this, Transform, centerOfExplosion, explosionRadius);
            if (CollisionTester.Collision(this))
            {
                foreach (var obj in CollisionTester.CollidingObjects)
                {
                    Enemy enemy = obj as Enemy;
                    if (enemy != null)
                    {
                        enemy.Damage(Damage, this);
                    }
                }
            }
        }
Esempio n. 4
0
        private void SlowEnemiesInRange()
        {
            var center = Transform.Transform(new Point(Width / 2, Height / 2));

            Collider = new CirlceCollider(this, Transform, center, slowRadius);
            if (CollisionTester.Collision(this))
            {
                foreach (var obj in CollisionTester.CollidingObjects)
                {
                    Enemy enemy = obj as Enemy;
                    if (enemy != null)
                    {
                        enemy.Slow(slowDurationMilliseconds, slowRate);
                    }
                }
            }
        }