示例#1
0
        public TargetList GetBestMeleeEnemy()
        {
            float meleeRange = 10f;  // TODO: possibly use equipped weapon range for this?

            // get all targets that could be hit by melee attack, then select the script's target if
            // it has one, otherwise use the closest target in range.
            TargetList targets = GetEnemiesInBeamDirection(User.Position, TargetPosition, meleeRange);

            Actor bestEnemy;

            if (targets.Actors.Contains(Target))
            {
                bestEnemy = Target;
            }
            else
            {
                bestEnemy = targets.GetClosestTo(User.Position);
            }

            targets.Actors.RemoveAll(actor => actor != bestEnemy);
            return(targets);
        }
示例#2
0
        private void _CheckCollisions()
        {
            if (OnCollision == null)
            {
                return;
            }

            // check if we collided with anything since last update

            float  radius      = this.ActorData.Cylinder.Ax2;
            Circle startCircle = new Circle(_prevUpdatePosition.X, _prevUpdatePosition.Y, radius);
            // make a velocity representing the change to the current position
            Vector2F velocity = PowerMath.VectorWithoutZ(this.Position - _prevUpdatePosition);

            Actor      hit     = null;
            TargetList targets = this.Context.GetEnemiesInRadius(this.Position, radius + 25f);

            if (CollisionFilter != null)
            {
                targets.Actors.RemoveAll(actor => !CollisionFilter(actor));
            }
            targets.SortByDistanceFrom(_prevUpdatePosition);

            foreach (Actor target in targets.Actors)
            {
                float targetRadius = 1.5f; // TODO: use target.ActorData.Cylinder.Ax2 ?
                if (PowerMath.MovingCircleCollides(startCircle, velocity, new Circle(target.Position.X, target.Position.Y, targetRadius)))
                {
                    hit = target;
                    break;
                }
            }

            if (hit != null)
            {
                OnCollision(hit);
            }
        }