public override void CheckAndApplyCollision(PhysicalBody unit, TimeSpan time)
        {
            if (!_firing || !unit.Collides)
                return;     //don't check collisions if not firing

            float fireAngle = XnaHelper.RadiansFromVector(_fireDirection);
            if (XnaHelper.RectangleIntersectsArc(unit.HitRect, _owner.Center, _range, fireAngle, _hitArc))
            {
                _tempVector = unit.Center - _owner.Center;
                _tempVector.Normalize();
                unit.ApplyImpact(_force * _tempVector, 1);
                unit.ApplyDamage(_damage);
            }
        }
 /// <summary>
 /// Check if target unit is in range. If so, apply force and damage
 /// </summary>
 /// <param name="effectPos">origin of effect</param>
 /// <param name="target">target unit</param>
 public void TryApply(Vector2 effectPos, PhysicalBody target, TimeSpan time)
 {
     if (utility.XnaHelper.RectangleIntersectsCircle(target.HitRect, effectPos, _radius))
     {
         tempVec.X = target.Position.X - effectPos.X;
         tempVec.Y = target.Position.Y - effectPos.Y;
         Vector2.Normalize(tempVec);
         float factor = Duration == TimeSpan.Zero ? 1 : (float)time.TotalSeconds / (float)Duration.TotalSeconds;
         target.ApplyForce(_force * factor * tempVec);
         target.ApplyDamage((_damage * factor));
         target.ApplyStatus(_statEffects);
     }
 }
Пример #3
0
 public void CheckAndApplyCollision(PhysicalBody unit, GameTime gameTime)
 {
     switch (_state)
     {
         case State.Dormant:
             break;
         case State.Appearing:
         case State.Scanning:
             unit.ApplyGravity(_gravity, gameTime);
             break;
         case State.Charging:
             unit.ApplyGravity(_gravity, gameTime);
             if (willCollide(unit.Top, unit.Bottom, unit.Left, unit.Right, gameTime.ElapsedGameTime))
             {
                 unit.ApplyImpact(_velocity, IMPACT_IMPULSE);
                 unit.ApplyDamage(IMPACT_DAMAGE);
                 break;
             }
             break;
     }
 }