Esempio n. 1
0
        public TargetList GetEnemiesInArcDirection(Vector3D center, Vector3D direction, float radius, float lengthDegrees)
        {
            Vector2F arcCenter2D    = PowerMath.VectorWithoutZ(center);
            Vector2F arcDirection2D = PowerMath.VectorWithoutZ(direction);
            float    arcLength      = lengthDegrees * PowerMath.DegreesToRadians;

            float fixedActorRadius = 1.5f;  // TODO: calculate based on actor.ActorData.Cylinder.Ax2 ?

            return(_GetTargetsInRadiusHelper(center, radius, -1,
                                             actor => PowerMath.ArcCircleCollides(arcCenter2D, arcDirection2D, radius, arcLength,
                                                                                  new Circle(actor.Position.X, actor.Position.Y, fixedActorRadius)),
                                             _EnemyActorFilter));
        }
Esempio n. 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);
            }
        }